geostyler / geostyler-openlayers-parser

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

SLD to OpenLayers-Style including GraphicFill #240

Closed thomas-romuald closed 2 years ago

thomas-romuald commented 4 years ago

Hi, first thanks for this great tools.

I have to display geojson features with OpenLayer on a vueJS application. The legacy application is based on geoserver and I would like to re-used slf files.

import SLDParser from "geostyler-sld-parser";
import OpenLayersParser from "geostyler-openlayers-parser";
import slfFile from '../../resources/RRP_09_VF.sld'
...
    /**
     * Load sld style
     */
    loadStyle() {
      const parser = new SLDParser();
      parser
        .readStyle(slfFile)
        .then(geostylerStyle => {
          this.geostylerStyle = geostylerStyle
        })
        .catch(error => console.log(error));
    },
...
    /**
     * Transform sld style to OL style and apply it on vector layer
     */
    styleFeatures() {
      this.$refs.map.$map.getLayers().forEach(layer => {
        if (layer.get("id") == "features-panel") {
        const parser = new OpenLayersParser();
        parser
          .writeStyle(this.geostylerStyle)
          .then(olStyle => layer.setStyle(olStyle))
          .catch(error => console.log(error));
        }
      });
    },

This works well for the color fill. However the legacy application has in addition GraphicFill (shape://horline, shape://dot etc).

After dying a bit it seems the solution for GraphicFill with Open layer is Styling feature with CanvasGradient or CanvasPattern.

Have you planned to implement this styling ? Would you have any workaround solution ideas ?

jansule commented 3 years ago

We did think about implementing GraphicFill for the openlayers-parser a while ago, but discarded the idea as we were only able to write but not to read an openlayers canvaspattern.

Some time ago, we implemented a workaround for such cases, which at least supports parsing when a style was created with geostyler (see https://github.com/geostyler/geostyler-openlayers-parser/blob/master/src/OlStyleParser.ts#L423, we basically keep the original geostyler-style and attach it to the openlayers style function).

So from my side, there aren't any blockers preventing the implementation for parsing GraphicFill.

Would you like to provide a PR for that?

KaiVolland commented 2 years ago

Solved with https://github.com/geostyler/geostyler-openlayers-parser/pull/388