我有一个显示土耳其地区的GeoJSON文件。我正在添加多边形作为GeoJSON层与叶,我需要一种方法来选择通过id或其他(我将使用jQuery )多边形。
我的目的是更改选定多边形的颜色并使其具有动画效果。
我知道我可以在GeoJSON上循环,并在循环时设置不同的样式,但我需要一种更动态的方式。
发布于 2014-04-11 04:47:57
好吧,我已经找到了一种方法,但不确定这是不是最好的方法……
var polygons = {};
addRegionalLayer();
function addRegionalLayer(){
cityjsonLayer = L.geoJson(turkeyadm_districts, {
onEachFeature: onEachFeature,
style: function(feature) {
return {
fillColor: 'red',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
}).addTo(map);
}
function onEachFeature(feature, layer){
// I am adding the polygon layer to the polygons dictionary with the districts name
polygons[feature.properties.NAME_2] = layer;
}
// this is test function ---> i am setting the color of the polygon that has key name //'Kadiköy' with random colors
setInterval(function() {
var back = ["#ff0000","blue","yellow"];
var rand = back[Math.floor(Math.random() * back.length)];
polygons['Kadiköy'].setStyle({
fillColor:rand,
opacity:1
});
}, 40);https://stackoverflow.com/questions/22992163
复制相似问题