【leaflet】地圖顯示、標記、圖層切換
阿新 • • 發佈:2019-02-02
leaflet
地圖和marker顯示:http://leafletjs.com/examples/quick-start.html
marker自定義圖片:http://leafletjs.com/examples/custom-icons.html
圖層切換(控制):http://leafletjs.com/examples/layers-control.html(其中cities的marker陣列是option,可以刪去)
具體文件:http://leafletjs.com/reference.html#marker
----------------------------------------------------------------------------------------------------------------------------------------------
移除Marker:
思路》》把marker放到layer中,刪除layer,因為Marker實現了ILayer介面
新增時:map.addLayer(marker);//而不用marker.addTo(map);
刪除時:map.removeLayer(marker);
Geojson圖層:
//畫導航線路 function drawGeojson(json){ if(map.hasLayer(routeline)){ map.removeLayer(routeline); } var route = [{ "type": "LineString", "coordinates": json }]; routeline = L.geoJson(route,{style:{"color": "#FF7F00", "weight": 5,"opacity": 0.65 }}); map.addLayer(routeline); }