Skip to content

Add configuration option to icon styles: referenceMapScale, minIconScaleFactor, maxIconScaleFactor#2211

Open
MattiasSp wants to merge 11 commits intoorigo-map:masterfrom
haninge-geodata:scale-icons-to-reference-map-scale
Open

Add configuration option to icon styles: referenceMapScale, minIconScaleFactor, maxIconScaleFactor#2211
MattiasSp wants to merge 11 commits intoorigo-map:masterfrom
haninge-geodata:scale-icons-to-reference-map-scale

Conversation

@MattiasSp
Copy link
Contributor

@MattiasSp MattiasSp commented Jun 26, 2025

Fixes #2210.

Lets icons, texts, circles and other basic shape styles grow and shrink when a user zooms in and out in the map.

"origo-logo": [
      [
        {
          "label": "Origokommuner",
          "icon": {
            "src": "img/kompass.svg",
            "referenceMapScale": 50000,
            "minStyleScaleFactor": 0.01,
            "maxStyleScaleFactor": 0.2
          }
        }
      ]
    ],
  • referenceMapScale defines the map scale at which the icon will be displayed at its normal size (provide the map scale denominator as a number, e g 10000 for a reference map scale of 1:10 000).
  • minStyleScaleFactor defines how small the icon is allowed to be relative to its normal size.
  • maxStyleScaleFactor defines how large the icon is allowed to be relative to its normal size.
  • In addition to the above three, the scale and rotation parameters are now also supported on icon, text, circle and the other basic shape styles, including feature attribute substitution.

These scale values play nice with the regular scale parameter.

Also, if the "updateWhileAnimating": true property is added to a layer with a style with a referenceMapScale, it will make the scaling of the style smooth as the user zooms:

"layers": [
    {
      "name": "origo-cities",
      "title": "Origokommuner",
      "group": "root",
      "source": "data/origo-cities-3857.geojson",
      "style": "origo-logo",
      "updateWhileAnimating": true,
      "type": "GEOJSON",
      [...]

EDIT: Updated the proposed names for the min- and max icon scale factors.

EDIT 2: Updated the names and description again to extend the issue to also generalize the scale and rotation handling so that it works the same for text, icon, circle and the other basic shape styles.

@MattiasSp MattiasSp added the Awaiting documentation Docs needs to be provided before approval label Jun 26, 2025
@MattiasSp
Copy link
Contributor Author

Added the option to control icon scales using feature attributes - similar to what already works for rotation, e g:

{
  "label": "Origokommuner",
  "icon": {
    "size": [22,37],
    "src": "img/geolocation_marker_heading.png",
    "referenceMapScale": 5000000,
    "minIconScaleFactor": 0.2,
    "maxIconScaleFactor": 2,
    "rotation": "{{rotation}}",
    "scale": "{{scale}}"
  }
}

@MattiasSp MattiasSp changed the title Add configuration option to icon styles: referenceMapScale, minScale, maxScale Add configuration option to icon styles: referenceMapScale, minIconScaleFactor, maxIconScaleFactor Sep 1, 2025
@MattiasSp
Copy link
Contributor Author

MattiasSp commented Sep 2, 2025

Now the above also works for text, circle or other basic shape styles, e g:

{
  "text": {
    "font": "Bold 12px Arial",
    "textAlign": "left",
    "offsetX": 11,
    "offsetY": -9,
    "text": "{{name}}",
    "fill": {
      "color": "rgba(0,0,0,1.0)"
    },
    "stroke": {
      "color": "rgba(255,255,255,0.7)",
      "width": 2
    },
    "referenceMapScale": 10000000,
    "minStyleScaleFactor": 0.4,
    "maxStyleScaleFactor": 3,
    "scale": "{{scale}}",
    "rotation": "{{rotation}}"
  }
}

For text styles, the offset parameters are also scaled accordingly.

@steff-o steff-o self-requested a review November 3, 2025 09:02
Copy link
Contributor

@steff-o steff-o left a comment

Choose a reason for hiding this comment

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

LGTM.

I was pretty confused with the rotation by attribute functionality, as if a feature has null in that column, the style part is not displayed at all while a layer without the column using the same style defaults to 0. It seems like rotation for icon already worked like that so nothing to complain about.

If the symbol consists of many parts (like the origo-logo) it becomes chatty to configure each part to scale each part, which could be solved by allowing all settings to be set at top level for the symbol and acta as default for each part. But that would not be worth to implement as there certainly be cases where a user would want to have different options for the part, so we would have to support both cases, and since most symbols are icons or just one part I don't think it is worth the hassle.

@steff-o steff-o added the PR approved To highlight approved PR:s as it is not shown in list which are approved. label Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting documentation Docs needs to be provided before approval PR approved To highlight approved PR:s as it is not shown in list which are approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scale feature styles according to a reference map scale and generalize rotation/scale handling for text, icon and circle

2 participants