making reprojection work for all kinds of geometries. Thanks crschmidt for the tests. r=crschmidt (closes #3418)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12218 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1223,12 +1223,6 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
* {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 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
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 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
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"
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user