我在Angular 7上使用:
@@ asymmetrik / ngx-leaflet“:” ^ 5.0.2“和” leaflet“:” ^ 1.5.1“
我有一个问题:我想更新一个特定的点位置及其属性,但不删除所有点。
例如:我有一个geoJSON文件:
[
{
"attribution": "AT_101000",
"recordid": "101000",
"type": "Feature",
"geometry":{
"coordinates": ["5.4933266666667", "43.471425"],
"type": "Point"
},
"properties":{
"label": "BT 9999844",
"latitude": "43.471425",
"longitude": "5.4933266666667"
}
},
{
"attribution": "AT_101010",
"recordid": "101010",
"type": "Feature",
"geometry":{
"coordinates": ["5.4933266666669", "43.471325"],
"type": "Point"
},
"properties":{
"label": "BT 456852",
"latitude": "43.471425",
"longitude": "5.4933266666669"
}
},
{
"attribution": "AT_104010",
"recordid": "104010",
"type": "Feature",
"geometry":{
"coordinates": ["5.49339", "43.48"],
"type": "Point"
},
"properties":{
"label": "BT 456852",
"latitude": "43.48",
"longitude": "5.49339"
}
}
]
我有一个功能:
createLayersLeaflet(){
let self = this;
return leaflet.geoJSON(geoJSONFile,{
pointToLayer: function(feature, latlng) {
let iconUrl = ("assets/img/dashboard-icons/map/do.png");
var smallIcon = leaflet.icon({
iconUrl: iconUrl,
iconSize: [33, 44],
iconAnchor: [16, 44],
popupAnchor: [0, -44]
});
return leaflet.marker(latlng, {icon: smallIcon,attribution: feature.recordid});
},
onEachFeature: function (feature,layer){
var html = '';
html += '<b>' + feature.properties.label + '</b>';
layer.bindPopup(html);
}
});
}
我将图层添加到:
self.createfeaturesForLayersLeaflet().addTo(self.map); // self.map is my leaflet.Map
我有2个问题:
感谢您的帮助。
您可以这样雇用Array.prototype.find()
:
const geoJSON = [{"attribution":"AT_101000","recordid":"101000","type":"Feature","geometry":{"coordinates":["5.4933266666667","43.471425"],"type":"Point"},"properties":{"label":"BT 9999844","latitude":"43.471425","longitude":"5.4933266666667"}},{"attribution":"AT_101010","recordid":"101010","type":"Feature","geometry":{"coordinates":["5.4933266666669","43.471325"],"type":"Point"},"properties":{"label":"BT 456852","latitude":"43.471425","longitude":"5.4933266666669"}},{"attribution":"AT_104010","recordid":"104010","type":"Feature","geometry":{"coordinates":["5.49339","43.48"],"type":"Point"},"properties":{"label":"BT 456852","latitude":"43.48","longitude":"5.49339"}}],
at104010 = geoJSON.find(({attribution}) => attribution == 'AT_104010')
at104010.label = 'new label'
console.log(geoJSON)