[OpenLayers-Commits] r12218 - in trunk/openlayers:
lib/OpenLayers/Format tests/Format
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Aug 8 09:51:58 EDT 2011
Author: ahocevar
Date: 2011-08-08 06:51:56 -0700 (Mon, 08 Aug 2011)
New Revision: 12218
Modified:
trunk/openlayers/lib/OpenLayers/Format/KML.js
trunk/openlayers/tests/Format/KML.html
Log:
making reprojection work for all kinds of geometries. Thanks crschmidt for the tests. r=crschmidt (closes #3418)
Modified: trunk/openlayers/lib/OpenLayers/Format/KML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/KML.js 2011-08-08 13:43:14 UTC (rev 12217)
+++ trunk/openlayers/lib/OpenLayers/Format/KML.js 2011-08-08 13:51:56 UTC (rev 12218)
@@ -1223,12 +1223,6 @@
* {DOMElement}
*/
buildGeometryNode: function(geometry) {
- if (this.internalProjection && this.externalProjection &&
- !(geometry instanceof OpenLayers.Geometry.Collection)) {
- geometry = geometry.clone();
- geometry.transform(this.internalProjection,
- this.externalProjection);
- }
var className = geometry.CLASS_NAME;
var type = className.substring(className.lastIndexOf(".") + 1);
var builder = this.buildGeometry[type.toLowerCase()];
@@ -1413,12 +1407,12 @@
var parts = new Array(numPoints);
for(var i=0; i<numPoints; ++i) {
point = points[i];
- parts[i] = point.x + "," + point.y;
+ parts[i] = this.buildCoordinates(point);
}
path = parts.join(" ");
} else {
// Point
- path = geometry.x + "," + geometry.y;
+ path = this.buildCoordinates(geometry);
}
var txtNode = this.createTextNode(path);
@@ -1426,6 +1420,24 @@
return coordinatesNode;
},
+
+ /**
+ * Method: buildCoordinates
+ *
+ * Parameters:
+ * point - {<OpenLayers.Geometry.Point>}
+ *
+ * Returns
+ * {String} a coordinate pair
+ */
+ buildCoordinates: function(point) {
+ if (this.internalProjection && this.externalProjection) {
+ point = point.clone();
+ point.transform(this.internalProjection,
+ this.externalProjection);
+ }
+ return point.x + "," + point.y;
+ },
CLASS_NAME: "OpenLayers.Format.KML"
});
Modified: trunk/openlayers/tests/Format/KML.html
===================================================================
--- trunk/openlayers/tests/Format/KML.html 2011-08-08 13:43:14 UTC (rev 12217)
+++ trunk/openlayers/tests/Format/KML.html 2011-08-08 13:51:56 UTC (rev 12218)
@@ -230,6 +230,18 @@
};
t.eq(f.read(f.write(feature))[0].attributes.name, feature.style.label, "placemark name from style.label");
}
+ function test_Format_KML_linestring_projected(t) {
+ t.plan(1);
+ var f = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(15555162, 4247484), new OpenLayers.Geometry.Point(15555163, 4247485)]));
+ var format = new OpenLayers.Format.KML({
+ internalProjection: new OpenLayers.Projection("EPSG:900913"),
+ externalProjection: new OpenLayers.Projection("EPSG:4326")
+ });
+ var data = format.write(f);
+ var found = (data.search('139.734') != -1);
+ t.ok(found, "Found 139.734 (correct reprojection) in data output.");
+ }
function test_extractTracks(t) {
More information about the Commits
mailing list