Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenLayers Google Maps Projection Problem w/ KML
    text
    copied!<p>This is my first time on stackoverflow and working with Openlayers &amp; Google Maps. </p> <p>I've been browsing different forums &amp; sites, including OpenLayers.org, to solve my issue. I've done searches on a combination of the following: openlayers, google map projections, and spherical mercator... but I have not found a solution. </p> <p>Problem: The KML data from a web service call (func setDataSource) is shifting as I zoom in and out of the map. My guess is that the projections in my code are wrong or perhaps wrongly placed. I don't have any background on map projections so it is difficult to digest mapping terminology online :-(. Can someone help? </p> <pre><code> //start here 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'); map = new OpenLayers.Map('map', options); var gphy = new OpenLayers.Layer.Google( "Google Street", {'sphericalMercator':true}); // Add the background images via WMS var bglayer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'}, {'reproject': true}); //map.addLayer(bglayer); map.addLayers([gphy, bglayer]); map.addControl(new OpenLayers.Control.LayerSwitcher()); map.zoomToMaxExtent(); //* Zoom all the way out, this command also initalizes the map 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, //projection: new OpenLayers.Projection("EPSG:4326"), } }); map.addLayer(layer); </code></pre> <p>Thank you!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload