The writeFeatures method should always return a string

This commit is contained in:
Bart van den Eijnden
2014-12-04 16:58:52 +01:00
parent dfb55fb6a5
commit 3587418888
13 changed files with 174 additions and 102 deletions
+45 -31
View File
@@ -38,7 +38,7 @@ describe('ol.format.KML', function() {
it('can write a Feature', function() {
var features = [new ol.Feature()];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -50,11 +50,25 @@ describe('ol.format.KML', function() {
expect(node).to.xmleql(ol.xml.parse(text));
});
it('can write a Feature as string', function() {
var features = [new ol.Feature()];
var node = format.writeFeatures(features);
var 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/>' +
'</kml>';
expect(ol.xml.parse(node)).to.xmleql(ol.xml.parse(text));
});
it('can write a Feature\'s id', function() {
var feature = new ol.Feature();
feature.setId('foo');
var features = [feature];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -85,7 +99,7 @@ describe('ol.format.KML', function() {
it('can write feature with null geometries', function() {
var features = [new ol.Feature(null)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -193,7 +207,7 @@ describe('ol.format.KML', function() {
var layout = ol.geom.GeometryLayout.XY;
var point = new ol.geom.Point([1, 2], layout);
var features = [new ol.Feature(point)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -213,7 +227,7 @@ describe('ol.format.KML', function() {
var layout = ol.geom.GeometryLayout.XYZ;
var point = new ol.geom.Point([1, 2, 3], layout);
var features = [new ol.Feature(point)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -243,7 +257,7 @@ describe('ol.format.KML', function() {
var point = new ol.geom.Point([1, 2, 3], layout).transform(
'EPSG:4326', 'double');
var features = [new ol.Feature(point)];
var node = format.writeFeatures(features, {
var node = format.writeFeaturesNode(features, {
featureProjection: 'double'
});
var text =
@@ -270,7 +284,7 @@ describe('ol.format.KML', function() {
var layout = ol.geom.GeometryLayout.XYM;
var point = new ol.geom.Point([1, 2, 100], layout);
var features = [new ol.Feature(point)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -290,7 +304,7 @@ describe('ol.format.KML', function() {
var layout = ol.geom.GeometryLayout.XYZM;
var point = new ol.geom.Point([1, 2, 3, 100], layout);
var features = [new ol.Feature(point)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -328,7 +342,7 @@ describe('ol.format.KML', function() {
var layout = ol.geom.GeometryLayout.XY;
var lineString = new ol.geom.LineString([[1, 2], [3, 4]], layout);
var features = [new ol.Feature(lineString)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -349,7 +363,7 @@ describe('ol.format.KML', function() {
var lineString = new ol.geom.LineString(
[[1, 2, 3], [4, 5, 6]], layout);
var features = [new ol.Feature(lineString)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -370,7 +384,7 @@ describe('ol.format.KML', function() {
var lineString = new ol.geom.LineString(
[[1, 2, 100], [3, 4, 200]], layout);
var features = [new ol.Feature(lineString)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -391,7 +405,7 @@ describe('ol.format.KML', function() {
var lineString = new ol.geom.LineString(
[[1, 2, 3, 100], [4, 5, 6, 200]], layout);
var features = [new ol.Feature(lineString)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -430,7 +444,7 @@ describe('ol.format.KML', function() {
var linearRing = new ol.geom.LinearRing(
[[1, 2], [3, 4], [1, 2]], layout);
var features = [new ol.Feature(linearRing)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -451,7 +465,7 @@ describe('ol.format.KML', function() {
var linearRing = new ol.geom.LinearRing(
[[1, 2, 3], [4, 5, 6], [1, 2, 3]], layout);
var features = [new ol.Feature(linearRing)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -472,7 +486,7 @@ describe('ol.format.KML', function() {
var linearRing = new ol.geom.LinearRing(
[[1, 2, 100], [3, 4, 200], [1, 2, 100]], layout);
var features = [new ol.Feature(linearRing)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -493,7 +507,7 @@ describe('ol.format.KML', function() {
var linearRing = new ol.geom.LinearRing(
[[1, 2, 3, 100], [4, 5, 6, 200], [1, 2, 3, 100]], layout);
var features = [new ol.Feature(linearRing)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -537,7 +551,7 @@ describe('ol.format.KML', function() {
var polygon = new ol.geom.Polygon(
[[[0, 0], [0, 2], [2, 2], [2, 0], [0, 0]]], layout);
var features = [new ol.Feature(polygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -562,7 +576,7 @@ describe('ol.format.KML', function() {
var polygon = new ol.geom.Polygon(
[[[0, 0, 1], [0, 2, 2], [2, 2, 3], [2, 0, 4], [0, 0, 5]]], layout);
var features = [new ol.Feature(polygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -589,7 +603,7 @@ describe('ol.format.KML', function() {
var polygon = new ol.geom.Polygon(
[[[0, 0, 1], [0, 2, 1], [2, 2, 1], [2, 0, 1], [0, 0, 1]]], layout);
var features = [new ol.Feature(polygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -617,7 +631,7 @@ describe('ol.format.KML', function() {
[[[0, 0, 1, 1], [0, 2, 2, 1], [2, 2, 3, 1],
[2, 0, 4, 1], [0, 0, 5, 1]]], layout);
var features = [new ol.Feature(polygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -679,7 +693,7 @@ describe('ol.format.KML', function() {
[[1, 1, 0], [1, 2, 0], [2, 2, 0], [2, 1, 0]],
[[3, 3, 0], [3, 4, 0], [4, 4, 0], [4, 3, 0]]], layout);
var features = [new ol.Feature(polygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -737,7 +751,7 @@ describe('ol.format.KML', function() {
var multiPoint = new ol.geom.MultiPoint(
[[1, 2, 3], [4, 5, 6]], layout);
var features = [new ol.Feature(multiPoint)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -787,7 +801,7 @@ describe('ol.format.KML', function() {
var multiLineString = new ol.geom.MultiLineString(
[[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]], layout);
var features = [new ol.Feature(multiLineString)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -847,7 +861,7 @@ describe('ol.format.KML', function() {
[[[[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]]],
[[[3, 0, 0], [3, 1, 0], [4, 1, 0], [4, 0, 0]]]], layout);
var features = [new ol.Feature(multiPolygon)];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1126,7 +1140,7 @@ describe('ol.format.KML', function() {
feature.set('name', 'My name');
feature.set('phoneNumber', 'My phone number');
var features = [feature];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1148,7 +1162,7 @@ describe('ol.format.KML', function() {
feature.set('open', true);
feature.set('visibility', false);
var features = [feature];
var node = format.writeFeatures(features);
var node = format.writeFeaturesNode(features);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1583,7 +1597,7 @@ describe('ol.format.KML', function() {
imageStyle.iconImage_.size_ = [192, 144]; // sprite de 12 images(4*3)
var feature = new ol.Feature();
feature.setStyle([style]);
var node = format.writeFeatures([feature]);
var node = format.writeFeaturesNode([feature]);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1623,7 +1637,7 @@ describe('ol.format.KML', function() {
});
var feature = new ol.Feature();
feature.setStyle([style]);
var node = format.writeFeatures([feature]);
var node = format.writeFeaturesNode([feature]);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1652,7 +1666,7 @@ describe('ol.format.KML', function() {
});
var feature = new ol.Feature();
feature.setStyle([style]);
var node = format.writeFeatures([feature]);
var node = format.writeFeaturesNode([feature]);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -1679,7 +1693,7 @@ describe('ol.format.KML', function() {
});
var feature = new ol.Feature();
feature.setStyle([style]);
var node = format.writeFeatures([feature]);
var node = format.writeFeaturesNode([feature]);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +
@@ -2196,7 +2210,7 @@ describe('ol.format.KML', function() {
feature1.setId('1');
var feature2 = new ol.Feature();
feature2.setId('2');
var node = format.writeFeatures([feature1, feature2]);
var node = format.writeFeaturesNode([feature1, feature2]);
var text =
'<kml xmlns="http://www.opengis.net/kml/2.2"' +
' xmlns:gx="http://www.google.com/kml/ext/2.2"' +