From 0c912b6c29fcc6694e9cd507733754228e894c1b Mon Sep 17 00:00:00 2001
From: mike-000 <49240900+mike-000@users.noreply.github.com>
Date: Sat, 4 Sep 2021 22:27:32 +0100
Subject: [PATCH] Test load icon image and reset the scale
---
test/browser/spec/ol/format/kml.test.js | 50 +++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/test/browser/spec/ol/format/kml.test.js b/test/browser/spec/ol/format/kml.test.js
index f8ad64f4cc..fc44e39305 100644
--- a/test/browser/spec/ol/format/kml.test.js
+++ b/test/browser/spec/ol/format/kml.test.js
@@ -2299,6 +2299,56 @@ describe('ol.format.KML', function () {
expect(style.getZIndex()).to.be(undefined);
});
+ it("can read a feature's IconStyle, load the image and reset the scale", function (done) {
+ format = new KML({
+ iconUrlFunction: function (href) {
+ return href.replace('http://foo/', 'spec/ol/data/');
+ },
+ });
+ const text =
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '';
+ const fs = format.readFeatures(text);
+ expect(fs).to.have.length(1);
+ const f = fs[0];
+ expect(f).to.be.an(Feature);
+ const styleFunction = f.getStyleFunction();
+ expect(styleFunction).not.to.be(undefined);
+ const styleArray = styleFunction(f, 0);
+ expect(styleArray).to.be.an(Array);
+ expect(styleArray).to.have.length(1);
+ const style = styleArray[0];
+ expect(style).to.be.an(Style);
+ expect(style.getFill()).to.be(getDefaultFillStyle());
+ expect(style.getStroke()).to.be(getDefaultStrokeStyle());
+ const imageStyle = style.getImage();
+ expect(imageStyle).to.be.an(Icon);
+ expect(imageStyle.getSrc()).to.eql('spec/ol/data/dot.png');
+ expect(imageStyle.getAnchor()).to.be(null);
+ expect(imageStyle.getOrigin()).to.be(null);
+ expect(imageStyle.getRotation()).to.eql(0);
+ expect(imageStyle.getSize()).to.be(null);
+ expect(imageStyle.getScale()).to.be(1);
+ expect(imageStyle.getImage().crossOrigin).to.eql('anonymous');
+ expect(style.getText()).to.be(getDefaultTextStyle());
+ expect(style.getZIndex()).to.be(undefined);
+
+ setTimeout(function () {
+ expect(imageStyle.getSize()).to.eql([20, 20]);
+ expect(imageStyle.getScale()).to.be(1.6); // 32 / 20
+ done();
+ }, 200);
+ });
+
it("can read a IconStyle's hotspot", function () {
const text =
'' +