From c8de70a027c13d08823a35b340950a9d76564c1a Mon Sep 17 00:00:00 2001 From: danji90 Date: Thu, 2 Oct 2025 10:49:13 +0200 Subject: [PATCH 1/3] fix(MapsetKmlFormat): extend functionality to support feature scaling disable in KML --- src/ol/utils/MapsetKmlFormat.ts | 48 ++++++++++++++++----------------- src/ol/utils/index.js | 2 ++ 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/ol/utils/MapsetKmlFormat.ts b/src/ol/utils/MapsetKmlFormat.ts index d9331aba..be1b5e49 100644 --- a/src/ol/utils/MapsetKmlFormat.ts +++ b/src/ol/utils/MapsetKmlFormat.ts @@ -69,6 +69,11 @@ interface IconOptions { zIndex: number; } +interface ScaleOptions { + defaultScale?: number; + resolution: number; +} + // Comes from ol >= 6.7, // https://github.com/openlayers/openlayers/blob/main/src/ol/format/KML.js#L320 const scaleForSize = (size: Size) => { @@ -168,7 +173,7 @@ class MapsetKmlFormat { transform( JSON.parse(circleGeometryCenter as string) as Coordinate, EPSG_4326, - featureProjection || EPSG_4326, + featureProjection ?? EPSG_4326, ), parseFloat(circleGeometryRadius as string), ); @@ -259,6 +264,13 @@ class MapsetKmlFormat { style?.setZIndex(parseInt(feature.get('zIndex') as string, 10)); } + const scaleOptions = (feature.get('pictureOptions') ?? + feature.get('scaleOptions')) as ScaleOptions | string; + if (scaleOptions && typeof scaleOptions === 'string') { + const parsed = JSON.parse(scaleOptions) as ScaleOptions; + feature.set('scaleOptions', parsed); + } + // if the feature is a Point and we are offline, we use default vector // style. // if the feature is a Point and has a name with a text style, we @@ -409,32 +421,18 @@ class MapsetKmlFormat { stroke = null; styles = (feat, resolution) => { - /* Options to be used for picture scaling with map, should have at least + /* Options to be used for feature scaling with map, should have at least * a resolution attribute (this is the map resolution at the zoom level when - * the picture is created), can take an optional constant for further scale + * the feature is created), can take an optional constant for further scale * adjustment. * e.g. { resolution: 0.123, defaultScale: 1 / 6 } */ - interface PictureOptions { - defaultScale?: number; - resolution: number; - } - - if (feat.get('pictureOptions')) { - let pictureOptions = feat.get('pictureOptions') as - | PictureOptions - | string; - if (typeof pictureOptions === 'string') { - pictureOptions = JSON.parse(pictureOptions) as PictureOptions; - } - (feat as FeatureType).set('pictureOptions', pictureOptions); - if (pictureOptions.resolution) { - image?.setScale( - (pictureOptions.resolution / resolution) * - (pictureOptions?.defaultScale ?? 1), - ); - } + const scaleOpts = feat.get('scaleOptions') as ScaleOptions; + if (scaleOpts && image instanceof Icon && scaleOpts.resolution) { + image.setScale( + (scaleOpts.resolution / resolution) * (scaleOpts.defaultScale ?? 1), + ); } return new Style({ @@ -744,10 +742,10 @@ class MapsetKmlFormat { } // Set map resolution to use for icon-to-map proportional scaling - if (feature.get('pictureOptions')) { + if (feature.get('pictureOptions') || feature.get('scaleOptions')) { clone.set( - 'pictureOptions', - JSON.stringify(feature.get('pictureOptions')), + 'scaleOptions', + JSON.stringify(feature.get('scaleOptions')), ); } } diff --git a/src/ol/utils/index.js b/src/ol/utils/index.js index 23dab6f1..38e985b7 100644 --- a/src/ol/utils/index.js +++ b/src/ol/utils/index.js @@ -1,2 +1,4 @@ export { default as getFeatureInfoAtCoordinate } from './getFeatureInfoAtCoordinate'; export { default as getGraphByZoom } from './getGraphByZoom'; +export { default as getMapsetPolygonPattern } from './getMapsetPolygonPattern'; +export { default as MapsetKmlFormat } from './MapsetKmlFormat'; From 1935bddcb6cc9481ae751df04cc1b1b50974731e Mon Sep 17 00:00:00 2001 From: danji90 Date: Thu, 23 Oct 2025 18:56:25 +0200 Subject: [PATCH 2/3] chore: add scaleOptions for all geom types in MapsetKmalFormat --- src/ol/utils/MapsetKmlFormat.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ol/utils/MapsetKmlFormat.ts b/src/ol/utils/MapsetKmlFormat.ts index be1b5e49..21455917 100644 --- a/src/ol/utils/MapsetKmlFormat.ts +++ b/src/ol/utils/MapsetKmlFormat.ts @@ -740,14 +740,6 @@ class MapsetKmlFormat { // We set the scale as extended metadata because the in the KML is related to a 32px img, since ol >= 6.10. clone.set('iconScale', newStyle.image.getScale()); } - - // Set map resolution to use for icon-to-map proportional scaling - if (feature.get('pictureOptions') || feature.get('scaleOptions')) { - clone.set( - 'scaleOptions', - JSON.stringify(feature.get('scaleOptions')), - ); - } } // In case a fill pattern should be applied (use fillPattern attribute to store pattern id, color etc) @@ -766,6 +758,14 @@ class MapsetKmlFormat { clone.set('minZoom', parseFloat(feature.get('minZoom') as string)); } + // Set map resolution to use for feature-to-map proportional scaling + if (feature.get('pictureOptions') || feature.get('scaleOptions')) { + clone.set( + 'scaleOptions', + JSON.stringify(feature.get('scaleOptions')), + ); + } + // If only text is displayed we must specify an // image style with scale=0 if (newStyle.text && !newStyle.image) { From 808dfaf784bbb3e996af087c2010b5294c06cf3d Mon Sep 17 00:00:00 2001 From: danji90 Date: Thu, 23 Oct 2025 18:57:01 +0200 Subject: [PATCH 3/3] chore(release): 3.4.6-beta.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2926f09b..b853f27d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "mobility-toolbox-js", "license": "MIT", "description": "Toolbox for JavaScript applications in the domains of mobility and logistics.", - "version": "3.4.5", + "version": "3.4.6-beta.0", "homepage": "https://mobility-toolbox-js.geops.io/", "exports": { ".": "./index.js",