geostyler / geostyler-openlayers-parser

GeoStyler Style Parser implementation for OpenLayers styles
BSD 2-Clause "Simplified" License
38 stars 28 forks source link

Why Geostyler IconSymbolyzer size is parsed as Ol Icon scale? #624

Closed pragmaeuge closed 1 year ago

pragmaeuge commented 1 year ago

Question

Why Geostyler IconSymbolyzer size is parsed as Ol Icon scale?

Maybe Ol Icon imgSize should be preferred?

 /**
   * Get the OL Style object  from an GeoStyler-Style IconSymbolizer.
   *
   * @param symbolizer  A GeoStyler-Style IconSymbolizer.
   * @return The OL Style object
   */
  getOlIconSymbolizerFromIconSymbolizer(symbolizer: IconSymbolizer, feat?: OlFeature): OlStyleIcon | OlStyleFunction {
    for (const key of Object.keys(symbolizer)) {
      if (isGeoStylerFunction(symbolizer[key])) {
        symbolizer[key] = OlStyleUtil.evaluateFunction(symbolizer[key], feat);
      }
    }

    const baseProps = {
      src: symbolizer.image,
      crossOrigin: 'anonymous',
      opacity: symbolizer.opacity,
      scale: symbolizer.size || 1,
      // Rotation in openlayers is radians while we use degree
      rotation: typeof(symbolizer.rotate) === 'number' ? symbolizer.rotate * Math.PI / 180 : undefined,
      displacement: symbolizer.offset
    };
jansule commented 1 year ago

According to the OpenLayers API, imgSize is only applicable when using the img instead of the src property of ol/style/Icon. In our parser, we use src, since we usually provide a URL to an image.

We also have a closed PR (#549) that was trying to make use of the size property, which was closed since it did not scale, but rather cut the image.

Unfortunately this approach is not working as i didn't read the API-Docs of OpenLayers carefully enough. The size property does not shrink or grow the selected image but cut a piece out of it...

source: https://github.com/geostyler/geostyler-openlayers-parser/pull/549#issuecomment-1153927001

jnewmoyer commented 1 year ago

We are also seeing this issue where basically icon sizes are being scaled up dramatically. So if you set size to 1, the icon is displayed at its normal size (size of the image file) and no scaling, but if you go higher than 1, the size increases in an exponential factor.

I feel like this line should say scale: symbolizer.scale || 1: https://github.com/geostyler/geostyler-openlayers-parser/blob/master/src/OlStyleParser.ts#L1125

KaiVolland commented 1 year ago

https://github.com/openlayers/openlayers/pull/14364 is now merged and we are able to adapt the geostyler-openlayers-parser with the next openlayers release. Until then we could remove the parsing of symbolizer.size and add it to the unsupportedProperties.

Any volunteers for a PR? :slightly_smiling_face:

KaiVolland commented 1 year ago

Thix should be fixed with the latest release.