[OpenLayers-Users] WFS reprojection on Google Maps

Luís de Sousa luis.a.de.sousa at gmail.com
Mon May 9 06:21:42 EDT 2011


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&amp;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&typename=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>


More information about the Users mailing list