不允许完全从世界地图上平移

问题描述 投票:0回答:1

[renderWorldCopies设置为false时,是否有一种方法可以限制在Mapbox容器内平移,从而无法通过平移完全隐藏世界?如果您完全缩小地图,则可以将地图平移到任一侧,直到完全隐藏为止。如何禁止这种情况并使地图停留在容器内?

我尝试通过将边界设置为MapBox GL JS documentation on restricting map panning area来改写[[-90, -90], [90, 90]]中的示例:

var bounds = [
  [-90, -90], // Southwest coordinates
  [90, 90]    // Northeast coordinates
];

var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v11',
  center: [-73.9978, 40.7209],
  zoom: 3,
  renderWorldCopies: false,
  maxBounds: bounds
});

这使我参与其中,但是在完全缩小时限制了太多的平移区域并切断了一些世界:

Screenshot of map

mapbox mapbox-gl-js
1个回答
0
投票

摄像机位置是该示例所限制的位置。因此,您可以看到的图像超出了平移限制范围内的范围。

您选择的限制确实切断了世界的一半。请尝试使用这些界限,它们应该可以解决此问题:

    var bounds = [
	  [-180, -90], // Southwest coordinates
	  [180, 90]    // Northeast coordinates
    ];
© www.soinside.com 2019 - 2024. All rights reserved.