geostyler / geostyler-openlayers-parser

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

Rectangle shape using ol.style.RegularShape do not get correctly parsed from ol style to geoserver style #453

Closed MichaelTang778 closed 3 months ago

MichaelTang778 commented 2 years ago

Bug

Describe the bug

When converting from openlayer style to geoserver style, the rectangle shape fails to parse correctly for ol.style.RegularShape. The reason for this is because the scale doesn't get parsed correctly. For rectangle shapes the scale have an array of two numbers and for shapes that are not of rectangle have a scale with one number stored.

A clear and concise description of what the bug is.

  1. Run the following code
var OlStyleParser = new GeoStylerOpenlayersParser.OlStyleParser(ol);

const rectangleStyle = new ol.style.Style({
          image: new ol.style.RegularShape({
              fill: new ol.style.Fill({ color: 'rgba(0,0,0,1)', width: 1}),
              stroke: new ol.style.Stroke({ color: 'rgba(0,0,0,1)', width: 1}),
              radius: 10 / Math.SQRT2,
              radius2: 10,
              points: 4,
              angle: 0,
              scale: [1, 0.5], // <------- note
              rotation: null
          })
  });

// To geoserver style
const olStyleOriginal = await OlStyleParser.readStyle(rectangleStyle );
const geoserverStyle = olStyleOriginal .output;

// back to ol style
var olStyleParser = await OlStyleParser.writeStyle(geoserverStyle );
const olStyleNew = olStyleParser.output;
  1. Note the the following:

rectangleStyle: images -> scale_ = [1, 0.5]

olStyleNew images -> scale_ = 1

Expected behavior It is expected that the rectangle shape can be parsed correctly from openlayer style to geoserver style.

Screenshots If applicable, add screenshots to help explain your problem.

Screenshot showing original rectangleStyle style

Screenshot showing ol style to geoserver style olToGeoserver

screenshot showing geoserver style converted back to ol style GeoserverToOl

Desktop (please complete the following information):

jansule commented 2 years ago

Thanks for the info @MichaelTang778

The openlayers parser does not support rectangular shapes and non-numeric scales, yet. Currently, we support:

Would you like to create a PR that introduces that feature?

MichaelTang778 commented 2 years ago

I would love to, but I'm moving on from my current role in January and will be working on other stuff. Maybe someone else can implement this :)

KaiVolland commented 3 months ago

I think the core issue is that the geostyler-style only accepts a single value for the size of a marker (radius). Changing this would be a breaking change. But we could consider to allow both. A single value or an array of values.

I created an issue in the geostyler-style in favour: https://github.com/geostyler/geostyler-style/issues/619