Merge pull request #1481 from twpayne/vector-api-kml-default-style

[vector-api] Configurable default styling for KML
This commit is contained in:
Tom Payne
2014-01-09 02:43:48 -08:00
3 changed files with 31 additions and 20 deletions

View File

@@ -262,6 +262,8 @@
/** /**
* @typedef {Object} olx.format.KMLOptions * @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} extractAttributes Extract attributes.
* @property {boolean|undefined} extractStyles Extract styles. * @property {boolean|undefined} extractStyles Extract styles.
*/ */
@@ -579,6 +581,7 @@
/** /**
* @typedef {Object} olx.source.KMLOptions * @typedef {Object} olx.source.KMLOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions. * @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {Array.<ol.style.Style>|undefined} defaultStyle Default style.
* @property {Document|undefined} doc Document. * @property {Document|undefined} doc Document.
* @property {ol.Extent|undefined} extent Extent. * @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo. * @property {string|undefined} logo Logo.

View File

@@ -65,10 +65,33 @@ ol.format.KMLGxTrackObject_;
*/ */
ol.format.KML = function(opt_options) { 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); 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>>} */ /** @type {Object.<string, Array.<ol.style.Style>>} */
var sharedStyles = {}; 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. * @param {ol.style.Style} style Style.
* @private * @private
@@ -1449,7 +1455,7 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
if (goog.isDef(styleUrl)) { if (goog.isDef(styleUrl)) {
featureStyleFunction = this.sharedStyleFeatureStyleFunction_; featureStyleFunction = this.sharedStyleFeatureStyleFunction_;
} else if (goog.isNull(style)) { } else if (goog.isNull(style)) {
featureStyleFunction = ol.format.KML.defaultFeatureStyleFunction_; featureStyleFunction = this.defaultFeatureStyleFunction_;
} else { } else {
featureStyleFunction = ol.format.KML.makeFeatureStyleFunction_(style); featureStyleFunction = ol.format.KML.makeFeatureStyleFunction_(style);
} }

View File

@@ -18,7 +18,9 @@ ol.source.KML = function(opt_options) {
attributions: options.attributions, attributions: options.attributions,
doc: options.doc, doc: options.doc,
extent: options.extent, extent: options.extent,
format: new ol.format.KML(), format: new ol.format.KML({
defaultStyle: options.defaultStyle
}),
logo: options.logo, logo: options.logo,
node: options.node, node: options.node,
projection: options.projection, projection: options.projection,