Search code examples
leafletngx-leaflet

How can you position zoom controls to bottom right?


I'm working with ngx-leaflet. By default the map shows the zoom controls on the top left. However I cannot find how the positioning of this can be changed.

Here is an outdated method:

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>

source

Is there an updated way to do this with the latest version of ngx-leaflet (3.0)?

Here's a screenshot that shows that there isn't a zoom method on the control object: enter image description here


Solution

  • Since you're using direct imports, you want to do the following:

    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' }));
      }