From 81f99f1579825bd7c6c63be3a995d9b45b270662 Mon Sep 17 00:00:00 2001 From: lucien Date: Tue, 7 May 2019 09:02:28 +0200 Subject: [PATCH 1/2] Write placemark's ExtendedData tag after Style tag --- src/ol/format/KML.js | 24 +++++++++++++----------- test/spec/ol/format/kml.test.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index dd32a1e641..a767242ce4 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -2674,22 +2674,12 @@ function writePlacemark(node, feature, objectStack) { } // serialize properties (properties unknown to KML are not serialized) - const properties = feature.getProperties(); + let properties = feature.getProperties(); // don't export these to ExtendedData const filter = {'address': 1, 'description': 1, 'name': 1, 'open': 1, 'phoneNumber': 1, 'styleUrl': 1, 'visibility': 1}; filter[feature.getGeometryName()] = 1; - const keys = Object.keys(properties || {}).sort().filter(function(v) { - return !filter[v]; - }); - - if (keys.length > 0) { - const sequence = makeSequence(properties, keys); - const namesAndValues = {names: keys, values: sequence}; - pushSerializeAndPop(context, PLACEMARK_SERIALIZERS, - EXTENDEDDATA_NODE_FACTORY, [namesAndValues], objectStack); - } const styleFunction = feature.getStyleFunction(); if (styleFunction) { @@ -2713,6 +2703,18 @@ function writePlacemark(node, feature, objectStack) { pushSerializeAndPop(context, PLACEMARK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys); + properties = feature.getProperties(); + const keys = Object.keys(properties || {}).sort().filter(function(v) { + return !filter[v]; + }); + + if (keys.length > 0) { + const sequence = makeSequence(properties, keys); + const namesAndValues = {names: keys, values: sequence}; + pushSerializeAndPop(context, PLACEMARK_SERIALIZERS, + EXTENDEDDATA_NODE_FACTORY, [namesAndValues], objectStack); + } + // serialize geometry const options = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[0]); let geometry = feature.getGeometry(); diff --git a/test/spec/ol/format/kml.test.js b/test/spec/ol/format/kml.test.js index 200570ebbf..b13c3051f7 100644 --- a/test/spec/ol/format/kml.test.js +++ b/test/spec/ol/format/kml.test.js @@ -1597,6 +1597,39 @@ describe('ol.format.KML', function() { expect(node).to.xmleql(parse(text)); }); + it('can write ExtendedData after Style tag', function() { + const style = new Style({ + stroke: new Stroke({ + color: '#112233', + width: 2 + }) + }); + const feature = new Feature(); + feature.set('foo', null); + feature.setStyle([style]); + const features = [feature]; + const node = format.writeFeaturesNode(features); + const text = + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + expect(node).to.xmleql(parse(text)); + }); + it('can read ExtendedData', function() { const text = '' + From 10c4ec0b37508bb3132d919fb12b47b3259891c2 Mon Sep 17 00:00:00 2001 From: lucien Date: Thu, 16 May 2019 09:10:40 +0200 Subject: [PATCH 2/2] Only use 'pushSerializeAndPop' later in code to write extendedData after --- src/ol/format/KML.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index a767242ce4..7f6abf5475 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -2674,12 +2674,15 @@ function writePlacemark(node, feature, objectStack) { } // serialize properties (properties unknown to KML are not serialized) - let properties = feature.getProperties(); + const properties = feature.getProperties(); // don't export these to ExtendedData const filter = {'address': 1, 'description': 1, 'name': 1, 'open': 1, 'phoneNumber': 1, 'styleUrl': 1, 'visibility': 1}; filter[feature.getGeometryName()] = 1; + const keys = Object.keys(properties || {}).sort().filter(function(v) { + return !filter[v]; + }); const styleFunction = feature.getStyleFunction(); if (styleFunction) { @@ -2703,11 +2706,6 @@ function writePlacemark(node, feature, objectStack) { pushSerializeAndPop(context, PLACEMARK_SERIALIZERS, OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys); - properties = feature.getProperties(); - const keys = Object.keys(properties || {}).sort().filter(function(v) { - return !filter[v]; - }); - if (keys.length > 0) { const sequence = makeSequence(properties, keys); const namesAndValues = {names: keys, values: sequence};