传单geojson点图层着色

时间:2019-04-08 19:29:23

标签: javascript json leaflet maps geojson

我有一个指向许多点数据的geojson链接,我想使用field_1中的值为某些点着色。

我使用此代码,但不起作用,请不要为这一点着色并保持默认的颜色样式。

知道我错了吗?

    var data= new L.GeoJSON.AJAX("url/path/",{
        style:function colors(feature) {
            switch (feature.properties.field_1){
                case 'some value':
                    return{
                        color:'#20ff78',
                        fillOpacity:0.8
                    };
                    break;
            }
        },
       onEachFeature:function (feature,layer) {
            layer.bindPopup('some text');
    }
    });
    data.addTo(map);

更新

json示例:

{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "MultiPoint", "coordinates": [[15.94, 30.63]]}, "properties": {"f1": 2, "f2": "value", "f3": "other value"}}]}]

0 个答案:

没有答案