diff --git a/src/objectliterals.jsdoc b/src/objectliterals.jsdoc index 3ffc24984c..fb1be4393a 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. */ @@ -579,6 +581,7 @@ /** * @typedef {Object} olx.source.KMLOptions * @property {Array.|undefined} attributions Attributions. + * @property {Array.|undefined} defaultStyle Default style. * @property {Document|undefined} doc Document. * @property {ol.Extent|undefined} extent Extent. * @property {string|undefined} logo Logo. 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); } diff --git a/src/ol/source/kmlsource.js b/src/ol/source/kmlsource.js index a10a5be288..9b645fb372 100644 --- a/src/ol/source/kmlsource.js +++ b/src/ol/source/kmlsource.js @@ -18,7 +18,9 @@ ol.source.KML = function(opt_options) { attributions: options.attributions, doc: options.doc, extent: options.extent, - format: new ol.format.KML(), + format: new ol.format.KML({ + defaultStyle: options.defaultStyle + }), logo: options.logo, node: options.node, projection: options.projection,