Javascript 如何替换geoJSON变量

Javascript 如何替换geoJSON变量,javascript,json,leaflet,mapbox,geojson,Javascript,Json,Leaflet,Mapbox,Geojson,我有一个geo JSON变量,如下所示: line_01.js var lines= { "type":"FeatureCollection", "features": [ { "type": "Feature", "geometry":{"type":"LineString", "coordinates":[[103.85909,1.2941],[103.85895,1.2940450000000

我有一个geo JSON变量,如下所示:

line_01.js

var lines= {


        "type":"FeatureCollection",

        "features": [

      {
       "type": "Feature",
       "geometry":{"type":"LineString", 
       "coordinates":[[103.85909,1.2941],[103.85895,1.2940450000000001],[103.85881,1.29399]]},
       "properties": {"id":"01","score":10}
      },
..//超过100行

                   ]};
因此,当我单击一个按钮时,我需要将变量行替换为

line_02.js

var lines= {

    "type":"FeatureCollection",

    "features": [

  {
   "type": "Feature",
   "geometry":{"type":"LineString", 
   "coordinates":[[103.8436,1.2893],[103.8890,1.2956],[103.8432,1.2874]]},
   "properties": {"id":"03","score":09}
  },
..../其余的行

                   ]};
所以我的按钮点击功能是

$('#update_map').click(function(){
         $("#grid_name").html("SINGAPORE");
        updatemap();

    });



function updatemap(){
if (geojson) {

                    geojson.remove(); 
                    console.log("removed");

                }

            //here I have to replace the lines variable to the new one    



                geojson = L.geoJson(lines, {
                     style: style,
                     onEachFeature: onEachFeature
                }).addTo(map);

}

因此,这意味着它将删除上一行(层)并替换新行。是否可能?感谢您的帮助。从外观上看,您希望在用户单击按钮时更新坐标和属性字段。如果是这样的话,那你会的

function updatemap(){
    if (geojson) {

            geojson.remove(); 
            console.log("removed");

    }

    //here I have to replace the lines variable to the new one    
    if (lines){
        // updates lines if necessary 
        lines["coordinates"] = [New coordinates]
        lines["properties"] = {new : score}
    }



    geojson = L.geoJson(lines, {
         style: style,
         onEachFeature: onEachFeature
    }).addTo(map);
}

是的,你是对的。但是我有行_01.js和行_02.js,它们的变量行具有不同的值。我如何更改它?