問題描述
我正在使用 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.
這篇關于如何在 180° 子午線附近顯示傳單標記?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!