2017-07-18 29 views
0

我使用來自geom的答案的代碼https://gis.stackexchange.com/questions/216792/is-there-an-easy-way-to-use-postgis-geojson-in-openlayers-3將PostGIS圖層加載到我的OL3地圖應用程序中。提高OpenLayers3中的geoJSON性能

問題是:大(原料)GeoJSON的數據集渲染性能是不是最佳的,所以我想用這樣的:

new ol.layer.Image({ 
      source: new ol.source.ImageVector({ 
       source: new ol.source.Vector({ 
       url: 'https://openlayers.org/en/v4.2.0/examples/data/geojson/countries.geojson', 
       format: new ol.format.GeoJSON() 
       }), 
       style: new ol.style.Style({ 
       fill: new ol.style.Fill({ 
        color: 'rgba(255, 255, 255, 0.6)' 
       }), 
       stroke: new ol.style.Stroke({ 
        color: '#319FD3', 
        width: 1 
       }) 
       }) 
      }) 
      }) 

我現在的構造是這樣看:

ol3Vector = function(options) { 

var options = { 
    title: options.title, 
    visible: false, 
    geotable: options.geotable, // table name in PostGis-database 
    fields: options.fields,  // field-names 
    where: options.where,  // where-string passed to PostGis 
    source: new ol.source.Vector({ 
     projection: "EPSG:4326", 
     attributions: [new ol.Attribution({ 
      html: options.attribution 
     })], 
     strategy: ol.loadingstrategy.bbox, //load only data off the visible map 
     loader: function(extent, resolution, projection) { 
      var extent = ol.proj.transformExtent(extent, projection.getCode(), ol.proj.get('EPSG:4326').getCode()); 
      $.ajax({ 
       type: "GET", 
       dataType: "json", 
       url: "../map/php/get_geojson.php?" +  // define path to the get_geojson.php script 
        "geotable=" + options.geotable + 
        "&fields=" + options.fields + 
        "&where=" + options.where + 
        "&bbox=" + extent.join(","), 
       context: this 
      }).done(function(data) { 
       var format = new ol.format.GeoJSON(); 
       this.addFeatures(format.readFeatures(data, { 
        dataProjection: "EPSG:4326", 
        featureProjection: "EPSG:3857" 
       })); 

      }); 

     } 
    }), 
    minResolution: options.minResolution, 
    maxResolution: options.maxResolution, 
    content: options.content, 
    symbology: options.symbology, 
    showLabels: options.showLabels, 
    label: options.label, 

} 

ol.layer.Vector.call(this, options); 

}; 

ol.inherits(ol3Vector, ol.layer.Vector); 

此外:

var landkreise = new ol3Vector({ 
    title: "Landkreise in Niedersachsen", // name of the layer to show up in the layerswitcher 
    geotable: "tbl_landkreise_geb_f", 
    fields: "KRS,sumarea", 
    where: "KRS IS NOT NULL", // You can use all the PostgreSQL or PostGis features here 
    minResolution: 0.01, 
    maxResolution: 50000, 
    content: " ", 
    showLabels: false, // show labels on map 
    label: "KRS" // field used for labeling 
}); 
baselayersArray=[OSM, landkreise]; 
baselayers.setLayers(new ol.Collection(baselayersArray)); 
landkreise.setVisible(true); 

如何將ol.layer.Image()(第一個代碼示例)包裝到我的構造函數中?

回答

0

貌似可以做到以下幾點:

  • 派生您ol3Vector從ol.layer.Image而不是ol.layer.Vector

  • 包裝你ol.source.Vector(內選擇對象)與ol.source.ImageVector(如圖比如你引用)

+0

我試過了,但後來我生成html字符串看起來是這樣的:getgeojson.php geotable =不確定&欄=不確定及磨片RE =未定義 – Revo