[OpenLayers-Users] KML data near Africa? Google Maps Projection Problem Repost

TiffL tiffnay at gmail.com
Thu Nov 5 13:22:53 EST 2009


Hi! Newbie here. In dire need of help! I really appreciate any
comments/pointers. 

I am not sure why my coordinates, no matter what KML is being served by a
webservice ( setDataSource) call, are all plotted near Africa after I put in
the options for google projection due to kml data shifting positions after
zooming in and out (http://trac.openlayers.org/wiki/SphericalMercator)...
:-( 

//start here 
        function init(){ 
        var options = { 
                projection: new OpenLayers.Projection("EPSG:900913"), 
                displayProjection: new OpenLayers.Projection("EPSG:4326"), 
                units: "m", 
                numZoomLevels: 18, 
                          maxResolution: 156543.0339, 
                     maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 
                                                         20037508, 20037508) 
                }; 

        map = new OpenLayers.Map('map', options); 
        var gphy = new OpenLayers.Layer.Google( 
               "Google Street", 
                {'sphericalMercator':true}); 

        var bglayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                   "http://labs.metacarta.com/wms/vmap0", 
           {layers: 'basic', projection: new
OpenLayers.Projection("EPSG:4326")}); 
                
        map.addLayers([gphy, bglayer]); 
        map.addControl(new OpenLayers.Control.LayerSwitcher()); 
             map.zoomToMaxExtent(); 
             OpenLayers.Console.log("initialized"); 
        } 

             function setDataSource() { 
        OpenLayers.Console.log("Setting data source to " +
OpenLayers.Util.getElement('loc').value); 
                if (layer != undefined) {map.removeLayer(layer)}; 
                if (selectControl != undefined)
{map.removeControl(selectControl)}; 
        
                // Encode the destination url as a parameter string. 
        var params =
OpenLayers.Util.getParameterString({url:OpenLayers.Util.getElement('loc').value}) 
                        
        //  Make the http request to the transformer, with the destination
url as a parameter. 
        layer = new OpenLayers.Layer.GML("KML", transformerURL + params, 
               { 
                format: OpenLayers.Format.KML, 
                formatOptions: { 
                extractStyles: true, 
                extractAttributes: true, 
                maxDepth: 2, 
          //tried the projection below, had no effect 
               //projection: new OpenLayers.Projection("EPSG:4326"), 
               } 
               }); 
        map.addLayer(layer); 
        selectControl = new OpenLayers.Control.SelectFeature(layer, 
               {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect}); 
                        map.addControl(selectControl); 
                        selectControl.activate(); 
        } 


-----
=)
-- 
View this message in context: http://n2.nabble.com/KML-data-near-Africa-Google-Maps-Projection-Problem-Repost-tp3954098p3954098.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list