We've coded an openlayers-based geoportal and recognized a problem with our scale settings.
The displayed scale in our geoportal seems to be wrong. When we connect a wms in our geoportal with an max scale denom of 1:5000, we can display this wms until 1:6500.
In QGIS the WMS is dispayed correctly until 1:5000 and then disappears.
We've already checked the QGIS source code for the calculation of the displayed scale and adapt this in our geoportal.
We use Openlayers 6.1.1 with utm32-projection.
Does somebody had similar problems or any advices about that?
[Edit]
For the map we use custom resolutions based on human readable scales converted with the following function:
scaleToResolution = function(
scale,
map_units,
dpi
) {
scale = scale || 0;
map_units = map_units || 1;
dpi = dpi || 1;
var inch_per_meter = 1/0.0254;
return scale / map_units / inch_per_meter / dpi;
};
The dpi depends on the device.
[Edit 2]
The problem was the TileGrid
with the default Resolutions
and Origin
of the TileWms
-Source. (See Answer from Mike)
In our geoportal we have a editable select for the scale with predefined scales (e.g. 1:5000, 1:10000 ...). Additionally the user can enter own scales for a custom view of the map. (e.g. 1:5321). This works fine with Openlayers ImageWms, XYZ and WMTS.
For the TileWms Openlayers pick the nearest (predefined) resolution of the TileWms when entering a custom scale. (which is logical)
e.g.
predefined scale custom scale
...
1:20000
1:10000
1:8345 --> 1:10000 (openlayers choice)
1:5321 --> 1:5000 (openlayers choice)
1:5000
1:2500
...
When i switch from TileWMS to ImageWMs (Single Tile), Openlayers requests the custom scale. I want OpenLayers to request the custom scale for the TileWms (like QGIS does).
Is that possible? (e.g. set the resolution of the TileGrid every time the user enter or pick a scale?)
With a default tile grid you will have zoom levels with somewhat arbitrary resolutions based initially on the projection extent and a zoom
factor of 2 . The tiles displayed will come from the zoom level nearest to the view resolution, so depending on the position of the server scale limit
relative to the tile resolutions the actual display cut-off for visible data might occur anywhere between limit*sqrt2
and limit/sqrt2
.
Defining an explicit tile grid with known resolutions which relate to the server limit, used in conjunction with OpenLayers maxResolution
or minResolution
options for the layer, would give more precise control of the cut-off point.