@angular-helpers/openlayers 0.8.0 → 21.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -377,22 +377,25 @@ class OlLayerService {
|
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
+
createVectorSource(config, map) {
|
|
381
|
+
const sourceOptions = {};
|
|
382
|
+
if (config.url && config.format) {
|
|
383
|
+
sourceOptions.url = config.url;
|
|
384
|
+
if (config.format === 'geojson')
|
|
385
|
+
sourceOptions.format = new GeoJSON();
|
|
386
|
+
else if (config.format === 'topojson')
|
|
387
|
+
sourceOptions.format = new TopoJSON();
|
|
388
|
+
else if (config.format === 'kml')
|
|
389
|
+
sourceOptions.format = new KML();
|
|
390
|
+
}
|
|
391
|
+
return new VectorSource(sourceOptions);
|
|
392
|
+
}
|
|
380
393
|
createLayer(config, map) {
|
|
381
394
|
let layer;
|
|
382
395
|
switch (config.type) {
|
|
383
396
|
case 'vector': {
|
|
384
397
|
const vConfig = config;
|
|
385
|
-
const
|
|
386
|
-
if (vConfig.url && vConfig.format) {
|
|
387
|
-
sourceOptions.url = vConfig.url;
|
|
388
|
-
if (vConfig.format === 'geojson')
|
|
389
|
-
sourceOptions.format = new GeoJSON();
|
|
390
|
-
else if (vConfig.format === 'topojson')
|
|
391
|
-
sourceOptions.format = new TopoJSON();
|
|
392
|
-
else if (vConfig.format === 'kml')
|
|
393
|
-
sourceOptions.format = new KML();
|
|
394
|
-
}
|
|
395
|
-
const vectorSource = new VectorSource(sourceOptions);
|
|
398
|
+
const vectorSource = this.createVectorSource(vConfig, map);
|
|
396
399
|
const targetProj = (typeof map.getView === 'function'
|
|
397
400
|
? map.getView()?.getProjection()?.getCode()
|
|
398
401
|
: undefined) ?? 'EPSG:3857';
|
|
@@ -497,6 +500,41 @@ class OlLayerService {
|
|
|
497
500
|
this.updateLayerState();
|
|
498
501
|
}
|
|
499
502
|
}
|
|
503
|
+
updateVectorLayerConfig(id, config) {
|
|
504
|
+
const layer = this.layerCache.get(id);
|
|
505
|
+
if (!(layer instanceof VectorLayer))
|
|
506
|
+
return;
|
|
507
|
+
const map = this.mapService.getMap();
|
|
508
|
+
const nextConfig = {
|
|
509
|
+
...(layer.get('cluster-config') ? { cluster: layer.get('cluster-config') } : {}),
|
|
510
|
+
...(layer.get('style-fn') !== undefined ? { style: layer.get('style-fn') } : {}),
|
|
511
|
+
...config,
|
|
512
|
+
};
|
|
513
|
+
const nextSource = this.createVectorSource(nextConfig, map ?? {});
|
|
514
|
+
const clusterCfg = nextConfig.cluster;
|
|
515
|
+
if (clusterCfg?.enabled) {
|
|
516
|
+
const clusterSource = new ClusterSource({
|
|
517
|
+
source: nextSource,
|
|
518
|
+
distance: clusterCfg.distance ?? 40,
|
|
519
|
+
minDistance: clusterCfg.minDistance ?? 20,
|
|
520
|
+
geometryFunction: (feature) => {
|
|
521
|
+
const geometry = feature.getGeometry();
|
|
522
|
+
if (!geometry)
|
|
523
|
+
return null;
|
|
524
|
+
if (geometry.getType() === 'Point')
|
|
525
|
+
return geometry;
|
|
526
|
+
return new Point(getCenter(geometry.getExtent()));
|
|
527
|
+
},
|
|
528
|
+
});
|
|
529
|
+
layer.setSource(clusterSource);
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
layer.setSource(nextSource);
|
|
533
|
+
}
|
|
534
|
+
layer.set('coordinate-projection', nextConfig.coordinateProjection ?? 'EPSG:4326');
|
|
535
|
+
this.updateFeatures(id, nextConfig.features ?? []);
|
|
536
|
+
this.updateLayerState();
|
|
537
|
+
}
|
|
500
538
|
setVisibility(id, visible) {
|
|
501
539
|
const layer = this.layerCache.get(id);
|
|
502
540
|
if (layer) {
|
|
@@ -746,11 +784,19 @@ class OlVectorLayerComponent {
|
|
|
746
784
|
// Effect to sync features when input changes
|
|
747
785
|
effect(() => {
|
|
748
786
|
const currentFeatures = this.features();
|
|
749
|
-
// Only update if layer already exists (afterNextRender already created it)
|
|
750
787
|
if (this.layerService.getLayer(this.id())) {
|
|
751
788
|
this.layerService.updateFeatures(this.id(), currentFeatures);
|
|
752
789
|
}
|
|
753
790
|
});
|
|
791
|
+
effect(() => {
|
|
792
|
+
if (this.layerService.getLayer(this.id())) {
|
|
793
|
+
this.layerService.updateVectorLayerConfig(this.id(), {
|
|
794
|
+
url: this.url(),
|
|
795
|
+
format: this.format(),
|
|
796
|
+
coordinateProjection: this.coordinateProjection(),
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
});
|
|
754
800
|
effect(() => {
|
|
755
801
|
this.layerService.setOpacity(this.id(), this.opacity());
|
|
756
802
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-helpers/openlayers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.14.1",
|
|
4
4
|
"description": "Modern Angular wrapper for OpenLayers with modular architecture, standalone components, and hybrid template/programmatic API",
|
|
5
5
|
"homepage": "https://gaspar1992.github.io/angular-helpers/docs/openlayers",
|
|
6
6
|
"repository": {
|
|
@@ -268,10 +268,12 @@ declare class OlLayerService {
|
|
|
268
268
|
id: string;
|
|
269
269
|
};
|
|
270
270
|
private flushPending;
|
|
271
|
+
private createVectorSource;
|
|
271
272
|
private createLayer;
|
|
272
273
|
getLayer(id: string): BaseLayer | undefined;
|
|
273
274
|
hasLayer(id: string): boolean;
|
|
274
275
|
removeLayer(id: string): void;
|
|
276
|
+
updateVectorLayerConfig(id: string, config: Partial<VectorLayerConfig>): void;
|
|
275
277
|
setVisibility(id: string, visible: boolean): void;
|
|
276
278
|
toggleVisibility(id: string): boolean;
|
|
277
279
|
setOpacity(id: string, opacity: number): void;
|