2009-11-04 14 views
6

Questa è la mia prima volta su StackOverflow e utilizzo di Openlayers & Google Maps.OpenLayers Google Maps Projection Problem w/KML

Ho esplorato diversi forum & siti, tra cui OpenLayers.org, per risolvere il mio problema. Ho effettuato ricerche su una combinazione di quanto segue: openlayers, google map projection e sferico mercator ... ma non ho trovato una soluzione.

Problema: i dati KML di una chiamata di servizio Web (func setDataSource) si stanno spostando mentre eseguo lo zoom avanti e indietro della mappa. La mia ipotesi è che le proiezioni nel mio codice siano sbagliate o forse poste in modo errato. Non ho alcun background su proiezioni cartografiche per cui è difficile da digerire la terminologia di mappe online :-(. Qualcuno può aiutarmi?

//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); 

Grazie !!!

+3

I ragazzi e le ragazze di [GIS.stackexchange.com] (http://gis.stackexchange.com/) probabilmente troveranno più facile aiutarti la prossima volta .. – DefenestrationDay

+0

forse puoi aiutarmi con questo poblem [Openlayers Google Map Bordi] [1] [1]: http://stackoverflow.com/questions/29120583/how-to-remove-countries-borders-from-a-google- map-integrated-in-opnelayers –

risposta

7

ho capito il problema. Invece di GML, ho provato ad utilizzare Vector invece in questo modo:

layer = new OpenLayers.Layer.Vector("KML", { 
      projection: map.displayProjection, 
      strategies: [new OpenLayers.Strategy.Fixed()], 
      protocol: new OpenLayers.Protocol.HTTP({ 
       url: transformerURL + params, 
       format: new OpenLayers.Format.KML({ 
        extractStyles: true, 
        extractAttributes: true 
       }) 
      }) 
     });  

ho trovato la soluzione in questo esempio meridiane: http://openlayers.org/dev/examples/sundials-spherical-mercator.html :-) Spero che questo aiuti chiunque w/lo stesso problema.

+1

Ho avuto un problema simile. Dopo il passaggio alla versione più recente di OpenLayers, non sapevo dove posizionare 'proiezione 'e senza di essa i miei file KML erano tutti compressi alla coordinata (0,0). Questa risposta l'ha risolto per me, grazie. –