Merge pull request #726 from bartvde/kml_serialize
Small fixes for KML write (r=@ahocevar)
This commit is contained in:
@@ -51,6 +51,8 @@ ol.parser.KML = function(opt_options) {
|
|||||||
options.extractAttributes : true;
|
options.extractAttributes : true;
|
||||||
this.extractStyles = goog.isDef(options.extractStyles) ?
|
this.extractStyles = goog.isDef(options.extractStyles) ?
|
||||||
options.extractStyles : false;
|
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
|
// TODO re-evaluate once shared structures support 3D
|
||||||
this.dimension = goog.isDef(options.dimension) ? options.dimension : 3;
|
this.dimension = goog.isDef(options.dimension) ? options.dimension : 3;
|
||||||
this.maxDepth = goog.isDef(options.maxDepth) ? options.maxDepth : 0;
|
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': {
|
'http://www.opengis.net/kml/2.2': {
|
||||||
'kml': function(options) {
|
'kml': function(options) {
|
||||||
var node = this.createElementNS('kml');
|
var node = this.createElementNS('kml');
|
||||||
node.setAttribute('xmlns', this.defaultNamespaceURI);
|
|
||||||
this.writeNode('Document', options, null, node);
|
this.writeNode('Document', options, null, node);
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
@@ -1046,5 +1047,8 @@ ol.parser.KML.prototype.createGeometry_ = function(container,
|
|||||||
*/
|
*/
|
||||||
ol.parser.KML.prototype.write = function(obj) {
|
ol.parser.KML.prototype.write = function(obj) {
|
||||||
var root = this.writeNode('kml', 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);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,7 +156,10 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
expect(obj.features[0].get('name')).to.eql('Pezinok');
|
||||||
});
|
});
|
||||||
it('Test line style', function() {
|
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> ' +
|
'<Document><Placemark><Style><LineStyle> <color>870000ff</color> ' +
|
||||||
'<width>10</width> </LineStyle> </Style> <LineString> ' +
|
'<width>10</width> </LineStyle> </Style> <LineString> ' +
|
||||||
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
|
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
|
||||||
@@ -173,7 +176,7 @@ describe('ol.parser.kml', function() {
|
|||||||
expect(symbolizer.strokeWidth).to.eql(10);
|
expect(symbolizer.strokeWidth).to.eql(10);
|
||||||
});
|
});
|
||||||
it('Test style fill', function() {
|
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> ' +
|
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
||||||
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
||||||
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
||||||
@@ -188,7 +191,10 @@ describe('ol.parser.kml', function() {
|
|||||||
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
|
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
|
||||||
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
||||||
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
|
'</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> ' +
|
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
|
||||||
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
|
||||||
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
|
<NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
|
||||||
</Document>
|
</Document>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Placemark>
|
||||||
<name>Extended data placemark</name>
|
<name>Extended data placemark</name>
|
||||||
<description>Attached to the ground. Intelligently places itself
|
<description>Attached to the ground. Intelligently places itself
|
||||||
|
|||||||
@@ -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>
|
<Document>
|
||||||
<Placemark>
|
<Placemark>
|
||||||
<name>Easy trail</name>
|
<name>Easy trail</name>
|
||||||
|
|||||||
@@ -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>
|
<Document>
|
||||||
<Style id="pushpin">
|
<Style id="pushpin">
|
||||||
<IconStyle id="mystyle">
|
<IconStyle id="mystyle">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<name>LineString.kml</name>
|
<name>LineString.kml</name>
|
||||||
<open>1</open>
|
<open>1</open>
|
||||||
|
|||||||
@@ -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>
|
<Document>
|
||||||
<Camera>
|
<Camera>
|
||||||
<gx:TimeStamp>
|
<gx:TimeStamp>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<name>Polygon.kml</name>
|
<name>Polygon.kml</name>
|
||||||
<open>0</open>
|
<open>0</open>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<name>Polygon.kml</name>
|
<name>Polygon.kml</name>
|
||||||
<open>0</open>
|
<open>0</open>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<Placemark>
|
<Placemark>
|
||||||
<name>Simple placemark</name>
|
<name>Simple placemark</name>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<Placemark>
|
<Placemark>
|
||||||
<name>Simple placemark</name>
|
<name>Simple placemark</name>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<Placemark>
|
<Placemark>
|
||||||
<name>Simple placemark</name>
|
<name>Simple placemark</name>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<Document>
|
||||||
<name>Polygon.kml</name>
|
<name>Polygon.kml</name>
|
||||||
<open>0</open>
|
<open>0</open>
|
||||||
|
|||||||
Reference in New Issue
Block a user