diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 7ae1194b99..d61284c5b9 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -358,7 +358,8 @@ ol.format.KML.createNameStyleFunction_ = function(foundStyle, name) { * @param {Array.} defaultStyle Default style. * @param {Object.|string)>} sharedStyles Shared * styles. - * @param {boolean|undefined} showPointNames true to show names for point placemarks. + * @param {boolean|undefined} showPointNames true to show names for point + * placemarks. * @return {ol.FeatureStyleFunction} Feature style function. * @private */ @@ -377,7 +378,7 @@ ol.format.KML.createFeatureStyleFunction_ = function(style, styleUrl, var nameStyle; /** @type {string} */ var name = ''; - if (drawName){ + if (drawName) { if (this.getGeometry()) { drawName = (this.getGeometry().getType() === ol.geom.GeometryType.POINT); @@ -1804,7 +1805,8 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) { var style = object['Style']; var styleUrl = object['styleUrl']; var styleFunction = ol.format.KML.createFeatureStyleFunction_( - style, styleUrl, this.defaultStyle_, this.sharedStyles_, this.showPointNames_); + style, styleUrl, this.defaultStyle_, this.sharedStyles_, + this.showPointNames_); feature.setStyle(styleFunction); } delete object['Style']; diff --git a/test/spec/ol/format/kmlformat.test.js b/test/spec/ol/format/kmlformat.test.js index 86de2fe384..e5608800cf 100644 --- a/test/spec/ol/format/kmlformat.test.js +++ b/test/spec/ol/format/kmlformat.test.js @@ -1633,6 +1633,104 @@ describe('ol.format.KML', function() { expect(style.getZIndex()).to.be(undefined); }); + it('can create text style for named point placemarks', function() { + var text = + '' + + ' ' + + ' ' + + ' ' + + ' normal' + + ' #sn_ylw-pushpin' + + ' ' + + ' ' + + ' highlight' + + ' #sh_ylw-pushpin' + + ' ' + + ' ' + + ' ' + + ' Test' + + ' #msn_ylw-pushpin0' + + ' ' + + ' 1,2' + + ' ' + + ' ' + + ''; + 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(2); + var style = styleArray[1]; + expect(style).to.be.an(ol.style.Style); + expect(style.getText().getText()).to.eql(f.getProperties()['name']); + }); + + it('can create text style for named point placemarks', function() { + var text = + '' + + ' ' + + ' ' + + ' ' + + ' normal' + + ' #sn_ylw-pushpin' + + ' ' + + ' ' + + ' highlight' + + ' #sh_ylw-pushpin' + + ' ' + + ' ' + + ' ' + + ' Test' + + ' #msn_ylw-pushpin0' + + ' ' + + ' 1,2' + + ' ' + + ' ' + + ''; + 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(2); + var style = styleArray[1]; + expect(style).to.be.an(ol.style.Style); + expect(style.getText().getText()).to.eql(f.getProperties()['name']); + }); + it('can write an feature\'s icon style', function() { var style = new ol.style.Style({ image: new ol.style.Icon({