diff --git a/package.json b/package.json index 92ae06db..1b59da3e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-spatial", "license": "MIT", "description": "Components to build React map apps.", - "version": "1.10.1", + "version": "1.10.2-beta.1", "dependencies": { "@emotion/react": "^11.11.4", "@emotion/styled": "^11.11.5", diff --git a/src/utils/KML.js b/src/utils/KML.js index 66431554..b5b962c0 100644 --- a/src/utils/KML.js +++ b/src/utils/KML.js @@ -84,7 +84,11 @@ const sanitizeFeature = (feature, doNotRevert32pxScaling = false) => { feature.set("minZoom", parseFloat(feature.get("minZoom"), 10)); } - // The use of clone is part of the scale fix line 156 + // The use of clone is part of the scale fix for OL > 6.7 + // If an IconStyle has no gx:w and gx:h defined, a scale factor is applied + // after the image is loaded. To avoided having the scale factor applied we + // clone the style and keep the scale as it is. + // Having gx:w and gx:h not defined should not happen, using the last version of the parser/reader. const tmpStyles = styles(feature); const style = (Array.isArray(tmpStyles) ? tmpStyles[0] : tmpStyles).clone(); @@ -211,8 +215,8 @@ const sanitizeFeature = (feature, doNotRevert32pxScaling = false) => { if (feature.get("iconScale")) { image.setScale(parseFloat(feature.get("iconScale")) || 0); - // We fix the 32px scaling introduced by OL 6.7 - } else if (!doNotRevert32pxScaling) { + // We fix the 32px scaling introduced by OL 6.7 only if the image has a size defined. + } else if (!doNotRevert32pxScaling && image.getSize()) { const resizeScale = scaleForSize(image.getSize()); image.setScale(image.getScaleArray()[0] / resizeScale); } diff --git a/src/utils/KML.test.js b/src/utils/KML.test.js index 07dce08b..029d444c 100644 --- a/src/utils/KML.test.js +++ b/src/utils/KML.test.js @@ -398,6 +398,72 @@ describe("KML", () => { expectWriteResult(feats, str, false, get("EPSG:3857")); }); + + test("should read/write IconStyle when no size defined", () => { + const str = ` + + + lala + + + + + 0,0,0 + + + + + `; + const strCorrected = ` + + + lala + + + + + + + 0.166666667 + + + + + 0,0,0 + + + + `; + let feats = KML.readFeatures(str); + let style = feats[0].getStyleFunction()(feats[0], 1); + expect(style.getImage().getScale()).toEqual(0.166666667); + const strKmlCorrected = expectWriteResult(feats, strCorrected); + + // Next read/write should produce the same KML + feats = KML.readFeatures(strKmlCorrected); + style = feats[0].getStyleFunction()(feats[0], 1); + expect(style.getImage().getScale()).toEqual(0.166666667); + expectWriteResult(feats, strKmlCorrected); + }); }); test("should add iconScale to extended data when writing, to revert effect of https://github.com/openlayers/openlayers/pull/12695.", () => { @@ -509,7 +575,7 @@ describe("KML", () => {