openlayers / ol-mapbox-style

Use Mapbox Style objects with OpenLayers
https://unpkg.com/ol-mapbox-style/dist/examples/index.html
BSD 2-Clause "Simplified" License
347 stars 120 forks source link

Hardcoded size value for symbols along the line #334

Open mshubin opened 3 years ago

mshubin commented 3 years ago

Hi,

I have a rotated symbols which are placed along the line by using 'symbol-placement' and 'icon-rotation-alignment'. But I've noticed that these symbols appear only when zooming really close to my lines, which is problematic. By reading the code there is a "magic number" test with a FIXME comment:

const extent = geom.getExtent();
const size = Math.sqrt(Math.max(
  Math.pow((extent[2] - extent[0]) / resolution, 2),
  Math.pow((extent[3] - extent[1]) / resolution, 2))
);
if (size > 150) {
   //FIXME Do not hard-code a size of 150
   ...
}

Do you know how you would like to fix it ? I don't think that we really need this check, because we can still hide these symbols by using 'minzoom' attribute ? What do you think ?

Thank you in advance,

ahocevar commented 3 years ago

To properly replace the hard-coded value with a style config option, you would have to use symbol-spacing. Then, instead of using the midpoint of the geometry, you would have to use getLength(), getCoordinateAtM() and the current resolution to determine one or more points along the line where the symbol would be placed.

mshubin commented 3 years ago

I see for symbol-spacing argument but correct me if I'm wrong, in this part of code we have only access to RenderFeature and not the LineString geometry. So to use getLength() & getCoordinateAtM() I can use lineStringLength & lineStringCoordinateAtM methods from ol.geom.flat ?

ahocevar commented 3 years ago

Yes exactly, you have to use the respective functions from ol/geom/flat.