我有这个json数据:
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]
]]
}
}
}];
通过这样做很容易在传单地图上看到这个:
L.geoJSON(states, {
style: function(feature) {
switch (feature.properties.party) {
case 'Republican': return {color: "#ff0000"};
}
}
}).addTo(map);
但我需要"类型"国家是"多边形"不是" geojson",所以结果将是这样的:
var states_polygon = L.polygon([[
[48.99,-104.05],
[48.98,-97.22],
[45.94,-96.58],
[45.94,-104.03],
[48.99,-104.05]
]]).addTo(map);
我知道这两个变量都会在传单地图上给出相同的视觉效果,但我需要的是该变量的对象类型为多边形..我该怎么做?