Merge pull request #2477 from fredj/2475

Add new olx.format.KMLOptions#extractStyles property
This commit is contained in:
Éric Lemoine
2014-08-08 08:57:15 +02:00
5 changed files with 31 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ goog.require('ol.source.Stamen');
var vector = new ol.layer.Heatmap({
source: new ol.source.KML({
extractStyles: false,
projection: 'EPSG:3857',
url: 'data/kml/2012_Earthquakes_Mag5.kml'
}),

View File

@@ -46,6 +46,7 @@ var styleFunction = function(feature, resolution) {
var vector = new ol.layer.Vector({
source: new ol.source.KML({
extractStyles: false,
projection: 'EPSG:3857',
url: 'data/kml/timezones.kml'
}),

View File

@@ -1221,12 +1221,20 @@ olx.format.IGCOptions.prototype.altitudeMode;
/**
* @typedef {{defaultStyle: (Array.<ol.style.Style>|undefined)}}
* @typedef {{extractStyles: (boolean|undefined),
* defaultStyle: (Array.<ol.style.Style>|undefined)}}
* @api
*/
olx.format.KMLOptions;
/**
* Extract styles from the KML. Default is `true`.
* @type {boolean|undefined}
*/
olx.format.KMLOptions.prototype.extractStyles;
/**
* Default style. The default default style is the same as Google Earth.
* @type {Array.<ol.style.Style>|undefined}
@@ -3310,6 +3318,7 @@ olx.source.MapGuideOptions.prototype.params;
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* defaultStyle: (Array.<ol.style.Style>|undefined),
* doc: (Document|undefined),
* extractStyles: (boolean|undefined),
* logo: (string|olx.LogoOptions|undefined),
* node: (Node|undefined),
* projection: ol.proj.ProjectionLike,
@@ -3342,6 +3351,13 @@ olx.source.KMLOptions.prototype.defaultStyle;
olx.source.KMLOptions.prototype.doc;
/**
* Extract styles from the KML document. Default is `true`.
* @type {boolean|undefined}
*/
olx.source.KMLOptions.prototype.extractStyles;
/**
* Logo.
* @type{string|olx.LogoOptions|undefined}

View File

@@ -2,6 +2,7 @@
// FIXME why does node.getAttribute return an unknown type?
// FIXME text
// FIXME serialize arbitrary feature properties
// FIXME don't parse style if extractStyles is false
goog.provide('ol.format.KML');
@@ -98,6 +99,13 @@ ol.format.KML = function(opt_options) {
}
};
/**
* @private
* @type {boolean}
*/
this.extractStyles_ = goog.isDef(options.extractStyles) ?
options.extractStyles : true;
/**
* @private
* @type {Object.<string, (Array.<ol.style.Style>|string)>}
@@ -1427,7 +1435,9 @@ ol.format.KML.prototype.readPlacemark_ = function(node, objectStack) {
feature.setId(id);
}
feature.setProperties(object);
feature.setStyle(this.featureStyleFunction_);
if (this.extractStyles_) {
feature.setStyle(this.featureStyleFunction_);
}
return feature;
};

View File

@@ -23,6 +23,7 @@ ol.source.KML = function(opt_options) {
attributions: options.attributions,
doc: options.doc,
format: new ol.format.KML({
extractStyles: options.extractStyles,
defaultStyle: options.defaultStyle
}),
logo: options.logo,