How to display Leaflet markers near the 180° meridian?

前端 未结 4 790
小蘑菇
小蘑菇 2020-12-04 00:07

I am using Leaflet 1.0.0-rc.2+e02b5c9. I know the default is rendering all markers, polylines ... from longitude -180 to 180 as screen shot here:

However, I

4条回答
  •  醉梦人生
    2020-12-04 00:30

    Another approach is to leverage the Leaflet.RepeatedMarkers plugin, which will display a copy of each marker per 360 degrees of longitude:

    Applying this to markers near the antimeridian works as well, e.g.:

    var myRepeatingMarkers = L.gridLayer.repeatedMarkers().addTo(map);
    
    L.polyline([[-85,180],[85,180]]).addTo(map);
    L.polyline([[-85,-180],[85,-180]]).addTo(map);
    
    myRepeatingMarkers.addMarker(L.marker([0,140]));
    myRepeatingMarkers.addMarker(L.marker([0,150]));
    myRepeatingMarkers.addMarker(L.marker([0,160]));
    myRepeatingMarkers.addMarker(L.marker([0,170]));
    myRepeatingMarkers.addMarker(L.marker([0,180]));
    myRepeatingMarkers.addMarker(L.marker([0,-170]));
    myRepeatingMarkers.addMarker(L.marker([0,-160]));
    myRepeatingMarkers.addMarker(L.marker([0,-150]));
    myRepeatingMarkers.addMarker(L.marker([0,-140]));
    

    will display something like:

    Check out the live example for using Leaflet.repeatedMarkers with markers near the antimeridian.

提交回复
热议问题