0

We have a custom loader for our vector source which sets the current resolution on the source and clears the source before loading the data via xhr from our spatial data API.

The custom strategy checks whether the resolution argument is different to the current resolution. The loadedExtentsRtree_ of the source will be cleared if the resolution is different. Clearing the extents tree ensures that the loader will be called with the transformed extent as argument.

Unfortunately we have no longer access to the loadedExtentsRtree_ object of the vector source in Openlayers 6.6.

Is there a way to clear the extents tree directly with OL 6.6?

new ol.source.Vector({
loader: function (extent, resolution, projection) {

this.resolution = resolution this.clear(true)

xhr && xhr.abort()

//create a new xhr request to load data

}, strategy: function(extent, resolution) {

this.resolution != resolution && this.loadedExtentsRtree_.clear()

return [ol.proj.transformExtent(extent, map_projection, data_projection)] }

Dennis Bauszus
  • 2,289
  • 3
  • 21
  • 31
  • 1
    This is just a shot in the dark: what about .removeLoadedExtent method? – TomazicM Jul 22 '21 at 13:56
  • removeLoadedExtent requires an extent argument and will remove loaded extents which match. Not sure how to make this work to remove all loaded extents. – Dennis Bauszus Jul 22 '21 at 14:16
  • 1
    You can use source,clear() in the strategy function but make sure the extent has changed to avoid getting into a loop (clearing the source in the loader can also cause loops). See https://gis.stackexchange.com/questions/322681/openlayers-refresh-vector-source-with-bbox-strategy-after-map-moved – Mike Jul 22 '21 at 14:25
  • that only works with an url function but not with a custom loader function which will not be called. – Dennis Bauszus Jul 22 '21 at 14:40
  • @Mike good call on the bbox setter to control whether data should be loaded from the strategy. I created a workaround calling my own custom loader function and assigning a bogus loader to the source. – Dennis Bauszus Jul 22 '21 at 15:26

1 Answers1

0

I achieve the same result with this workaround. I assign a bogus loader function which does nothing and call my custom loader directly from the strategy method, returning the extent to the bogus loader assigned to the vector source.

const source = new ol.source.Vector({
  loader: () => {},
  strategy: function(extent, resolution) {
extent = [ol.proj.transformExtent(extent, 'EPSG:' + layer.mapview.srid, 'EPSG:' + layer.srid)]

const bbox = extent.join(',');
if (bbox != this.get('bbox')) {
  this.set('bbox', bbox)
  loader(extent)
}

return extent

} })

function loader(extent){ source.clear(true)

//load data from extent }

Dennis Bauszus
  • 2,289
  • 3
  • 21
  • 31