[OpenLayers-Dev] Beginner: mapping different coordinate sources systems together

Christopher Schmidt crschmidt at metacarta.com
Wed Apr 8 07:26:27 EDT 2009


On Wed, Apr 08, 2009 at 02:07:03AM -0700, naskew wrote:
> 
> Hi,
> 
> I am fairly new to OpenLayers but not GIS or ASP.Net and I'm trying to get OpenLayers working on an ASP.Net site. I've started by copying the sample OSM + Gooogle Maps + KML Reprojection and it seems that the Open Street Maps and Google layers are working fine. However the KML is not being projected onto the same coordinate system as the tiles (the KML is is WGS84/EPSG:4326) and all the points appear to be being rendered somewhere just off the west coast of Africa (where I guess 0,0 is for the tile coordinate system EPSG:900913) but clearly at different points if you zoom in enough.
> 
> It all seems to work on the openlayers sample site and I'm sure that I've copied the code correctly (I've pasted it below, I removed the google stuff just to make this as simple as possible). Is there perhaps something tricky to setting up the reprojection?
> 
> I've worked with a local copy of OpenLayers.js and the separate file version and the hosted version, they all give the same result. 

The HTTP Protocol did not support reprojection until after 2.7 aws
released. The functionalit you are seeking will exist in 2.8; until
then, you'd be better off using a "GML" layer, which should work:

   http://docs.openlayers.org/library/spherical_mercator.html#reprojecting-vector-data

If you look at the sundials example included in the 2.7   download, it
should provide a reasonable example for you, I think.

-- Chris

> var map, select;
> 
> function init(){
> 
>     window.onresize = onWindowResize;
>     sizeMap();
>     
>     var options = {
>         projection: new OpenLayers.Projection("EPSG:900913"),
>         displayProjection: new OpenLayers.Projection("EPSG:4326"),
>         units: "m",
>         maxResolution: 156543.0339,
>         maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
>                                          20037508.34, 20037508.34)
>     };
>     map = new OpenLayers.Map('map', options);
>     
>     var mapnik = new OpenLayers.Layer.TMS(
>         "OpenStreetMap (Mapnik)",
>         "http://tile.openstreetmap.org/",
>         {
>             type: 'png', getURL: osm_getTileURL,
>             displayOutsideMaxExtent: true,
>             attribution: ' OpenStreetMap '
>         }
>     );
> 
>     var sundials = new OpenLayers.Layer.Vector("KML", {
>         projection: map.displayProjection,
>         strategies: [new OpenLayers.Strategy.Fixed()],
>         protocol: new OpenLayers.Protocol.HTTP({
>             url: "kml/sundials.kml",
>             format: new OpenLayers.Format.KML({
>                 extractStyles: true,
>                 extractAttributes: true
>             })
>         })
>     });
>     
>     map.addLayers([mapnik, sundials]);
> 
>     select = new OpenLayers.Control.SelectFeature(sundials);
>     
>     sundials.events.on({
>         "featureselected": onFeatureSelect,
>         "featureunselected": onFeatureUnselect
>     });
> 
>     map.addControl(select);
>     select.activate();   
> 
>     map.addControl(new OpenLayers.Control.LayerSwitcher());
> 
>     map.zoomToExtent(
>         new OpenLayers.Bounds(
>             16, 33, 47, 54
>         ).transform(map.displayProjection, map.projection)
>     );
> 
> -- 
> View this message in context: http://n2.nabble.com/Beginner%3A-mapping-different-coordinate-sources-systems-together-tp2604043p2604043.html
> Sent from the OpenLayers Dev mailing list archive at Nabble.com.
> 
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev

-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list