Leaflet 如何在lapper.js中正确添加多边形

Leaflet 如何在lapper.js中正确添加多边形,leaflet,Leaflet,使用传单.js渲染多边形时。 下面的例子有不同的结果 例1 例2 为什么呢? 如果我必须设置latlngs数据,如例2所示,我该怎么办?原因是传单默认使用纬度和经度,并使用Web墨卡托投影将其投影到平面上。在第二个多边形上,坐标为 如果您只需要在“像素”坐标系中绘制三角形,可以使用 参见JSFIDLE: const map = L.map('map', { preferCanvas: true, zoomControl: false, attributionCont

使用传单.js渲染多边形时。 下面的例子有不同的结果

例1


例2

为什么呢?
如果我必须设置latlngs数据,如例2所示,我该怎么办?原因是传单默认使用纬度和经度,并使用Web墨卡托投影将其投影到平面上。在第二个多边形上,坐标为

如果您只需要在“像素”坐标系中绘制三角形,可以使用

参见JSFIDLE:

const map = L.map('map', {
    preferCanvas: true,
    zoomControl: false,
    attributionControl: false
});
const latlngs = [
    [
        6,
        5
    ],
    [
        7,
        1
    ],
    [
        9,
        2
    ]
];
const polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
map.fitBounds(polygon.getBounds());
    ...
    const latlngs = [
        [
            116,
            115
        ],
        [
            117,
            111
        ],
        [
            119,
            112
        ]
    ];
    const polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
    map.fitBounds(polygon.getBounds());
const map = L.map('map', {
    preferCanvas: true,
    zoomControl: false,
    attributionControl: false,
    // Add this line:
    crs: L.CRS.Simple
});