2009-11-04 17 views
6

Bu benim stackoverflow üzerinde ilk kez ve Openlayers & Google Maps ile çalışıyorum.OpenLayers Google Maps Projection Sorunu w/KML

Sorunumu çözmek için OpenLayers.org dahil olmak üzere farklı forumlarda & sitelere göz atıyorum. Aşağıdakilerin bir kombinasyonunu kullanarak arama yaptım: openlayers, google harita projeksiyonları ve küresel mercator ... ama bir çözüm bulamadım.

Sorun: Web hizmeti çağrısından (func setDataSource) gelen KML verileri, haritayı yakınlaştırıp uzaklaştırırken kayıyor. Benim tahminim, kodumdaki projeksiyonların yanlış ya da yanlış yerleştirilmiş olmasıdır. online :-(haritalama terminolojisini sindirimi zordur bu yüzden

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

teşekkür ederiz? Biri yardım edebilir. harita projeksiyonları üzerinde herhangi bir arka plan yok !!! Sorunu düşündüm

+3

[GIS.stackexchange.com] (http://gis.stackexchange.com/) adresindeki çocuklar ve kızlar muhtemelen bir dahaki sefere size yardımcı olmayı daha kolay bulacaklardır. – DefenestrationDay

+0

belki de bana bu poblemde yardımcı olabilirsiniz [openlayers Google Harita Sınırlar] [1] [1]: http://stackoverflow.com/questions/29120583/how-to-remove-countries-borders-from-a-google- map-integrated-in-opnelayers –

cevap

7

. Bunun yerine GML, böyle yerine Vector kullanarak çalıştı:

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

bu güneş saatlerinden örnekte çözüm buldu: http://openlayers.org/dev/examples/sundials-spherical-mercator.html Umut :-) aynı sorun w/herkes yardımcı olur.

+1

Benzer bir sorunla karşılaştım. En son OpenLayers sürümüne geçtikten sonra, 'projeksiyonu' nereye yerleştireceğimi bilmiyordum ve onsuz KML dosyalarımın hepsi (0,0) koordinatına çöktü. Bu cevap benim için çözdü, teşekkürler. –