Skip to content

Commit

Permalink
Merge pull request #2477 from fredj/2475
Browse files Browse the repository at this point in the history
Add new olx.format.KMLOptions#extractStyles property
  • Loading branch information
Éric Lemoine committed Aug 8, 2014
2 parents 253d64d + 9e37aa7 commit 8959aaa
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/heatmap-earthquakes.js
Expand Up @@ -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'
}),
Expand Down
1 change: 1 addition & 0 deletions examples/kml-timezones.js
Expand Up @@ -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'
}),
Expand Down
18 changes: 17 additions & 1 deletion externs/olx.js
Expand Up @@ -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}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down
12 changes: 11 additions & 1 deletion src/ol/format/kmlformat.js
Expand Up @@ -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');

Expand Down Expand Up @@ -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)>}
Expand Down Expand Up @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions src/ol/source/kmlsource.js
Expand Up @@ -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,
Expand Down

0 comments on commit 8959aaa

Please sign in to comment.