Formats now support reprojection using internalProjection and

externalProjection properties. These allow for the reprojection of data --
OpenLayers users with SphericalMercator get this built in for EPSG:900913, and
other users can use the external proj4js library available from MapBuilder SVN
to add support for any number of projections. This means that featres can be,
for example, transformed from a KML doc in 4326 to Spherical Mercator before
being added to a layer, making using SphericalMercator slightly more enticing. 
r=elemoine
(Closes #1039)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5516 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-19 22:07:12 +00:00
parent 7440556585
commit 6d6c08fbef
8 changed files with 128 additions and 11 deletions
+9
View File
@@ -147,6 +147,10 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
var parser = this.parseGeometry[type.toLowerCase()];
if(parser) {
geometry = parser.apply(this, [nodeList[0]]);
if (this.internalProjection && this.externalProjection) {
geometry.transform(this.externalProjection,
this.internalProjection);
}
} else {
OpenLayers.Console.error("Unsupported geometry type: " +
type);
@@ -619,6 +623,11 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, {
* APIMethod: buildGeometryNode
*/
buildGeometryNode: function(geometry) {
if (this.externalProjection && this.internalProjection) {
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()];
+9
View File
@@ -231,6 +231,10 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
throw err;
}
}
if (this.internalProjection && this.externalProjection) {
geometry.transform(this.externalProjection,
this.internalProjection);
}
return geometry;
},
@@ -526,6 +530,11 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
* {Object} An object representing the geometry.
*/
'geometry': function(geometry) {
if (this.internalProjection && this.externalProjection) {
geometry = geometry.clone();
geometry.transform(this.internalProjection,
this.externalProjection);
}
var geometryType = geometry.CLASS_NAME.split('.')[2];
var data = this.extract[geometryType.toLowerCase()].apply(this, [geometry]);
var json;
+11
View File
@@ -152,6 +152,12 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
var feature = this.gmlParser.parseFeature(where[0]);
geometry = feature.geometry;
}
if (this.internalProjection && this.externalProjection) {
geometry.transform(this.externalProjection,
this.internalProjection);
}
return geometry;
},
@@ -324,6 +330,11 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
* {DOMElement} A gml node.
*/
buildGeometryNode: function(geometry) {
if (this.internalProjection && this.externalProjection) {
geometry = geometry.clone();
geometry.transform(this.internalProjection,
this.externalProjection);
}
var node;
// match Polygon
if (geometry.CLASS_NAME == "OpenLayers.Geometry.Polygon") {
+9
View File
@@ -132,6 +132,10 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
var parser = this.parseGeometry[type.toLowerCase()];
if(parser) {
geometry = parser.apply(this, [nodeList[0]]);
if (this.internalProjection && this.externalProjection) {
geometry.transform(this.externalProjection,
this.internalProjection);
}
} else {
OpenLayers.Console.error("Unsupported geometry type: " +
type);
@@ -450,6 +454,11 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
* {DOMElement}
*/
buildGeometryNode: function(geometry) {
if (this.internalProjection && this.externalProjection) {
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()];
+4
View File
@@ -94,6 +94,10 @@ OpenLayers.Format.Text = OpenLayers.Class(OpenLayers.Format, {
}
}
if (set) {
if (this.internalProjection && this.externalProjection) {
geometry.transform(this.externalProjection,
this.internalProjection);
}
var feature = new OpenLayers.Feature.Vector(geometry, attributes, style);
features.push(feature);
}
+19 -1
View File
@@ -60,7 +60,20 @@ OpenLayers.Format.WKT = OpenLayers.Class(OpenLayers.Format, {
if(this.parse[type]) {
features = this.parse[type].apply(this, [str]);
}
}
if (this.internalProjection && this.externalProjection) {
if (features &&
features.CLASS_NAME == "OpenLayers.Feature.Vector") {
features.geometry.transform(this.externalProjection,
this.internalProjection);
} else if (features && typeof features == "object") {
for (var i = 0; i < features.length; i++) {
var component = features[i];
component.geometry.transform(this.externalProjection,
this.internalProjection);
}
}
}
}
return features;
},
@@ -97,6 +110,11 @@ OpenLayers.Format.WKT = OpenLayers.Class(OpenLayers.Format, {
if(!this.extract[type]) {
return null;
}
if (this.internalProjection && this.externalProjection) {
geometry = geometry.clone();
geometry.transform(this.internalProjection,
this.externalProjection);
}
data = this.extract[type].apply(this, [geometry]);
pieces.push(type.toUpperCase() + '(' + data + ')');
}