且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

标记不会出现在传单中的连续世界上

更新时间:2023-10-29 22:43:28

不幸的是,据我所知,没有自动和开箱即用的解决方案可以将相邻的所有内容(标记,向量等)复制传单中的世界副本.

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.

Tomislav提出的最简单的技巧是手动生成内容的额外副本,以360度经度的倍数偏移.我认为continuousWorld tileLayer选项必须留在false 上.结合worldCopyJump映射选项,您可以达到预期的效果,但必须多次克隆内容.

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.

演示: http://jsfiddle.net/ve2huzxw/20/

注意:如果minZoom设置得足够高,则使用 worldCopyJump地图选项的效果与Google Maps非常相似,也就是说,您认为自己正在世界各地滚动浏览并重新找到内容.只是您永远不会有机会在同一屏幕上两次看到完全相同的位置,并且地图会自动回滚360度以保留在内容上.在-180/+180度经度边界处,这仍然很明显,因为您在左侧或右侧都具有内容,但是永远不会同时出现.

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.

演示: http://jsfiddle.net/ve2huzxw/21/