我在Mapbox中繪製LineStrings。現在,我正在更新屬性更改時的線條顏色。僅更新那些屬性
function update_the_map(){
$.ajax({
url:"http://dataurl",
contentType : "application/json; charset=utf-8",
type: "GET",
dataformat:"JSON",
async : false,
success: function(data){
for (i = 0; i <lines.features.length; i++) {
lines['features'][i]['properties']['points']=data[i].points;
var style_update =getColor(lines['features'][i]['properties']['points']);
geojson.setFeatureStyle(lines['features'][i]['properties']['id'], style_update);
}
setTimeout(update_the_map, 10000);
console.log("updated");
},
error:function(){}
});
}
但是,這改變了線路的所有顏色,而不是這些點都大於5.Because我取色,功能就像是
function getColor(d) {
if(d==10 || d==9 || d==8 || d==7 || d==6){
return '#ff0000';
}
else {
return '#00a1ff';
}
}
如果點> 5,否則返回所以它返回紅blue.But這一切都會返回藍色,並且整個線條的顏色都會發生變化。如果有幫助,我會很感激。這就是我創建圖層的方式。
geojson = L.vectorGrid.slicer(lines, {
vectorTileLayerStyles: {
sliced: style},
maxZoom: 24, // max zoom to preserve detail on
interactive: true,
getFeatureId: function(f) {
return f.properties.id;
}
}).on('mouseover', mouseover_function).addTo(map);
我行是如下的變量:
var lines= {
"type":"FeatureCollection","features": [{"type": "Feature","geometry":{"type":"LineString",
"coordinates":[[ 101.942139,4.252606],[101.766357,3.134346]]},
"properties": {"id":"01","points":10}},....
]};
當你創建圖層時,'links'和'style'的值是什麼? – IvanSanchez
當我創建圖層時,所有的點都是10。所以每一行都是紅色的。 10秒後他們改變了>> 5變紅,然後<5變藍。但是現在我調試了我在'var style_update = getColor(lines ['features'] [i] ['properties'] ['points'])得到的顏色;'這是根據點。所以我覺得我錯了某處設置線條的樣式。 – Ricky