Add a writeStyles option to KML format
This commit is contained in:
@@ -92,6 +92,13 @@ ol.format.KML = function(opt_options) {
|
||||
this.extractStyles_ = options.extractStyles !== undefined ?
|
||||
options.extractStyles : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.writeStyles_ = options.writeStyles !== undefined ?
|
||||
options.writeStyles : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, (Array.<ol.style.Style>|string)>}
|
||||
@@ -2169,6 +2176,7 @@ ol.format.KML.writeCoordinatesTextNode_ =
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @this {ol.format.KML}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.writeDocument_ = function(node, features, objectStack) {
|
||||
@@ -2366,6 +2374,7 @@ ol.format.KML.writeBoundaryIs_ = function(node, linearRing, objectStack) {
|
||||
* @param {Node} node Node.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @this {ol.format.KML}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
|
||||
@@ -2378,14 +2387,18 @@ ol.format.KML.writePlacemark_ = function(node, feature, objectStack) {
|
||||
|
||||
// serialize properties (properties unknown to KML are not serialized)
|
||||
var properties = feature.getProperties();
|
||||
|
||||
var styleFunction = feature.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
// FIXME the styles returned by the style function are supposed to be
|
||||
// resolution-independent here
|
||||
var styles = styleFunction.call(feature, 0);
|
||||
if (styles && styles.length > 0) {
|
||||
properties['Style'] = styles[0];
|
||||
var textStyle = styles[0].getText();
|
||||
var style = styles[0];
|
||||
if (this.writeStyles_) {
|
||||
properties['Style'] = styles[0];
|
||||
}
|
||||
var textStyle = style.getText();
|
||||
if (textStyle) {
|
||||
properties['name'] = textStyle.getText();
|
||||
}
|
||||
@@ -2988,6 +3001,7 @@ ol.format.KML.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||
var orderedKeys = ol.format.KML.KML_SEQUENCE_[kml.namespaceURI];
|
||||
var values = ol.xml.makeSequence(properties, orderedKeys);
|
||||
ol.xml.pushSerializeAndPop(context, ol.format.KML.KML_SERIALIZERS_,
|
||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys);
|
||||
ol.xml.OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys,
|
||||
this);
|
||||
return kml;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user