How can I add a north arrow to a leaflet.js map?

人走茶凉 提交于 2020-01-05 04:14:15

问题


Is there an easy way to add a north arrow to a leaflet.js map? I have searched a bit online but I cannot find much.


回答1:


You can add a control that contains a div with your north arrow image:

var north = L.control({position: "bottomright"});
north.onAdd = function(map) {
    var div = L.DomUtil.create("div", "info legend");
    div.innerHTML = '<img src="your-north-arrow.png">';
    return div;
}
north.addTo(map);

See Leaflet's control documentation for more info on positioning and other options.



来源:https://stackoverflow.com/questions/22325460/how-can-i-add-a-north-arrow-to-a-leaflet-js-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!