2016-03-24 12 views
0

Yerel bir geojson dosyasından vektör kaynağı yükleyen bir fonksiyona sahibim.Kaynak vektör görüntüleniyor (Özellikler gösterilmiyor mu?)

Sorun şu ki, katmanlardan biri için uzak olmasına gerek yok, ancak özellikler kaynağın düzgün bir şekilde yüklenmesine rağmen hiçbir zaman gösterilmiyor ve konsol.loglar bana gerçekten onu getirdiğini gösteriyordu ... Satırı atıyorum: "this.layerSwitcherGroup.getLayers(). Push (this.pointsLayer)"; koddan. Bu satır yorumlandığında, yükleyici hiçbir zaman çalışmaz (konsoldan bir konsol.log görünmez).

Not: Sunucudaki dosya cr'ler eski haline gelinceye kadar güncellenene kadar cr'leri yalnızca geçici olarak düzenliyorum. Geojson dosyasını yerel işlevli sunucudan indirip indirip crs bölümünü düzenlediğimde de aynısını yaptım. Yerel işlev çalıştı, ancak uzak değil.

addPoints: function() { 
    this.addPointInteraction(); 

    this.pointsLayer = new ol.layer.Vector({ 
     source: new ol.source.Vector({ 
      /** 
      * The function is responsible for loading the features and adding them to the source. 
      * ol.source.Vector sources use a function of this type to load features. 
      * @param extent - the area to be loaded 
      * @param resolution - the resolution (map units per pixel) 
      * @param projection - ol.proj.Projection for the projection as arguments 
      * 
      * this (keyword): within the function is bound to the ol.source.Vector it's called from. 
      */ 
      loader: function(extent, resolution, projection) { 
       console.log('vector Loader...'); 

       var url = //can't show the url here; 
       $.ajax({ 
        url: url, 
        context: this, 
        success: function(json) { 
         console.log('Data: ', json); 

         json.data.crs = { 
          "type": "name", 
          "properties": { 
           "name": "urn:ogc:def:crs:OGC:1.3:CRS84" 
          } 
         }; 

         console.log('changed CRS: ', json); 

         var features = new ol.format.GeoJSON().readFeatures(json.data); 

         console.log('this inside loader: ', this); 

         this.addFeatures(features); 
        } 
       }); 
      } 
     }), 
     style: this.defaultPointStyleFunction 
    }); 

    this.layerSwitcherGroup.getLayers().push(this.pointsLayer); 

    this.pointsLayer.getSource().once("change", function(evt) { 
     console.log('pointsLayer once'); 
     //console.log('pointsLayer changed: ', this.pointsLayer); 
     //console.log('pointsLayer source: ', this.pointsLayer.getSource()); 
     console.log('pointsLayer features: ', this.pointsLayer.getSource().getFeatures()); 
     //console.log('current layerSwitcherGroup layers: ', this.layerSwitcherGroup.getLayers()); 

     this.hidePoints(); 
     this.onSetSelection(1); 
    }, this); 

    this.currPointId = null; 
}, 

yerel modu ile eserler yukarıda listelenen her işlev, bu yüzden ben uzaktan yükleyici ile yanlış yapıyorum emin değilim ...

+0

Günlük ifadelerinin çıktısını ekler misiniz? –

+0

Çıktı, vektörün doğru şekilde eklendiğini, tam olarak gösterilemediğini gösterir çünkü ondan çok fazla gizli bilgi gizlemek zorunda kaldım. :/Noktaların * yanlış yerde olduğunu gösteren * olduğunu keşfettim, bu yüzden bir yerde bir projeksiyon hatası var. – Ada

cevap

1

Yani {featureProjection: ': 3857 EPSG'} ekleyerek oldu eksikti tüm özellikleri düzgün harita görünümünde yansıtılabilir böylece Sabit

(yani harita projeksiyonu olduğundan) ... readFeatures için

var features = format.readFeatures(json.data, {featureProjection: 'EPSG:3857'}); 

ile

var features = new ol.format.GeoJSON().readFeatures(json.data); 

değiştirerek o https://stackoverflow.com/a/32455939/2340999 aracılığıyla buldum ve özellikleri şimdi uygun pozisyonlarda gösteriyorlar!

Tüm önerileriniz için teşekkür ederiz!

0

Değişim bu

var features = new ol.format.GeoJSON().readFeatures(json.data); 

Bu

var features = (new ol.format.GeoJSON()).readFeatures(json.data); 
+0

Bu bir şey yapmadı:/ – Ada

0

için burada mevcut örneği kullanarak yapmış: http://openlayersbook.github.io/ch11-creating-web-map-apps/example-03.html

Bunun yardımcı olup olmadığından emin değil.

+0

Hm, benim özellikleri bir geojson dosyası olsa da. Sonunda, bağladığınız şeyi yapmak temel olarak dosyada zaten var olan özellikleri yeniden oluşturacaktır. Benim yaklaşımımla ilgili tek sorun, noktaların düzgün bir şekilde yansıtılmadığı ve afrika yakınlarında okyanusta görülemeyeceğidir:/Uzaktaki olası bir yokluğu bulmak zorunda olduğum geojson dosyalarının hem yerel hem de uzaktan yüklenmesinde hata ayıklamaya çalışıyorum ama şu ana kadar hiçbir şey yok. – Ada

İlgili konular