祝大家节日快乐。
我在尝试使用 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]
]]
}
}];
and
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) 来自动执行此反射?
非常感谢大家。