Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WellKnownName's to support extra styles from QGIS #828

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

terry-longmacch
Copy link

@terry-longmacch terry-longmacch commented Jan 28, 2025

Description

Support for a large number of WellKnownName's has been added. This is to align with the point markers provided in the styling used with QGIS. Most of the new styles could not be replicated using OpenLayer's RegularShape specification, which is quite limited. As a result styling for points has been changed to use OpenLayer's Icon styles with SVG used for the image source. In most cases the SVG code for shapes was translated directly from the QGIS Python code.

The code has been tested as much as possible, but I have mainly been concentrating on converting SLD (from QGIS Server) to OpenLayers, and this seems to be working pretty well. I've had limited exposure to the other parts of Geostyler, so please let me know if there are other areas that need attention. I completely understand that there may be a lot of work needed, but hopefully it can be incorporated at some point. An attempt was made to use it with Geostyler Demo, but I think there might be other issues with this repository, as I couldn't get my fork working without the code changes.

Good luck!!

Polygon fill pattern issue

An attempt was made to use SVG point markers with graphicFill fills for polygons. The SVG is loaded as a utf8 encoded data URL (see example below), which should be almost instantaneous to load, however the process of saving it as an HTMLImageElement for the canvas pattern seems to introduce a timing issue where the image isn't loaded before being passed as the fill for the polygon. This can be replicated by changing the preferSvg parameter on this line to true, which will revert to using SVG's.

Example SVG

data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%22-12%20-12%2024%2024%22%3E%3Cpolygon%20id%3D%22diamond%22%20points%3D%22-10%2C0%200%2C10%2010%2C0%200%2C-10%20-10%2C0%22%20style%3D%22fill%3A%23ff7f00%3B%20stroke%3A%23ffffff%3B%20stroke-width%3A1%3B%22%20%2F%3E%3C%2Fsvg%3E

Some evidence that it was a timing issue. Firstly, if a single SVG is hardcoded for all graphicFill styles, it will not load for the first layer loaded, but it will load for all subsequent layers. Secondly, if a zoom-based style is applied, the style will not show on the initial load, but once any zoom level change is made the style becomes available.

A further attempt to get this working was made where the writeStyle and all of its nested functions were made asynchronous (see this commit). This successfully loaded SVG's as the marker in pattern fill, however it broke all function based styling - zoom based and styling based on feature attributes. I believe this is because OpenLayers loads styles synchronously, so when presented with a style function that should be asynchronous, it doesn't respect the async nature.

Further notes

Polygon fill patterns currently don't have any mechanism to alter the spacing of point markers in the fill. For the moment, if a line pattern is specified (horline, vertline, line) the spacing between markers has been reduced to 0. This is an attempt to support hash pattern fills where lines should be joining across canvas tiles. There are tile border issues when lines aren't either vertical or horizontal, that become more evident the thicker the stroke width - I don't know that there is any simple solution to this.

Thick diagonal hash pattern line issue

image

For the remaining marker styles a default fixed spacing of 2x the marker width has been set to allow for some gaps between the markers, until marker spacing is supported.

image

Related issues or pull requests

The following pull requests are related due to the new definition of the accepted WellKnownTypes.

Geostyler Style - geostyler/geostyler-style#652
Geostyler SLD Parser - geostyler/geostyler-sld-parser#978

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Dependency updates
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe)
  • I am unsure (we'll look into it together)

Do you introduce a breaking change?

  • Yes
  • No
  • I am unsure (no worries, we'll find out)

Checklist

  • I understand and agree that the changes in this PR will be licensed under the BSD 2-Clause License
  • I have followed the guidelines for contributing
  • The proposed change fits to the content of the code of conduct
  • I have added or updated tests and documentation, and the test suite passes (run npm test locally)
  • I'm lost; why do I have to check so many boxes? Please help!

@terry-longmacch
Copy link
Author

I think there may still be an issue with zoom styling. It seems to apply the first style, but ignores subsequent ones.

Tried using async to manage SVG loading for pattern fills, but it broke the style functions.  Reverted back to using RegularShapes for pattern fills to avoid timing issues with loading.  Added a number of extra RegularShapes.
@terry-longmacch
Copy link
Author

I believe the earlier issues with zoom and style functions is now rectified. Instead of using SVG's for polygon pattern fills, I've reverted to OpenLayers RegularShapes, so not all shapes are supported, but many are.

Copy link
Contributor

@jansule jansule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @terry-longmacch. This is quite a lot to review. At first, just a few questions.

I also just updated the geostyler-style version in #829. So if you rebase this PR, we can see if the checks pass.

@terry-longmacch
Copy link
Author

@jansule Yes, plenty to review here, but hopefully it makes sense? Also, hope I didn't add too many extra unnecessary changes. It was a bit of a process trying to get it all working, so there were many iterations of the code!

@jansule
Copy link
Contributor

jansule commented Feb 10, 2025

No worries @terry-longmacch, from a first glance this looks great! We are happy to have contributors like you that dedicate quite an amount of time and work into improving GeoStyler.

I will try to review this PR properly as soon as possible.

Copy link
Contributor

@jansule jansule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work @terry-longmacch! There is just one remark left to address. Otherwise I'm +1 for getting this in.

const diameter = graphicFill.radius as number * 2;
iconSize = [diameter, diameter];
// Hack to try to join lines for hatch patterns, but space out icon patterns.
// Diagonal lines still do not render nicely in the corners, due to tiling.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this into a separate PR, so we can have a streamlined discussion about this specific feature?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry Jan, are you just referring to the calculations to join lines that aren't horizontal or vertical? Currently I have the iconSpacing factor at 2 for all non-line markers (line 1366), do you want this kept or would you like the spacing reverted to 1 for everything?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert both parts and put them into a separate PR, so this PR stays as simple as possible?

We can then see in the other PR how we might need to adjust the changes regarding the join lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants