diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js
index 2f2ccbf1c2..11c1ec076c 100644
--- a/src/ol/format/KML.js
+++ b/src/ol/format/KML.js
@@ -386,6 +386,8 @@ function createStyleDefaults() {
* @property {Array' +
+ ' ' +
+ '';
+ 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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://foo.png').href);
+ 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.be(null);
expect(style.getText()).to.be(getDefaultTextStyle());
expect(style.getZIndex()).to.be(undefined);
});
@@ -2066,8 +2107,6 @@ describe('ol.format.KML', function() {
' ' +
'';
const fs = format.readFeatures(text);
-
-
expect(fs).to.have.length(1);
const f = fs[0];
expect(f).to.be.an(Feature);
@@ -2552,6 +2591,53 @@ describe('ol.format.KML', function() {
expect(s.getFill().getColor()).to.eql([0, 0, 0, 0]);
});
+ it('can read a normal IconStyle (and set the crossOrigin option)', function() {
+ format = new KML({crossOrigin: null});
+ const text =
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' normal' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '';
+ 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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://bar.png').href);
+ 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.be(null);
+ expect(style.getText()).to.be(getDefaultTextStyle());
+ expect(style.getZIndex()).to.be(undefined);
+ });
+
it('ignores highlight styles', function() {
const text =
'' +
@@ -2582,7 +2668,6 @@ describe('ol.format.KML', function() {
const s = styleArray[0];
expect(s).to.be.an(Style);
expect(s).to.be(getDefaultStyle());
-
});
it('uses normal styles instead of highlight styles', function() {
@@ -2701,7 +2786,7 @@ describe('ol.format.KML', function() {
' ' +
' normal' +
' #foo' +
- ' ' +
+ ' ' +
' ' +
' ' +
+ ' ' +
+ ' #fooMap' +
+ ' ' +
+ ' ' +
+ '';
+ 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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://bar.png').href);
+ 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.be(null);
+ expect(style.getText()).to.be(getDefaultTextStyle());
+ expect(style.getZIndex()).to.be(undefined);
+ });
+
});
describe('shared styles', function() {
@@ -2762,6 +2896,49 @@ describe('ol.format.KML', function() {
expect(fillStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
});
+ it('can apply a shared IconStyle to a feature (and set the crossOrigin option)', function() {
+ format = new KML({crossOrigin: null});
+ const text =
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' #foo' +
+ ' ' +
+ ' ' +
+ '';
+ 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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://bar.png').href);
+ 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.be(null);
+ expect(style.getText()).to.be(getDefaultTextStyle());
+ expect(style.getZIndex()).to.be(undefined);
+ });
+
it('can read a shared style from a Folder', function() {
const text =
'' +
@@ -2794,6 +2971,51 @@ describe('ol.format.KML', function() {
expect(fillStyle.getColor()).to.eql([0x78, 0x56, 0x34, 0x12 / 255]);
});
+ it('can read a shared IconStyle from a Folder (and set the crossOrigin option)', function() {
+ format = new KML({crossOrigin: null});
+ const text =
+ '' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' ' +
+ ' #foo' +
+ ' ' +
+ ' ' +
+ '';
+ 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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://bar.png').href);
+ 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.be(null);
+ expect(style.getText()).to.be(getDefaultTextStyle());
+ expect(style.getZIndex()).to.be(undefined);
+ });
+
it('can apply a shared style to multiple features', function() {
const text =
'' +