缩小使用 R 中的传单创建的世界地图时世界的多个副本

multiple copies of the world when zooming out in worldmap created with leaflet in R

我正在使用 R 中的传单库,我正在使用以下代码创建世界地图:

 leaflet(data = sPDF) %>%

  addProviderTiles("Stamen.Watercolor") %>%
  addPolygons(fillColor = ~pal(sPDF$Colonizer_col), 
              fillOpacity = 0.8, 
              color = "#BDBDC3", 
              weight = 1, 
              popup = state_popup) %>%
  addLegend("bottomright", pal = pal, values = ~na.omit(Colonizer),
            title = "Colony Information",
            labFormat = labelFormat(prefix = ""),
            opacity = 1 ) %>%

  addCircles(data=left, lng = ~LONG, lat = ~LAT, weight = 1,
             radius = ~sqrt(Totals)*300, popup = ~area_popup_left) %>%


  addCircles(data=arrived, lng = ~LONG, lat = ~LAT, weight = 1,
             radius = ~sqrt(Totals)*300, popup = ~area_popup_arrive, fillColor = "Green" )%>%


  setView(lng = -1.5, lat = 53.4, zoom = 2.5)#%>%# set centre and extent of map 

当地图显示在 R 中时一切正常,但当我将其导出到 .html 文件时,它允许用户缩小到世界地图的三个副本。 我想设置它,以便最大缩小只允许地图的一个副本作为网页(与在 R 中呈现的方式相同)。 我试过了 tileOptions(maxZoom=5) 但这只会影响在 R 中查看地图时的缩放,而不是当它导出到 html.

Leaflet 的 L.Map class 有一个选项可以停止复制地图的叠加层:

With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.

http://leafletjs.com/reference.html#map-worldcopyjump

确保用户不会平移某个区域的正确方法是使用 L.MapmaxBounds 选项:

When this option is set, the map restricts the view to the given geographical bounds, bouncing the user back when he tries to pan outside the view.

http://leafletjs.com/reference.html#map-maxbounds

在代码中:

leafletMap(
    "map", "100%", "100%",
    initialTileLayer = "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",
    initialTileLayerAttribution = HTML('&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>'),
    options=list(
        center = c(0, 0),
        zoom = 0,
        worldCopyJump = FALSE,
        maxBounds = list(
            list(-90, -180),
            list(90, 180)
        )
    )
)

你确实可以通过在你的 L.TileLayer 上设置 noWrap 选项来结束它,但实际上所做的只是阻止图块重复,这不是你实际问题的解决方案:

If set to true, the tiles just won't load outside the world width (-180 to 180 longitude) instead of repeating.

http://leafletjs.com/reference.html#tilelayer-nowrap