geoJSON的一些用法
1、画点
var geojsonFeature = { "type": "Feature",
"properties": { "name": "Coors Field", "amenity": "Baseball Stadium", "popupContent": "This is where the Rockies play!" }, "geometry":
{ "type": "Point",
"coordinates": [-104.99404, 39.75621] }
};
L.geoJSON(geojsonFeature).addTo(map);
1、画线
var myLines = [
{ "type": "LineString",
"coordinates": [[-100, 40], [-105, 45], [-110, 55]] },
{ "type": "LineString",
"coordinates": [[-105, 40], [-110, 45], [-115, 55]] }
];
var myStyle = { "color": "#ff7800", "weight": 5, "opacity": 0.65 };
L.geoJSON(myLines, { style: myStyle }).addTo(map);
3、画多边形
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);
参考:https://leafletjs.com/examples/geojson/