From e54074e6f1216a8dda11f1c7e3ac05cc58766c76 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Fri, 29 Feb 2008 18:39:37 +0000 Subject: [PATCH] Improve WFS reprojection: * Transform bbox back to layer projection * Transform commits back to layer projection r=tschaub, (Closes #1406) git-svn-id: http://svn.openlayers.org/trunk/openlayers@6422 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/wfs-reprojection.html | 169 +++++++++++++++++++++++++++++++++ lib/OpenLayers/Layer/WFS.js | 17 +++- 2 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 examples/wfs-reprojection.html diff --git a/examples/wfs-reprojection.html b/examples/wfs-reprojection.html new file mode 100644 index 0000000000..15f02eb5c3 --- /dev/null +++ b/examples/wfs-reprojection.html @@ -0,0 +1,169 @@ + + + + + + + + + + +

WFS Reprojection Example

+ +
+
+

+ Shows the use of the WFS layer reprojection support +

+ +
+ +
+

This example shows automatic WFS reprojection, displaying an 'unprojected' + WFS layer projected on the client side over Google Maps. The key configuration + here is the 'projection' option on the WFS layer.

+

Also shown is styleMap for the layer with unique value rules. Colors + are assigned based on the STATE_FIPS attribute.

+
+ + + + + + + + + + + + + + + + + +

WFS Reprojection Example

+ +
+
+

+ Shows the use of the WFS layer reprojection support +

+ +
+ +
+ This example shows automatic WFS reprojection, displaying an 'unprojected' WFS layer projected on the client side over Google Maps. The key configuration here is the 'projection' option on the WFS layer. +
+ + + + + + + diff --git a/lib/OpenLayers/Layer/WFS.js b/lib/OpenLayers/Layer/WFS.js index 5d501db61a..f7f9c950ec 100644 --- a/lib/OpenLayers/Layer/WFS.js +++ b/lib/OpenLayers/Layer/WFS.js @@ -277,6 +277,15 @@ OpenLayers.Layer.WFS = OpenLayers.Class( var params = {BBOX: this.encodeBBOX ? tileBounds.toBBOX() : tileBounds.toArray()}; + + if (this.map && !this.projection.equals(this.map.getProjectionObject())) { + var projectedBounds = tileBounds.clone(); + projectedBounds.transform(this.map.getProjectionObject(), + this.projection); + params.BBOX = this.encodeBBOX ? projectedBounds.toBBOX() + : projectedBounds.toArray(); + } + url += "&" + OpenLayers.Util.getParameterString(params); if (!this.tile) { @@ -434,7 +443,13 @@ OpenLayers.Layer.WFS = OpenLayers.Class( */ commit: function() { if (!this.writer) { - this.writer = new OpenLayers.Format.WFS({},this); + var options = {}; + if (this.map && !this.projection.equals(this.map.getProjectionObject())) { + options.externalProjection = this.projection; + options.internalProjection = this.map.getProjectionObject(); + } + + this.writer = new OpenLayers.Format.WFS(options,this); } var data = this.writer.write(this.features);