zoukankan      html  css  js  c++  java
  • 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);
    复制代码

    多边形(Polygon)

    复制代码
    var states = [{
        "type": "Feature",
        "properties": {"party": "Republican"},
        "geometry": {
            "type": "Polygon",
            "coordinates": [[
                [-104.05, 48.99],
                [-97.22,  48.98],
                [-96.58,  45.94],
                [-104.03, 45.94],
                [-104.05, 48.99]
            ]]
        }
    }, {
        "type": "Feature",
        "properties": {"party": "Democrat"},
        "geometry": {
            "type": "Polygon",
            "coordinates": [[
                [-109.05, 41.00],
                [-102.06, 40.99],
                [-102.03, 36.99],
                [-109.04, 36.99],
                [-109.05, 41.00]
            ]]
        }
    }];
    
    L.geoJSON(states, {
        style: function(feature) {
            switch (feature.properties.party) {
                case 'Republican': return {color: "#ff0000"};
                case 'Democrat':   return {color: "#0000ff"};
            }
        }
    }).addTo(map);
    复制代码
  • 相关阅读:
    虚拟化技术一些概念整理
    更改KVM虚拟机root的密码
    文件作为块设备访问
    KVM虚拟机IO处理过程(二) ----QEMU/KVM I/O 处理过程
    KVM虚拟机IO处理过程(一) ----Guest VM I/O 处理过程
    KVM的初始化过程
    linux删除文件未释放空间问题处理
    cgroup测试存储设备IOPS分配
    数组中的逆序对
    VMware Tools安装方法及解决无法全屏显示问题
  • 原文地址:https://www.cnblogs.com/tiandi/p/12828716.html
Copyright © 2011-2022 走看看