How to load Open layers 3 geojson vector layer with bbox?

前端 未结 2 1943
闹比i
闹比i 2020-12-19 19:23

I am struggling with building OL3 Vector layer BBOX strategy loading. So far I can easily load Geojson file with valid json syntax, however this is one time strategy. My ano

2条回答
  •  有刺的猬
    2020-12-19 19:40

    To get this working with the newest version of OL3 (v3.7.0) I had to read the features using the GeoJSON format class.

    var geoJSONFormat = new ol.format.GeoJSON();
    
    var vectorSource = new ol.source.Vector({
      loader: function(extent, resolution, projection) {
        var url = 'geojson2.php?p=' + extent.join(',');
        $.ajax({
          url: url,
          success: function(data) {
            var features = geoJSONFormat.readFeatures(data);
            vectorSource.addFeatures(features);
          }
        }); 
      },
      strategy: ol.loadingstrategy.bbox
    });
    

提交回复
热议问题