1. 程式人生 > >leaflet入門(三)使用GeoJSON創建矢量圖形

leaflet入門(三)使用GeoJSON創建矢量圖形

onf ack type play coo bus blog content roc

點對象:

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創建矢量圖形