diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 4cfaa99bf8..16b2a0d86b 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -163,6 +163,17 @@ ol.format.KML.NAMESPACE_URIS_ = [ ]; +/** + * @const + * @type {Array.} + * @private + */ +ol.format.KML.XSD_URIS_ = [ + 'http://www.opengis.net/kml/2.2', + 'https://developers.google.com/kml/schema/kml22gx.xsd' +]; + + /** * @const * @type {ol.Color} @@ -2516,9 +2527,14 @@ ol.format.KML.prototype.writeFeatures; * @inheritDoc */ ol.format.KML.prototype.writeFeaturesNode = function(features) { - var kml = ol.xml.createElementNS('http://earth.google.com/kml/2.2', 'kml'); - kml.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gx', - ol.format.KML.GX_NAMESPACE_URIS_[0]); + var kml = ol.xml.createElementNS('http://www.opengis.net/kml/2.2', 'kml'); + var xmlnsUri = 'http://www.w3.org/2000/xmlns/'; + var xmlSchemaInstanceUri = 'http://www.w3.org/2001/XMLSchema-instance'; + kml.setAttributeNS(xmlnsUri, 'xmlns:gx', ol.format.KML.GX_NAMESPACE_URIS_[0]); + kml.setAttributeNS(xmlnsUri, 'xmlns:xsi', xmlSchemaInstanceUri); + kml.setAttributeNS(xmlSchemaInstanceUri, 'xsi:schemaLocation', + ol.format.KML.XSD_URIS_.join(' ')); + var /** @type {ol.xml.NodeStackItem} */ context = {node: kml}; var properties = {}; if (features.length > 1) { diff --git a/test/spec/ol/format/kmlformat.test.js b/test/spec/ol/format/kmlformat.test.js index 494bd4e27f..64796ff84d 100644 --- a/test/spec/ol/format/kmlformat.test.js +++ b/test/spec/ol/format/kmlformat.test.js @@ -40,7 +40,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature()]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ''; expect(node).to.xmleql(ol.xml.load(text)); @@ -52,7 +56,11 @@ describe('ol.format.KML', function() { var features = [feature]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ''; expect(node).to.xmleql(ol.xml.load(text)); @@ -79,7 +87,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(null)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ''; expect(node).to.xmleql(ol.xml.load(text)); @@ -87,7 +99,11 @@ describe('ol.format.KML', function() { it('can read Point geometries', function() { var text = - '' + + '' + ' ' + ' ' + ' 1,2,3' + @@ -109,7 +125,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(point)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2' + @@ -125,7 +145,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(point)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3' + @@ -141,7 +165,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(point)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2' + @@ -157,7 +185,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(point)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3' + @@ -191,7 +223,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(lineString)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2 3,4' + @@ -208,7 +244,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(lineString)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3 4,5,6' + @@ -225,7 +265,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(lineString)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2 3,4' + @@ -242,7 +286,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(lineString)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3 4,5,6' + @@ -277,7 +325,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(linearRing)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2 3,4 1,2' + @@ -294,7 +346,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(linearRing)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3 4,5,6 1,2,3' + @@ -311,7 +367,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(linearRing)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2 3,4 1,2' + @@ -328,7 +388,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(linearRing)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' 1,2,3 4,5,6 1,2,3' + @@ -368,7 +432,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(polygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -389,7 +457,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(polygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -412,7 +484,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(polygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -436,7 +512,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(polygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -494,7 +574,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(polygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -548,7 +632,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(multiPoint)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -594,7 +682,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(multiLineString)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -650,7 +742,11 @@ describe('ol.format.KML', function() { var features = [new ol.Feature(multiPolygon)]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' ' + ' ' + @@ -925,7 +1021,11 @@ describe('ol.format.KML', function() { var features = [feature]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + '
My address
' + ' My description' + @@ -943,7 +1043,11 @@ describe('ol.format.KML', function() { var features = [feature]; var node = format.writeFeatures(features); var text = - '' + + '' + ' ' + ' 1' + ' 0' + @@ -1339,8 +1443,11 @@ describe('ol.format.KML', function() { feature.setStyle([style]); var node = format.writeFeatures([feature]); var text = - '' + + '' + ' ' + '