Skip to content

Commit

Permalink
feat(module:vector-source): add support for components
Browse files Browse the repository at this point in the history
- heatmap layer
- vector image layer
- cluster source
  • Loading branch information
Jonnytoshen committed Feb 18, 2024
1 parent 72fbee7 commit 0fb1501
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/source/vector/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { InjectOptions } from '@angular/core';
import { useHeatmapLayer } from 'ngx-ol-library/layer/heatmap';
import { injectVectorLayer } from 'ngx-ol-library/layer/vector';
import { useVectorImageLayer } from 'ngx-ol-library/layer/vector-image';
import { useClusterSource } from 'ngx-ol-library/source/cluster';

export function injectVectorSourceHost() {
export function useVectorSourceHost() {
const options: InjectOptions = { optional: true, host: true };
const vectorSourceHost = injectVectorLayer(options);
const vectorLayer = injectVectorLayer(options);
const vectorImageLayer = useVectorImageLayer(options);
const heatmapLayer = useHeatmapLayer(options);
const clusterSource = useClusterSource(options);
const host = clusterSource || heatmapLayer || vectorImageLayer || vectorLayer;

if (!vectorSourceHost) {
if (!host) {
throw new Error(
'`nol-vector-source` component must be nested within `nol-vector-layer` component.'
'`nol-vector-source` component must be nested within `nol-vector-layer`, ' +
'`nol-heatmap-layer`, `nol-vector-image-layer` or `nol-cluster-source` component.'
);
}

return vectorSourceHost;
return host;
}
4 changes: 2 additions & 2 deletions src/source/vector/vector-source.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Collection from 'ol/Collection';
import FeatureFormat from 'ol/format/Feature';
import BaseEvent from 'ol/events/Event';
import { NolPrefixedOptions, NolSafeAny } from 'ngx-ol-library/core';
import { injectVectorSourceHost } from './utils';
import { useVectorSourceHost } from './utils';

/**
* Provides a source of features for `nol-vector-layer` components.
Expand Down Expand Up @@ -66,7 +66,7 @@ export class NolVectorSourceComponent implements NolPrefixedOptions<Options>, On
@Output() nolRemovefeature = new EventEmitter<VectorSourceEvent>();

private readonly destroyRef = inject(DestroyRef);
private readonly host = injectVectorSourceHost();
private readonly host = useVectorSourceHost();
private instance!: VectorSource;

getInstance() {
Expand Down

0 comments on commit 0fb1501

Please sign in to comment.