Customize Zoom in/out button in leaflet.js

前端 未结 2 1986
我寻月下人不归
我寻月下人不归 2021-02-06 22:37

I am trying to customize zoom control (+/-), so it should appear in the right side like Google maps (https://www.google.com/maps/)

I tried to add float:right;

2条回答
  •  青春惊慌失措
    2021-02-06 23:03

    Your zoom in/out controls are wrapped with absolutely positioned element with left:0 (due to .leaflet-left class), so float:left wouldn't help, you could align it to right by overriding left:0 by right:0, or changing .leaflet-left class to .leaflet-right

    But more correct way would be to use provided api.

    //disable zoomControl when initializing map (which is topleft by default)
    var map = L.map("map", {
        zoomControl: false
        //... other options
    });
    
    //add zoom control with your options
    L.control.zoom({
         position:'topright'
    }).addTo(map);
    

    see updated fiddle

    api reference for the library you use can be found here

提交回复
热议问题