diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index c787d828be..6751f8d610 100644 --- a/src/objectliterals.jsdoc +++ b/src/objectliterals.jsdoc @@ -262,6 +262,8 @@ /** * @typedef {Object} olx.format.KMLOptions + * @property {Array.|undefined} defaultStyle Default style. The default + * default style is the same as Google Earth. * @property {boolean|undefined} extractAttributes Extract attributes. * @property {boolean|undefined} extractStyles Extract styles. */ diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index a9cb6483d3..aff6e5c5ad 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -65,10 +65,33 @@ ol.format.KMLGxTrackObject_; */ ol.format.KML = function(opt_options) { - //var options = goog.isDef(opt_options) ? opt_options : {}; + var options = goog.isDef(opt_options) ? opt_options : {}; goog.base(this); + var defaultStyle = goog.isDef(options.defaultStyle) ? + options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_; + + /** + * @private + * @type {ol.feature.FeatureStyleFunction} + */ + this.defaultFeatureStyleFunction_ = + /** + * @param {number} resolution Resolution. + * @this {ol.Feature} + * @return {Array.} Style. + */ + function(resolution) { + if (ol.KML_RESPECT_VISIBILITY) { + var visibility = this.get('visibility'); + if (goog.isDef(visibility) && !visibility) { + return null; + } + } + return defaultStyle; + }; + /** @type {Object.>} */ var sharedStyles = {}; @@ -248,23 +271,6 @@ ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = { }; -/** - * @param {number} resolution Resolution. - * @private - * @return {Array.} - * @this {ol.Feature} - */ -ol.format.KML.defaultFeatureStyleFunction_ = function(resolution) { - if (ol.KML_RESPECT_VISIBILITY) { - var visibility = this.get('visibility'); - if (goog.isDef(visibility) && !visibility) { - return null; - } - } - return ol.format.KML.DEFAULT_STYLE_ARRAY_; -}; - - /** * @param {ol.style.Style} style Style. * @private @@ -1449,7 +1455,7 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) { if (goog.isDef(styleUrl)) { featureStyleFunction = this.sharedStyleFeatureStyleFunction_; } else if (goog.isNull(style)) { - featureStyleFunction = ol.format.KML.defaultFeatureStyleFunction_; + featureStyleFunction = this.defaultFeatureStyleFunction_; } else { featureStyleFunction = ol.format.KML.makeFeatureStyleFunction_(style); }