[OpenLayers-Users] reprojection problem

Didrik Pinte lists at dipole-consulting.com
Wed Nov 12 05:37:09 EST 2008


On Mon, 2008-11-10 at 21:30 -0500, Christopher Schmidt wrote:
> 
> http://openlayers.org/pipermail/users/2008-November/008615.html , 
> http://faq.openlayers.org/vector-related-questions/why-dont-my-vector-features-work-over-google-yahoo-virtual-earth-etc/ , 
> http://crschmidt.net/~crschmidt/spherical_mercator.html#reprojecting-vector-data


Hi Christopher,
Hi list,

I have tested the reprojection according to your doc but it does not
work. 

See the very simple attached example. They are two points that should be
in the south of France but they appear in the south atlantic ...The two
points are latlon coordinates (EPSG:4326) and the map is set to a
sphericalMercator projection.

Example  :
---------------------------------------------------------------------------------------
<html>
<head>
  <title>Test with mercator projection</title>
    
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    
    <script
src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
    </head>    

    <body>
     <div id="map"y></div>
    
    <script defer="defer" type="text/javascript">
        var mapOptions = {
           projection: new OpenLayers.Projection("EPSG:900913") ,
           displayProjection: new OpenLayers.Projection("EPSG:4326")
        };
    
       var  map = new OpenLayers.Map('map', mapOptions);

        var gphy = new OpenLayers.Layer.Google(
                "Google Physical",
                {type: G_PHYSICAL_MAP, 
                 sphericalMercator: true}
            );
      
        var test_layer = new OpenLayers.Layer.Vector('Tests', {
            projection: new OpenLayers.Projection("EPSG:4326")
        });
        
        var p1 =  new OpenLayers.Geometry.Point(-0.8751825,
43.5078933333333)
        var feat1 = new OpenLayers.Feature.Vector(p1);
        var p2 = new OpenLayers.Geometry.Point(-0.9251825,
43.4578933333333)
        var feat2 = new OpenLayers.Feature.Vector(p2);
        test_layer.addFeatures([feat1, feat2]);

        map.addControl(new OpenLayers.Control.PanZoomBar());
        map.addControl(new OpenLayers.Control.NavToolbar());
       
        map.addLayers([gphy, test_layer]);        
        map.setBaseLayer(gphy);
        
        // sets the map center 
        var proj = new OpenLayers.Projection("EPSG:4326");
        var point = new OpenLayers.LonLat(-0.9, 43.5);
        point.transform(proj, map.getProjectionObject());
        map.setCenter(point, 4, false, false);
    </script>
</body>
</html>
---------------------------------------------------------------------------------------

Didrik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081112/23961db5/attachment.bin


More information about the Users mailing list