[OpenLayers-Users] google, kml and projection alignment

Christopher Schmidt crschmidt at metacarta.com
Tue Dec 16 15:51:56 EST 2008


On Tue, Dec 16, 2008 at 12:46:50PM -0800, Tim Perkis wrote:
> I'm new to this list, and to openlayers, so pardon me if this is a
> well-discussed problem. But where I have seen some discussion of
> projection issues with spherical mercator maps such as google's, I don't
> seem to be able to find the right combination that allows my application
> to work properly.
> 
> I'm attempting to build a viewer of a client's plant, an openlayers-based
> view of three layers: a satellite base map such as a google hybrid, some
> simple site features (building outlines) and a layer of real-time computed
> data.  To derive the building layer, I defined a set of polygons tracing
> building features in google earth and exported them as a .kml file.
> 
> The polygons display properly over the satellite map in Google Earth, but
> in openlayers they are skewed and float nearby (moving relative to the base layer
> with zoom level and site center). My openlayers code:
>           ...
>       function init() {
>             var map = new OpenLayers.Map("map", {
>               projection: new OpenLayers.Projection("EPSG:900913")
>             });
>              map.addControl(new OpenLayers.Control.LayerSwitcher());
> 
>            var ghyb = new OpenLayers.Layer.Google(
>                 "Google Hybrid",
>                 {type: G_HYBRID_MAP,
>                   sphericalProjection: true,
                        ^^ This should be spherical*Mercator*, not
                        sphericalProjection.
>                    numZoomLevels: 30}
>             );
>             map.addLayer(ghyb);
> 
>              var pgbldgs = new OpenLayers.Layer.GML("Buildings",
> "kml/png-stl-SF.kml",
>               {
>               projection: new OpenLayers.Projection("EPSG:4326"),
>               format: OpenLayers.Format.KML,
>                formatOptions: {
>                   extractStyles: true,
>                   extractAttributes: true
>                  }
>             });
>             map.addLayer(pgbldgs);
>           map.zoomToExtent(new OpenLayers.Bounds(long1, lat1, long2, lat2));

                                       ^^ These will need to be in
                                       meters: you can use:

    bounds.transform(new OpenLayers.Projection("EPSG:4326"), 
                     new OpenLayers.Projection("EPSG:900913"));
                  
                  To transform.   
> Any help at where I might be going wrong in setting up the layer
> projections -- or whatever else might be the problem! -- would be appreciated.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list