Skip to content

Commit c3bed7d

Browse files
build: update to Angular 17
BREAKING CHANGE: Angular 15 is no more supported
1 parent 5188480 commit c3bed7d

22 files changed

+2147
-2877
lines changed

.github/workflows/angular.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ jobs:
5454
- run: yarn --frozen-lockfile
5555
- run: yarn build:lib
5656
- run: yarn build:demo --base-href "/ngx-openlayers/" --progress false
57-
- uses: actions/upload-artifact@v3
57+
- uses: actions/upload-artifact@v4
5858
with:
5959
name: lib-build
6060
path: dist/ngx-openlayers/
61-
- uses: actions/upload-artifact@v3
61+
- uses: actions/upload-artifact@v4
6262
with:
6363
name: demo-build
6464
path: dist/demo-ngx-openlayers/

angular.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@
8383
"serve": {
8484
"builder": "@angular-devkit/build-angular:dev-server",
8585
"options": {
86-
"browserTarget": "demo-ngx-openlayers:build"
86+
"buildTarget": "demo-ngx-openlayers:build"
8787
},
8888
"configurations": {
8989
"production": {
90-
"browserTarget": "demo-ngx-openlayers:build:production"
90+
"buildTarget": "demo-ngx-openlayers:build:production"
9191
}
9292
}
9393
},
9494
"extract-i18n": {
9595
"builder": "@angular-devkit/build-angular:extract-i18n",
9696
"options": {
97-
"browserTarget": "demo-ngx-openlayers:build"
97+
"buildTarget": "demo-ngx-openlayers:build"
9898
}
9999
},
100100
"test": {

package.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,39 @@
1515
},
1616
"private": true,
1717
"dependencies": {
18-
"@angular/animations": "^16.2.12",
19-
"@angular/common": "^16.2.12",
20-
"@angular/compiler": "^16.2.12",
21-
"@angular/core": "^16.2.12",
22-
"@angular/forms": "^16.2.12",
23-
"@angular/platform-browser": "^16.2.12",
24-
"@angular/platform-browser-dynamic": "^16.2.12",
25-
"@angular/router": "^16.2.12",
18+
"@angular/animations": "^17.3.12",
19+
"@angular/common": "^17.3.12",
20+
"@angular/compiler": "^17.3.12",
21+
"@angular/core": "^17.3.12",
22+
"@angular/forms": "^17.3.12",
23+
"@angular/platform-browser": "^17.3.12",
24+
"@angular/platform-browser-dynamic": "^17.3.12",
25+
"@angular/router": "^17.3.12",
2626
"hammerjs": "^2.0.8",
2727
"ol": "~8.2.0",
2828
"rxjs": "~7.5.0",
2929
"tslib": "^2.5.0",
30-
"zone.js": "~0.13.3"
30+
"zone.js": "~0.14.10"
3131
},
3232
"devDependencies": {
33-
"@angular-devkit/build-angular": "^16.2.16",
34-
"@angular-eslint/builder": "16.3.1",
35-
"@angular-eslint/eslint-plugin": "16.3.1",
36-
"@angular-eslint/eslint-plugin-template": "16.3.1",
37-
"@angular-eslint/schematics": "16.3.1",
38-
"@angular-eslint/template-parser": "16.3.1",
39-
"@angular/cli": "^16.2.16",
40-
"@angular/compiler-cli": "^16.2.12",
41-
"@angular/language-service": "^16.2.12",
33+
"@angular-devkit/build-angular": "^17.3.15",
34+
"@angular-eslint/builder": "17.5.3",
35+
"@angular-eslint/eslint-plugin": "17.5.3",
36+
"@angular-eslint/eslint-plugin-template": "17.5.3",
37+
"@angular-eslint/schematics": "17.5.3",
38+
"@angular-eslint/template-parser": "17.5.3",
39+
"@angular/cli": "^17.3.15",
40+
"@angular/compiler-cli": "^17.3.12",
41+
"@angular/language-service": "^17.3.12",
4242
"@types/arcgis-rest-api": "^10.4.5",
4343
"@types/hammerjs": "^2.0.41",
4444
"@types/jasmine": "~5.1.5",
45-
"@types/node": "^12.11.1",
45+
"@types/node": "^18.19.86",
4646
"@types/topojson-specification": "^1.0.2",
47-
"@typescript-eslint/eslint-plugin": "^5.59.2",
48-
"@typescript-eslint/parser": "^5.59.2",
47+
"@typescript-eslint/eslint-plugin": "^7.2.0",
48+
"@typescript-eslint/parser": "^7.2.0",
4949
"commit-and-tag-version": "^12.5.0",
50-
"eslint": "^8.39.0",
50+
"eslint": "^8.57.0",
5151
"eslint-plugin-import": "^2.31.0",
5252
"eslint-plugin-jsdoc": "^47.0.2",
5353
"eslint-plugin-prefer-arrow": "latest",
@@ -59,11 +59,11 @@
5959
"karma-coverage": "~2.2.0",
6060
"karma-jasmine": "~5.1.0",
6161
"karma-jasmine-html-reporter": "~2.1.0",
62-
"ng-packagr": "~16.2.3",
62+
"ng-packagr": "~17.3.0",
6363
"prettier": "^3.4.2",
6464
"protractor": "~7.0.0",
6565
"ts-node": "~8.3.0",
66-
"typescript": "~5.1.6"
66+
"typescript": "~5.4.5"
6767
},
6868
"volta": {
6969
"node": "18.20.5"

projects/ngx-openlayers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"release": "commit-and-tag-version -m \"chore(release): version %s\" -t \"\" --prerelease next"
66
},
77
"peerDependencies": {
8-
"@angular/common": ">=15.0.0 <=16.x.x",
9-
"@angular/core": ">=15.0.0 <=16.x.x",
8+
"@angular/common": ">=16.0.0 <=17.x.x",
9+
"@angular/core": ">=16.0.0 <=17.x.x",
1010
"ol": "~8.2.0"
1111
}
1212
}

