如何替换 geoJSON 变量
how to replace the geoJSON variable
我有一个 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);
}
所以这意味着它会擦除前一行(层)并替换一个新的 line.is 可能吗?appreciated.Thank 你有什么帮助。
从外观上看,您希望在用户单击按钮时更新 坐标和属性字段。如果是这样,那么你
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);
}
我有一个 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);
}
所以这意味着它会擦除前一行(层)并替换一个新的 line.is 可能吗?appreciated.Thank 你有什么帮助。
从外观上看,您希望在用户单击按钮时更新 坐标和属性字段。如果是这样,那么你
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);
}