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);