如何在不删除和重新创建所有点的情况下更新一个点的纬度,经度和属性

问题描述 投票:0回答:1

我在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个问题:

  1. 我如何在不刷新所有其他对象的情况下更改geoJSON对象«AT_104010»中的属性'label'?
  2. 我如何在不刷新所有其他对象的情况下更改geoJSON对象«AT_101010»中的纬度和经度位置?

感谢您的帮助。

javascript leaflet angular7 geojson ngx-leaflet
1个回答
0
投票

您可以这样雇用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)
© www.soinside.com 2019 - 2024. All rights reserved.