I am using openlayers tile strategy and custom load function.

this.source = new Vector({
  format: new EsriJSON(),
  strategy: tile(createXYZ({tileSize: 512})),
  loader: (extent: any, resolution: any, projection: any) => {
        let source = layer.getSource();
        this.http.get(url, this.httpOptions).subscribe(
            (response: any) => {                   

            (error: any) => {                    

But the features are icreasing in source while zooming in or out. So I want to remove features that out of the current extent from source after add. How can I do it?

  • 1
    You would need to do it before the add source.getFeaturesInExtent(extent).forEach(function(feature){ source.removeFeature(feature)); }); – Mike Jul 21 at 9:11
  • @Mike I tried, but loader function is working per tile 512. Data is coming for every 512 tiles. So it does not remove features, source count is increasing. – barteloma Jul 21 at 10:50
  • Yes, you would also have features which cover more than one tile so you could remove some just added. Do do what I think you want you might need to clear the whole source on every change of tile zoom level. – Mike Jul 21 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.