简体   繁体   English

传单地图图层(圆形、多边形)在缩放期间未正确缩放

[英]Leaflet map layers (circle, polygon) not scaling properly during zoom

I can't figure out why the radiusmap layer (first map shown) and the isochronemap layer (second map shown) don't scale correctly when I zoom in and out.我不明白为什么当我放大和缩小时,radiusmap 图层(显示的第一张地图)和等时线图层(显示的第二张地图)不能正确缩放。 The third map, which has the exact same layers, works just fine.第三张地图具有完全相同的图层,效果很好。

在此处输入图片说明

Here's the code for a) creating the circle and polygon layers and then b) adding them to the radiusmap, the isochronemap and finally, the combined map.这是 a) 创建圆形和多边形图层,然后 b) 将它们添加到半径图、等时线图和最后组合地图的代码。

        var isochrone = L.polygon(isochronedetails, {color: 'red'});
        var radius = L.circle([radiuslat, radiuslng], {fillColor: circleStyle.color[0], fillOpacity: circleStyle.opacity[0],radius: radiusmeters});
        radius.addTo(radiusmap);
        isochrone.addTo(drivetimemap);
        radius.addTo(combinedmap);
        isochrone.addTo(combinedmap);

The code that is creating / initializing the three maps is here:创建/初始化三个地图的代码在这里:

        radiusmap = L.map('radiusmap').setView([radiuslat, radiuslng],10);
        radiusmap.addControl(new L.Control.Fullscreen());
        drivetimemap = L.map('drivetimemap').setView([isochronelat, isochronelng], 10);
        drivetimemap.addControl(new L.Control.Fullscreen());
        combinedmap = L.map('combinedmap').setView([isochronelat, isochronelng], 10);
        combinedmap.addControl(new L.Control.Fullscreen());

And here's a gif of what happens on zoom in/out for each map.这是放大/缩小每张地图时发生的情况的 gif。 You'll see that when the zoom happens for the first two maps, the circle or polygon moves away from the original drawing position.您会看到,当对前两张地图进行缩放时,圆形或多边形会远离原始绘图位置。 But, on the third map, it behaves correctly.但是,在第三张地图上,它的行为是正确的。

https://screencast-o-matic.com/watch/cYe1VQx6pZ https://screencast-o-matic.com/watch/cYe1VQx6pZ

What am I doing wrong?我究竟做错了什么? I just want the first two maps to behave like the third map.我只希望前两张地图表现得像第三张地图。 :-) :-)

Simply do not add your layers (namely isochrone and radius) to several maps, but create different layers (possibly with same parameters) for each separate map.只需不要将您的图层(即等时线和半径)添加到多个地图,而是为每个单独的地图创建不同的图层(可能具有相同的参数)。

Leaflet makes the assumption for simplicity that when a layer is added to a map, it belongs only to that map.为简单起见,Leaflet 假设当一个图层添加到地图时,它只属于该地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM