leaflet入门使用GeoJSON创建矢量图形

Posted YuRi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leaflet入门使用GeoJSON创建矢量图形相关的知识,希望对你有一定的参考价值。

点对象:

function g(feature, layer) {
            // does this feature have a property named popupContent?
            if (feature.properties && feature.properties.popupContent) {
                layer.bindPopup(feature.properties.popupContent);
            }
        }

        var geojsonFeature = {
            "type": "Feature",
            "properties": {
                "name": "Coors Field",
                "amenity": "Baseball Stadium",
                "popupContent": "This is where the Rockies play!"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [100, 31]
            }
        };

        L.geoJSON(geojsonFeature, {
            onEachFeature: g
        }).addTo(map);

线要素:

var draw_line = {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [
                    [110, 11],
                    [110, 49]
                ]
            },
            "properties": {
                "popupContent": "This is a free bus line that will take you across downtown.",
                "underConstruction": true
            },
            "id": 2
        };

//绑定事件
function f(feature, layer) {
    layer.bindPopup(feature.properties.popupContent);
}

//增加到地图
var ss = L.geoJson(draw_line, {
    style: {
        "color": ‘black‘,
        "weight": 1
    },
    onEachFeature: f
}).addTo(map);

 

以上是关于leaflet入门使用GeoJSON创建矢量图形的主要内容,如果未能解决你的问题,请参考以下文章

QGIS入门实战精品教程004:如何将矢量数据转为GeoJSON格式?

leaflet 结合 d3.js 实现 geojson 数据地形剖面分析(附源码下载)

QGIS入门实战精品教程4.7:QGIS如何将矢量数据转为GeoJSON格式?

从外部访问 Leaflet.js GeoJson 功能

Leaflet GeoJson addToMap Loader

leaflet怎么加载天地图的wmts服务