Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markers do not appear on continuous world in Leaflet

When I set option continuousWorld=true markers are not shown on the cloned tiles, only on the main world. Is it designed behavior? May be other option, which I haven't noticed, to show these markers exists?

UPD: My aim to repeat markers on every world like on the picture below. I investigated that continuousWorld and worldcopyjump are not suitable for this. So is this possible to make leaflet work as on the picture? enter image description here

like image 638
cadmy Avatar asked Nov 10 '15 14:11

cadmy


People also ask

Why is map not showing in leaflet?

There are a number of reasons why your map might not be displaying: You have an error in your JavaScript (most likely) - use whichever debugging tool is provided with your browser to verify. you are using Internet Explorer and you have Compatibility mode ON....

How many markers can leaflet handle?

The Clusterer can handle 10,000 or even 50,000 markers (in chrome).

How do you remove a marker in leaflet?

You just need to filter the clicked marker' coords not to be included anymore to your state variable and that's it!


2 Answers

Unfortunately there is no automatic and out-of-the-box solution that I know of that would copy all content (markers, vectors, etc.) on adjacent copies of the world in Leaflet.

The easiest trick as proposed by Tomislav would be to manually generate extra copies of your content, offset by multiples of 360 degrees longitude. I think the continuousWorld tileLayer option must be left at false for that. In conjunction with worldCopyJump map option, you could achieve the desired effect, at the expense of having to clone your content several times.

That being said, this may be just 1 possible solution for your objective, which you have not really explicited?

If you want to avoid the user from seeing an empty world, maybe you could simply not show the adjacent copies of the world. You have several ways of achieving that, and you can use them in conjunction:

  • noWrap tileLayer option to not display adjacent copies.
  • maxBounds map option to clamp panning to 1 world boundaries (or any other specified bounds).
  • minZoom map option to prevent zooming out too much so that there is no room in the view port for several copies of the world.

Demo: http://jsfiddle.net/ve2huzxw/20/

Note: if minZoom is set high enough, the use of worldCopyJump map option renders a very similar effect as in Google Maps, i.e. you think you are rolling all around the world and find your content again. It is just that you never have a chance to see the exact same location twice on the same screen, and that the map automatically rolls back 360 degrees to remain on the content. This is still noticeable at the -180 / +180 degrees longitude border, as you have either content on the left or on the right, but never both simultaneously.

Demo: http://jsfiddle.net/ve2huzxw/21/

like image 159
ghybs Avatar answered Sep 27 '22 19:09

ghybs


When using continuous world and want to markers to appear on other "copies" of the map you should set coordinates of that marker to coordinates of that "world".

Only "central" world has coordinates in range -180 to 180 and -90 to 90

So for the world to the right longitude would start at 180 for that worlds -180. Similar to other sides.

Basically you can add a new marker with longitude increased/decreased by 360 degrees for each "copy".

like image 33
Tomislav Muic Avatar answered Sep 27 '22 21:09

Tomislav Muic