Write placemark's ExtendedData tag after Style tag
This commit is contained in:
@@ -2674,22 +2674,12 @@ function writePlacemark(node, feature, objectStack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serialize properties (properties unknown to KML are not serialized)
|
// serialize properties (properties unknown to KML are not serialized)
|
||||||
const properties = feature.getProperties();
|
let properties = feature.getProperties();
|
||||||
|
|
||||||
// don't export these to ExtendedData
|
// don't export these to ExtendedData
|
||||||
const filter = {'address': 1, 'description': 1, 'name': 1, 'open': 1,
|
const filter = {'address': 1, 'description': 1, 'name': 1, 'open': 1,
|
||||||
'phoneNumber': 1, 'styleUrl': 1, 'visibility': 1};
|
'phoneNumber': 1, 'styleUrl': 1, 'visibility': 1};
|
||||||
filter[feature.getGeometryName()] = 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();
|
const styleFunction = feature.getStyleFunction();
|
||||||
if (styleFunction) {
|
if (styleFunction) {
|
||||||
@@ -2713,6 +2703,18 @@ function writePlacemark(node, feature, objectStack) {
|
|||||||
pushSerializeAndPop(context, PLACEMARK_SERIALIZERS,
|
pushSerializeAndPop(context, PLACEMARK_SERIALIZERS,
|
||||||
OBJECT_PROPERTY_NODE_FACTORY, values, objectStack, orderedKeys);
|
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
|
// serialize geometry
|
||||||
const options = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[0]);
|
const options = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[0]);
|
||||||
let geometry = feature.getGeometry();
|
let geometry = feature.getGeometry();
|
||||||
|
|||||||
@@ -1597,6 +1597,39 @@ describe('ol.format.KML', function() {
|
|||||||
expect(node).to.xmleql(parse(text));
|
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 =
|
||||||
|
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
|
||||||
|
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
|
||||||
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
|
||||||
|
' xsi:schemaLocation="http://www.opengis.net/kml/2.2' +
|
||||||
|
' https://developers.google.com/kml/schema/kml22gx.xsd">' +
|
||||||
|
' <Placemark>' +
|
||||||
|
' <Style>' +
|
||||||
|
' <LineStyle>' +
|
||||||
|
' <color>ff332211</color>' +
|
||||||
|
' <width>2</width>' +
|
||||||
|
' </LineStyle>' +
|
||||||
|
' </Style>' +
|
||||||
|
' <ExtendedData>' +
|
||||||
|
' <Data name="foo"/>' +
|
||||||
|
' </ExtendedData>' +
|
||||||
|
' </Placemark>' +
|
||||||
|
'</kml>';
|
||||||
|
expect(node).to.xmleql(parse(text));
|
||||||
|
});
|
||||||
|
|
||||||
it('can read ExtendedData', function() {
|
it('can read ExtendedData', function() {
|
||||||
const text =
|
const text =
|
||||||
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
|||||||
Reference in New Issue
Block a user