Leaflet - put controls outside the div map

2019-03-05 08:21发布

问题:

I made the following app : http://lae2.alwaysdata.net/carte/exppng/

I'd like to put my two controls (leaflet-control-zoom and leaflet-control-layers) outside the div map. I'd want to use them inside the grey area for example.

I'd like to know if it's possible : I looked for some tricks but I didn't find anything...

If it is could you help me ?

Thanks you !

回答1:

You would probably be interested in the following posts:

  • Retrieve current scale value of Leaflet
  • https://gis.stackexchange.com/questions/83942/display-a-control-zoom-bar-outside-map-container-in-leaflet

In essence:

document.getElementById("myNewContainerId").appendChild(
    L.control.layers(base, overlays).onAdd(map)
);

External sources:

  • https://groups.google.com/forum/#!searchin/leaflet-js/control$20onadd/leaflet-js/rKMZX3PKFuI