I have a PostGIS table that contains geometry, min_scale, and max_scale fields. The PostGIS table is published as a Geoserver layer with EPSG = 4326. I have created a CSS Style Doc that will show each geoemtry only in its scale range; something like:

[@sd <= max_scale] [@sd >= min_scale]{
     mark: symbol(circle); 

My problem is how to set the min_scale and max_scale fields to work properly with Openlayers zoom levels. I tried to use the scale values from the EPSG:4326 Gridset:


But it didn't work properly; for example if I set

min_scale = 545978 which corresponds to zoom 9

max_scale = 2183915 which corresponds to zoom 7

The feature appears only at zoom 7 and 8, and didn't appear at zoom 9.

I also tried the values at this table (Default Gridset):

https://docs.geoserver.org/latest/en/user/styling/ysld/reference/scalezoom.html#default-gridset But the same problem occurred.

My question is what is my problem? which scale values should I use in order to work properly with Openlayers zoom levels?

  • which DPI have you set in OpenLayers? – Ian Turton Dec 8 '18 at 12:08
  • @IanTurton I didn't understand your question. I don't have any DPI settings in OL. – Faz B Dec 8 '18 at 12:48
  • 1
    Geoserver uses the OGC standard scale while ol uses 96dpi – Ian Turton Dec 8 '18 at 16:24
  • @IanTurton, What does the DPI affect in Scale calculation? – abd0991 Dec 8 '18 at 17:15
  • 1
    because scale is the ratio between pixels and real world units – Ian Turton Dec 9 '18 at 10:40

As discussed in this question GeoServer uses a DPI (or more correctly a Pixels per inch) of 90.714. Meanwhile this question suggests that OpenLayers uses 72. This is why you get a miss match in scales. The easy answer used to be you added an OpenLayers.DOTS_PER_INCH variable. I don't know how OL3+ handles it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.