diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index f2cdbca34f..5c6d1fd512 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -476,25 +476,22 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) { anchor = [0.5, 1]; anchorXUnits = ol.style.IconAnchorUnits.FRACTION; anchorYUnits = ol.style.IconAnchorUnits.FRACTION; - } else { - anchor = null; } + var rotation; var heading = /** @type {number|undefined} */ (goog.object.get(object, 'heading')); if (goog.isDef(heading)) { rotation = goog.math.toRadians(heading); - } else { - rotation = 0; } + var scale = /** @type {number|undefined} */ (goog.object.get(object, 'scale')); var size; if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) { size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_; - } else { - size = null; } + var imageStyle = new ol.style.Icon({ anchor: anchor, anchorXUnits: anchorXUnits, diff --git a/test/spec/ol/format/kmlformat.test.js b/test/spec/ol/format/kmlformat.test.js index 77609b60be..1dd15895e6 100644 --- a/test/spec/ol/format/kmlformat.test.js +++ b/test/spec/ol/format/kmlformat.test.js @@ -526,6 +526,42 @@ describe('ol.format.KML', function() { expect(style.getStroke().getWidth()).to.be(1); }); + it('can read a feature\'s IconStyle', function() { + var text = + '' + + ' ' + + ' ' + + ' ' + + ''; + var fs = format.readFeatures(text); + expect(fs).to.have.length(1); + var f = fs[0]; + expect(f).to.be.an(ol.Feature); + var styleFunction = f.getStyleFunction(); + expect(styleFunction).not.to.be(undefined); + var styleArray = styleFunction.call(f, 0); + expect(styleArray).to.be.an(Array); + expect(styleArray).to.have.length(1); + var style = styleArray[0]; + expect(style).to.be.an(ol.style.Style); + expect(style.getFill()).to.be(ol.format.KML.DEFAULT_FILL_STYLE_); + expect(style.getStroke()).to.be(ol.format.KML.DEFAULT_STROKE_STYLE_); + var imageStyle = style.getImage(); + expect(imageStyle).to.be.an(ol.style.Icon); + expect(imageStyle.getSrc()).to.eql('http://foo.png'); + expect(imageStyle.getAnchor()).to.eql([0.5, 0.5]); + expect(imageStyle.getRotation()).to.eql(0); + expect(imageStyle.getSize()).to.be(null); + expect(style.getText()).to.be(null); + expect(style.getZIndex()).to.be(undefined); + }); + it('can read a feature\'s LineStyle', function() { var text = '' + @@ -1440,5 +1476,6 @@ goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.Point'); goog.require('ol.geom.Polygon'); goog.require('ol.style.Fill'); +goog.require('ol.style.Icon'); goog.require('ol.style.Stroke'); goog.require('ol.style.Style');