Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions src/utils/KML.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
Expand Down
76 changes: 71 additions & 5 deletions src/utils/KML.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,72 @@ describe("KML", () => {

expectWriteResult(feats, str, false, get("EPSG:3857"));
});

test("should read/write IconStyle when no size defined", () => {
const str = `
<kml ${xmlns}>
<Document>
<name>lala</name>
<Placemark>
<description></description>
<Style>
<IconStyle>
<scale>
0.166666667
</scale>
<Icon>
<href>https://icon-generator.geops.io/pictogram?urlPrefix=https%3A%2F%2Feditor.mapset.ch%2Fstatic%2Fimages%2F&amp;columns=2&amp;color=%2C&amp;fontsize=%2C&amp;text=%2C&amp;fill=inc%3Ach%2F02_Gleis-2_g_fr_v1.png%2Cinc%3ASBB%2F03_Gleis-3_g_fr_v1.png&amp;iconMargin=26&amp;iconSize=144&amp;format=png&amp;border=%2C</href>
</Icon>
<hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
</IconStyle>
</Style>
<Point>
<coordinates>0,0,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
`;
const strCorrected = `
<kml ${xmlns}>
<Document>
<name>lala</name>
<Placemark>
<description></description>
<Style>
<IconStyle>
<scale>
0.333333
</scale>
<Icon>
<href>https://icon-generator.geops.io/pictogram?urlPrefix=https%3A%2F%2Feditor.mapset.ch%2Fstatic%2Fimages%2F&amp;columns=2&amp;color=%2C&amp;fontsize=%2C&amp;text=%2C&amp;fill=inc%3Ach%2F02_Gleis-2_g_fr_v1.png%2Cinc%3ASBB%2F03_Gleis-3_g_fr_v1.png&amp;iconMargin=26&amp;iconSize=144&amp;format=png&amp;border=%2C</href>
</Icon>
</IconStyle>
</Style>
<ExtendedData>
<Data name="iconScale">
<value>
0.166666667
</value>
</Data>
</ExtendedData>
<Point>
<coordinates>0,0,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>`;
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.", () => {
Expand Down Expand Up @@ -509,7 +575,7 @@ describe("KML", () => {
<Style>
<IconStyle>
<scale>
4
2
</scale>
<Icon>
<href>https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
Expand All @@ -522,7 +588,7 @@ describe("KML", () => {
<ExtendedData>
<Data name="iconScale">
<value>
2
1
</value>
</Data>
</ExtendedData>
Expand All @@ -532,15 +598,15 @@ describe("KML", () => {
</Placemark>
</Document>
</kml>`;
let feats = KML.readFeatures(str, null);
let feats = KML.readFeatures(str, null, true);
let style = feats[0].getStyleFunction()(feats[0], 1);
expect(style.getImage().getScale()).toEqual(2);
expect(style.getImage().getScale()).toEqual(1);
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(2);
expect(style.getImage().getScale()).toEqual(1);
expectWriteResult(feats, strKmlCorrected);
});
});
Expand Down