AW: [OpenLayers-Users] WFS reprojection on Google Maps
Arnd Wippermann
arnd.wippermann at web.de
Mon May 9 15:39:25 EDT 2011
Hi,
If you want to use projections other than EPSG:4326 or EPSG:900913 in
connection with vectors, you have to add proj4js.
With proj4js and your projection EPSG:3763
Proj4js.defs["EPSG:3763"] = "+proj=tmerc +lat_0=39.66825833333333
+lon_0=-8.133108333333334 +k=1 +x_0=0 +y_0=0 +ellps=GRS80 +units=m
+no_defs";
the bbox for the wfs request is transformed from EPSG:900913
(map.projection) to EPSG:3763 as declared in your WFS layer. Then your wfs
server should send the data.
map = new OpenLayers.Map('map');
If you set no options on your map object, then projection EPSG:4326 is used.
You should use always options to set things to defined properties.
Here you have to set EPSG:4326
map.setCenter(new OpenLayers.LonLat(-8, 39).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 7);
Arnd
-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Luís de
Sousa
Gesendet: Montag, 9. Mai 2011 12:22
An: Andreas Hocevar
Cc: users at openlayers.org
Betreff: Re: [OpenLayers-Users] WFS reprojection on Google Maps
Thank you all for the help so far, the WFS reprojection is working perfectly
fine now with the Tasmania data.
Now I need to add WFS layers in a different SRS to the map. I used the same
setup as I used for the Tasmania data, but the reprojection is not working
in this case, the shapes are being rendered at the Gulf of Guinea, around
the (0,0) origin of the Spherical Mercator system. It seems I'm not
providing enough information for the reprojection.
The code goes below. Thanks in advance for your help,
Luís
--------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width;
initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<style type="text/css">
#map {
width: 560px;
height: 460px;
border: 1px solid black;
}
</style>
<script
src="http://localhost:8090/geoserver/www/OpenLayers-2.10/OpenLayers.js"
type="text/javascript"></script>
<!-- Google API-->
<script
src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script defer="defer" type="text/javascript">
var map;
function init() {
var extent = new OpenLayers.Bounds(
-11593508, 5509847, -11505759, 5557774
);
var options = {
// the "community" epsg code for spherical mercator
projection: "EPSG:900913",
//displayProjection: new OpenLayers.Projection("EPSG:4326"),
displayProjection: new OpenLayers.Projection("EPSG:3763"),
// map horizontal units are meters
units: "m",
// this resolution displays the globe in one 256x256 pixel
tile
maxResolution: 78271.51695,
// these are the bounds of the globe in sperical mercator
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508),
restrictedExtent: extent,
};
map = new OpenLayers.Map('map');
map.addControl(new OpenLayers.Control.LayerSwitcher());
var gphy = new OpenLayers.Layer.Google(
"Google Physical",
{type: google.maps.MapTypeId.TERRAIN}
);
var gmap = new OpenLayers.Layer.Google(
"Google Streets", // the default
{numZoomLevels: 20}
);
var ghyb = new OpenLayers.Layer.Google(
"Google Hybrid",
{type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
);
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
);
var arht = new OpenLayers.Layer.Vector("Limites ARHT", {
strategies: [new OpenLayers.Strategy.BBOX()],
projection: new OpenLayers.Projection("EPSG:3763"),
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0",
srsName: "EPSG:3763",
url: "http://localhost:8090/geoserver/wfs",
featureNS : "http://www.arhtejo.pt",
featureType: "LimitesARHT",
schema:
"http://localhost:8090/geoserver/wfs/DescribeFeatureType?version=1.1.0&typen
ame=ARH:LimitesARHT"
})
});
map.addLayers([gphy, gmap, ghyb, gsat, arht]);
// Google.v3 uses EPSG:900913 as projection, so we have to
// transform our coordinates
map.setCenter(new OpenLayers.LonLat(-8, 39).transform(
new OpenLayers.Projection("EPSG:3763"),
map.getProjectionObject()
), 7);
}
</script>
</head>
<body onload="init()">
<h5>This is a test with Google Maps v3.</h5>
<div id="map" class="smallmap"></div>
</body>
</html>
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
More information about the Users
mailing list