[OpenLayers-Users] Some question on WFS projected maps

Tim Schaub noreply at geocartic.com
Tue Jun 19 15:48:06 EDT 2007


Hey Andrea-

Andrea Aime wrote:
> Hi,
> I'm trying to setup a WFS layer for WFS-T editing, but having a hard
> time doing so.
> The layer is projected, in EPSG:27700 projection. First of all, after
> lots of trial and error (and I mean, lots!) I managed to have the WFS
> layer display at all. The code looks more or less like:
> 
> ---------------------------------------------------------------------
> 
> map = new OpenLayers.Map( $('map') );
> OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
> var bounds = new 
> OpenLayers.Bounds(518772.8833465263,233451.16243928167,569351.5567723501,278119.59184872644)
> map.projection = "EPSG:27700";
> map.maxExtent = bounds;
> 

Check out 
http://trac.openlayers.org/wiki/FrequentlyAskedQuestions#Projections

If you want all layers to use this same projection related information 
(which you do), set the options on your map.  For example:

var options = {
     maxExtent: new OpenLayers.Bounds(minx, miny, maxx, maxy),
     projection: "EPSG:27700",
     maxResolution: 10,
     units: "meters"
};
var map = new OpenLayers.Map("map", options);

More below...

> // add the wms layer (we need a base layer, no matter what)
> var base = new OpenLayers.Layer.WMS(
>   "topp:mylayer", "http://localhost:8080/geoserver/wms",
>   {
>     height: '662', width: '800',
>     layers: 'topp:mylayer',
>     srs: 'EPSG:27700', format: 'image/png'
>   },
>   {
>     maxExtent: bounds, maxResolution: 200,
>     projection: "EPSG:27700"
>   }
> );
> map.addLayer(base);
> 
> // add the wfs layer
> layer = new OpenLayers.Layer.WFS(
>          "topp:mylayer", "/geoserver/wfs",
>          {
>            typename: 'topp:mylayer',
>            featureNS: 'http://www.openplans.org/topp',
>            extractAttributes: false
>          },
>          {
>            geometry_column : 'GEOLOC',
>            projection: 'EPSG:27700',
>            maxResolution: 10,
>            maxExtent: bounds
>          }
> );
> map.addLayer(layer);
> 
> -------------------------------------------------------------------
> 
> There are some non obvious bits that kept me from getting the layer 
> displayed at all:
> - geometry_column: this is a layer contained in a BDMS, and Geoserver 
> users the name of the db column for the geometry attribute, yet the
> code defaults to "the_geom" if geometry column is not provided
> (which is the default name for shapefiles in Geoserver)
> - projection: ok, did not know I had to set it
> - maxResolution: this is a projected map on a small area, if one
>    does not raise the maxResolution there is no way to have the layer
>    displayed. Yet, better not use the same value as WMS, since there
>    are too many geometries, and the WFS layer just kills Firefox as
>    a result. Using a max resolution 1/20 of the WMS layer I managed to
>    make the map display in reasonable times.

There are some drive-you-crazy issues with SVG rendering in Firefox. 
You may be exposing one of them.  Geometries with extents that are very 
large relative to the map viewport extent can cause problems.

> 
> Now, the question. I've added a DrawFeature control to the map, but
> no matter what, it does not work: it activates, but then I cannot see
> the lines I'm trying to draw on the screen.
> I guess there is a secret ingredient needed to make it work on
> projected coordinates, but I don't know what it is.
> Can anybody enlighten me? :)

I can't think of what secret ingredient you might be missing. 
OpenLayers defaults to a geographic projection/WGS84 datum - but there 
is no difference between this and any other coordinate reference system. 
  (Though you do have to figure out which parameters to set.)

You could be running up against this Firefox SVG issue again.  You might 
have better luck troubleshooting on #openlayers - I'd be interested in 
seeing what is happening.

Good luck,
Tim

> 
> Cheers
> Andrea
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list