leaflet 渲染geoJSON数据


leaflet 渲染GeoJSON数据

//设置样式
 var myStyle = {
            "color": "#00f",
            "weight": 3,
            "opacity": 0.5,

        };
//geojson数据
var someFeatures = [{
    "type": "Feature",
    "properties": {
        "name": "Coors Field",
        "show_on_map": true
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99404, 39.75621]
    }
}, {
    "type": "Feature",
    "properties": {
        "name": "Busch Field",
        "show_on_map": false
    },
    "geometry": {
        "type": "Point",
        "coordinates": [-104.98404, 39.74621]
    }
}];
//渲染方法
var layerGeo = L.geoJSON(someFeatures, {
    style:myStyle
}).addTo(map);
//添加点击事件
layerGeo.on('click',function(e){
    console.log(e.layer.feature.properties.name) //当前点击的物体的名称
})

详细内容参见leafelt官网:Using GeoHSON

转载自:https://blog.csdn.net/zhongshijun521/article/details/80021288

You may also like...

退出移动版