首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >LeafletJS,GeoJSON,选择多边形

LeafletJS,GeoJSON,选择多边形
EN

Stack Overflow用户
提问于 2014-04-10 23:17:19
回答 1查看 1.4K关注 0票数 1

我有一个显示土耳其地区的GeoJSON文件。我正在添加多边形作为GeoJSON层与叶,我需要一种方法来选择通过id或其他(我将使用jQuery )多边形。

我的目的是更改选定多边形的颜色并使其具有动画效果。

我知道我可以在GeoJSON上循环,并在循环时设置不同的样式,但我需要一种更动态的方式。

EN

回答 1

Stack Overflow用户

发布于 2014-04-11 04:47:57

好吧,我已经找到了一种方法,但不确定这是不是最好的方法……

代码语言:javascript
运行
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22992163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档