[OpenLayers-Users] WFS reprojection on Google Maps
Andreas Hocevar
ahocevar at opengeo.org
Thu May 5 06:00:43 EDT 2011
Hey,
OpenLayers.Layer.WFS is depracated. See
http://openlayers.org/dev/examples/wfs-protocol-transactions.html for
an example of how to overlay WFS layers properly on a Web Mercator
map.
Note, however, that the main issue in your code is not the fact that
you are using OpenLayers.Layer.WFS (it seems like it is configured
properly), but missing map configuration parameters (units,
maxResolution, maxExtent). You either have to set them manually, or
use GMaps v3 instead of v2, because OpenLayers.Layer.Google v3 base
layers have these settings configured already. See
http://openlayers.org/dev/examples/google-v3.html for an example on
how to use v3.
Also note that as soon as you work with Web Mercator maps, you cannot
specify coordinates in longitude/latitude. If you do so, you need to
transform them, which is also shown in the google-v3 example I linked
above.
Regards,
Andreas.
2011/5/4 Luís de Sousa <luis.a.de.sousa at gmail.com>:
> Dear all,
>
> I've been trying to reproject WFS layers on Google Maps without
> success. After reading several threads here and elsewhere it became
> apparent that WFS 1.1.0 takes care of reprojections by itself, without any
> processing needed client side. Hence I tried simply to reproject the
> Tazmania shapes from Geoserver on a Google Maps base layer; while the
> WFS layers are indeed there, they do not seem to have been reprojected:
>
> http://www.flickr.com/photos/46630302@N04/5686739802/in/set-72157626519940667/
>
> Below goes the code, note that I'm using a local version of Geoserver
> on port 8090. I'd thank if anyone could hint at what I'm missing.
>
> Thanks,
>
> Luís
>
> -----
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <style type="text/css">
> #map {
> width: 560px;
> height: 460px;
> border: 1px solid black;
> }
> </style>
>
> <script src="http://localhost:8090/geoserver/www/OpenLayers-2.9/OpenLayers.js"
> type="text/javascript"></script>
>
> <!-- Google API-->
> <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
>
> <script defer="defer" type="text/javascript">
>
> function init(){
>
> var map = new OpenLayers.Map("map", {
> projection: new OpenLayers.Projection("EPSG:900913")
> });
>
> var gphy = new OpenLayers.Layer.Google(
> "Google Physical",
> {type: G_PHYSICAL_MAP}
> );
>
> var roads = new OpenLayers.Layer.WFS(
> "Roads",
> "http://localhost:8090/geoserver/wfs",
> {typename: 'topp:tasmania_roads'},
> {
> typename: 'tasmania_roads',
> featureNS: 'http://www.openplans.org/topp',
> extractAttributes: false,
> version: "1.1.0",
> srsName: "EPSG:900913"
> }
> );
> roads.style = OpenLayers.Util.applyDefaults(
> {strokeWidth: 2, strokeColor: "#ff0000"},
> OpenLayers.Feature.Vector.style["default"]);
>
> var states = new OpenLayers.Layer.WFS(
> "States",
> "http://localhost:8090/geoserver/wfs",
> {typename: 'topp:tasmania_state_boundaries'},
> {
> typename: 'tasmania_state_boundaries',
> featureNS: 'http://www.openplans.org/topp',
> extractAttributes: false,
> version: "1.1.0",
> srsName: "EPSG:900913"
> }
> );
> states.style = OpenLayers.Util.applyDefaults(
> {strokeWidth: 3, strokeColor: "#333333"},
> OpenLayers.Feature.Vector.style["default"]);
>
> map.addLayers([gphy, roads, states]);
>
> map.addControl(new OpenLayers.Control.Navigation());
> map.addControl(new OpenLayers.Control.LayerSwitcher());
>
> map.setCenter(new OpenLayers.LonLat(147, -42), 7);
>
> }
> </script>
>
> </head>
> <body onload="init()">
> <h5>This is a reprojection test on Google Maps.</h5>
> <div id="map"> </div>
> </body>
> </html>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list