如何在 180° 子午线附近显示传单标记?
我正在使用 Leaflet 1.0.0-rc.2+e02b5c9.我知道默认将所有标记、折线...从经度 -180 到 180 渲染为此处的屏幕截图:
I am using Leaflet 1.0.0-rc.2+e02b5c9. I know the default is rendering all markers, polylines ... from longitude -180 to 180 as screen shot here:
但是,我想将地图显示为此时要显示的经度(它位于日本和美国之间的中海):
However, I want to show the map as this longitude I want to show at this point (It is middle sea between Japan and US):
但您会看到所有标记都未呈现在右侧.即使,如果我设置
but you see all the markers are not rendered on the right side. Even though, If i set
worldCopyJump: true
当我向右拖动时,所有标记都出现在右侧,但它们在左侧消失,反之亦然.实际上,我希望它们同时出现.
when I drag to the right, all markers are appeared on the right but they are disappeared on the left and vice versa. Actually, I want they are appeared at the same time.
有什么办法可以解决这个问题吗?
Any ideas to fix that??
推荐答案
只要确保标记的经度在 0..360
范围内,而不是在 范围内 -180..180
.查看工作示例.
Just make sure that the longitudes of your markers are in the range 0..360
instead of in the range -180..180
. See a working example.
即而不是
L.marker([0,170]).addTo(map);
L.marker([0,-180]).addTo(map);
L.marker([0,-170]).addTo(map);
做类似的事情
L.marker([0,170]).addTo(map);
L.marker([0,180]).addTo(map);
L.marker([0,190]).addTo(map);
换句话说,如果经度小于零,则在其上加上 360.如果您打算一次过滤所有经度,则可能需要使用 L.Util.wrapNum(lng, [0,360], true)
.
In other words, if a longitude is smaller than zero, add 360 to it. You might want to use L.Util.wrapNum(lng, [0,360], true)
instead, if you plan to filter all your longitudes at once.
相关文章