AW-6526 update angular 21
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit

This commit is contained in:
2026-01-19 12:19:09 +01:00
parent c35114b2d3
commit 9cc581dd3d
102 changed files with 3287 additions and 4023 deletions

View File

@@ -1,16 +1,19 @@
import { Component, ElementRef, OnInit } from '@angular/core';
import { Component, ElementRef, OnInit, inject } from '@angular/core';
import { Attribution } from 'ol/control';
@Component({
selector: 'aol-attribution',
template: '<ng-content></ng-content>',
standalone: false
selector: 'aol-attribution',
template: '<ng-content></ng-content>',
standalone: true,
})
export class AttributionComponent implements OnInit {
label: string;
private elementRef = inject(ElementRef);
constructor(private elementRef: ElementRef) {}
instance: Attribution;
html: string;
ngOnInit() {
this.label = this.elementRef.nativeElement.innerHTML;
ngOnInit(): void {
this.html = this.elementRef.nativeElement.innerHTML;
this.instance = new Attribution();
}
}

View File

@@ -1,24 +1,24 @@
import { AfterViewInit, Component, ContentChildren, Host, QueryList } from '@angular/core';
import { SourceComponent } from './sources/source.component';
import { AfterViewInit, Component, ContentChildren, QueryList, inject } from '@angular/core';
import { AttributionComponent } from './attribution.component';
import { SourceComponent } from './sources/source.component';
@Component({
selector: 'aol-attributions',
template: '<ng-content></ng-content>',
standalone: false
selector: 'aol-attributions',
template: '<ng-content></ng-content>',
standalone: true,
})
export class AttributionsComponent implements AfterViewInit {
private source = inject(SourceComponent, { host: true });
@ContentChildren(AttributionComponent)
attributions: QueryList<AttributionComponent>;
instance: Array<string>;
constructor(@Host() private source: SourceComponent) {}
/* we can do this at the very end */
ngAfterViewInit() {
ngAfterViewInit(): void {
if (this.attributions.length) {
this.instance = this.attributions.map((cmp) => cmp.label);
this.instance = this.attributions.map((cmp) => cmp.html);
// console.log('setting attributions:', this.instance);
this.source.instance.setAttributions(this.instance);
}

View File

@@ -1,90 +1,88 @@
import { Component, Input, OnChanges, OnInit, Optional, SimpleChanges } from '@angular/core';
import { MapComponent } from './map.component';
import { GeometryLinestringComponent } from './geom/geometrylinestring.component';
import { GeometryPolygonComponent } from './geom/geometrypolygon.component';
import { GeometryMultiPointComponent } from './geom/geometrymultipoint.component';
import { GeometryMultiLinestringComponent } from './geom/geometrymultilinestring.component';
import { GeometryMultiPolygonComponent } from './geom/geometrymultipolygon.component';
import { Component, Input, OnChanges, OnInit, inject } from '@angular/core';
import { Coordinate } from 'ol/coordinate';
import { transform } from 'ol/proj';
import { GeometryLinestringComponent } from './geom/geometrylinestring.component';
import { GeometryMultiLinestringComponent } from './geom/geometrymultilinestring.component';
import { GeometryMultiPointComponent } from './geom/geometrymultipoint.component';
import { GeometryMultiPolygonComponent } from './geom/geometrymultipolygon.component';
import { GeometryPolygonComponent } from './geom/geometrypolygon.component';
import { MapComponent } from './map.component';
@Component({
selector: 'aol-collection-coordinates',
template: ` <div class="aol-collection-coordinates"></div> `,
standalone: false
selector: 'aol-collection-coordinates',
template: ` <div class="aol-collection-coordinates"></div> `,
standalone: true,
})
export class CollectionCoordinatesComponent implements OnChanges, OnInit {
private map = inject(MapComponent);
@Input()
coordinates: Coordinate[] | Coordinate[][] | Coordinate[][][];
@Input()
srid = 'EPSG:3857';
private host: any;
private readonly host:
| GeometryLinestringComponent
| GeometryPolygonComponent
| GeometryMultiPointComponent
| GeometryMultiLinestringComponent
| GeometryMultiPolygonComponent;
private mapSrid = 'EPSG:3857';
constructor(
private map: MapComponent,
@Optional() geometryLinestring: GeometryLinestringComponent,
@Optional() geometryPolygon: GeometryPolygonComponent,
@Optional() geometryMultipoint: GeometryMultiPointComponent,
@Optional() geometryMultilinestring: GeometryMultiLinestringComponent,
@Optional() geometryMultipolygon: GeometryMultiPolygonComponent
) {
if (!!geometryLinestring) {
this.host = geometryLinestring;
} else if (!!geometryPolygon) {
this.host = geometryPolygon;
} else if (!!geometryMultipoint) {
this.host = geometryMultipoint;
} else if (!!geometryMultilinestring) {
this.host = geometryMultilinestring;
} else if (!!geometryMultipolygon) {
this.host = geometryMultipolygon;
constructor() {
const geometryLinestring = inject(GeometryLinestringComponent, { optional: true });
const geometryPolygon = inject(GeometryPolygonComponent, { optional: true });
const geometryMultipoint = inject(GeometryMultiPointComponent, { optional: true });
const geometryMultilinestring = inject(GeometryMultiLinestringComponent, { optional: true });
const geometryMultipolygon = inject(GeometryMultiPolygonComponent, { optional: true });
const geometryComponent =
geometryLinestring ??
geometryPolygon ??
geometryMultipoint ??
geometryMultilinestring ??
geometryMultipolygon ??
undefined;
if (geometryComponent) {
this.host = geometryComponent;
} else {
throw new Error('aol-collection-coordinates must be a child of a geometry component');
}
}
ngOnInit() {
ngOnInit(): void {
this.map.instance.on('change:view', (e) => this.onMapViewChanged(e));
this.mapSrid = this.map.instance.getView().getProjection().getCode();
this.transformCoordinates();
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(): void {
this.transformCoordinates();
}
private onMapViewChanged(event) {
private onMapViewChanged(event): void {
this.mapSrid = event.target.get(event.key).getProjection().getCode();
this.transformCoordinates();
}
private transformCoordinates() {
let transformedCoordinates: Coordinate[] | Coordinate[][] | Coordinate[][][];
private transformCoordinates(): void {
if (this.srid === this.mapSrid) {
transformedCoordinates = this.coordinates;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.host.instance.setCoordinates(this.coordinates as any[]);
} else if (this.host instanceof GeometryLinestringComponent || this.host instanceof GeometryMultiPointComponent) {
this.host.instance.setCoordinates(
(this.coordinates as Coordinate[]).map((c) => transform(c, this.srid, this.mapSrid))
);
} else if (this.host instanceof GeometryPolygonComponent || this.host instanceof GeometryMultiLinestringComponent) {
this.host.instance.setCoordinates(
(this.coordinates as Coordinate[][]).map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
);
} else {
switch (this.host.componentType) {
case 'geometry-linestring':
case 'geometry-multipoint':
transformedCoordinates = (this.coordinates as Coordinate[]).map((c) => transform(c, this.srid, this.mapSrid));
break;
case 'geometry-polygon':
case 'geometry-multilinestring':
transformedCoordinates = (this.coordinates as Coordinate[][]).map((cc) =>
cc.map((c) => transform(c, this.srid, this.mapSrid))
);
break;
case 'geometry-multipolygon':
transformedCoordinates = (this.coordinates as Coordinate[][][]).map((ccc) =>
ccc.map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
);
break;
}
this.host.instance.setCoordinates(
(this.coordinates as Coordinate[][][]).map((ccc) =>
ccc.map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
)
);
}
this.host.instance.setCoordinates(transformedCoordinates);
}
}

View File

@@ -1,10 +1,10 @@
import { Component, ElementRef } from '@angular/core';
import { Component, ElementRef, inject } from '@angular/core';
@Component({
selector: 'aol-content',
template: '<ng-content></ng-content>',
standalone: false
selector: 'aol-content',
template: '<ng-content></ng-content>',
standalone: true,
})
export class ContentComponent {
constructor(public elementRef: ElementRef) {}
readonly elementRef = inject(ElementRef);
}

View File

@@ -1,33 +1,31 @@
import { Component, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, ElementRef, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Attribution } from 'ol/control';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-attribution',
template: ``,
standalone: false
selector: 'aol-control-attribution',
template: ``,
standalone: true,
})
export class ControlAttributionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
private element = inject(ElementRef);
@Input()
collapsible: boolean;
public componentType = 'control';
componentType = 'control';
instance: Attribution;
target: HTMLElement;
constructor(
private map: MapComponent,
private element: ElementRef
) {}
ngOnInit() {
ngOnInit(): void {
this.target = this.element.nativeElement;
// console.log('ol.control.Attribution init: ', this);
this.instance = new Attribution(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-attribution');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,24 +1,24 @@
import { Component, ContentChild, OnDestroy, OnInit } from '@angular/core';
import { Component, ContentChild, OnDestroy, OnInit, inject } from '@angular/core';
import { Control } from 'ol/control';
import { MapComponent } from '../map.component';
import { ContentComponent } from '../content.component';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@ContentChild(ContentComponent, { static: true })
content: ContentComponent;
public componentType = 'control';
componentType = 'control';
instance: Control;
element: HTMLElement;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
if (this.content) {
this.element = this.content.elementRef.nativeElement;
this.instance = new Control(this);
@@ -26,7 +26,7 @@ export class ControlComponent implements OnInit, OnDestroy {
}
}
ngOnDestroy() {
ngOnDestroy(): void {
if (this.instance) {
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { Control, defaults } from 'ol/control';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Collection } from 'ol';
import { Control, defaults } from 'ol/control';
import { Options as AttributionOptions } from 'ol/control/Attribution';
import { Options as RotateOptions } from 'ol/control/Rotate';
import { Options as ZoomOptions } from 'ol/control/Zoom';
@@ -8,11 +8,13 @@ import { Options as ZoomOptions } from 'ol/control/Zoom';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-defaults',
template: '',
standalone: false
selector: 'aol-control-defaults',
template: '',
standalone: true,
})
export class DefaultControlComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
attribution: boolean;
@Input()
@@ -28,15 +30,13 @@ export class DefaultControlComponent implements OnInit, OnDestroy {
instance: Collection<Control>;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
// console.log('ol.control.defaults init: ', this);
this.instance = defaults(this);
this.instance.forEach((c) => this.map.instance.addControl(c));
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-defaults');
this.instance.forEach((c) => this.map.instance.removeControl(c));
}

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { FullScreen } from 'ol/control';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-fullscreen',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-fullscreen',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlFullScreenComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -21,16 +23,12 @@ export class ControlFullScreenComponent implements OnInit, OnDestroy {
instance: FullScreen;
constructor(private map: MapComponent) {
// console.log('instancing aol-control-fullscreen');
}
ngOnInit() {
ngOnInit(): void {
this.instance = new FullScreen(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-fullscreen');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,36 +1,36 @@
import { Component, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, ElementRef, Input, OnDestroy, OnInit, inject } from '@angular/core';
import MousePosition from 'ol/control/MousePosition';
import { MapComponent } from '../map.component';
import { CoordinateFormat } from 'ol/coordinate';
import { ProjectionLike } from 'ol/proj';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-mouseposition',
template: ``,
standalone: false
selector: 'aol-control-mouseposition',
template: ``,
standalone: true,
})
export class ControlMousePositionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
private element = inject(ElementRef);
@Input()
coordinateFormat: CoordinateFormat;
@Input()
projection: ProjectionLike;
instance: MousePosition;
@Input()
wrapX: boolean;
target: HTMLElement;
constructor(
private map: MapComponent,
private element: ElementRef
) {}
instance: MousePosition;
ngOnInit() {
ngOnInit(): void {
this.target = this.element.nativeElement;
// console.log('ol.control.MousePosition init: ', this);
this.instance = new MousePosition(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-mouseposition');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,15 +1,17 @@
import { Component, Input, OnDestroy, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Layer } from 'ol/layer';
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, inject } from '@angular/core';
import { View } from 'ol';
import { OverviewMap } from 'ol/control';
import { Layer } from 'ol/layer';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-overviewmap',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-overviewmap',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlOverviewMapComponent implements OnInit, OnChanges, OnDestroy {
private map = inject(MapComponent);
@Input()
collapsed: boolean;
@Input()
@@ -29,24 +31,22 @@ export class ControlOverviewMapComponent implements OnInit, OnChanges, OnDestroy
instance: OverviewMap;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new OverviewMap(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeControl(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (this.instance != null && changes.hasOwnProperty('view')) {
this.reloadInstance();
}
}
private reloadInstance() {
private reloadInstance(): void {
this.map.instance.removeControl(this.instance);
this.instance = new OverviewMap(this);
this.map.instance.addControl(this.instance);

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Rotate } from 'ol/control';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-rotate',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-rotate',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlRotateComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -21,16 +23,12 @@ export class ControlRotateComponent implements OnInit, OnDestroy {
instance: Rotate;
constructor(private map: MapComponent) {
// console.log('instancing aol-control-rotate');
}
ngOnInit() {
ngOnInit(): void {
this.instance = new Rotate(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-rotate');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,27 +1,28 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { ScaleLine } from 'ol/control';
import { MapComponent } from '../map.component';
import { Units } from 'ol/control/ScaleLine';
@Component({
selector: 'aol-control-scaleline',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-scaleline',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlScaleLineComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
units: Units;
instance: ScaleLine;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new ScaleLine(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-scaleline');
this.map.instance.removeControl(this.instance);
}
}

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Zoom } from 'ol/control';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-zoom',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-zoom',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlZoomComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
duration: number;
@Input()
@@ -23,16 +25,12 @@ export class ControlZoomComponent implements OnInit, OnDestroy {
instance: Zoom;
constructor(private map: MapComponent) {
// console.log('instancing aol-control-zoom');
}
ngOnInit() {
ngOnInit(): void {
this.instance = new Zoom(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-zoom');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { ZoomSlider } from 'ol/control';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-zoomslider',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-zoomslider',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlZoomSliderComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -19,16 +21,12 @@ export class ControlZoomSliderComponent implements OnInit, OnDestroy {
instance: ZoomSlider;
constructor(private map: MapComponent) {
// console.log('instancing aol-control-zoomslider');
}
ngOnInit() {
ngOnInit(): void {
this.instance = new ZoomSlider(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-zoomslider');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,14 +1,16 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { ZoomToExtent } from 'ol/control';
import { MapComponent } from '../map.component';
import { Extent } from 'ol/extent';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-control-zoomtoextent',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-control-zoomtoextent',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ControlZoomToExtentComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -20,16 +22,12 @@ export class ControlZoomToExtentComponent implements OnInit, OnDestroy {
instance: ZoomToExtent;
constructor(private map: MapComponent) {
// console.log('instancing aol-control-zoomtoextent');
}
ngOnInit() {
ngOnInit(): void {
this.instance = new ZoomToExtent(this);
this.map.instance.addControl(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-control-zoomtoextent');
this.map.instance.removeControl(this.instance);
}

View File

@@ -1,17 +1,19 @@
import { Component, Optional, OnChanges, Input, SimpleChanges, OnInit } from '@angular/core';
import { Component, Input, OnChanges, OnInit, inject } from '@angular/core';
import { transform } from 'ol/proj';
import { MapComponent } from './map.component';
import { GeometryPointComponent } from './geom/geometrypoint.component';
import { GeometryCircleComponent } from './geom/geometrycircle.component';
import { ViewComponent } from './view.component';
import { GeometryPointComponent } from './geom/geometrypoint.component';
import { MapComponent } from './map.component';
import { OverlayComponent } from './overlay.component';
import { ViewComponent } from './view.component';
@Component({
selector: 'aol-coordinate',
template: ` <div class="aol-coordinate"></div> `,
standalone: false
selector: 'aol-coordinate',
template: ` <div class="aol-coordinate"></div> `,
standalone: true,
})
export class CoordinateComponent implements OnChanges, OnInit {
private map = inject(MapComponent);
@Input()
x: number;
@Input()
@@ -19,16 +21,15 @@ export class CoordinateComponent implements OnChanges, OnInit {
@Input()
srid = 'EPSG:3857';
private host: any;
private host: ViewComponent | GeometryPointComponent | GeometryCircleComponent | OverlayComponent;
private mapSrid = 'EPSG:3857';
constructor(
private map: MapComponent,
@Optional() viewHost: ViewComponent,
@Optional() geometryPointHost: GeometryPointComponent,
@Optional() geometryCircleHost: GeometryCircleComponent,
@Optional() overlayHost: OverlayComponent
) {
constructor() {
const viewHost = inject(ViewComponent, { optional: true });
const geometryPointHost = inject(GeometryPointComponent, { optional: true });
const geometryCircleHost = inject(GeometryCircleComponent, { optional: true });
const overlayHost = inject(OverlayComponent, { optional: true });
// console.log('instancing aol-coordinate');
if (geometryPointHost !== null) {
this.host = geometryPointHost;
@@ -41,22 +42,22 @@ export class CoordinateComponent implements OnChanges, OnInit {
}
}
ngOnInit() {
ngOnInit(): void {
this.map.instance.on('change:view', (e) => this.onMapViewChanged(e));
this.mapSrid = this.map.instance.getView().getProjection().getCode();
this.transformCoordinates();
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(): void {
this.transformCoordinates();
}
private onMapViewChanged(event) {
private onMapViewChanged(event): void {
this.mapSrid = event.target.get(event.key).getProjection().getCode();
this.transformCoordinates();
}
private transformCoordinates() {
private transformCoordinates(): void {
let transformedCoordinates: number[];
if (this.srid === this.mapSrid) {
@@ -65,17 +66,12 @@ export class CoordinateComponent implements OnChanges, OnInit {
transformedCoordinates = transform([this.x, this.y], this.srid, this.mapSrid);
}
switch (this.host.componentType) {
case 'geometry-point':
this.host.instance.setCoordinates(transformedCoordinates);
break;
case 'geometry-circle':
case 'view':
this.host.instance.setCenter(transformedCoordinates);
break;
case 'overlay':
this.host.instance.setPosition(transformedCoordinates);
break;
if (this.host instanceof GeometryPointComponent) {
this.host.instance.setCoordinates(transformedCoordinates);
} else if (this.host instanceof OverlayComponent) {
this.host.instance.setPosition(transformedCoordinates);
} else {
this.host.instance.setCenter(transformedCoordinates);
}
}
}

View File

@@ -1,22 +1,22 @@
import { Component, OnInit, OnDestroy, OnChanges, Input, SimpleChanges } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit, inject } from '@angular/core';
import { Feature } from 'ol';
import { SourceVectorComponent } from './sources/vector.component';
@Component({
selector: 'aol-feature',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-feature',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class FeatureComponent implements OnInit, OnDestroy, OnChanges {
private host = inject(SourceVectorComponent);
@Input()
id: string | number | undefined;
public componentType = 'feature';
public instance: Feature;
componentType = 'feature';
instance: Feature;
constructor(private host: SourceVectorComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new Feature();
if (this.id !== undefined) {
this.instance.setId(this.id);
@@ -24,11 +24,11 @@ export class FeatureComponent implements OnInit, OnDestroy, OnChanges {
this.host.instance.addFeature(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.host.instance.removeFeature(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(): void {
if (this.instance) {
this.instance.setId(this.id);
}

View File

@@ -1,6 +1,7 @@
import Feature from 'ol/format/Feature';
import FeatureFormat from 'ol/format/Feature';
import RenderFeature from 'ol/render/Feature';
export class FormatComponent {
public instance: Feature;
public instance: FeatureFormat<RenderFeature>;
public componentType = 'format';
}

View File

@@ -1,17 +1,18 @@
import { Component, forwardRef, Input } from '@angular/core';
import { FormatComponent } from './format.component';
import { MVT } from 'ol/format';
import { FeatureClass } from 'ol/Feature';
import { FormatComponent } from './format.component';
import RenderFeature from 'ol/render/Feature';
import { FeatureToFeatureClass } from 'ol/format/Feature';
@Component({
selector: 'aol-format-mvt',
template: '',
providers: [{ provide: FormatComponent, useExisting: forwardRef(() => FormatMVTComponent) }],
standalone: false
selector: 'aol-format-mvt',
template: '',
providers: [{ provide: FormatComponent, useExisting: forwardRef(() => FormatMVTComponent) }],
standalone: true,
})
export class FormatMVTComponent extends FormatComponent {
@Input()
featureClass: FeatureClass;
featureClass: FeatureToFeatureClass<RenderFeature>;
@Input()
geometryName: string;
@Input()

View File

@@ -1,15 +1,16 @@
import { Component, Input, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component, Input } from '@angular/core';
import { Circle } from 'ol/geom';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-geometry-circle',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-circle',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryCircleComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryCircleComponent extends SimpleGeometryComponent {
componentType = 'geometry-circle';
instance = new Circle([0, 0]);
@Input()
get radius(): number {
return this.instance.getRadius();
@@ -17,13 +18,4 @@ export class GeometryCircleComponent extends SimpleGeometryComponent implements
set radius(radius: number) {
this.instance.setRadius(radius);
}
public componentType = 'geometry-circle';
public instance: Circle;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
// defaulting coordinates to [0,0]. To be overridden in child component.
this.instance = new Circle([0, 0]);
}
}

View File

@@ -1,27 +1,16 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { LineString } from 'ol/geom';
@Component({
selector: 'aol-geometry-linestring',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-linestring',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryLinestringComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryLinestringComponent extends SimpleGeometryComponent {
public componentType = 'geometry-linestring';
public instance: LineString;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new LineString([
[0, 0],
[1, 1],
]);
super.ngOnInit();
}
public instance = new LineString([
[0, 0],
[1, 1],
]);
}

View File

@@ -1,29 +1,18 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { MultiLineString } from 'ol/geom';
@Component({
selector: 'aol-geometry-multilinestring',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-multilinestring',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryMultiLinestringComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryMultiLinestringComponent extends SimpleGeometryComponent {
public componentType = 'geometry-multilinestring';
public instance: MultiLineString;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new MultiLineString([
[
[0, 0],
[1, 1],
],
]);
super.ngOnInit();
}
public instance = new MultiLineString([
[
[0, 0],
[1, 1],
],
]);
}

View File

@@ -1,27 +1,16 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { MultiPoint } from 'ol/geom';
@Component({
selector: 'aol-geometry-multipoint',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-multipoint',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryMultiPointComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryMultiPointComponent extends SimpleGeometryComponent {
public componentType = 'geometry-multipoint';
public instance: MultiPoint;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new MultiPoint([
[0, 0],
[1, 1],
]);
super.ngOnInit();
}
public instance = new MultiPoint([
[0, 0],
[1, 1],
]);
}

View File

@@ -1,32 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { MultiPolygon } from 'ol/geom';
@Component({
selector: 'aol-geometry-multipolygon',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-multipolygon',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryMultiPolygonComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryMultiPolygonComponent extends SimpleGeometryComponent {
public componentType = 'geometry-multipolygon';
public instance: MultiPolygon;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new MultiPolygon([
public instance = new MultiPolygon([
[
[
[
[0, 0],
[1, 1],
[0, 1],
],
[0, 0],
[1, 1],
[0, 1],
],
]);
super.ngOnInit();
}
],
]);
}

View File

@@ -1,24 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { Point } from 'ol/geom';
@Component({
selector: 'aol-geometry-point',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-point',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryPointComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryPointComponent extends SimpleGeometryComponent {
public componentType = 'geometry-point';
public instance: Point;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new Point([0, 0]);
super.ngOnInit();
}
public instance = new Point([0, 0]);
}

View File

@@ -1,30 +1,19 @@
import { Component, OnInit } from '@angular/core';
import { FeatureComponent } from '../feature.component';
import { Component } from '@angular/core';
import { SimpleGeometryComponent } from './simplegeometry.component';
import { MapComponent } from '../map.component';
import { Polygon } from 'ol/geom';
@Component({
selector: 'aol-geometry-polygon',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-geometry-polygon',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class GeometryPolygonComponent extends SimpleGeometryComponent implements OnInit {
export class GeometryPolygonComponent extends SimpleGeometryComponent {
public componentType = 'geometry-polygon';
public instance: Polygon;
constructor(map: MapComponent, host: FeatureComponent) {
super(map, host);
}
ngOnInit() {
this.instance = new Polygon([
[
[0, 0],
[1, 1],
[0, 1],
],
]);
super.ngOnInit();
}
public instance = new Polygon([
[
[0, 0],
[1, 1],
[0, 1],
],
]);
}

View File

@@ -1,22 +1,19 @@
import { Input, OnInit, Directive } from '@angular/core';
import { Directive, inject, Input, OnInit } from '@angular/core';
import SimpleGeometry from 'ol/geom/SimpleGeometry';
import { FeatureComponent } from '../feature.component';
import { MapComponent } from '../map.component';
import SimpleGeometry from 'ol/geom/SimpleGeometry';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class SimpleGeometryComponent implements OnInit {
@Input() srid: string;
public instance: SimpleGeometry;
public componentType = 'simple-geometry';
instance: SimpleGeometry;
componentType = 'simple-geometry';
protected constructor(
protected map: MapComponent,
protected host: FeatureComponent
) {}
protected readonly map = inject(MapComponent);
protected readonly host = inject(FeatureComponent);
ngOnInit() {
ngOnInit(): void {
this.host.instance.setGeometry(this.instance);
}
}

View File

@@ -1,14 +1,17 @@
import { Component, Input, AfterContentInit, OnChanges, SimpleChanges, OnDestroy } from '@angular/core';
import { AfterContentInit, Component, Input, OnChanges, OnDestroy, SimpleChanges, inject } from '@angular/core';
import { Graticule } from 'ol';
import { Stroke } from 'ol/style';
import { MapComponent } from './map.component';
import { Options } from 'ol/layer/Graticule';
@Component({
selector: 'aol-graticule',
template: '<ng-content></ng-content>',
standalone: false
selector: 'aol-graticule',
template: '<ng-content></ng-content>',
standalone: true,
})
export class GraticuleComponent implements AfterContentInit, OnChanges, OnDestroy {
private map = inject(MapComponent);
@Input()
strokeStyle: Stroke;
@Input()
@@ -18,24 +21,17 @@ export class GraticuleComponent implements AfterContentInit, OnChanges, OnDestro
@Input()
latLabelPosition: number;
instance: any;
public componentType = 'graticule';
constructor(private map: MapComponent) {}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
instance: Graticule;
componentType = 'graticule';
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Options = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
properties[key] = changes[key].currentValue;
}
properties[key] = changes[key].currentValue;
}
if (properties) {
this.instance = new Graticule(properties);
}

View File

@@ -1,47 +1,24 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { defaults, Interaction } from 'ol/interaction';
import { Collection } from 'ol';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-default',
template: '',
standalone: false
selector: 'aol-interaction-default',
template: '',
standalone: true,
})
export class DefaultInteractionComponent implements OnInit, OnDestroy {
@Input()
altShiftDragRotate: boolean;
@Input()
onFocusOnly: boolean;
@Input()
doubleClickZoom: boolean;
@Input()
keyboard: boolean;
@Input()
mouseWheelZoom: boolean;
@Input()
shiftDragZoom: boolean;
@Input()
dragPan: boolean;
@Input()
pinchRotate: boolean;
@Input()
pinchZoom: boolean;
@Input()
zoomDelta: number;
@Input()
zoomDuration: number;
private map = inject(MapComponent);
instance: Collection<Interaction>;
constructor(private map: MapComponent) {}
ngOnInit() {
this.instance = defaults(this);
ngOnInit(): void {
this.instance = defaults();
this.instance.forEach((i) => this.map.instance.addInteraction(i));
}
ngOnDestroy() {
ngOnDestroy(): void {
this.instance.forEach((i) => this.map.instance.removeInteraction(i));
}
}

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { DoubleClickZoom } from 'ol/interaction';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-doubleclickzoom',
template: '',
standalone: false
selector: 'aol-interaction-doubleclickzoom',
template: '',
standalone: true,
})
export class DoubleClickZoomInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
duration: number;
@Input()
@@ -15,14 +17,12 @@ export class DoubleClickZoomInteractionComponent implements OnInit, OnDestroy {
instance: DoubleClickZoom;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DoubleClickZoom(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,15 +1,17 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { DragAndDrop } from 'ol/interaction';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import FeatureFormat from 'ol/format/Feature';
import { MapComponent } from '../map.component';
import { DragAndDrop } from 'ol/interaction';
import { ProjectionLike } from 'ol/proj';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-draganddrop',
template: '',
standalone: false
selector: 'aol-interaction-draganddrop',
template: '',
standalone: true,
})
export class DragAndDropInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
formatConstructors: FeatureFormat[];
@Input()
@@ -19,14 +21,12 @@ export class DragAndDropInteractionComponent implements OnInit, OnDestroy {
instance: DragAndDrop;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragAndDrop(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,15 +1,17 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { DragBox } from 'ol/interaction';
import { MapComponent } from '../map.component';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Condition } from 'ol/events/condition';
import { DragBox } from 'ol/interaction';
import { EndCondition } from 'ol/interaction/DragBox';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-dragbox',
template: '',
standalone: false
selector: 'aol-interaction-dragbox',
template: '',
standalone: true,
})
export class DragBoxInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -19,14 +21,12 @@ export class DragBoxInteractionComponent implements OnInit, OnDestroy {
instance: DragBox;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragBox(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,15 +1,17 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { DragPan } from 'ol/interaction';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import Kinetic from 'ol/Kinetic';
import { MapComponent } from '../map.component';
import { Condition } from 'ol/events/condition';
import { DragPan } from 'ol/interaction';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-dragpan',
template: '',
standalone: false
selector: 'aol-interaction-dragpan',
template: '',
standalone: true,
})
export class DragPanInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
condition: Condition;
@Input()
@@ -17,14 +19,12 @@ export class DragPanInteractionComponent implements OnInit, OnDestroy {
instance: DragPan;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragPan(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,14 +1,16 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Condition } from 'ol/events/condition';
import { DragRotate } from 'ol/interaction';
import { MapComponent } from '../map.component';
import { Condition } from 'ol/events/condition';
@Component({
selector: 'aol-interaction-dragrotate',
template: '',
standalone: false
selector: 'aol-interaction-dragrotate',
template: '',
standalone: true,
})
export class DragRotateInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
condition: Condition;
@Input()
@@ -16,14 +18,12 @@ export class DragRotateInteractionComponent implements OnInit, OnDestroy {
instance: DragRotate;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragRotate(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,14 +1,16 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Condition } from 'ol/events/condition';
import { DragRotateAndZoom } from 'ol/interaction';
import { MapComponent } from '../map.component';
import { Condition } from 'ol/events/condition';
@Component({
selector: 'aol-interaction-dragrotateandzoom',
template: '',
standalone: false
selector: 'aol-interaction-dragrotateandzoom',
template: '',
standalone: true,
})
export class DragRotateAndZoomInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
condition: Condition;
@Input()
@@ -16,14 +18,12 @@ export class DragRotateAndZoomInteractionComponent implements OnInit, OnDestroy
instance: DragRotateAndZoom;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragRotateAndZoom(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,14 +1,16 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Condition } from 'ol/events/condition';
import { DragZoom } from 'ol/interaction';
import { MapComponent } from '../map.component';
import { Condition } from 'ol/events/condition';
@Component({
selector: 'aol-interaction-dragzoom',
template: '',
standalone: false
selector: 'aol-interaction-dragzoom',
template: '',
standalone: true,
})
export class DragZoomInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
className: string;
@Input()
@@ -20,14 +22,12 @@ export class DragZoomInteractionComponent implements OnInit, OnDestroy {
instance: DragZoom;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new DragZoom(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,22 +1,23 @@
import { Component, Input, OnDestroy, OnInit, EventEmitter, Output } from '@angular/core';
import { MapComponent } from '../map.component';
import { Draw } from 'ol/interaction';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { Collection, Feature } from 'ol';
import { ObjectEvent } from 'ol/Object';
import { Condition } from 'ol/events/condition';
import { Draw } from 'ol/interaction';
import { DrawEvent, GeometryFunction } from 'ol/interaction/Draw';
import { Vector } from 'ol/source';
import { Style } from 'ol/style';
import { DrawEvent, GeometryFunction } from 'ol/interaction/Draw';
import { StyleFunction } from 'ol/style/Style';
import { Condition } from 'ol/events/condition';
import { MapComponent } from '../map.component';
import { Type } from 'ol/geom/Geometry';
import { ObjectEvent } from 'ol/Object';
import BaseEvent from 'ol/events/Event';
@Component({
selector: 'aol-interaction-draw',
template: '',
standalone: false
selector: 'aol-interaction-draw',
template: '',
standalone: true,
})
export class DrawInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
clickTolerance?: number;
@Input()
@@ -53,33 +54,25 @@ export class DrawInteractionComponent implements OnInit, OnDestroy {
@Output()
olChangeActive = new EventEmitter<ObjectEvent>();
@Output()
olDrawAbort = new EventEmitter<DrawEvent>();
@Output()
drawEnd = new EventEmitter<DrawEvent>();
@Output()
drawStart = new EventEmitter<DrawEvent>();
@Output()
olError = new EventEmitter<BaseEvent>();
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
instance: Draw;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new Draw(this);
this.instance.on('change', (event: DrawEvent) => this.olChange.emit(event));
this.instance.on('change:active', (event: ObjectEvent) => this.olChangeActive.emit(event));
this.instance.on('drawabort', (event: DrawEvent) => this.olDrawAbort.emit(event));
this.instance.on('drawend', (event: DrawEvent) => this.drawEnd.emit(event));
this.instance.on('drawstart', (event: DrawEvent) => this.drawStart.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,22 +1,22 @@
import { Component, OnDestroy, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { MapComponent } from '../map.component';
import { Modify } from 'ol/interaction';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { Collection, Feature } from 'ol';
import { Style } from 'ol/style';
import { Vector } from 'ol/source';
import { ModifyEvent } from 'ol/interaction/Modify';
import { StyleFunction } from 'ol/style/Style';
import { Condition } from 'ol/events/condition';
import { ObjectEvent } from 'ol/Object';
import { DrawEvent } from 'ol/interaction/Draw';
import BaseEvent from 'ol/events/Event';
import { Condition } from 'ol/events/condition';
import { Modify } from 'ol/interaction';
import { ModifyEvent } from 'ol/interaction/Modify';
import { Vector } from 'ol/source';
import { Style } from 'ol/style';
import { StyleFunction } from 'ol/style/Style';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-modify',
template: '',
standalone: false
selector: 'aol-interaction-modify',
template: '',
standalone: true,
})
export class ModifyInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
condition?: Condition;
@Input()
@@ -33,34 +33,29 @@ export class ModifyInteractionComponent implements OnInit, OnDestroy {
source?: Vector;
@Output()
olChange = new EventEmitter<DrawEvent>();
modifyEnd = new EventEmitter<ModifyEvent>();
@Output()
modifyStart = new EventEmitter<ModifyEvent>();
@Output()
olChange = new EventEmitter<ModifyEvent>();
@Output()
olChangeActive = new EventEmitter<ObjectEvent>();
@Output()
olError = new EventEmitter<BaseEvent>();
@Output()
olModifyEnd = new EventEmitter<ModifyEvent>();
@Output()
olModifyStart = new EventEmitter<ModifyEvent>();
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
instance: Modify;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new Modify(this);
this.instance.on('change', (event: DrawEvent) => this.olChange.emit(event));
this.instance.on('change', (event: ModifyEvent) => this.olChange.emit(event));
this.instance.on('change:active', (event: ObjectEvent) => this.olChangeActive.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('modifyend', (event: ModifyEvent) => this.olModifyEnd.emit(event));
this.instance.on('modifystart', (event: ModifyEvent) => this.olModifyStart.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.instance.on('modifyend', (event: ModifyEvent) => this.modifyEnd.emit(event));
this.instance.on('modifystart', (event: ModifyEvent) => this.modifyStart.emit(event));
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,13 +1,15 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { MouseWheelZoom } from 'ol/interaction';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-mousewheelzoom',
template: '',
standalone: false
selector: 'aol-interaction-mousewheelzoom',
template: '',
standalone: true,
})
export class MouseWheelZoomInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
duration: number;
@Input()
@@ -17,14 +19,12 @@ export class MouseWheelZoomInteractionComponent implements OnInit, OnDestroy {
instance: MouseWheelZoom;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new MouseWheelZoom(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,13 +1,15 @@
import { Component, OnDestroy, OnInit, Input } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { PinchZoom } from 'ol/interaction';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-pinchzoom',
template: '',
standalone: false
selector: 'aol-interaction-pinchzoom',
template: '',
standalone: true,
})
export class PinchZoomInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
duration: number;
@Input()
@@ -15,14 +17,12 @@ export class PinchZoomInteractionComponent implements OnInit, OnDestroy {
instance: PinchZoom;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new PinchZoom(this);
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,21 +1,22 @@
import { Component, OnDestroy, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { MapComponent } from '../map.component';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { Collection, Feature } from 'ol';
import { ObjectEvent } from 'ol/Object';
import { Condition } from 'ol/events/condition';
import { Select } from 'ol/interaction';
import { FilterFunction, SelectEvent } from 'ol/interaction/Select';
import { Layer } from 'ol/layer';
import { Style } from 'ol/style';
import { Collection, Feature } from 'ol';
import { SelectEvent, FilterFunction } from 'ol/interaction/Select';
import { StyleFunction } from 'ol/style/Style';
import { Condition } from 'ol/events/condition';
import { ObjectEvent } from 'ol/Object';
import BaseEvent from 'ol/events/Event';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-select',
template: '',
standalone: false
selector: 'aol-interaction-select',
template: '',
standalone: true,
})
export class SelectInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
addCondition?: Condition;
@Input()
@@ -40,30 +41,23 @@ export class SelectInteractionComponent implements OnInit, OnDestroy {
@Output()
olChange = new EventEmitter<SelectEvent>();
@Output()
olChangeActive = new EventEmitter<ObjectEvent>();
@Output()
olError = new EventEmitter<BaseEvent>();
olSelect = new EventEmitter<SelectEvent>();
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
@Output()
olSelect = new EventEmitter<SelectEvent>();
instance: Select;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
this.instance = new Select(this);
this.instance.on('change', (event: SelectEvent) => this.olChange.emit(event));
this.instance.on('change:active', (event: ObjectEvent) => this.olChangeActive.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.instance.on('select', (event: SelectEvent) => this.olSelect.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -0,0 +1,66 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { Collection, Feature } from 'ol';
import { ObjectEvent } from 'ol/Object';
import { Snap } from 'ol/interaction';
import { MapComponent } from '../map.component';
import { SnapEvent } from 'ol/events/SnapEvent';
import { Segmenters } from 'ol/interaction/Snap';
import VectorSource from 'ol/source/Vector';
import { Geometry } from 'ol/geom';
@Component({
selector: 'aol-interaction-snap',
template: '',
standalone: true,
})
export class SnapInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
features?: Collection<Feature>;
@Input()
source?: VectorSource<Feature<Geometry>>;
@Input()
edge?: boolean;
@Input()
vertex?: boolean;
@Input()
intersection?: boolean;
@Input()
pixelTolerance?: number;
@Input()
segmenters?: Segmenters;
@Output()
olChange: EventEmitter<SnapEvent>;
@Output()
propertyChange: EventEmitter<ObjectEvent>;
@Output()
snap: EventEmitter<SnapEvent>;
@Output()
unsnap: EventEmitter<SnapEvent>;
instance: Snap;
constructor() {
this.olChange = new EventEmitter<SnapEvent>();
this.propertyChange = new EventEmitter<ObjectEvent>();
this.snap = new EventEmitter<SnapEvent>();
this.unsnap = new EventEmitter<SnapEvent>();
}
ngOnInit(): void {
this.instance = new Snap(this);
this.instance.on('change', (event: SnapEvent) => this.olChange.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.instance.on('snap', (event: SnapEvent) => this.snap.emit(event));
this.instance.on('unsnap', (event: SnapEvent) => this.unsnap.emit(event));
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,18 +1,19 @@
import { Component, OnDestroy, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Translate } from 'ol/interaction';
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
import { Collection, Feature } from 'ol';
import { Layer } from 'ol/layer';
import { TranslateEvent } from 'ol/interaction/Translate';
import { MapComponent } from '../map.component';
import BaseEvent from 'ol/events/Event';
import { ObjectEvent } from 'ol/Object';
import { Translate } from 'ol/interaction';
import { TranslateEvent } from 'ol/interaction/Translate';
import { Layer } from 'ol/layer';
import { MapComponent } from '../map.component';
@Component({
selector: 'aol-interaction-translate',
template: '',
standalone: false
selector: 'aol-interaction-translate',
template: '',
standalone: true,
})
export class TranslateInteractionComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@Input()
features?: Collection<Feature>;
@Input()
@@ -21,30 +22,30 @@ export class TranslateInteractionComponent implements OnInit, OnDestroy {
hitTolerance?: number;
@Output()
olChange = new EventEmitter<BaseEvent>();
olChange: EventEmitter<TranslateEvent>;
@Output()
olChangeActive = new EventEmitter<ObjectEvent>();
propertyChange: EventEmitter<ObjectEvent>;
@Output()
olError = new EventEmitter<BaseEvent>();
translateEnd: EventEmitter<TranslateEvent>;
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
translateStart: EventEmitter<TranslateEvent>;
@Output()
translateEnd = new EventEmitter<TranslateEvent>();
@Output()
translateStart = new EventEmitter<TranslateEvent>();
@Output()
translating = new EventEmitter<TranslateEvent>();
translating: EventEmitter<TranslateEvent>;
instance: Translate;
constructor(private map: MapComponent) {}
constructor() {
this.olChange = new EventEmitter<TranslateEvent>();
this.propertyChange = new EventEmitter<ObjectEvent>();
this.translateEnd = new EventEmitter<TranslateEvent>();
this.translateStart = new EventEmitter<TranslateEvent>();
this.translating = new EventEmitter<TranslateEvent>();
}
ngOnInit() {
ngOnInit(): void {
this.instance = new Translate(this);
this.instance.on('change', (event: BaseEvent) => this.olChange.emit(event));
this.instance.on('change:active', (event: ObjectEvent) => this.olChangeActive.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('change', (event: TranslateEvent) => this.olChange.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.instance.on('translateend', (event: TranslateEvent) => this.translateEnd.emit(event));
this.instance.on('translatestart', (event: TranslateEvent) => this.translateStart.emit(event));
@@ -53,7 +54,7 @@ export class TranslateInteractionComponent implements OnInit, OnDestroy {
this.map.instance.addInteraction(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.map.instance.removeInteraction(this.instance);
}
}

View File

@@ -1,12 +1,15 @@
import { OnDestroy, OnInit, OnChanges, Input, SimpleChanges, Directive } from '@angular/core';
import Event from 'ol/events/Event';
import { Directive, inject, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { Extent } from 'ol/extent';
import RenderEvent from 'ol/render/Event';
import { MapComponent } from '../map.component';
import { LayerGroupComponent } from './layergroup.component';
import { Extent } from 'ol/extent';
import BaseObject from 'ol/Object';
import Map from 'ol/Map';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
@Input()
className: string;
@Input()
opacity: number;
@Input()
@@ -19,18 +22,32 @@ export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
minResolution: number;
@Input()
maxResolution: number;
@Input()
minZoom: number;
@Input()
maxZoom: number;
@Input()
map: Map;
@Input()
properties: {
[x: string]: unknown;
};
@Input()
prerender: (evt: Event) => void;
prerender: (evt: RenderEvent) => void;
@Input()
postrender: (evt: Event) => void;
postrender: (evt: RenderEvent) => void;
public instance: any;
public componentType = 'layer';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
instance: any;
componentType = 'layer';
protected constructor(protected host: MapComponent | LayerGroupComponent) {}
private readonly mapComponent = inject(MapComponent);
private readonly group = inject(LayerGroupComponent, { optional: true });
ngOnInit() {
protected host = this.group || this.mapComponent;
ngOnInit(): void {
if (this.prerender !== null && this.prerender !== undefined) {
this.instance.on('prerender', this.prerender);
}
@@ -40,26 +57,24 @@ export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
this.host.instance.getLayers().push(this.instance);
}
ngOnDestroy() {
ngOnDestroy(): void {
this.host.instance.getLayers().remove(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
properties[key] = changes[key].currentValue;
if (key === 'prerender') {
this.instance.un('prerender', changes[key].previousValue);
this.instance.on('prerender', changes[key].currentValue);
}
if (key === 'postrender') {
this.instance.un('postrender', changes[key].previousValue);
this.instance.on('postrender', changes[key].currentValue);
}
properties[key] = changes[key].currentValue;
if (key === 'prerender') {
this.instance.un('prerender', changes[key].previousValue);
this.instance.on('prerender', changes[key].currentValue);
}
if (key === 'postrender') {
this.instance.un('postrender', changes[key].previousValue);
this.instance.on('postrender', changes[key].currentValue);
}
}
// console.log('changes detected in aol-layer, setting new properties: ', properties);

View File

@@ -1,28 +1,64 @@
import { Component, OnDestroy, OnInit, SkipSelf, Optional } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, inject } from '@angular/core';
import { Group } from 'ol/layer';
import { LayerComponent } from './layer.component';
import { MapComponent } from '../map.component';
import { Extent } from 'ol/extent';
import BaseObject from 'ol/Object';
import BaseLayer from 'ol/layer/Base';
import Collection from 'ol/Collection';
@Component({
selector: 'aol-layer-group',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-layer-group',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class LayerGroupComponent extends LayerComponent implements OnInit, OnDestroy {
export class LayerGroupComponent implements OnInit, OnDestroy, OnChanges {
@Input()
opacity: number;
@Input()
visible: boolean;
@Input()
extent: Extent;
@Input()
zIndex: number;
@Input()
minResolution: number;
@Input()
maxResolution: number;
@Input()
minZoom: number;
@Input()
maxZoom: number;
@Input()
layers: BaseLayer[] | Collection<BaseLayer>;
@Input()
properties: {
[x: string]: unknown;
};
public instance: Group;
componentType = 'layer';
private readonly map = inject(MapComponent);
private readonly group = inject(LayerGroupComponent, { skipSelf: true, optional: true });
private readonly host = this.group || this.map;
constructor(
map: MapComponent,
@SkipSelf()
@Optional()
group?: LayerGroupComponent
) {
super(group || map);
}
ngOnInit() {
ngOnInit(): void {
// console.log(`creating ol.layer.Group instance with:`, this);
this.instance = new Group(this);
super.ngOnInit();
this.host.instance.getLayers().push(this.instance);
}
ngOnDestroy(): void {
this.host.instance.getLayers().remove(this.instance);
}
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
properties[key] = changes[key].currentValue;
}
this.instance.setProperties(properties, false);
}
}

View File

@@ -1,39 +1,18 @@
import { Component, Input, OnChanges, OnInit, Optional, SimpleChanges } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Image } from 'ol/layer';
import { MapComponent } from '../map.component';
import ImageSource from 'ol/source/Image';
import { LayerComponent } from './layer.component';
import { LayerGroupComponent } from './layergroup.component';
import { Extent } from 'ol/extent';
@Component({
selector: 'aol-layer-image',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-layer-image',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class LayerImageComponent extends LayerComponent implements OnInit, OnChanges {
@Input()
opacity: number;
@Input()
visible: boolean;
@Input()
extent: Extent;
@Input()
minResolution: number;
@Input()
maxResolution: number;
@Input()
zIndex: number;
export class LayerImageComponent extends LayerComponent implements OnInit {
source: ImageSource;
constructor(map: MapComponent, @Optional() group?: LayerGroupComponent) {
super(group || map);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new Image(this);
super.ngOnInit();
}
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
}
}

View File

@@ -1,31 +1,28 @@
import { Component, OnDestroy, OnInit, Input, Optional, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { Tile } from 'ol/layer';
import { MapComponent } from '../map.component';
import TileSource from 'ol/source/Tile';
import { LayerComponent } from './layer.component';
import { LayerGroupComponent } from './layergroup.component';
import { BackgroundColor } from 'ol/layer/Base';
@Component({
selector: 'aol-layer-tile',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-layer-tile',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class LayerTileComponent extends LayerComponent implements OnInit, OnDestroy, OnChanges {
export class LayerTileComponent extends LayerComponent implements OnInit {
@Input()
preload: number;
@Input()
background: BackgroundColor;
@Input()
useInterimTilesOnError: boolean;
@Input()
cacheSize: number;
constructor(map: MapComponent, @Optional() group?: LayerGroupComponent) {
super(group || map);
}
source: TileSource;
ngOnInit() {
// console.log('creating ol.layer.Tile instance with:', this);
ngOnInit(): void {
this.instance = new Tile(this);
super.ngOnInit();
}
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
}
}

View File

@@ -1,40 +1,37 @@
import { Component, OnDestroy, OnInit, Input, Optional, OnChanges, SimpleChanges } from '@angular/core';
import { MapComponent } from '../map.component';
import { Component, Input, OnInit } from '@angular/core';
import { Vector } from 'ol/layer';
import VectorSource from 'ol/source/Vector';
import { Style } from 'ol/style';
import { StyleFunction } from 'ol/style/Style';
import { LayerComponent } from './layer.component';
import { LayerGroupComponent } from './layergroup.component';
import { OrderFunction } from 'ol/render';
import { BackgroundColor } from 'ol/layer/Base';
@Component({
selector: 'aol-layer-vector',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-layer-vector',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class LayerVectorComponent extends LayerComponent implements OnInit, OnDestroy, OnChanges {
export class LayerVectorComponent extends LayerComponent implements OnInit {
@Input()
renderBuffer: number;
@Input()
style: Style | Style[] | StyleFunction;
@Input()
updateWhileAnimating: boolean;
@Input()
updateWhileInteracting: boolean;
@Input()
renderOrder: OrderFunction;
@Input()
declutter: string | number | boolean;
@Input()
background: BackgroundColor;
constructor(map: MapComponent, @Optional() group?: LayerGroupComponent) {
super(group || map);
}
source: VectorSource;
ngOnInit() {
// console.log('creating ol.layer.Vector instance with:', this);
ngOnInit(): void {
this.instance = new Vector(this);
super.ngOnInit();
}
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
}
}

View File

@@ -1,25 +1,24 @@
import { Component, OnInit, Input, Optional, SimpleChanges, OnChanges } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { VectorTile } from 'ol/layer';
import { Feature } from 'ol';
import { Style } from 'ol/style';
import { MapComponent } from '../map.component';
import { LayerComponent } from './layer.component';
import { LayerGroupComponent } from './layergroup.component';
import { StyleFunction } from 'ol/style/Style';
import { LayerComponent } from './layer.component';
import { VectorTileRenderType } from 'ol/layer/VectorTile';
import { OrderFunction } from 'ol/render';
import { BackgroundColor } from 'ol/layer/Base';
@Component({
selector: 'aol-layer-vectortile',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-layer-vectortile',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class LayerVectorTileComponent extends LayerComponent implements OnInit, OnChanges {
export class LayerVectorTileComponent extends LayerComponent implements OnInit {
@Input()
renderOrder: OrderFunction;
@Input()
renderBuffer: number;
@Input()
renderMode: any | string;
/* not marked as optional in the typings */
@Input()
renderOrder: (feature1: Feature, feature2: Feature) => number;
renderMode: VectorTileRenderType;
@Input()
style: Style | Style[] | StyleFunction;
@Input()
@@ -27,19 +26,18 @@ export class LayerVectorTileComponent extends LayerComponent implements OnInit,
@Input()
updateWhileInteracting: boolean;
@Input()
visible: boolean;
declutter: string | number | boolean;
@Input()
background: BackgroundColor;
@Input()
preload: number;
@Input()
useInterimTilesOnError: boolean;
@Input()
cacheSize: number;
constructor(map: MapComponent, @Optional() group?: LayerGroupComponent) {
super(group || map);
}
ngOnInit() {
// console.log('creating ol.layer.VectorTile instance with:', this);
ngOnInit(): void {
this.instance = new VectorTile(this);
super.ngOnInit();
}
ngOnChanges(changes: SimpleChanges) {
super.ngOnChanges(changes);
}
}

View File

@@ -1,33 +1,35 @@
import {
Component,
OnInit,
ElementRef,
Input,
Output,
EventEmitter,
AfterViewInit,
SimpleChanges,
Component,
ElementRef,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
inject,
} from '@angular/core';
import { Map } from 'ol';
import Map from 'ol/Map';
import MapBrowserEvent from 'ol/MapBrowserEvent';
import MapEvent from 'ol/MapEvent';
import { ObjectEvent } from 'ol/Object';
import RenderEvent from 'ol/render/Event';
import { Control } from 'ol/control';
import { Interaction } from 'ol/interaction';
import { DrawEvent } from 'ol/interaction/Draw';
import BaseEvent from 'ol/events/Event';
import { Interaction } from 'ol/interaction';
import RenderEvent from 'ol/render/Event';
import BaseObject from 'ol/Object';
@Component({
selector: 'aol-map',
template: `
selector: 'aol-map',
template: `
<div [style.width]="width" [style.height]="height"></div>
<ng-content></ng-content>
`,
standalone: false
standalone: true,
})
export class MapComponent implements OnInit, AfterViewInit, OnChanges {
private host = inject(ElementRef);
@Input()
width = '100%';
@Input()
@@ -46,98 +48,78 @@ export class MapComponent implements OnInit, AfterViewInit, OnChanges {
renderer: 'canvas' | 'webgl';
@Output()
olChange = new EventEmitter<DrawEvent>();
olClick: EventEmitter<MapBrowserEvent>;
@Output()
olChangeLayerGroup = new EventEmitter<ObjectEvent>();
dblClick: EventEmitter<MapBrowserEvent>;
@Output()
olChangeSize = new EventEmitter<ObjectEvent>();
moveStart: EventEmitter<MapEvent>;
@Output()
olChangeTarget = new EventEmitter<ObjectEvent>();
moveEnd: EventEmitter<MapEvent>;
@Output()
olChangeView = new EventEmitter<ObjectEvent>();
pointerDrag: EventEmitter<MapBrowserEvent>;
@Output()
olClick = new EventEmitter<MapBrowserEvent<MouseEvent>>();
pointerMove: EventEmitter<MapBrowserEvent>;
@Output()
dblClick = new EventEmitter<MapBrowserEvent<MouseEvent>>();
onpostrender: EventEmitter<RenderEvent>;
@Output()
olError = new EventEmitter<BaseEvent>();
postRender: EventEmitter<MapEvent>;
@Output()
loadEnd = new EventEmitter<MapEvent>();
onpreCompose: EventEmitter<RenderEvent>;
@Output()
loadStart = new EventEmitter<MapEvent>();
propertyChange: EventEmitter<BaseEvent>;
@Output()
moveEnd = new EventEmitter<MapEvent>();
@Output()
moveStart = new EventEmitter<MapEvent>();
@Output()
pointerDrag = new EventEmitter<MapBrowserEvent<MouseEvent>>();
@Output()
pointerMove = new EventEmitter<MapBrowserEvent<MouseEvent>>();
@Output()
olPostCompose = new EventEmitter<RenderEvent>();
@Output()
olPostRender = new EventEmitter<RenderEvent>();
@Output()
olPreCompose = new EventEmitter<RenderEvent>();
@Output()
olPropertyChange = new EventEmitter<ObjectEvent>();
@Output()
postRender = new EventEmitter<MapEvent>();
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
@Output()
singleClick = new EventEmitter<MapBrowserEvent<MouseEvent>>();
public instance: Map;
public componentType = 'map';
singleClick: EventEmitter<MapBrowserEvent>;
instance: Map;
componentType = 'map';
// we pass empty arrays to not get default controls/interactions because we have our own directives
controls: Control[] = [];
interactions: Interaction[] = [];
constructor(private host: ElementRef) {}
constructor() {
this.olClick = new EventEmitter<MapBrowserEvent>();
this.dblClick = new EventEmitter<MapBrowserEvent>();
this.moveStart = new EventEmitter<MapEvent>();
this.moveEnd = new EventEmitter<MapEvent>();
this.pointerDrag = new EventEmitter<MapBrowserEvent>();
this.pointerMove = new EventEmitter<MapBrowserEvent>();
this.onpostrender = new EventEmitter<RenderEvent>();
this.postRender = new EventEmitter<MapEvent>();
this.onpreCompose = new EventEmitter<RenderEvent>();
this.propertyChange = new EventEmitter<BaseEvent>();
this.singleClick = new EventEmitter<MapBrowserEvent>();
}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.Map instance with:', this);
this.instance = new Map(this);
this.instance.setTarget(this.host.nativeElement.firstElementChild);
this.instance.on('change', (event: DrawEvent) => this.olChange.emit(event));
this.instance.on('change:layergroup', (event: ObjectEvent) => this.olChangeLayerGroup.emit(event));
this.instance.on('change:size', (event: ObjectEvent) => this.olChangeSize.emit(event));
this.instance.on('change:target', (event: ObjectEvent) => this.olChangeTarget.emit(event));
this.instance.on('change:view', (event: ObjectEvent) => this.olChangeView.emit(event));
this.instance.on('click', (event: MapBrowserEvent<MouseEvent>) => this.olClick.emit(event));
this.instance.on('dblclick', (event: MapBrowserEvent<MouseEvent>) => this.dblClick.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('loadend', (event: MapEvent) => this.loadEnd.emit(event));
this.instance.on('loadstart', (event: MapEvent) => this.loadStart.emit(event));
this.instance.on('moveend', (event: MapEvent) => this.moveEnd.emit(event));
this.instance.on('click', (event: MapBrowserEvent) => this.olClick.emit(event));
this.instance.on('dblclick', (event: MapBrowserEvent) => this.dblClick.emit(event));
this.instance.on('movestart', (event: MapEvent) => this.moveStart.emit(event));
this.instance.on('pointerdrag', (event: MapBrowserEvent<MouseEvent>) => this.pointerDrag.emit(event));
this.instance.on('pointermove', (event: MapBrowserEvent<MouseEvent>) => this.pointerMove.emit(event));
this.instance.on('postcompose', (event: RenderEvent) => this.olPostCompose.emit(event));
this.instance.on('postrender', (event: RenderEvent) => this.olPostRender.emit(event));
this.instance.on('moveend', (event: MapEvent) => this.moveEnd.emit(event));
this.instance.on('pointerdrag', (event: MapBrowserEvent) => this.pointerDrag.emit(event));
this.instance.on('pointermove', (event: MapBrowserEvent) => this.pointerMove.emit(event));
this.instance.on('postrender', (event: RenderEvent) => this.onpostrender.emit(event));
this.instance.on('postrender', (event: MapEvent) => this.postRender.emit(event));
this.instance.on('precompose', (event: RenderEvent) => this.olPreCompose.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.olPropertyChange.emit(event));
this.instance.on('singleclick', (event: MapBrowserEvent<MouseEvent>) => this.singleClick.emit(event));
this.instance.on('precompose', (event: RenderEvent) => this.onpreCompose.emit(event));
this.instance.on('propertychange', (event: BaseEvent) => this.propertyChange.emit(event));
this.instance.on('singleclick', (event: MapBrowserEvent) => this.singleClick.emit(event));
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
properties[key] = changes[key].currentValue;
}
properties[key] = changes[key].currentValue;
}
// console.log('changes detected in aol-map, setting new properties: ', properties);
this.instance.setProperties(properties, false);
}
ngAfterViewInit() {
ngAfterViewInit(): void {
this.instance.updateSize();
}
}

View File

@@ -1,14 +1,17 @@
import { Component, ContentChild, Input, OnDestroy, OnInit } from '@angular/core';
import { MapComponent } from './map.component';
import Overlay, { PanOptions, Positioning } from 'ol/Overlay';
import { Component, ContentChild, Input, OnDestroy, OnInit, inject } from '@angular/core';
import { Overlay } from 'ol';
import { PanOptions, Positioning } from 'ol/Overlay';
import { ContentComponent } from './content.component';
import { MapComponent } from './map.component';
@Component({
selector: 'aol-overlay',
template: '<ng-content></ng-content>',
standalone: false
selector: 'aol-overlay',
template: '<ng-content></ng-content>',
standalone: true,
})
export class OverlayComponent implements OnInit, OnDestroy {
private map = inject(MapComponent);
@ContentChild(ContentComponent, { static: true })
content: ContentComponent;
@@ -33,9 +36,7 @@ export class OverlayComponent implements OnInit, OnDestroy {
instance: Overlay;
element: HTMLElement;
constructor(private map: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
if (this.content) {
this.element = this.content.elementRef.nativeElement;
this.instance = new Overlay(this);
@@ -43,7 +44,7 @@ export class OverlayComponent implements OnInit, OnDestroy {
}
}
ngOnDestroy() {
ngOnDestroy(): void {
if (this.instance) {
this.map.instance.removeOverlay(this.instance);
}

View File

@@ -1,14 +1,14 @@
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
import { BingMaps } from 'ol/source';
import { SourceComponent } from './source.component';
import { LayerTileComponent } from '../layers/layertile.component';
import { Component, forwardRef, inject, Input, OnInit } from '@angular/core';
import { LoadFunction } from 'ol/Tile';
import { BingMaps } from 'ol/source';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
@Component({
selector: 'aol-source-bingmaps',
template: ` <div class="aol-source-bingmaps"></div> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceBingmapsComponent) }],
standalone: false
selector: 'aol-source-bingmaps',
template: ` <div class="aol-source-bingmaps"></div> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceBingmapsComponent) }],
standalone: true,
})
export class SourceBingmapsComponent extends SourceComponent implements OnInit {
@Input()
@@ -29,14 +29,13 @@ export class SourceBingmapsComponent extends SourceComponent implements OnInit {
tileLoadFunction: LoadFunction;
@Input()
wrapX: boolean;
@Input()
placeholderTiles = false;
instance: BingMaps;
host = inject(LayerTileComponent, { host: true });
constructor(@Host() layer: LayerTileComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new BingMaps(this);
this.host.instance.setSource(this.instance);
}

View File

@@ -3,13 +3,13 @@ import {
Component,
ContentChild,
forwardRef,
Host,
inject,
Input,
OnChanges,
SimpleChanges,
} from '@angular/core';
import { Feature } from 'ol';
import { Point } from 'ol/geom';
import { Geometry, Point } from 'ol/geom';
import { Cluster, Vector } from 'ol/source';
import { LayerVectorComponent } from '../layers/layervector.component';
@@ -17,10 +17,10 @@ import { SourceComponent } from './source.component';
import { SourceVectorComponent } from './vector.component';
@Component({
selector: 'aol-source-cluster',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceClusterComponent) }],
standalone: false
selector: 'aol-source-cluster',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceClusterComponent) }],
standalone: true,
})
export class SourceClusterComponent extends SourceComponent implements AfterContentInit, OnChanges {
@Input()
@@ -30,24 +30,20 @@ export class SourceClusterComponent extends SourceComponent implements AfterCont
@Input()
wrapX?: boolean;
@ContentChild(SourceVectorComponent, { static: false })
@ContentChild(SourceVectorComponent)
sourceVectorComponent: SourceVectorComponent;
instance: Cluster;
source: Vector;
instance: Cluster<Feature<Geometry>>;
host = inject(LayerVectorComponent, { host: true });
constructor(@Host() layer: LayerVectorComponent) {
super(layer);
}
ngAfterContentInit() {
ngAfterContentInit(): void {
this.source = this.sourceVectorComponent.instance;
this.instance = new Cluster(this);
this.host.instance.setSource(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (this.instance && changes.hasOwnProperty('distance')) {
this.instance.setDistance(this.distance);
}

View File

@@ -1,16 +1,16 @@
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
import { Component, forwardRef, inject, Input, OnInit } from '@angular/core';
import { GeoJSON } from 'ol/format';
import FeatureFormat from 'ol/format/Feature';
import { ProjectionLike } from 'ol/proj';
import { Vector } from 'ol/source';
import { LayerVectorComponent } from '../layers/layervector.component';
import { SourceComponent } from './source.component';
import FeatureFormat from 'ol/format/Feature';
import { Vector } from 'ol/source';
import { GeoJSON } from 'ol/format';
import { ProjectionLike } from 'ol/proj';
@Component({
selector: 'aol-source-geojson',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceGeoJSONComponent) }],
standalone: false
selector: 'aol-source-geojson',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceGeoJSONComponent) }],
standalone: true,
})
export class SourceGeoJSONComponent extends SourceComponent implements OnInit {
@Input()
@@ -24,12 +24,9 @@ export class SourceGeoJSONComponent extends SourceComponent implements OnInit {
instance: Vector;
format: FeatureFormat;
host = inject(LayerVectorComponent, { host: true });
constructor(@Host() layer: LayerVectorComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.format = new GeoJSON(this);
this.instance = new Vector(this);
this.host.instance.setSource(this.instance);

View File

@@ -2,26 +2,26 @@ import {
Component,
EventEmitter,
forwardRef,
Host,
inject,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import ImageArcGISRest from 'ol/source/ImageArcGISRest';
import { LoadFunction } from 'ol/Image';
import { ProjectionLike } from 'ol/proj';
import { ImageArcGISRest } from 'ol/source';
import { ImageSourceEvent } from 'ol/source/Image';
import { AttributionLike } from 'ol/source/Source';
import { LayerImageComponent } from '../layers/layerimage.component';
import { SourceComponent } from './source.component';
import { ProjectionLike } from 'ol/proj';
import { AttributionLike } from 'ol/source/Source';
import { LoadFunction } from 'ol/Image';
import { ImageSourceEvent } from 'ol/source/Image';
@Component({
selector: 'aol-source-imagearcgisrest',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageArcGISRestComponent) }],
standalone: false
selector: 'aol-source-imagearcgisrest',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageArcGISRestComponent) }],
standalone: true,
})
export class SourceImageArcGISRestComponent extends SourceComponent implements OnInit, OnChanges {
@Input() projection: ProjectionLike | string;
@@ -29,7 +29,7 @@ export class SourceImageArcGISRestComponent extends SourceComponent implements O
@Input() attributions: AttributionLike;
@Input() crossOrigin?: string;
@Input() imageLoadFunction?: LoadFunction;
@Input() params?: { [k: string]: any };
@Input() params?: Record<string, unknown>;
@Input() ratio = 1.5;
@Input() resolutions?: number[];
@Input() wrapX?: boolean;
@@ -42,12 +42,9 @@ export class SourceImageArcGISRestComponent extends SourceComponent implements O
imageLoadError = new EventEmitter<ImageSourceEvent>();
instance: ImageArcGISRest;
host = inject(LayerImageComponent, { host: true });
constructor(@Host() layer: LayerImageComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new ImageArcGISRest(this);
this.host.instance.setSource(this.instance);
this.instance.on('imageloadstart', (event: ImageSourceEvent) => this.imageLoadStart.emit(event));
@@ -55,7 +52,7 @@ export class SourceImageArcGISRestComponent extends SourceComponent implements O
this.instance.on('imageloaderror', (event: ImageSourceEvent) => this.imageLoadError.emit(event));
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (this.instance && changes.hasOwnProperty('params')) {
this.instance.updateParams(this.params);
}

View File

@@ -1,29 +1,29 @@
import {
Component,
Host,
Input,
forwardRef,
Output,
EventEmitter,
forwardRef,
inject,
Input,
OnChanges,
SimpleChanges,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import { ImageStatic } from 'ol/source';
import { SourceComponent } from './source.component';
import { LayerImageComponent } from '../layers/layerimage.component';
import { ProjectionLike } from 'ol/proj';
import { Extent } from 'ol/extent';
import { AttributionLike } from 'ol/source/Source';
import { LoadFunction } from 'ol/Image';
import { Size } from 'ol/size';
import { Extent } from 'ol/extent';
import { ProjectionLike } from 'ol/proj';
import { ImageStatic } from 'ol/source';
import { ImageSourceEvent } from 'ol/source/Image';
import { AttributionLike } from 'ol/source/Source';
import { LayerImageComponent } from '../layers/layerimage.component';
import { SourceComponent } from './source.component';
import BaseObject from 'ol/Object';
@Component({
selector: 'aol-source-imagestatic',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageStaticComponent) }],
standalone: false
selector: 'aol-source-imagestatic',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageStaticComponent) }],
standalone: true,
})
export class SourceImageStaticComponent extends SourceComponent implements OnInit, OnChanges {
@Input()
@@ -38,8 +38,6 @@ export class SourceImageStaticComponent extends SourceComponent implements OnIni
crossOrigin?: string;
@Input()
imageLoadFunction?: LoadFunction;
@Input()
imageSize?: Size;
@Output()
imageLoadStart = new EventEmitter<ImageSourceEvent>();
@@ -49,10 +47,7 @@ export class SourceImageStaticComponent extends SourceComponent implements OnIni
imageLoadError = new EventEmitter<ImageSourceEvent>();
instance: ImageStatic;
constructor(@Host() layer: LayerImageComponent) {
super(layer);
}
host = inject(LayerImageComponent, { host: true });
setLayerSource(): void {
this.instance = new ImageStatic(this);
@@ -62,27 +57,25 @@ export class SourceImageStaticComponent extends SourceComponent implements OnIni
this.instance.on('imageloaderror', (event: ImageSourceEvent) => this.imageLoadError.emit(event));
}
ngOnInit() {
ngOnInit(): void {
this.setLayerSource();
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
switch (key) {
case 'url':
this.url = changes[key].currentValue;
this.setLayerSource();
break;
default:
break;
}
properties[key] = changes[key].currentValue;
switch (key) {
case 'url':
this.url = changes[key].currentValue;
this.setLayerSource();
break;
default:
break;
}
properties[key] = changes[key].currentValue;
}
this.instance.setProperties(properties, false);
}

View File

@@ -1,13 +1,13 @@
import {
Component,
Host,
EventEmitter,
forwardRef,
inject,
Input,
OnChanges,
OnInit,
forwardRef,
SimpleChanges,
Output,
EventEmitter,
SimpleChanges,
} from '@angular/core';
import { ImageWMS } from 'ol/source';
import { LayerImageComponent } from '../layers/layerimage.component';
@@ -19,47 +19,31 @@ import { ImageSourceEvent } from 'ol/source/Image';
import { ServerType } from 'ol/source/wms';
@Component({
selector: 'aol-source-imagewms',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageWMSComponent) }],
standalone: false
selector: 'aol-source-imagewms',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceImageWMSComponent) }],
standalone: true,
})
export class SourceImageWMSComponent extends SourceComponent implements OnChanges, OnInit {
@Input()
attributions: AttributionLike;
@Input()
crossOrigin: string;
@Input()
hidpi: boolean;
@Input()
serverType: ServerType;
@Input()
imageLoadFunction?: LoadFunction;
@Input()
params: { [key: string]: any };
@Input()
projection: ProjectionLike | string;
@Input()
ratio: number;
@Input()
resolutions: Array<number>;
@Input()
url: string;
@Input() attributions: AttributionLike;
@Input() crossOrigin: string;
@Input() hidpi: boolean;
@Input() serverType: ServerType;
@Input() imageLoadFunction?: LoadFunction;
@Input() params: Record<string, unknown>;
@Input() projection: ProjectionLike | string;
@Input() ratio: number;
@Input() resolutions: Array<number>;
@Input() url: string;
@Output()
imageLoadStart = new EventEmitter<ImageSourceEvent>();
@Output()
imageLoadEnd = new EventEmitter<ImageSourceEvent>();
@Output()
imageLoadError = new EventEmitter<ImageSourceEvent>();
@Output() imageLoadStart = new EventEmitter<ImageSourceEvent>();
@Output() imageLoadEnd = new EventEmitter<ImageSourceEvent>();
@Output() imageLoadError = new EventEmitter<ImageSourceEvent>();
instance: ImageWMS;
host = inject(LayerImageComponent, { host: true });
constructor(@Host() layer: LayerImageComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new ImageWMS(this);
this.host.instance.setSource(this.instance);
this.instance.on('imageloadstart', (event: ImageSourceEvent) => this.imageLoadStart.emit(event));
@@ -67,7 +51,7 @@ export class SourceImageWMSComponent extends SourceComponent implements OnChange
this.instance.on('imageloaderror', (event: ImageSourceEvent) => this.imageLoadError.emit(event));
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (this.instance && changes.hasOwnProperty('params')) {
this.instance.updateParams(this.params);
}

View File

@@ -1,17 +1,16 @@
import { AfterContentInit, Component, EventEmitter, forwardRef, Host, Input, Optional, Output } from '@angular/core';
import { AfterContentInit, Component, EventEmitter, forwardRef, Input, Output } from '@angular/core';
import { OSM } from 'ol/source';
import { AttributionLike } from 'ol/source/Source';
import { TileSourceEvent } from 'ol/source/Tile';
import { LoadFunction } from 'ol/Tile';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
import { SourceXYZComponent } from './xyz.component';
@Component({
selector: 'aol-source-osm',
template: ` <div class="aol-source-osm"></div> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceOsmComponent) }],
standalone: false
selector: 'aol-source-osm',
template: ` <div class="aol-source-osm"></div> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceOsmComponent) }],
standalone: true,
})
export class SourceOsmComponent extends SourceXYZComponent implements AfterContentInit {
@Input()
@@ -34,30 +33,24 @@ export class SourceOsmComponent extends SourceXYZComponent implements AfterConte
wrapX: boolean;
@Output()
tileLoadStart = new EventEmitter<TileSourceEvent>();
tileLoadStart: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadEnd = new EventEmitter<TileSourceEvent>();
tileLoadEnd: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadError = new EventEmitter<TileSourceEvent>();
tileLoadError: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
instance: OSM;
constructor(
@Optional()
@Host()
protected layer?: LayerTileComponent
) {
super(layer);
}
ngAfterContentInit() {
ngAfterContentInit(): void {
if (this.tileGridXYZ) {
this.tileGrid = this.tileGridXYZ.instance;
}
this.instance = new OSM(this);
this.instance.on('tileloadstart', (event: TileSourceEvent) => this.tileLoadStart.emit(event));
this.instance.on('tileloadend', (event: TileSourceEvent) => this.tileLoadEnd.emit(event));
this.instance.on('tileloaderror', (event: TileSourceEvent) => this.tileLoadError.emit(event));
this.register(this.instance);
this._register(this.instance);
}
}

View File

@@ -4,46 +4,47 @@ import {
ContentChild,
EventEmitter,
forwardRef,
Host,
inject,
Input,
Output,
} from '@angular/core';
import { Raster, Source } from 'ol/source';
import { Operation, RasterSourceEvent } from 'ol/source/Raster';
import { Options, RasterSourceEvent } from 'ol/source/Raster';
import { LayerImageComponent } from '../layers/layerimage.component';
import { SourceComponent } from './source.component';
@Component({
selector: 'aol-source-raster',
template: ` <ng-content></ng-content> `,
providers: [
{
provide: SourceComponent,
useExisting: forwardRef(() => SourceRasterComponent),
},
],
standalone: false
selector: 'aol-source-raster',
template: ` <ng-content></ng-content> `,
providers: [
{
provide: SourceComponent,
useExisting: forwardRef(() => SourceRasterComponent),
},
],
standalone: true,
})
export class SourceRasterComponent extends SourceComponent implements AfterContentInit {
@Input()
operation?: Operation;
operation?: Options['operation'];
@Input()
threads?: number;
threads?: Options['threads'];
@Input()
lib?: any;
lib?: Options['lib'];
@Input()
operationType?: 'pixel' | 'image';
operationType?: Options['operationType'];
@Output()
beforeOperations = new EventEmitter<RasterSourceEvent>();
beforeOperations: EventEmitter<RasterSourceEvent> = new EventEmitter<RasterSourceEvent>();
@Output()
afterOperations = new EventEmitter<RasterSourceEvent>();
afterOperations: EventEmitter<RasterSourceEvent> = new EventEmitter<RasterSourceEvent>();
instance: Raster;
sources: Source[] = [];
host = inject(LayerImageComponent, { host: true });
@ContentChild(SourceComponent, { static: false })
@ContentChild(SourceComponent)
set source(sourceComponent: SourceComponent) {
this.sources = [sourceComponent.instance];
if (this.instance) {
@@ -52,18 +53,14 @@ export class SourceRasterComponent extends SourceComponent implements AfterConte
}
}
constructor(@Host() layer: LayerImageComponent) {
super(layer);
}
ngAfterContentInit() {
ngAfterContentInit(): void {
this.init();
}
init() {
init(): void {
this.instance = new Raster(this);
this.instance.on('beforeoperations', (event: RasterSourceEvent) => this.beforeOperations.emit(event));
this.instance.on('afteroperations', (event: RasterSourceEvent) => this.afterOperations.emit(event));
this.register(this.instance);
this._register(this.instance);
}
}

View File

@@ -1,26 +1,26 @@
import { Input, OnDestroy, Directive } from '@angular/core';
import Source from 'ol/source/Source';
import { Directive, Input, OnDestroy } from '@angular/core';
import { Source } from 'ol/source';
import { LayerComponent } from '../layers/layer.component';
import { AttributionLike } from 'ol/source/Source';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class SourceComponent implements OnDestroy {
@Input()
attributions: any;
attributions: AttributionLike;
public instance: Source;
public componentType = 'source';
protected constructor(protected host: LayerComponent) {}
protected host: LayerComponent;
ngOnDestroy() {
ngOnDestroy(): void {
if (this.host && this.host.instance) {
this.host.instance.setSource(null);
}
}
protected register(s: Source) {
protected _register(s: Source): void {
if (this.host) {
this.host.instance.setSource(s);
}

View File

@@ -1,25 +1,22 @@
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
import { Component, forwardRef, inject, Input, OnInit } from '@angular/core';
import { TileJSON } from 'ol/source';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
@Component({
selector: 'aol-source-tilejson',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileJSONComponent) }],
standalone: false
selector: 'aol-source-tilejson',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileJSONComponent) }],
standalone: true,
})
export class SourceTileJSONComponent extends SourceComponent implements OnInit {
@Input()
url: string;
instance: TileJSON;
host = inject(LayerTileComponent, { host: true });
constructor(@Host() layer: LayerTileComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new TileJSON(this);
this.host.instance.setSource(this.instance);
}

View File

@@ -1,57 +1,42 @@
import { Component, Host, Input, OnChanges, OnInit, forwardRef, SimpleChanges } from '@angular/core';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
import { Component, forwardRef, inject, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { LoadFunction } from 'ol/Tile';
import { TileWMS } from 'ol/source';
import TileGrid from 'ol/tilegrid/TileGrid';
import { LoadFunction } from 'ol/Tile';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
import { ProjectionLike } from 'ol/proj';
import { ServerType } from 'ol/source/wms';
@Component({
selector: 'aol-source-tilewms',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMSComponent) }],
standalone: false
selector: 'aol-source-tilewms',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMSComponent) }],
standalone: true,
})
export class SourceTileWMSComponent extends SourceComponent implements OnChanges, OnInit {
@Input()
cacheSize: number;
@Input()
crossOrigin: string;
@Input()
gutter: number;
@Input()
hidpi: boolean;
@Input()
params: { [key: string]: any };
@Input()
projection: string;
@Input()
reprojectionErrorThreshold: number;
@Input()
serverType: ServerType;
@Input()
tileGrid: TileGrid;
@Input()
tileLoadFunction: LoadFunction;
@Input()
url: string;
@Input()
urls: string[];
@Input()
wrapX: boolean;
@Input() cacheSize: number;
@Input() crossOrigin: string;
@Input() gutter: number;
@Input() hidpi: boolean;
@Input() params: Record<string, unknown>;
@Input() projection: ProjectionLike;
@Input() reprojectionErrorThreshold: number;
@Input() serverType: ServerType;
@Input() tileGrid: TileGrid;
@Input() tileLoadFunction: LoadFunction;
@Input() url: string;
@Input() urls: string[];
@Input() wrapX: boolean;
instance: TileWMS;
host = inject(LayerTileComponent, { host: true });
constructor(@Host() layer: LayerTileComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new TileWMS(this);
this.host.instance.setSource(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (this.instance && changes.hasOwnProperty('params')) {
this.instance.updateParams(this.params);
}

View File

@@ -1,108 +1,101 @@
import {
Component,
Host,
Input,
forwardRef,
AfterContentInit,
Component,
ContentChild,
SimpleChanges,
EventEmitter,
forwardRef,
Input,
OnChanges,
Output,
EventEmitter,
SimpleChanges,
inject,
} from '@angular/core';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
import { TileGridWMTSComponent } from '../tilegridwmts.component';
import { WMTS as SourceWMTS } from 'ol/source';
import WMTS from 'ol/tilegrid/WMTS';
import { ProjectionLike } from 'ol/proj';
import { LoadFunction } from 'ol/Tile';
import { WMTS } from 'ol/source';
import { TileSourceEvent } from 'ol/source/Tile';
import { RequestEncoding } from 'ol/source/WMTS';
import { LayerTileComponent } from '../layers/layertile.component';
import { TileGridWMTSComponent } from '../tilegridwmts.component';
import { SourceComponent } from './source.component';
import { Options } from 'ol/source/WMTS';
import BaseObject from 'ol/Object';
@Component({
selector: 'aol-source-tilewmts',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMTSComponent) }],
standalone: false
selector: 'aol-source-tilewmts',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceTileWMTSComponent) }],
standalone: true,
})
export class SourceTileWMTSComponent extends SourceComponent implements AfterContentInit, OnChanges {
@Input()
cacheSize?: number;
cacheSize?: Options['cacheSize'];
@Input()
crossOrigin?: string;
crossOrigin?: Options['crossOrigin'];
@Input()
tileGrid: WMTS;
tileGrid: Options['tileGrid'];
@Input()
projection: ProjectionLike;
projection: Options['projection'];
@Input()
reprojectionErrorThreshold?: number;
reprojectionErrorThreshold?: Options['reprojectionErrorThreshold'];
@Input()
requestEncoding?: RequestEncoding | undefined;
requestEncoding?: Options['requestEncoding'];
@Input()
layer: string;
layer: Options['layer'];
@Input()
style: string;
style: Options['style'];
@Input()
tileClass?: any;
tileClass?: Options['tileClass'];
@Input()
tilePixelRatio?: number;
tilePixelRatio?: Options['tilePixelRatio'];
@Input()
version?: string;
version?: Options['version'];
@Input()
format?: string;
format?: Options['format'];
@Input()
matrixSet: string;
matrixSet: Options['matrixSet'];
@Input()
dimensions?: any;
dimensions?: Options['dimensions'];
@Input()
url?: string;
url?: Options['url'];
@Input()
tileLoadFunction?: LoadFunction;
tileLoadFunction?: Options['tileLoadFunction'];
@Input()
urls?: string[];
urls?: Options['urls'];
@Input()
wrapX?: boolean;
wrapX?: Options['wrapX'];
@Output()
tileLoadStart = new EventEmitter<TileSourceEvent>();
tileLoadStart: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadEnd = new EventEmitter<TileSourceEvent>();
tileLoadEnd: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadError = new EventEmitter<TileSourceEvent>();
tileLoadError: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@ContentChild(TileGridWMTSComponent, { static: false })
@ContentChild(TileGridWMTSComponent)
tileGridWMTS: TileGridWMTSComponent;
instance: SourceWMTS;
instance: WMTS;
host = inject(LayerTileComponent, { host: true });
constructor(@Host() layer: LayerTileComponent) {
super(layer);
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
switch (key) {
case 'url':
this.url = changes[key].currentValue;
this.setLayerSource();
break;
default:
break;
}
properties[key] = changes[key].currentValue;
switch (key) {
case 'url':
this.url = changes[key].currentValue;
this.setLayerSource();
break;
default:
break;
}
properties[key] = changes[key].currentValue;
}
this.instance.setProperties(properties, false);
}
setLayerSource(): void {
this.instance = new SourceWMTS(this);
this.instance = new WMTS(this);
this.instance.on('tileloadstart', (event: TileSourceEvent) => this.tileLoadStart.emit(event));
this.instance.on('tileloadend', (event: TileSourceEvent) => this.tileLoadEnd.emit(event));
this.instance.on('tileloaderror', (event: TileSourceEvent) => this.tileLoadError.emit(event));

View File

@@ -1,26 +1,23 @@
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
import { SourceComponent } from './source.component';
import { LayerTileComponent } from '../layers/layertile.component';
import { Component, forwardRef, inject, Input, OnInit } from '@angular/core';
import { UTFGrid } from 'ol/source';
import { Config } from 'ol/source/TileJSON';
import { LayerTileComponent } from '../layers/layertile.component';
import { SourceComponent } from './source.component';
@Component({
selector: 'aol-source-utfgrid',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceUTFGridComponent) }],
standalone: false
selector: 'aol-source-utfgrid',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceUTFGridComponent) }],
standalone: true,
})
export class SourceUTFGridComponent extends SourceComponent implements OnInit {
@Input() tileJSON: Config;
@Input() url: string;
instance: UTFGrid;
host = inject(LayerTileComponent, { host: true });
constructor(@Host() layer: LayerTileComponent) {
super(layer);
}
ngOnInit() {
ngOnInit(): void {
this.instance = new UTFGrid(this);
this.host.instance.setSource(this.instance);
}

View File

@@ -1,15 +1,19 @@
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
import { Component, forwardRef, inject, 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',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceVectorComponent) }],
standalone: false
selector: 'aol-source-vector',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceVectorComponent) }],
standalone: true,
})
export class SourceVectorComponent extends SourceComponent implements OnInit {
@Input()
@@ -21,18 +25,41 @@ 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;
host = inject(LayerVectorComponent, { host: true });
constructor(@Host() layer: LayerVectorComponent) {
super(layer);
}
ngOnInit(): void {
this.instance = new Vector({
...this,
loader: this.loader
? (extent, resolution, projection, success, failure) =>
this.loader(extent, resolution, projection, success, failure, this.instance)
: undefined,
});
ngOnInit() {
this.instance = new Vector(this);
this.host.instance.setSource(this.instance);
}
}

View File

@@ -1,19 +1,21 @@
import { Component, Host, Input, forwardRef, ContentChild, AfterContentInit } from '@angular/core';
import { AfterContentInit, Component, ContentChild, forwardRef, inject, Input } from '@angular/core';
import { UrlFunction } from 'ol/Tile';
import FeatureFormat from 'ol/format/Feature';
import { ProjectionLike } from 'ol/proj';
import { VectorTile } from 'ol/source';
import Feature from 'ol/format/Feature';
import TileGrid from 'ol/tilegrid/TileGrid';
import { LayerVectorTileComponent } from '../layers/layervectortile.component';
import { FormatComponent } from '../formats/format.component';
import { LayerVectorTileComponent } from '../layers/layervectortile.component';
import { TileGridComponent } from '../tilegrid.component';
import { SourceComponent } from './source.component';
import { ProjectionLike } from 'ol/proj';
import { UrlFunction } from 'ol/Tile';
import { FeatureLike } from 'ol/Feature';
import RenderFeature from 'ol/render/Feature';
@Component({
selector: 'aol-source-vectortile',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceVectorTileComponent) }],
standalone: false
selector: 'aol-source-vectortile',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceVectorTileComponent) }],
standalone: true,
})
export class SourceVectorTileComponent extends SourceComponent implements AfterContentInit {
@Input()
@@ -33,21 +35,19 @@ export class SourceVectorTileComponent extends SourceComponent implements AfterC
@Input()
wrapX: boolean;
@ContentChild(FormatComponent, { static: false })
@ContentChild(FormatComponent)
formatComponent: FormatComponent;
@ContentChild(TileGridComponent, { static: false })
@ContentChild(TileGridComponent)
tileGridComponent: TileGridComponent;
public instance: VectorTile;
format: Feature;
format: FeatureFormat<RenderFeature>;
tileGrid: TileGrid;
constructor(@Host() layer: LayerVectorTileComponent) {
super(layer);
}
instance: VectorTile<FeatureLike>;
host = inject(LayerVectorTileComponent, { host: true });
/* need the children to construct the OL3 object */
ngAfterContentInit() {
ngAfterContentInit(): void {
this.format = this.formatComponent.instance;
this.tileGrid = this.tileGridComponent.instance;
// console.log('creating ol.source.VectorTile instance with:', this);

View File

@@ -4,10 +4,9 @@ import {
ContentChild,
EventEmitter,
forwardRef,
Host,
inject,
Input,
OnChanges,
Optional,
Output,
SimpleChanges,
} from '@angular/core';
@@ -20,14 +19,17 @@ import TileGrid from 'ol/tilegrid/TileGrid';
import { LayerTileComponent } from '../layers/layertile.component';
import { TileGridComponent } from '../tilegrid.component';
import { SourceComponent } from './source.component';
import BaseObject from 'ol/Object';
@Component({
selector: 'aol-source-xyz',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceXYZComponent) }],
standalone: false
selector: 'aol-source-xyz',
template: ` <ng-content></ng-content> `,
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceXYZComponent) }],
standalone: true,
})
export class SourceXYZComponent extends SourceComponent implements AfterContentInit, OnChanges {
protected layer?: LayerTileComponent;
@Input()
cacheSize: number;
@Input()
@@ -59,58 +61,47 @@ export class SourceXYZComponent extends SourceComponent implements AfterContentI
@Input()
wrapX: boolean;
@ContentChild(TileGridComponent, { static: false })
@ContentChild(TileGridComponent)
tileGridXYZ: TileGridComponent;
@Output()
tileLoadStart = new EventEmitter<TileSourceEvent>();
tileLoadStart: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadEnd = new EventEmitter<TileSourceEvent>();
tileLoadEnd: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
@Output()
tileLoadError = new EventEmitter<TileSourceEvent>();
tileLoadError: EventEmitter<TileSourceEvent> = new EventEmitter<TileSourceEvent>();
instance: XYZ;
host = inject(LayerTileComponent, { optional: true, host: true });
constructor(
@Optional()
@Host()
protected layer?: LayerTileComponent
) {
super(layer);
}
ngAfterContentInit() {
ngAfterContentInit(): void {
if (this.tileGridXYZ) {
this.tileGrid = this.tileGridXYZ.instance;
}
this.init();
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
properties[key] = changes[key].currentValue;
}
properties[key] = changes[key].currentValue;
}
this.instance.setProperties(properties, false);
if (changes.hasOwnProperty('url')) {
this.init();
}
}
init() {
init(): void {
this.instance = new XYZ(this);
this.instance.on('tileloadstart', (event: TileSourceEvent) => this.tileLoadStart.emit(event));
this.instance.on('tileloadend', (event: TileSourceEvent) => this.tileLoadEnd.emit(event));
this.instance.on('tileloaderror', (event: TileSourceEvent) => this.tileLoadError.emit(event));
this.register(this.instance);
this._register(this.instance);
}
}

View File

@@ -1,33 +1,31 @@
import { Component, Input, Host, AfterContentInit, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
import { AfterContentInit, Component, Input, OnChanges, OnDestroy, SimpleChanges, inject } from '@angular/core';
import { Circle, Fill, Stroke } from 'ol/style';
import { StyleComponent } from './style.component';
@Component({
selector: 'aol-style-circle',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-style-circle',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class StyleCircleComponent implements AfterContentInit, OnChanges, OnDestroy {
private host = inject(StyleComponent, { host: true });
@Input()
fill: Fill;
@Input()
radius: number;
@Input()
snapToPixel: boolean;
@Input()
stroke: Stroke;
public componentType = 'style-circle';
public instance: Circle;
constructor(@Host() private host: StyleComponent) {}
componentType = 'style-circle';
instance: Circle;
/**
* WORK-AROUND: since the re-rendering is not triggered on style change
* we trigger a radius change.
* see openlayers #6233 and #5775
*/
update() {
update(): void {
if (!!this.instance) {
// console.log('setting ol.style.Circle instance\'s radius');
this.instance.setRadius(this.radius);
@@ -35,14 +33,14 @@ export class StyleCircleComponent implements AfterContentInit, OnChanges, OnDest
this.host.update();
}
ngAfterContentInit() {
ngAfterContentInit(): void {
// console.log('creating ol.style.Circle instance with: ', this);
this.instance = new Circle(this);
this.host.instance.setImage(this.instance);
this.host.update();
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
@@ -52,7 +50,7 @@ export class StyleCircleComponent implements AfterContentInit, OnChanges, OnDest
// console.log('changes detected in aol-style-circle, setting new radius: ', changes['radius'].currentValue);
}
ngOnDestroy() {
ngOnDestroy(): void {
// console.log('removing aol-style-circle');
this.host.instance.setImage(null);
}

View File

@@ -1,4 +1,4 @@
import { Component, Input, Optional, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core';
import { Fill } from 'ol/style';
import { StyleComponent } from './style.component';
import { StyleCircleComponent } from './circle.component';
@@ -7,22 +7,22 @@ import { Color } from 'ol/color';
import { ColorLike } from 'ol/colorlike';
@Component({
selector: 'aol-style-fill',
template: ` <div class="aol-style-fill"></div> `,
standalone: false
selector: 'aol-style-fill',
template: ` <div class="aol-style-fill"></div> `,
standalone: true,
})
export class StyleFillComponent implements OnInit, OnChanges {
@Input()
color: Color | ColorLike;
public instance: Fill;
instance: Fill;
private readonly host: StyleComponent | StyleCircleComponent | StyleTextComponent;
constructor(
@Optional() styleHost: StyleComponent,
@Optional() styleCircleHost: StyleCircleComponent,
@Optional() styleTextHost: StyleTextComponent
) {
constructor() {
const styleHost = inject(StyleComponent, { optional: true });
const styleCircleHost = inject(StyleCircleComponent, { optional: true });
const styleTextHost = inject(StyleTextComponent, { optional: true });
if (!styleHost) {
throw new Error('aol-style-stroke must be a descendant of aol-style');
}
@@ -36,34 +36,26 @@ export class StyleFillComponent implements OnInit, OnChanges {
// console.log('creating aol-style-fill with: ', this);
}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.style.Fill instance with: ', this);
this.instance = new Fill(this);
switch (this.host.componentType) {
case 'style':
this.host.instance.setFill(this.instance);
// console.log('setting ol.style instance\'s fill:', this.host);
break;
case 'style-text':
this.host.instance.setFill(this.instance);
break;
case 'style-circle':
(this.host as StyleCircleComponent).fill = this.instance;
// console.log('setting ol.style.circle instance\'s fill:', this.host);
break;
default:
throw new Error('unknown host type: ' + this.host);
if (this.host instanceof StyleComponent || this.host instanceof StyleTextComponent) {
this.host.instance.setFill(this.instance);
} else {
this.host.fill = this.instance;
}
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
if (changes.color) {
this.instance.setColor(changes.color.currentValue);
}
this.host.update();
if (this.host instanceof StyleCircleComponent || this.host instanceof StyleComponent) {
this.host.update();
}
// console.log('changes detected in aol-style-fill, setting new color: ', changes);
}
}

View File

@@ -1,18 +1,20 @@
import { Component, Input, Host, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core';
import { Color } from 'ol/color';
import { Size } from 'ol/size';
import { Icon } from 'ol/style';
// TODO https://github.com/openlayers/openlayers/issues/12694
// import IconAnchorUnits from 'ol/style/IconAnchorUnits';
// import IconOrigin from 'ol/style/IconOrigin';
import { StyleComponent } from './style.component';
import { IconAnchorUnits, IconOrigin } from 'ol/style/Icon';
type IconAnchorUnits = 'fraction' | 'pixels';
type IconOrigin = 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
@Component({
selector: 'aol-style-icon',
template: ` <div class="aol-style-icon"></div> `,
standalone: false
selector: 'aol-style-icon',
template: ` <div class="aol-style-icon"></div> `,
standalone: true,
})
export class StyleIconComponent implements OnInit, OnChanges {
private host = inject(StyleComponent, { host: true });
@Input()
anchor: [number, number];
@Input()
@@ -22,11 +24,11 @@ export class StyleIconComponent implements OnInit, OnChanges {
@Input()
anchorOrigin: IconOrigin;
@Input()
color: [number, number, number, number];
color: Color;
@Input()
crossOrigin: IconOrigin;
crossOrigin: string;
@Input()
img: HTMLCanvasElement | HTMLImageElement;
img: HTMLImageElement | HTMLCanvasElement;
@Input()
offset: [number, number];
@Input()
@@ -42,23 +44,19 @@ export class StyleIconComponent implements OnInit, OnChanges {
@Input()
rotation: number;
@Input()
size: [number, number];
@Input()
imgSize: [number, number];
size: Size;
@Input()
src: string;
public instance: Icon;
instance: Icon;
constructor(@Host() private host: StyleComponent) {}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.style.Icon instance with: ', this);
this.instance = new Icon(this);
this.host.instance.setImage(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}

View File

@@ -1,39 +1,38 @@
import { Component, Input, Optional, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Stroke } from 'ol/style';
import { StyleComponent } from './style.component';
import { StyleCircleComponent } from './circle.component';
import { StyleTextComponent } from './text.component';
import { Component, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core';
import { Color } from 'ol/color';
import { ColorLike } from 'ol/colorlike';
import { Stroke } from 'ol/style';
import { StyleCircleComponent } from './circle.component';
import { StyleComponent } from './style.component';
import { StyleTextComponent } from './text.component';
@Component({
selector: 'aol-style-stroke',
template: ` <div class="aol-style-stroke"></div> `,
standalone: false
selector: 'aol-style-stroke',
template: ` <div class="aol-style-stroke"></div> `,
standalone: true,
})
export class StyleStrokeComponent implements OnInit, OnChanges {
@Input()
color: Color | ColorLike;
@Input()
lineCap: CanvasLineCap | undefined;
lineCap: CanvasLineCap;
@Input()
lineDash: number[];
@Input()
lineJoin: CanvasLineJoin | undefined;
lineJoin: CanvasLineJoin;
@Input()
miterLimit: number;
@Input()
width: number;
public instance: Stroke;
/* the typings do not have the setters */
instance: Stroke;
private readonly host: StyleComponent | StyleCircleComponent | StyleTextComponent;
constructor(
@Optional() styleHost: StyleComponent,
@Optional() styleCircleHost: StyleCircleComponent,
@Optional() styleTextHost: StyleTextComponent
) {
constructor() {
const styleHost = inject(StyleComponent, { optional: true });
const styleCircleHost = inject(StyleCircleComponent, { optional: true });
const styleTextHost = inject(StyleTextComponent, { optional: true });
if (!styleHost) {
throw new Error('aol-style-stroke must be a descendant of aol-style');
}
@@ -47,28 +46,18 @@ export class StyleStrokeComponent implements OnInit, OnChanges {
// console.log('creating aol-style-stroke with: ', this);
}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.style.Stroke instance with: ', this);
this.instance = new Stroke(this);
switch (this.host.componentType) {
case 'style':
this.host.instance.setStroke(this.instance);
// console.log('setting ol.style instance\'s stroke:', this.host);
break;
case 'style-text':
this.host.instance.setStroke(this.instance);
break;
case 'style-circle':
(this.host as StyleCircleComponent).stroke = this.instance;
// console.log('setting ol.style.circle instance\'s stroke:', this.host);
break;
default:
throw new Error('unknown host type: ' + this.host);
// break;
if (this.host instanceof StyleComponent || this.host instanceof StyleTextComponent) {
this.host.instance.setStroke(this.instance);
} else {
this.host.stroke = this.instance;
}
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
@@ -90,7 +79,9 @@ export class StyleStrokeComponent implements OnInit, OnChanges {
if (changes.width) {
this.instance.setWidth(changes.width.currentValue);
}
this.host.update();
if (this.host instanceof StyleCircleComponent || this.host instanceof StyleComponent) {
this.host.update();
}
// console.log('changes detected in aol-style-stroke, setting new properties: ', changes);
}
}

View File

@@ -1,4 +1,4 @@
import { Component, Input, Optional, OnInit } from '@angular/core';
import { Component, Input, OnInit, inject } from '@angular/core';
import { Fill, Image, Stroke, Style, Text } from 'ol/style';
import { Geometry } from 'ol/geom';
import { FeatureComponent } from '../feature.component';
@@ -6,9 +6,9 @@ import { LayerVectorComponent } from '../layers/layervector.component';
import { GeometryFunction } from 'ol/style/Style';
@Component({
selector: 'aol-style',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-style',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class StyleComponent implements OnInit {
@Input()
@@ -24,11 +24,14 @@ export class StyleComponent implements OnInit {
@Input()
zIndex: number;
public instance: Style;
public componentType = 'style';
private readonly host: FeatureComponent | LayerVectorComponent;
instance: Style;
componentType = 'style';
private host: FeatureComponent | LayerVectorComponent;
constructor() {
const featureHost = inject(FeatureComponent, { optional: true });
const layerHost = inject(LayerVectorComponent, { optional: true });
constructor(@Optional() featureHost: FeatureComponent, @Optional() layerHost: LayerVectorComponent) {
// console.log('creating aol-style');
this.host = !!featureHost ? featureHost : layerHost;
if (!this.host) {
@@ -36,12 +39,12 @@ export class StyleComponent implements OnInit {
}
}
update() {
update(): void {
// console.log('updating style\'s host: ', this.host);
this.host.instance.changed();
}
ngOnInit() {
ngOnInit(): void {
// console.log('creating aol-style instance with: ', this);
this.instance = new Style(this);
this.host.instance.setStyle(this.instance);

View File

@@ -1,13 +1,15 @@
import { Component, Input, Optional, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit, SimpleChanges, inject } from '@angular/core';
import { Text } from 'ol/style';
import { StyleComponent } from './style.component';
@Component({
selector: 'aol-style-text',
template: ` <div class="aol-style-text"></div> `,
standalone: false
selector: 'aol-style-text',
template: ` <div class="aol-style-text"></div> `,
standalone: true,
})
export class StyleTextComponent implements OnInit, OnChanges {
private host = inject(StyleComponent, { optional: true });
@Input()
font: string | undefined;
@Input()
@@ -27,23 +29,25 @@ export class StyleTextComponent implements OnInit, OnChanges {
@Input()
textBaseLine: string | undefined;
public instance: Text;
public componentType = 'style-text';
instance: Text;
componentType = 'style-text';
constructor() {
const host = this.host;
constructor(@Optional() private host: StyleComponent) {
if (!host) {
throw new Error('aol-style-text must be a descendant of aol-style');
}
// console.log('creating aol-style-text with: ', this);
}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.style.Text instance with: ', this);
this.instance = new Text(this);
this.host.instance.setText(this.instance);
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
@@ -74,6 +78,4 @@ export class StyleTextComponent implements OnInit, OnChanges {
this.host.update();
// console.log('changes detected in aol-style-text, setting new properties: ', changes);
}
update() {}
}

View File

@@ -1,4 +1,4 @@
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { createXYZ } from 'ol/tilegrid';
import TileGrid from 'ol/tilegrid/TileGrid';
import { Extent } from 'ol/extent';
@@ -6,9 +6,9 @@ import { Coordinate } from 'ol/coordinate';
import { Size } from 'ol/size';
@Component({
selector: 'aol-tilegrid',
template: '',
standalone: false
selector: 'aol-tilegrid',
template: '',
standalone: true,
})
export class TileGridComponent implements OnInit, OnChanges {
@Input()
@@ -26,7 +26,7 @@ export class TileGridComponent implements OnInit, OnChanges {
instance: TileGrid;
ngOnInit() {
ngOnInit(): void {
if (!this.resolutions) {
this.instance = createXYZ(this);
} else {
@@ -34,7 +34,7 @@ export class TileGridComponent implements OnInit, OnChanges {
}
}
ngOnChanges(changes: SimpleChanges) {
ngOnChanges(): void {
if (!this.resolutions) {
this.instance = createXYZ(this);
} else {

View File

@@ -5,9 +5,9 @@ import { Coordinate } from 'ol/coordinate';
import { Size } from 'ol/size';
@Component({
selector: 'aol-tilegrid-wmts',
template: '',
standalone: false
selector: 'aol-tilegrid-wmts',
template: '',
standalone: true,
})
export class TileGridWMTSComponent extends TileGridComponent implements OnInit {
@Input()
@@ -27,7 +27,7 @@ export class TileGridWMTSComponent extends TileGridComponent implements OnInit {
instance: WMTS;
ngOnInit() {
ngOnInit(): void {
this.instance = new WMTS(this);
}
}

View File

@@ -1,18 +1,19 @@
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChanges, EventEmitter, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, inject } from '@angular/core';
import BaseObject, { ObjectEvent } from 'ol/Object';
import View from 'ol/View';
import { MapComponent } from './map.component';
import { ObjectEvent } from 'ol/Object';
import { Extent } from 'ol/extent';
import { Coordinate } from 'ol/coordinate';
import { DrawEvent } from 'ol/interaction/Draw';
import BaseEvent from 'ol/events/Event';
import { Extent } from 'ol/extent';
import { MapComponent } from './map.component';
import { ProjectionLike } from 'ol/proj';
@Component({
selector: 'aol-view',
template: ` <ng-content></ng-content> `,
standalone: false
selector: 'aol-view',
template: ` <ng-content></ng-content> `,
standalone: true,
})
export class ViewComponent implements OnInit, OnChanges, OnDestroy {
export class ViewComponent implements OnInit, OnChanges {
private host = inject(MapComponent);
@Input()
constrainRotation: boolean | number;
@Input()
@@ -40,7 +41,7 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
@Input()
center: Coordinate;
@Input()
projection: string;
projection: ProjectionLike;
@Input()
constrainOnlyCenter: boolean;
@Input()
@@ -58,71 +59,51 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
zoomAnimation = false;
@Output()
olChange = new EventEmitter<DrawEvent>();
changeResolution: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
@Output()
changeCenter = new EventEmitter<ObjectEvent>();
@Output()
changeResolution = new EventEmitter<ObjectEvent>();
@Output()
changeRotation = new EventEmitter<ObjectEvent>();
@Output()
olError = new EventEmitter<BaseEvent>();
@Output()
propertyChange = new EventEmitter<ObjectEvent>();
changeCenter: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
public instance: View;
public componentType = 'view';
instance: View;
componentType = 'view';
constructor(private host: MapComponent) {}
ngOnInit() {
ngOnInit(): void {
// console.log('creating ol.View instance with: ', this);
this.instance = new View(this);
this.host.instance.setView(this.instance);
this.instance.on('change', (event: DrawEvent) => this.olChange.emit(event));
this.instance.on('change:center', (event: ObjectEvent) => this.changeCenter.emit(event));
this.instance.on('change:resolution', (event: ObjectEvent) => this.changeResolution.emit(event));
this.instance.on('change:rotation', (event: ObjectEvent) => this.changeRotation.emit(event));
this.instance.on('error', (event: BaseEvent) => this.olError.emit(event));
this.instance.on('propertychange', (event: ObjectEvent) => this.propertyChange.emit(event));
this.instance.on('change:center', (event: ObjectEvent) => this.changeCenter.emit(event));
}
ngOnChanges(changes: SimpleChanges) {
const properties: { [index: string]: any } = {};
ngOnChanges(changes: SimpleChanges): void {
if (!this.instance) {
return;
}
const properties: Parameters<BaseObject['setProperties']>[0] = {};
for (const key in changes) {
if (changes.hasOwnProperty(key)) {
switch (key) {
case 'zoom':
/** Work-around: setting the zoom via setProperties does not work. */
if (this.zoomAnimation) {
this.instance.animate({ zoom: changes[key].currentValue });
} else {
this.instance.setZoom(changes[key].currentValue);
}
break;
case 'projection':
this.instance = new View(this);
this.host.instance.setView(this.instance);
break;
case 'center':
/** Work-around: setting the center via setProperties does not work. */
this.instance.setCenter(changes[key].currentValue);
break;
default:
break;
}
properties[key] = changes[key].currentValue;
switch (key) {
case 'zoom':
/** Work-around: setting the zoom via setProperties does not work. */
if (this.zoomAnimation) {
this.instance.animate({ zoom: changes[key].currentValue });
} else {
this.instance.setZoom(changes[key].currentValue);
}
break;
case 'projection':
this.instance = new View(this);
this.host.instance.setView(this.instance);
break;
case 'center':
/** Work-around: setting the center via setProperties does not work. */
this.instance.setCenter(changes[key].currentValue);
break;
default:
break;
}
properties[key] = changes[key].currentValue;
}
// console.log('changes detected in aol-view, setting new properties: ', properties);
this.instance.setProperties(properties, false);
}
ngOnDestroy() {
// console.log('removing aol-view');
}
}

View File

@@ -1,8 +1,7 @@
/*
* Public API Surface of ng-openlayers
* Public API Surface of ngx-openlayers
*/
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SimpleGeometryComponent } from './lib/geom/simplegeometry.component';
import { SourceComponent } from './lib/sources/source.component';
import { ViewComponent } from './lib/view.component';
@@ -68,8 +67,6 @@ import { DragZoomInteractionComponent } from './lib/interactions/dragzoom.compon
import { MouseWheelZoomInteractionComponent } from './lib/interactions/mousewheelzoom.component';
import { PinchZoomInteractionComponent } from './lib/interactions/pinchzoom.component';
import { DrawInteractionComponent } from './lib/interactions/draw.component';
import { KeyboardPanInteractionComponent } from './lib/interactions/keyboardpan.component';
import { KeyboardZoomInteractionComponent } from './lib/interactions/keyboardzoom.component';
import { SelectInteractionComponent } from './lib/interactions/select.component';
import { ModifyInteractionComponent } from './lib/interactions/modify.component';
import { TranslateInteractionComponent } from './lib/interactions/translate.component';
@@ -79,6 +76,7 @@ import { AttributionsComponent } from './lib/attributions.component';
import { AttributionComponent } from './lib/attribution.component';
import { SourceUTFGridComponent } from './lib/sources/utfgrid.component';
import { LayerComponent } from './lib/layers/layer.component';
import { SnapInteractionComponent } from './lib/interactions/snap.component';
export {
MapComponent,
@@ -148,11 +146,10 @@ export {
MouseWheelZoomInteractionComponent,
PinchZoomInteractionComponent,
DrawInteractionComponent,
KeyboardPanInteractionComponent,
KeyboardZoomInteractionComponent,
SelectInteractionComponent,
ModifyInteractionComponent,
TranslateInteractionComponent,
SnapInteractionComponent,
OverlayComponent,
ContentComponent,
AttributionsComponent,
@@ -242,9 +239,11 @@ const COMPONENTS = [
AttributionComponent,
];
/**
* @deprecated please use standalone components instead
*/
@NgModule({
declarations: COMPONENTS,
imports: [CommonModule],
imports: COMPONENTS,
exports: COMPONENTS,
})
export class AngularOpenlayersModule {}

View File

@@ -1,6 +1,5 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'core-js/es7/reflect';
import 'zone.js';
import 'zone.js/testing';
import { getTestBed } from '@angular/core/testing';
@@ -8,5 +7,5 @@ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@ang
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false },
teardown: { destroyAfterEach: true },
});