Add ol.format.KML defaultStyle option

This commit is contained in:
Tom Payne
2014-01-07 14:38:40 +01:00
parent 2cc4dd8985
commit 6b94baf291
2 changed files with 27 additions and 19 deletions

View File

@@ -262,6 +262,8 @@
/**
* @typedef {Object} olx.format.KMLOptions
* @property {Array.<ol.style.Style>|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.
*/

View File

@@ -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.<ol.style.Style>} Style.
*/
function(resolution) {
if (ol.KML_RESPECT_VISIBILITY) {
var visibility = this.get('visibility');
if (goog.isDef(visibility) && !visibility) {
return null;
}
}
return defaultStyle;
};
/** @type {Object.<string, Array.<ol.style.Style>>} */
var sharedStyles = {};
@@ -248,23 +271,6 @@ ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = {
};
/**
* @param {number} resolution Resolution.
* @private
* @return {Array.<ol.style.Style>}
* @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);
}