2

我正在使用 ngx 传单。默认情况下,地图在左上角显示缩放控件。但是我找不到如何改变它的定位。

这是一个过时的方法:

options = {
  layers: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 10, attribution: '...' }),
  zoom: 5,
  zoomControl: false,
  center: L.latLng(46.879966, -121.726909)
};

mapReady(map: L.Map) {
  map.addControl(L.control.zoom({ position: 'bottomright' }));
}

.

<div class="leaflet-container grow z-0" leaflet [leafletZoom]="leafletZoom" [leafletCenter]="leafletCenter" (leafletMapReady)="($event)">
    <div [leafletLayer]="tileLayer"></div>
    <div *ngFor="let marker of markerLayers " [leafletLayer]="marker"></div>
  </div>

资源

使用最新版本的 ngx-leaflet (3.0) 是否有更新的方法来执行此操作?

这是一个屏幕截图,显示控件对象上没有缩放方法: 在此处输入图像描述

4

1 回答 1

4

由于您使用的是直接导入,因此您需要执行以下操作:

import { control, Map, latLng, tileLayer } from 'leaflet';

  options = {
    layers: tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 10, attribution: '...' }),
    zoom: 5,
    zoomControl: false,
    center: latLng(46.879966, -121.726909)
  };

  mapReady(map: Map) {
    map.addControl(control.zoom({ position: 'bottomright' }));
  }
于 2018-06-15T18:32:06.160 回答