projects/ngx-openlayers/src/lib/collectioncoordinates.component.ts

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ export class CollectionCoordinatesComponent implements OnChanges, OnInit {
1818
@Input()
1919
srid = 'EPSG:3857';
2020

21-
private host: any;
21+
private readonly host:
22+
| GeometryLinestringComponent
23+
| GeometryPolygonComponent
24+
| GeometryMultiPointComponent
25+
| GeometryMultiLinestringComponent
26+
| GeometryMultiPolygonComponent;
2227
private mapSrid = 'EPSG:3857';
2328

2429
constructor(
@@ -29,16 +34,15 @@ export class CollectionCoordinatesComponent implements OnChanges, OnInit {
2934
@Optional() geometryMultilinestring: GeometryMultiLinestringComponent,
3035
@Optional() geometryMultipolygon: GeometryMultiPolygonComponent
3136
) {
32-
if (!!geometryLinestring) {
33-
this.host = geometryLinestring;
34-
} else if (!!geometryPolygon) {
35-
this.host = geometryPolygon;
36-
} else if (!!geometryMultipoint) {
37-
this.host = geometryMultipoint;
38-
} else if (!!geometryMultilinestring) {
39-
this.host = geometryMultilinestring;
40-
} else if (!!geometryMultipolygon) {
41-
this.host = geometryMultipolygon;
37+
const geometryComponent =
38+
geometryLinestring ??
39+
geometryPolygon ??
40+
geometryMultipoint ??
41+
geometryMultilinestring ??
42+
geometryMultipolygon ??
43+
undefined;
44+
if (geometryComponent) {
45+
this.host = geometryComponent;
4246
} else {
4347
throw new Error('aol-collection-coordinates must be a child of a geometry component');
4448
}
@@ -60,30 +64,23 @@ export class CollectionCoordinatesComponent implements OnChanges, OnInit {
6064
}
6165

6266
private transformCoordinates(): void {
63-
let transformedCoordinates: Coordinate[] | Coordinate[][] | Coordinate[][][];
64-
6567
if (this.srid === this.mapSrid) {
66-
transformedCoordinates = this.coordinates;
68+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69+
this.host.instance.setCoordinates(this.coordinates as any[]);
70+
} else if (this.host instanceof GeometryLinestringComponent || this.host instanceof GeometryMultiPointComponent) {
71+
this.host.instance.setCoordinates(
72+
(this.coordinates as Coordinate[]).map((c) => transform(c, this.srid, this.mapSrid))
73+
);
74+
} else if (this.host instanceof GeometryPolygonComponent || this.host instanceof GeometryMultiLinestringComponent) {
75+
this.host.instance.setCoordinates(
76+
(this.coordinates as Coordinate[][]).map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
77+
);
6778
} else {
68-
switch (this.host.componentType) {
69-
case 'geometry-linestring':
70-
case 'geometry-multipoint':
71-
transformedCoordinates = (this.coordinates as Coordinate[]).map((c) => transform(c, this.srid, this.mapSrid));
72-
break;
73-
case 'geometry-polygon':
74-
case 'geometry-multilinestring':
75-
transformedCoordinates = (this.coordinates as Coordinate[][]).map((cc) =>
76-
cc.map((c) => transform(c, this.srid, this.mapSrid))
77-
);
78-
break;
79-
case 'geometry-multipolygon':
80-
transformedCoordinates = (this.coordinates as Coordinate[][][]).map((ccc) =>
81-
ccc.map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
82-
);
83-
break;
84-
}
79+
this.host.instance.setCoordinates(
80+
(this.coordinates as Coordinate[][][]).map((ccc) =>
81+
ccc.map((cc) => cc.map((c) => transform(c, this.srid, this.mapSrid)))
82+
)
83+
);
8584
}
86-
87-
this.host.instance.setCoordinates(transformedCoordinates);
8885
}
8986
}

projects/ngx-openlayers/src/lib/coordinate.component.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class CoordinateComponent implements OnChanges, OnInit {
1818
@Input()
1919
srid = 'EPSG:3857';
2020

21-
private host: any;
21+
private host: ViewComponent | GeometryPointComponent | GeometryCircleComponent | OverlayComponent;
2222
private mapSrid = 'EPSG:3857';
2323

2424
constructor(
@@ -64,17 +64,12 @@ export class CoordinateComponent implements OnChanges, OnInit {
6464
transformedCoordinates = transform([this.x, this.y], this.srid, this.mapSrid);
6565
}
6666

67-
switch (this.host.componentType) {
68-
case 'geometry-point':
69-
this.host.instance.setCoordinates(transformedCoordinates);
70-
break;
71-
case 'geometry-circle':
72-
case 'view':
73-
this.host.instance.setCenter(transformedCoordinates);
74-
break;
75-
case 'overlay':
76-
this.host.instance.setPosition(transformedCoordinates);
77-
break;
67+
if (this.host instanceof GeometryPointComponent) {
68+
this.host.instance.setCoordinates(transformedCoordinates);
69+
} else if (this.host instanceof OverlayComponent) {
70+
this.host.instance.setPosition(transformedCoordinates);
71+
} else {
72+
this.host.instance.setCenter(transformedCoordinates);
7873
}
7974
}
8075
}

projects/ngx-openlayers/src/lib/graticule.component.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AfterContentInit, Component, Input, OnChanges, OnDestroy, SimpleChanges
22
import { Graticule } from 'ol';
33
import { Stroke } from 'ol/style';
44
import { MapComponent } from './map.component';
5+
import { Options } from 'ol/layer/Graticule';
56

67
@Component({
78
selector: 'aol-graticule',
@@ -23,18 +24,13 @@ export class GraticuleComponent implements AfterContentInit, OnChanges, OnDestro
2324
constructor(private map: MapComponent) {}
2425

2526
ngOnChanges(changes: SimpleChanges): void {
26-
const properties: { [index: string]: any } = {};
27-
2827
if (!this.instance) {
2928
return;
3029
}
31-
30+
const properties: Options = {};
3231
for (const key in changes) {
33-
if (changes.hasOwnProperty(key)) {
34-
properties[key] = changes[key].currentValue;
35-
}
32+
properties[key] = changes[key].currentValue;
3633
}
37-
3834
if (properties) {
3935
this.instance = new Graticule(properties);
4036
}

projects/ngx-openlayers/src/lib/layers/layer.component.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Extent } from 'ol/extent';
33
import RenderEvent from 'ol/render/Event';
44
import { MapComponent } from '../map.component';
55
import { LayerGroupComponent } from './layergroup.component';
6+
import BaseObject from 'ol/Object';
67

78
@Directive()
89
export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
@@ -24,6 +25,7 @@ export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
2425
@Input()
2526
postrender: (evt: RenderEvent) => void;
2627

28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2729
instance: any;
2830
componentType = 'layer';
2931

@@ -44,21 +46,19 @@ export abstract class LayerComponent implements OnInit, OnChanges, OnDestroy {
4446
}
4547

4648
ngOnChanges(changes: SimpleChanges): void {
47-
const properties: { [index: string]: any } = {};
4849
if (!this.instance) {
4950
return;
5051
}
52+
const properties: Parameters<BaseObject['setProperties']>[0] = {};
5153
for (const key in changes) {
52-
if (changes.hasOwnProperty(key)) {
53-
properties[key] = changes[key].currentValue;
54-
if (key === 'prerender') {
55-
this.instance.un('prerender', changes[key].previousValue);
56-
this.instance.on('prerender', changes[key].currentValue);
57-
}
58-
if (key === 'postrender') {
59-
this.instance.un('postrender', changes[key].previousValue);
60-
this.instance.on('postrender', changes[key].currentValue);
61-
}
54+
properties[key] = changes[key].currentValue;
55+
if (key === 'prerender') {
56+
this.instance.un('prerender', changes[key].previousValue);
57+
this.instance.on('prerender', changes[key].currentValue);
58+
}
59+
if (key === 'postrender') {
60+
this.instance.un('postrender', changes[key].previousValue);
61+
this.instance.on('postrender', changes[key].currentValue);
6262
}
6363
}
6464
// console.log('changes detected in aol-layer, setting new properties: ', properties);
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
1-
import { Component, OnDestroy, OnInit, SkipSelf, Optional } from '@angular/core';
1+
import { Component, Input, OnChanges, OnDestroy, OnInit, Optional, SimpleChanges, SkipSelf } from '@angular/core';
22
import { Group } from 'ol/layer';
3-
import { LayerComponent } from './layer.component';
43
import { MapComponent } from '../map.component';
4+
import { Extent } from 'ol/extent';
5+
import BaseObject from 'ol/Object';
56

67
@Component({
78
selector: 'aol-layer-group',
89
template: ` <ng-content></ng-content> `,
910
})
10-
export class LayerGroupComponent extends LayerComponent implements OnInit, OnDestroy {
11+
export class LayerGroupComponent implements OnInit, OnDestroy, OnChanges {
12+
@Input()
13+
opacity: number;
14+
@Input()
15+
visible: boolean;
16+
@Input()
17+
extent: Extent;
18+
@Input()
19+
zIndex: number;
20+
@Input()
21+
minResolution: number;
22+
@Input()
23+
maxResolution: number;
24+
1125
public instance: Group;
26+
componentType = 'layer';
27+
private host: MapComponent | LayerGroupComponent;
1228

1329
constructor(
1430
map: MapComponent,
1531
@SkipSelf()
1632
@Optional()
1733
group?: LayerGroupComponent
1834
) {
19-
super(group || map);
35+
this.host = group || map;
2036
}
2137

2238
ngOnInit(): void {
2339
// console.log(`creating ol.layer.Group instance with:`, this);
2440
this.instance = new Group(this);
25-
super.ngOnInit();
41+
this.host.instance.getLayers().push(this.instance);
42+
}
43+
44+
ngOnDestroy(): void {
45+
this.host.instance.getLayers().remove(this.instance);
46+
}
47+
48+
ngOnChanges(changes: SimpleChanges): void {
49+
if (!this.instance) {
50+
return;
51+
}
52+
const properties: Parameters<BaseObject['setProperties']>[0] = {};
53+
for (const key in changes) {
54+
properties[key] = changes[key].currentValue;
55+
}
56+
this.instance.setProperties(properties, false);
2657
}
2758
}

0 commit comments

Comments
 (0)