【leaflet】地图显示、标记、图层切换

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);

}


你可能感兴趣的:(笔记,js,code,前端,地图,leaflet)