Merge pull request #726 from bartvde/kml_serialize

Small fixes for KML write (r=@ahocevar)
This commit is contained in:
Bart van den Eijnden
2013-05-23 07:36:33 -07:00
14 changed files with 30 additions and 17 deletions

View File

@@ -51,6 +51,8 @@ ol.parser.KML = function(opt_options) {
options.extractAttributes : true;
this.extractStyles = goog.isDef(options.extractStyles) ?
options.extractStyles : false;
this.schemaLocation = 'http://www.opengis.net/kml/2.2 ' +
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd';
// TODO re-evaluate once shared structures support 3D
this.dimension = goog.isDef(options.dimension) ? options.dimension : 3;
this.maxDepth = goog.isDef(options.maxDepth) ? options.maxDepth : 0;
@@ -557,7 +559,6 @@ ol.parser.KML = function(opt_options) {
'http://www.opengis.net/kml/2.2': {
'kml': function(options) {
var node = this.createElementNS('kml');
node.setAttribute('xmlns', this.defaultNamespaceURI);
this.writeNode('Document', options, null, node);
return node;
},
@@ -1046,5 +1047,8 @@ ol.parser.KML.prototype.createGeometry_ = function(container,
*/
ol.parser.KML.prototype.write = function(obj) {
var root = this.writeNode('kml', obj);
return goog.dom.xml.serialize(root);
this.setAttributeNS(
root, 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation', this.schemaLocation);
return this.serialize(root);
};

View File

@@ -156,7 +156,10 @@ describe('ol.parser.kml', function() {
expect(obj.features[0].get('name')).to.eql('Pezinok');
});
it('Test line style', function() {
var test_style = '<kml xmlns="http://www.opengis.net/kml/2.2"> ' +
var test_style = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd"> ' +
'<Document><Placemark><Style><LineStyle> <color>870000ff</color> ' +
'<width>10</width> </LineStyle> </Style> <LineString> ' +
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
@@ -173,7 +176,7 @@ describe('ol.parser.kml', function() {
expect(symbolizer.strokeWidth).to.eql(10);
});
it('Test style fill', function() {
var test_style_fill = '<kml xmlns="http://www.opengis.net/kml/2.2"> ' +
var test_style_fill = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
@@ -188,7 +191,10 @@ describe('ol.parser.kml', function() {
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
var style_fill_write = '<kml xmlns="http://www.opengis.net/kml/2.2"> ' +
var style_fill_write = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:schemaLocation="http://www.opengis.net/kml/2.2 ' +
'http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd"> ' +
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
</Document>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Placemark>
<name>Extended data placemark</name>
<description>Attached to the ground. Intelligently places itself

View File

@@ -1,4 +1,5 @@
<kml xmlns="http://earth.google.com/kml/2.2">
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Placemark>
<name>Easy trail</name>

View File

@@ -1,4 +1,5 @@
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<?xml version="1.0" encoding="UTF-8"?>
<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 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Style id="pushpin">
<IconStyle id="mystyle">

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<name>LineString.kml</name>
<open>1</open>

View File

@@ -1,4 +1,5 @@
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
<?xml version="1.0" encoding="UTF-8"?>
<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 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Camera>
<gx:TimeStamp>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<name>Polygon.kml</name>
<open>0</open>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<name>Polygon.kml</name>
<open>0</open>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Placemark>
<name>Simple placemark</name>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Placemark>
<name>Simple placemark</name>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Placemark>
<name>Simple placemark</name>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<name>Polygon.kml</name>
<open>0</open>