Skip to content

Commit

Permalink
feat(source-vector): support of 'loader' input
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-lhotellerie authored and jeremy-eychenne committed Apr 29, 2024
1 parent ff7a391 commit 58c1a6b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Live example will be viewable at locahost:4200
- Malorie Berthoin <malorie.berthoin.neo-soft@externalgcp.ds.airbus.com>
- Mazzoléni <yoahn.mazzoleni.external@airbus.com>
- Michael Parry <michael.m.parry.external@airbus.com>
- Matthieu Lhotellerie <matthieu.lhotellerie@airbus.com>

### Other

Expand Down
36 changes: 33 additions & 3 deletions projects/ngx-openlayers/src/lib/sources/vector.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Component, forwardRef, Host, Input, OnInit } from '@angular/core';
import { Vector } from 'ol/source';
import Feature from 'ol/format/Feature';
import { default as FeatureFormat } from 'ol/format/Feature';
import { LayerVectorComponent } from '../layers/layervector.component';
import { SourceComponent } from './source.component';
import { LoadingStrategy } from 'ol/source/Vector';
import { Geometry } from 'ol/geom';
import { Extent } from 'ol/extent';
import { Projection } from 'ol/proj';
import { Feature } from 'ol';

@Component({
selector: 'aol-source-vector',
Expand All @@ -20,18 +24,44 @@ export class SourceVectorComponent extends SourceComponent implements OnInit {
@Input()
url: string;
@Input()
format: Feature;
format: FeatureFormat;
@Input()
strategy: LoadingStrategy;

/**
* The loader function used to load features, from a remote source for example.
* If this is not set and `url` is set, the source will create and use an XHR
* feature loader. The `'featuresloadend'` and `'featuresloaderror'` events
* will only fire if the `success` and `failure` callbacks are used.
*
* An extra argument is provided to the OpenLayers callback to enable retrieval
* of the parent VectorSource.
*/
@Input()
loader: (
extent: Extent,
resolution: number,
projection: Projection,
success: (geos: Feature<Geometry>[]) => void,
failure: () => void,
vectorSource: Vector
) => void;

instance: Vector;

constructor(@Host() layer: LayerVectorComponent) {
super(layer);
}

ngOnInit(): void {
this.instance = new Vector(this);
this.instance = new Vector({
...this,
loader: this.loader
? (extent, resolution, projection, success, failure) =>
this.loader(extent, resolution, projection, success, failure, this.instance)
: undefined,
});

this.host.instance.setSource(this.instance);
}
}

0 comments on commit 58c1a6b

Please sign in to comment.