leaflet选中要素,设置矢量样式,点击要素获取其属性
leaflet自身没有选择的控制,需要自己写代码实现
主要是通过featurelayer的onclick事件来设置点击要素的style,并获取对应feature的属性信息
let featureLayer = L.esri.featureLayer({ url:'http://mgr.easylinking.net:6080/arcgis/rest/services/TDZT/TDCBTB/FeatureServer/2' }); map.addLayer(featureLayer); featureLayer.on('click',function (evt) { // console.log(evt.layer.feature.properties.party) let fea=evt.layer.feature target=evt.target evt.sourceTarget.setStyle({ fillColor: '#53e033',//填充颜 color: "#ff0000" }) let shuxing=evt.layer.feature.properties for(var p in shuxing){//遍历json数组时,这么写p为索引,0,1 console.log(p); console.log(shuxing[p]); } // fea.geometry.setStyle({ // fillColor: '#53e033',//填充颜 // color: "#ff0000" // }) })
转载自:https://blog.csdn.net/A873054267/article/details/83833527