Skip to content

Commit bbe90d6

Browse files
committed
fix (map-maplibre): replaced TypedStyleLayer with StyleLayer
1 parent 9800560 commit bbe90d6

8 files changed

Lines changed: 29 additions & 26 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
- Removed `pipes` and moved it to new library `@dlr-eoc/ngx-ukis-utilities` [Issue #267](https://github.com/dlr-eoc/ukis-frontend-libraries/issues/267).
1414

1515
### Bug Fixes
16+
* **@dlr-eoc/map-maplibre:**
17+
- Replaced `TypedStyleLayer` with `StyleLayer` because `TypedStyleLayer` is not exported anymore.
18+
1619
* **@dlr-eoc/services-ogc:**
1720
* **@dlr-eoc/utils-ogc:**
1821
* **@dlr-eoc/demo-maps:**

projects/map-maplibre/src/lib/map-maplibre.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AfterViewChecked, AfterViewInit, Component, ElementRef, Input, NgZone, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
2-
import { Map as glMap, MapLibreEvent, NavigationControl, ScaleControl, StyleSpecification, TypedStyleLayer, GeoJSONSource, Evented, addSourceType } from 'maplibre-gl';
2+
import { Map as glMap, MapLibreEvent, NavigationControl, ScaleControl, StyleSpecification, StyleLayer, GeoJSONSource, Evented, addSourceType } from 'maplibre-gl';
33
import { setExtent, setCenter, setZoom, getExtent, getAllLayers, getUkisLayerIDs, removeLayerAndSource, changeOrderOfLayers, setRotation, setPitch, getRotation, getUkisLayerMetadata, UKIS_METADATA } from './maplibre.helpers';
44

55
import { MapState, MapStateService } from '@dlr-eoc/services-map-state';
@@ -393,7 +393,7 @@ export class MapMaplibreComponent implements OnInit, AfterViewInit, AfterViewChe
393393

394394
for (const layer of layers) {
395395
const mllayers = getAllLayers(this.map).filter(l => {
396-
const ukismetadata = getUkisLayerMetadata(l as TypedStyleLayer)
396+
const ukismetadata = getUkisLayerMetadata(l as StyleLayer)
397397
return ukismetadata[UKIS_METADATA.layerID] === layer.id;
398398
}).map(l => this.map.getLayer(l.id)).filter(l => l);
399399

projects/map-maplibre/src/lib/map-maplibre.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe('MapMaplibreService', () => {
233233
});
234234

235235

236-
it('should update a TypedStyleLayer with updateMlLayer', () => {
236+
it('should update a StyleLayer with updateMlLayer', () => {
237237
const layers = [ukisGeoJson];
238238
const filtertype = 'Layers';
239239
service.setUkisLayers(layers, filtertype, map);

projects/map-maplibre/src/lib/map-maplibre.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22
import {
33
Layer as ukisLayer, TFiltertypesUncap, TFiltertypes,
44
} from '@dlr-eoc/services-layers';
5-
import { Map as glMap, StyleSpecification, TypedStyleLayer } from 'maplibre-gl';
5+
import { Map as glMap, StyleSpecification, StyleLayer } from 'maplibre-gl';
66
import { BehaviorSubject } from 'rxjs';
77
import { LayerSourceSpecification, UKIS_METADATA } from './maplibre.helpers';
88
import { createLayer, layerIsSupported, updateSource, updateStyleLayerProperties } from './maplibre-layers.helpers';
@@ -112,7 +112,7 @@ export class MapMaplibreService {
112112
public getLayers(filtertype: Tgroupfiltertype, map: glMap) {
113113
const style = map.getStyle();
114114
const layerSpecifications = style.layers.filter(l => l.metadata[UKIS_METADATA.filtertype] === filtertype);
115-
const styleLayers = layerSpecifications.map(ls => map.getLayer(ls.id)) as TypedStyleLayer[]; //Temp fix of : Property ... of exported class expression may not be private or protected
115+
const styleLayers = layerSpecifications.map(ls => map.getLayer(ls.id)) as StyleLayer[]; //Temp fix of : Property ... of exported class expression may not be private or protected
116116

117117
return {
118118
layerSpecifications,
@@ -132,7 +132,7 @@ export class MapMaplibreService {
132132
const alllayers = this.getLayers(filtertype, map);
133133
const layerSpecifications = alllayers.layerSpecifications.filter(l => l.metadata[UKIS_METADATA.layerID] === id);
134134
if (layerSpecifications.length) {
135-
const styleLayers = layerSpecifications.map(ls => map.getLayer(ls.id)) as TypedStyleLayer[]; //Temp fix of : Property ... of exported class expression may not be private or protected
135+
const styleLayers = layerSpecifications.map(ls => map.getLayer(ls.id)) as StyleLayer[]; //Temp fix of : Property ... of exported class expression may not be private or protected
136136
return {
137137
layerSpecifications,
138138
styleLayers
@@ -191,7 +191,7 @@ export class MapMaplibreService {
191191
return layers;
192192
}
193193

194-
public updateMlLayer(mllayer: TypedStyleLayer, layer: ukisLayer, map: glMap) {
194+
public updateMlLayer(mllayer: StyleLayer, layer: ukisLayer, map: glMap) {
195195
/**
196196
* update ml layer
197197
* - map.setLayoutProperty() > Visibility
@@ -207,7 +207,7 @@ export class MapMaplibreService {
207207
updateStyleLayerProperties(map, mllayer, layer);
208208
}
209209

210-
private updateLayerParamsAndSource(map: glMap, mllayer: TypedStyleLayer, layer: ukisLayer) {
210+
private updateLayerParamsAndSource(map: glMap, mllayer: StyleLayer, layer: ukisLayer) {
211211
if (layer.type === 'wms' || layer.type === 'wmts' || layer.type === 'tms' || layer.type === 'wfs' || layer.type === 'geojson') {
212212
const oldSource = map.getSource(mllayer.source);
213213
updateSource(map, layer, oldSource);

projects/map-maplibre/src/lib/maplibre-layers.helpers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
createGetMapUrl, createGetTileUrl, createBaseLayer, updateStyleLayerProperties
55
} from './maplibre-layers.helpers';
66
import testFeatureCollection from '@dlr-eoc/shared-assets/geojson/testFeatureCollection.json';
7-
import { RasterSourceSpecification, StyleSpecification, TypedStyleLayer, Map as glMap } from 'maplibre-gl';
7+
import { RasterSourceSpecification, StyleSpecification, StyleLayer, Map as glMap } from 'maplibre-gl';
88
import { UKIS_METADATA, getOpacityPaintProperty, addUkisLayerMetadata } from './maplibre.helpers';
99
import { TestBed } from '@angular/core/testing';
1010
import { MapMaplibreService } from './map-maplibre.service';
@@ -385,7 +385,7 @@ describe('MaplibreLayerHelpers - use mapservice', () => {
385385
// TODO: service.setUkisLayers changes the id on the original object????
386386
const waterLayer = ukisCustom.custom_layer.layers.find(l => l.id === waterId);
387387
waterLayer.paint[paintProp] = newColor;
388-
updateStyleLayerProperties(map, waterLayerBefor as TypedStyleLayer, ukisCustom)
388+
updateStyleLayerProperties(map, waterLayerBefor as StyleLayer, ukisCustom)
389389

390390
const layerAfterUpdate = service.getLayersForId(ukisCustom.id, filtertype, map).styleLayers;
391391
const waterLayerAfter = layerAfterUpdate.find(l => l.id === waterIdStyledObj);

projects/map-maplibre/src/lib/maplibre-layers.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
CircleLayerSpecification, FillLayerSpecification, GeoJSONSourceSpecification, LayerSpecification, Map as glMap,
3-
LineLayerSpecification, RasterLayerSpecification, RasterSourceSpecification, SourceSpecification, StyleSpecification, SymbolLayerSpecification, TypedStyleLayer, VectorSourceSpecification, Source, FilterSpecification, DataDrivenPropertyValueSpecification,
3+
LineLayerSpecification, RasterLayerSpecification, RasterSourceSpecification, SourceSpecification, StyleSpecification, SymbolLayerSpecification, StyleLayer, VectorSourceSpecification, Source, FilterSpecification, DataDrivenPropertyValueSpecification,
44
MapGeoJSONFeature
55
} from "maplibre-gl";
66
import {
@@ -620,7 +620,7 @@ export function updateSource(map: glMap, layer: ukisLayer, oldSource: Source) {
620620
}
621621
}
622622

623-
export function updateStyleLayerProperties(map: glMap, mllayer: TypedStyleLayer, layer: ukisLayer) {
623+
export function updateStyleLayerProperties(map: glMap, mllayer: StyleLayer, layer: ukisLayer) {
624624
// https://maplibre.org/maplibre-style-spec/layers/#layer-properties
625625
// paint -> map.setPaintProperty(l.id...)
626626
// layout -> map.setLayoutProperty(l.id...)

projects/map-maplibre/src/lib/maplibre.helpers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getOpacity, setOpacity, setVisibility, getAllLayers, getUkisLayerIDs, getLayersAndSources, removeLayerAndSource, changeOrderOfLayers, LayerSourceSpecification, setRotation, setPitch, getRotation, UKIS_METADATA, addUkisLayerMetadata, getUkisLayerMetadata, IukisMetadata, setUkisLayerMetadata } from './maplibre.helpers';
2-
import { StyleSpecification, LayerSpecification, SourceSpecification, Map as glMap, TypedStyleLayer } from 'maplibre-gl';
2+
import { StyleSpecification, LayerSpecification, SourceSpecification, Map as glMap, StyleLayer } from 'maplibre-gl';
33
import { CustomLayer, Layer } from '@dlr-eoc/services-layers';
44

55
const createMapTarget = (size: number[]) => {
@@ -439,7 +439,7 @@ describe('MaplibreHelpers', () => {
439439
map.addSource('planet_eoc', planet_eoc);
440440
map.addLayer(waterLayer_test);
441441

442-
const mapLayer = map.getLayer(waterLayer_test.id) as TypedStyleLayer;
442+
const mapLayer = map.getLayer(waterLayer_test.id) as StyleLayer;
443443

444444
const meta = getUkisLayerMetadata(mapLayer);
445445
expect(meta[UKIS_METADATA.ignoreOpacity]).toBe(true);

projects/map-maplibre/src/lib/maplibre.helpers.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Map as glMap, LngLatBounds, LngLat, LayerSpecification, TypedStyleLayer, SourceSpecification } from 'maplibre-gl';
2+
import { Map as glMap, LngLatBounds, LngLat, LayerSpecification, StyleLayer, SourceSpecification } from 'maplibre-gl';
33
import { TGeoExtent, Layer as ukisLayer, TFiltertypes, TFiltertypesUncap } from '@dlr-eoc/services-layers';
44

55
/** Layers can consist of multiple layers and sources, e.g. if they are a VectorTileLayer - StyleSpecification */
@@ -30,7 +30,7 @@ export function addUkisLayerMetadata(l: ukisLayer) {
3030
return metadata;
3131
}
3232

33-
export function getUkisLayerMetadata(ml: TypedStyleLayer) {
33+
export function getUkisLayerMetadata(ml: StyleLayer) {
3434
const metadata: Partial<IukisMetadata> = {};
3535
metadata[UKIS_METADATA.filtertype] = (ml?.metadata as any)[UKIS_METADATA.filtertype];
3636
metadata[UKIS_METADATA.layerID] = (ml?.metadata as any)[UKIS_METADATA.layerID];
@@ -39,7 +39,7 @@ export function getUkisLayerMetadata(ml: TypedStyleLayer) {
3939
return metadata;
4040
}
4141

42-
export function setUkisLayerMetadata(ml: TypedStyleLayer, meta: Partial<IukisMetadata>) {
42+
export function setUkisLayerMetadata(ml: StyleLayer, meta: Partial<IukisMetadata>) {
4343
Object.keys(meta).forEach(k => {
4444
(ml?.metadata as any)[k] = meta[k];
4545
});
@@ -123,10 +123,10 @@ export function getRotation(map: glMap):number {
123123
return rotation;
124124
}
125125

126-
export function setVisibility(map: glMap, layerOrId: string | TypedStyleLayer, visibility: boolean, cb?: () => void) {
126+
export function setVisibility(map: glMap, layerOrId: string | StyleLayer, visibility: boolean, cb?: () => void) {
127127
let mllayer;
128128
if (typeof layerOrId === 'string') {
129-
mllayer = map.getLayer(layerOrId) as TypedStyleLayer | undefined;
129+
mllayer = map.getLayer(layerOrId) as StyleLayer | undefined;
130130
} else {
131131
mllayer = layerOrId;
132132
}
@@ -152,10 +152,10 @@ export function setVisibility(map: glMap, layerOrId: string | TypedStyleLayer, v
152152
}
153153
}
154154

155-
export function setOpacity(map: glMap, layerOrId: string | TypedStyleLayer, opacity: number, cb?: () => void) {
155+
export function setOpacity(map: glMap, layerOrId: string | StyleLayer, opacity: number, cb?: () => void) {
156156
let mllayer;
157157
if (typeof layerOrId === 'string') {
158-
mllayer = map.getLayer(layerOrId) as TypedStyleLayer | undefined;
158+
mllayer = map.getLayer(layerOrId) as StyleLayer | undefined;
159159
} else {
160160
mllayer = layerOrId;
161161
}
@@ -177,10 +177,10 @@ export function setOpacity(map: glMap, layerOrId: string | TypedStyleLayer, opac
177177
}
178178
}
179179

180-
export function getOpacity(map: glMap, layerOrId: string | TypedStyleLayer) {
180+
export function getOpacity(map: glMap, layerOrId: string | StyleLayer) {
181181
let mllayer;
182182
if (typeof layerOrId === 'string') {
183-
mllayer = map.getLayer(layerOrId) as TypedStyleLayer | undefined;
183+
mllayer = map.getLayer(layerOrId) as StyleLayer | undefined;
184184
} else {
185185
mllayer = layerOrId;
186186
}
@@ -189,10 +189,10 @@ export function getOpacity(map: glMap, layerOrId: string | TypedStyleLayer) {
189189
}
190190
}
191191

192-
export function getLayerbeforeId(map: glMap, layerOrId: string | TypedStyleLayer) {
192+
export function getLayerbeforeId(map: glMap, layerOrId: string | StyleLayer) {
193193
let mllayer;
194194
if (typeof layerOrId === 'string') {
195-
mllayer = map.getLayer(layerOrId) as TypedStyleLayer | undefined;
195+
mllayer = map.getLayer(layerOrId) as StyleLayer | undefined;
196196
} else {
197197
mllayer = layerOrId;
198198
}
@@ -209,7 +209,7 @@ export function getLayerbeforeId(map: glMap, layerOrId: string | TypedStyleLayer
209209
}
210210

211211
// https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.StyleLayer/
212-
export function styleLayerGetOpacity(mllayer: TypedStyleLayer) {
212+
export function styleLayerGetOpacity(mllayer: StyleLayer) {
213213
let opacityPaintProperty = getOpacityPaintProperty(mllayer.type);
214214
return mllayer.getPaintProperty(opacityPaintProperty);
215215
}

0 commit comments

Comments
 (0)