【发布时间】:2013-12-19 02:04:53
【问题描述】:
祝大家节日快乐。 在尝试使用 L.geoJson() 绘制多边形图层时,我注意到了一个有趣的行为怪癖。考虑以下代码:
var polygonCoords = [
{"type": "Feature",
"properties": {"group": "Violations"},
"geometry": {
"type" : "Polygon",
"coordinates": [[
[-107.69348, 43.22519],
[-105.48523, 42.99259],
[-107.7594, 42.26105]
]]
}
}];
和
var polygons = L.polygon([
[43.22519, -107.69348],
[42.99259, -105.48523],
[42.26105, -107.7594]
]);
现在,两者都在各自的上下文中工作。我只是想知道为什么必须反映 L.polygon() 中的坐标矩阵,以便在像这样传递给 L.goeJson() 时显示人们期望的位置:
var jsonPoly = L.geoJson(polygonCoords, {
style: function(feature) {
if (feature.properties.group == "Violations") {
return {color: "#ff0000"};
}
}
});
或者这是传单中的疏忽?另外,有没有办法通过 toGeoJson(polygons) 来自动化这种反射?
非常感谢大家。
【问题讨论】:
标签: javascript json leaflet