相对最大和最小缩放 - Openlayers

Relative Max and Min Zoom - Openlayers

我目前正在从事一个项目,该项目的目标是使用静态图像层来显示实时数据。我们已经走了很远,一切都运作良好。我注意到的问题之一是,例如,最小缩放时地图上显示的 ImageLayer 的大小是相对于浏览器分辨率的。我对 Openlayers 文档做了一些研究,但我找不到解决这个问题的确切方法。在初始化地图时也将视图中的分辨率设置为1,但仍然有一些浏览器分辨率在完全缩小时不会显示整个地图。

我们使用静态 ImageLayer,其中投影是我们在地图上使用的自定义坐标系。

有什么办法解决这个问题吗?这样 minZoom 和 maxZoom 是相对于浏览器分辨率的?

如 OpenLayers 网站所述:

The zoom option is a convenient way to specify the map resolution. The available zoom levels are determined by maxZoom (default: 28), zoomFactor (default: 2) and max resolution (default is calculated in such a way that the projection's validity extent fits in a 256x256 pixel tile). Starting at zoom level 0 with a resolution of maxResolution units per pixel, subsequent zoom levels are calculated by dividing the previous zoom level's resolution by zoomFactor, until zoom level maxZoom is reached.

因此当缩放在 0-28 之间时,您可以使用 view.getResolutionForZoom(zoom) 找到最小和最大分辨率或任何缩放分辨率。您只需要调整图层的缩放级别并计算图层加载时的分辨率并设置它们的属性。

但这可能不像你说的那样准确。还有另一种方法,首先,获取图层的范围并将地图适合图层。有一种方法 view.fit(geometryOrExtent, opt_options) 您可以找到更多信息 here。然后为地图 maxResolution 设置当前分辨率。
在此之后,您可以确保整个图层都可见。

为了更好的地图装箱,您可以将图层范围的缩放数减少一或两个。它使图层更适合地图。