From 46303b79449a43c859f4bedc91c937fff7aaaa1d Mon Sep 17 00:00:00 2001 From: Merge angular migration to maplibre/mapbox refactor Date: Thu, 12 Dec 2024 18:59:08 +0100 Subject: [PATCH] Fix linting --- projects/arlas-map/karma.conf.js | 19 + .../src/lib/arlas-map-logic.service.ts | 40 +- .../src/lib/arlas-map.component.html | 4 +- .../arlas-map/src/lib/arlas-map.component.ts | 75 ++- .../arlas-map/src/lib/arlas-map.module.ts | 21 +- projects/arlas-map/src/lib/arlas-map.pipe.ts | 21 +- .../src/lib/basemaps/basemap.component.ts | 4 +- .../legend-icon/layer-icon.component.ts | 1 - .../src/lib/legend/legend.component.ts | 6 +- .../arlas-map/src/lib/legend/legend.config.ts | 10 +- .../src/lib/legend/legend.service.ts | 3 +- .../arlas-map/src/lib/legend/legend.tools.ts | 23 +- .../arlas-map/src/lib/map/model/controls.ts | 2 +- .../arlas-map/src/lib/map/model/events.ts | 2 +- .../arlas-map/src/lib/map/model/geometry.ts | 2 +- projects/arlas-map/src/lib/map/model/map.ts | 49 +- .../src/lib/map/model/vector-style.ts | 2 +- .../src/lib/map/service/arlas-map.service.ts | 28 +- projects/arlas-map/src/lib/map/tools.ts | 2 +- projects/arlas-map/src/public-api.ts | 33 +- projects/arlas-map/src/test.ts | 19 + projects/arlas-mapbox/karma.conf.js | 19 + .../src/lib/arlas-map-logic.service.ts | 27 +- .../src/lib/arlas-mapbox.module.ts | 19 + .../src/lib/arlas-mapbox.service.ts | 86 ++- .../lib/basemaps/mapbox-basemap.service.ts | 4 +- .../lib/basemaps/mapgl-basemap.component.ts | 7 +- .../arlas-mapbox/src/lib/draw/ArlasDraw.ts | 4 +- .../src/lib/legend/legend.service.ts | 12 +- .../arlas-mapbox/src/lib/map/ArlasMapboxGL.ts | 2 +- .../src/lib/map/model/controls.ts | 6 +- .../arlas-mapbox/src/lib/map/model/sources.ts | 4 +- .../src/lib/map/model/vector-style.ts | 2 +- projects/arlas-mapbox/src/public-api.ts | 21 +- projects/arlas-mapbox/src/test.ts | 19 + projects/arlas-maplibre/karma.conf.js | 19 + .../src/lib/arlas-map-logic.service.ts | 27 +- .../src/lib/arlas-maplibre.module.ts | 19 + .../src/lib/arlas-maplibre.service.ts | 79 ++- .../lib/basemaps/mapgl-basemap.component.ts | 6 +- .../lib/basemaps/maplibre-basemap.service.ts | 10 +- .../src/lib/legend/legend.service.ts | 586 +++++++++--------- .../src/lib/map/model/sources.ts | 21 +- .../src/lib/map/model/vector-style.ts | 2 +- projects/arlas-maplibre/src/public-api.ts | 22 +- projects/arlas-maplibre/src/test.ts | 19 + 46 files changed, 913 insertions(+), 495 deletions(-) diff --git a/projects/arlas-map/karma.conf.js b/projects/arlas-map/karma.conf.js index 7a3fe8fa..cc8f8db3 100644 --- a/projects/arlas-map/karma.conf.js +++ b/projects/arlas-map/karma.conf.js @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html diff --git a/projects/arlas-map/src/lib/arlas-map-logic.service.ts b/projects/arlas-map/src/lib/arlas-map-logic.service.ts index 1e35f724..4dff5659 100644 --- a/projects/arlas-map/src/lib/arlas-map-logic.service.ts +++ b/projects/arlas-map/src/lib/arlas-map-logic.service.ts @@ -1,17 +1,36 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; import { ArlasMapService } from './map/service/arlas-map.service'; import { FeatureCollection } from '@turf/helpers'; import { AbstractArlasMapGL } from './map/AbstractArlasMapGL'; import { ArlasMapSource } from './map/model/sources'; import { VisualisationSetConfig } from './map/model/visualisationsets'; -import { ARLAS_ID, ExternalEvent, FILLSTROKE_LAYER_PREFIX, MapLayers, SCROLLABLE_ARLAS_ID } from './map/model/layers'; +import { ExternalEvent, MapLayers } from './map/model/layers'; import { ElementIdentifier } from 'arlas-web-components'; @Injectable({ providedIn: 'root' }) -export abstract class ArlasMapFunctionalService { +export abstract class MapLogicService { /** IMPORTANT NOTE: All the attributes/params that are typed with "any", will have the right type in the implementation. */ public dataSources: any[] = []; public abstract layersMap: Map; @@ -28,7 +47,7 @@ export abstract class ArlasMapFunctionalService { public declareArlasDataSources(dataSourcesIds: Set, data: FeatureCollection, map: AbstractArlasMapGL) { if (dataSourcesIds) { dataSourcesIds.forEach(sourceId => { - const source = this.mapService.createGeojsonSource(data) + const source = this.mapService.createGeojsonSource(data); this.dataSources.push(source); /** For an implementation that doesn't add a source to map * --- for instance Openalayers, adds the source to layer --- @@ -41,7 +60,7 @@ export abstract class ArlasMapFunctionalService { public declareLabelSources(labelSourceId: string, data: FeatureCollection, map: AbstractArlasMapGL) { if (labelSourceId) { - const source = this.mapService.createGeojsonSource(data) + const source = this.mapService.createGeojsonSource(data); this.mapService.setSource(labelSourceId, source, map); } } @@ -129,7 +148,7 @@ export abstract class ArlasMapFunctionalService { if (!!visualisation.layers && visualisation.enabled) { for (let j = visualisation.layers.length - 1; j >= 0; j--) { const l = visualisation.layers[j]; - this.mapService.moveArlasDataLayer(map, l, this.layersMap) + this.mapService.moveArlasDataLayer(map, l, this.layersMap); } } } @@ -143,7 +162,8 @@ export abstract class ArlasMapFunctionalService { } - public filterLayersOnEvent(mapLayers: MapLayers, map: AbstractArlasMapGL, visibilityCondition: boolean, visibilityFilter: Array, visibilityEvent: ExternalEvent, + public filterLayersOnEvent(mapLayers: MapLayers, map: AbstractArlasMapGL, + visibilityCondition: boolean, visibilityFilter: Array, visibilityEvent: ExternalEvent, collection?: string): void { if (mapLayers && mapLayers.externalEventLayers) { mapLayers.externalEventLayers.filter(layer => layer.on === visibilityEvent).forEach(layer => { @@ -193,7 +213,8 @@ export abstract class ArlasMapFunctionalService { } } - public highlightFeature(mapLayers: MapLayers, map: AbstractArlasMapGL, featureToHightLight: { isleaving: boolean; elementidentifier: ElementIdentifier; }) { + public highlightFeature(mapLayers: MapLayers, map: AbstractArlasMapGL, + featureToHightLight: { isleaving: boolean; elementidentifier: ElementIdentifier; }) { if (featureToHightLight && featureToHightLight.elementidentifier) { const ids: Array = [featureToHightLight.elementidentifier.idValue]; if (!isNaN(+featureToHightLight.elementidentifier.idValue)) { @@ -290,7 +311,4 @@ export abstract class ArlasMapFunctionalService { public abstract updateMapStyle(map: AbstractArlasMapGL, l: any, ids: Array, sourceName: string): void; public abstract getVisibleIdsFilter(map: AbstractArlasMapGL, layer: any, ids: Array); - - - -} \ No newline at end of file +} diff --git a/projects/arlas-map/src/lib/arlas-map.component.html b/projects/arlas-map/src/lib/arlas-map.component.html index b9731de5..69b3f59b 100644 --- a/projects/arlas-map/src/lib/arlas-map.component.html +++ b/projects/arlas-map/src/lib/arlas-map.component.html @@ -21,8 +21,8 @@
drag_indicator
- diff --git a/projects/arlas-map/src/lib/arlas-map.component.ts b/projects/arlas-map/src/lib/arlas-map.component.ts index 93b1a3a2..80b5543e 100644 --- a/projects/arlas-map/src/lib/arlas-map.component.ts +++ b/projects/arlas-map/src/lib/arlas-map.component.ts @@ -1,8 +1,30 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Component, EventEmitter, HostListener, Input, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core'; import { marker } from '@biesbjerg/ngx-translate-extract-marker'; import { Feature, FeatureCollection, Geometry, Polygon, polygon } from '@turf/helpers'; import { BasemapStyle } from './basemaps/basemap.config'; -import { ArlasMapOffset, AbstractArlasMapGL, ElementIdentifier, MapConfig, ZOOM_IN, ZOOM_OUT, RESET_BEARING, CROSS_LAYER_PREFIX } from './map/AbstractArlasMapGL'; +import { + ArlasMapOffset, AbstractArlasMapGL, ElementIdentifier, MapConfig, + ZOOM_IN, ZOOM_OUT, RESET_BEARING, CROSS_LAYER_PREFIX +} from './map/AbstractArlasMapGL'; import { IconConfig, ControlPosition, DrawControlsOption } from './map/model/controls'; import { AoiDimensions, BboxDrawCommand } from './draw/draw.models'; import { LegendData } from './legend/legend.config'; @@ -19,7 +41,7 @@ import { MatSnackBar } from '@angular/material/snack-bar'; import { TranslateService } from '@ngx-translate/core'; import { ArlasBasemaps } from './basemaps/basemaps.model'; import { ArlasMapService } from './map/service/arlas-map.service'; -import * as styles from './draw/themes/default-theme' +import * as styles from './draw/themes/default-theme'; import limitVertexDirectSelectMode from './draw/modes/LimitVertexDirectSelectMode'; import validGeomDrawPolygonMode from './draw/modes/ValidGeomDrawPolygonMode'; import { circleMode } from './draw/modes/circles/circle.mode'; @@ -35,7 +57,7 @@ import { ARLAS_VSET } from './map/model/layers'; import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; import { OnMoveResult } from './map/model/map'; import { MapMouseEvent } from './map/model/events'; -import { ArlasMapFunctionalService } from './arlas-map-logic.service'; +import { MapLogicService } from './arlas-map-logic.service'; import { latLngToWKT } from './map/tools'; @Component({ @@ -184,7 +206,8 @@ export class ArlasMapComponent implements OnInit { /** @description Margin applied to the map extent. Data will be fetched in all this extent. */ @Input() public margePanForLoad: number; - /** @description Margin applied to the map extent. Before loading data, the components checks first if there are features already loaded in this extent. */ + /** @description Margin applied to the map extent. Before loading data, + * the components checks first if there are features already loaded in this extent. */ @Input() public margePanForTest: number; /** @description A callback run before the Map makes a request for an external URL/ */ @@ -242,6 +265,7 @@ export class ArlasMapComponent implements OnInit { /** @description Subject of [collection, [field, legendData]] map. The map subscribes to it to keep */ /** the legend updated with the data displayed on the map. */ @Input() public legendUpdater: Subject>> = new Subject(); + /** @description Subject of [layerId, boolean] map. The map subscribes to it to keep */ /** the legend updated with the visibility of the layer.*/ @Input() public visibilityUpdater: Subject> = new Subject(); @@ -256,9 +280,6 @@ export class ArlasMapComponent implements OnInit { /** ANGULAR OUTPUTS */ - - /** @description Subject of [layerId, boolean] map. The map subscribes to it to keep */ - /** the legend updated with the visibility of the layer.*/declareArlasDataSources /** @description Emits true after the map is loaded and all sources & layers are added. */ @Output() public onMapLoaded: Subject = new Subject(); @@ -306,7 +327,7 @@ export class ArlasMapComponent implements OnInit { public constructor(private http: HttpClient, private drawService: MapboxAoiDrawService, private basemapService: BasemapService, private _snackBar: MatSnackBar, private translate: TranslateService, protected mapService: ArlasMapService, - protected mapFunctionalService: ArlasMapFunctionalService) { + protected mapLogicService: MapLogicService) { this.aoiEditSubscription = this.drawService.editAoi$.subscribe(ae => this.onAoiEdit.emit(ae)); this.drawBboxSubscription = this.drawService.drawBbox$.subscribe({ next: (bboxDC: BboxDrawCommand) => { @@ -368,7 +389,7 @@ export class ArlasMapComponent implements OnInit { this.drawService.addFeatures(this.drawData, /** deleteOld */ true); } this.drawSelectionChanged = false; - this.mapFunctionalService.updateLabelSources(this.map.POLYGON_LABEL_SOURCE, this.polygonlabeldata, this.map); + this.mapLogicService.updateLabelSources(this.map.POLYGON_LABEL_SOURCE, this.polygonlabeldata, this.map); } if (changes['boundsToFit'] !== undefined) { const newBoundsToFit = changes['boundsToFit'].currentValue; @@ -555,10 +576,10 @@ export class ArlasMapComponent implements OnInit { this.basemapService.declareProtomapProtocol(this.map); this.basemapService.addProtomapBasemap(this.map); this.addIcons(); - this.mapFunctionalService.declareArlasDataSources(this.dataSources, this.emptyData, this.map); - this.mapFunctionalService.declareBasemapSources(this.mapSources, this.map); - this.mapFunctionalService.declareLabelSources('', this.polygonlabeldata, this.map); - this.mapFunctionalService.addArlasDataLayers(this.visualisationSetsConfig, this.mapLayers, this.map); + this.mapLogicService.declareArlasDataSources(this.dataSources, this.emptyData, this.map); + this.mapLogicService.declareBasemapSources(this.mapSources, this.map); + this.mapLogicService.declareLabelSources('', this.polygonlabeldata, this.map); + this.mapLogicService.addArlasDataLayers(this.visualisationSetsConfig, this.mapLayers, this.map); this.bindLayerEvents(); }); @@ -566,7 +587,7 @@ export class ArlasMapComponent implements OnInit { this.draw.changeMode('static'); if (this.mapLayers !== null) { this.visibilityUpdater.subscribe(visibilityStatus => { - this.mapFunctionalService.updateVisibility(visibilityStatus, this.visualisationSetsConfig, this.map); + this.mapLogicService.updateVisibility(visibilityStatus, this.visualisationSetsConfig, this.map); }); } this.canvas = this.map.getCanvasContainer(); @@ -767,7 +788,7 @@ export class ArlasMapComponent implements OnInit { this.onMapLoaded.next(true); }); - this.map.onMoveEnd(this.mapFunctionalService.visualisationsSets).subscribe((moveResult => { + this.map.onMoveEnd(this.mapLogicService.visualisationsSets).subscribe((moveResult => { this.onMove.next(moveResult); })); @@ -862,7 +883,7 @@ export class ArlasMapComponent implements OnInit { /** Sets the layers order according to the order of `visualisationSetsConfig` list*/ public reorderLayers() { - this.mapFunctionalService.reorderLayers(this.visualisationSetsConfig, this.map); + this.mapLogicService.reorderLayers(this.visualisationSetsConfig, this.map); } /** ------------------------------------------------------- VISUAL SEPERATOR - DRAWING ----------------------------------------- */ @@ -884,7 +905,7 @@ export class ArlasMapComponent implements OnInit { private mousemove = (e) => { // Capture the ongoing xy coordinates - this.current = this.mapService.getPointFromScreen(e, this.canvas) + this.current = this.mapService.getPointFromScreen(e, this.canvas); // Append the box element if it doesnt exist if (this.box === undefined) { this.box = document.createElement('div'); @@ -941,10 +962,10 @@ export class ArlasMapComponent implements OnInit { /** * Emits the newly drawn bbox. It completes the drawBbox event emitted by the drawService. - * @param east - * @param south - * @param west - * @param north + * @param east + * @param south + * @param west + * @param north */ protected drawBbox(east, south, west, north) { const coordinates = [[ @@ -1120,7 +1141,7 @@ export class ArlasMapComponent implements OnInit { } public emitVisualisations(visualisationName: string) { - const layers = this.mapFunctionalService.updateLayoutVisibility(visualisationName, this.visualisationSetsConfig, this.map); + const layers = this.mapLogicService.updateLayoutVisibility(visualisationName, this.visualisationSetsConfig, this.map); this.visualisations.emit(layers); this.reorderLayers(); } @@ -1144,9 +1165,9 @@ export class ArlasMapComponent implements OnInit { /** puts the layers list in the new order after dropping */ public dropLayer(event: CdkDragDrop, visuName: string) { - const layers = Array.from(this.mapFunctionalService.findVisualisationSetLayer(visuName, this.visualisationSetsConfig)); + const layers = Array.from(this.mapLogicService.findVisualisationSetLayer(visuName, this.visualisationSetsConfig)); moveItemInArray(layers, event.previousIndex, event.currentIndex); - this.mapFunctionalService.setVisualisationSetLayers(visuName, layers, this.visualisationSetsConfig); + this.mapLogicService.setVisualisationSetLayers(visuName, layers, this.visualisationSetsConfig); this.reorderLayers(); } @@ -1168,7 +1189,7 @@ export class ArlasMapComponent implements OnInit { } public selectFeaturesByCollection(features: Array, collection: string) { - this.mapFunctionalService.selectFeaturesByCollection(this.mapLayers, this.map, features, collection); + this.mapLogicService.selectFeaturesByCollection(this.mapLayers, this.map, features, collection); } public hideBasemapSwitcher() { @@ -1187,11 +1208,11 @@ export class ArlasMapComponent implements OnInit { } private highlightFeature(featureToHightLight: { isleaving: boolean; elementidentifier: ElementIdentifier; }) { - this.mapFunctionalService.highlightFeature(this.mapLayers, this.map, featureToHightLight); + this.mapLogicService.highlightFeature(this.mapLayers, this.map, featureToHightLight); } private selectFeatures(elementToSelect: Array) { - this.mapFunctionalService.selectFeatures(this.mapLayers, this.map, elementToSelect); + this.mapLogicService.selectFeatures(this.mapLayers, this.map, elementToSelect); } } diff --git a/projects/arlas-map/src/lib/arlas-map.module.ts b/projects/arlas-map/src/lib/arlas-map.module.ts index c86b9926..2307296b 100644 --- a/projects/arlas-map/src/lib/arlas-map.module.ts +++ b/projects/arlas-map/src/lib/arlas-map.module.ts @@ -1,11 +1,28 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { NgModule } from '@angular/core'; import { ArlasMapComponent } from './arlas-map.component'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { TranslateModule } from '@ngx-translate/core'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; -import { BasemapComponent } from './basemaps/basemap.component'; -import { CoordinatesComponent } from './coordinates/coordinates.component'; import { MapboxAoiDrawService } from './draw/draw.service'; import { LayerIconComponent } from './legend/legend-icon/layer-icon.component'; import { LegendComponent } from './legend/legend.component'; diff --git a/projects/arlas-map/src/lib/arlas-map.pipe.ts b/projects/arlas-map/src/lib/arlas-map.pipe.ts index 700339d0..005296db 100644 --- a/projects/arlas-map/src/lib/arlas-map.pipe.ts +++ b/projects/arlas-map/src/lib/arlas-map.pipe.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'getCollection' }) @@ -11,4 +30,4 @@ export class GetCollectionPipe implements PipeTransform { } return collection; } -} \ No newline at end of file +} diff --git a/projects/arlas-map/src/lib/basemaps/basemap.component.ts b/projects/arlas-map/src/lib/basemaps/basemap.component.ts index f2006397..4ecabdcd 100644 --- a/projects/arlas-map/src/lib/basemaps/basemap.component.ts +++ b/projects/arlas-map/src/lib/basemaps/basemap.component.ts @@ -25,7 +25,7 @@ import { ArlasBasemaps } from './basemaps.model'; import { BasemapService } from './basemap.service'; import { BasemapStyle } from './basemap.config'; import { ArlasMapService } from '../map/service/arlas-map.service'; -import { ArlasMapFunctionalService } from '../arlas-map-logic.service'; +import { MapLogicService } from '../arlas-map-logic.service'; import { takeUntil } from 'rxjs'; @Component({ @@ -47,7 +47,7 @@ export class BasemapComponent implements OnInit, OnDestroy { public basemaps: ArlasBasemaps; public constructor(protected basemapService: BasemapService, - protected mapFunctionalService: ArlasMapFunctionalService, + protected mapLogicService: MapLogicService, protected mapService: ArlasMapService) { this.basemapService.basemapChanged$.pipe(takeUntil(this._onDestroy$)).subscribe(() => this.basemapChanged.emit()); diff --git a/projects/arlas-map/src/lib/legend/legend-icon/layer-icon.component.ts b/projects/arlas-map/src/lib/legend/legend-icon/layer-icon.component.ts index b158e842..f4b6eaf7 100644 --- a/projects/arlas-map/src/lib/legend/legend-icon/layer-icon.component.ts +++ b/projects/arlas-map/src/lib/legend/legend-icon/layer-icon.component.ts @@ -95,7 +95,6 @@ export class LayerIconComponent implements OnInit, AfterViewInit, OnChanges { break; } case 'symbol': { - //todo type const l: any = (this.layer.layout); if (l['text-field']) { drawTextIcon(this.layerIconElement.nativeElement, this.colorLegend); diff --git a/projects/arlas-map/src/lib/legend/legend.component.ts b/projects/arlas-map/src/lib/legend/legend.component.ts index f46c6164..8112ea8a 100644 --- a/projects/arlas-map/src/lib/legend/legend.component.ts +++ b/projects/arlas-map/src/lib/legend/legend.component.ts @@ -49,7 +49,7 @@ export class LegendComponent implements OnInit, AfterViewInit, OnChanges { * @Input : Angular * @description Layer object */ - @Input() public layer: any + @Input() public layer: any; /** * @Input : Angular * @description Collection of the layer @@ -90,8 +90,8 @@ export class LegendComponent implements OnInit, AfterViewInit, OnChanges { */ @Output() public downloadSourceEmitter: Subject<{ layer: any; downloadType: string; }> = new Subject(); - @ViewChild('width_legend', { static: false }) public lineWidthLegend: any//MapglLegendItemComponent; - @ViewChild('radius_legend', { static: false }) public circleRadiusLegend: any//MapglLegendItemComponent; + @ViewChild('width_legend', { static: false }) public lineWidthLegend: any; + @ViewChild('radius_legend', { static: false }) public circleRadiusLegend: any; public colorLegend: Legend = {}; public lineDasharray: Array; diff --git a/projects/arlas-map/src/lib/legend/legend.config.ts b/projects/arlas-map/src/lib/legend/legend.config.ts index 46875f04..be4999a6 100644 --- a/projects/arlas-map/src/lib/legend/legend.config.ts +++ b/projects/arlas-map/src/lib/legend/legend.config.ts @@ -17,7 +17,7 @@ * under the License. */ -import { HistogramData } from "arlas-d3/histograms/utils/HistogramUtils"; +import { HistogramData } from 'arlas-d3/histograms/utils/HistogramUtils'; export interface LegendData { minValue?: string; @@ -39,7 +39,7 @@ export interface Legend { } export interface CircleLegend extends FillLegend { - radius: Legend + radius: Legend; } export interface FillLegend { @@ -52,20 +52,20 @@ export interface FillLegend { export interface HeatmapLegend { color: Legend; colorPalette: string; - radius: Legend + radius: Legend; } export interface LabelLegend { color: Legend; colorPalette: string; - size: Legend + size: Legend; } export interface LineLegend { color: Legend; colorPalette: string; dashes: Array; - width: Legend, + width: Legend; } export enum PROPERTY_SELECTOR_SOURCE { diff --git a/projects/arlas-map/src/lib/legend/legend.service.ts b/projects/arlas-map/src/lib/legend/legend.service.ts index 487ed87c..7aa71d27 100644 --- a/projects/arlas-map/src/lib/legend/legend.service.ts +++ b/projects/arlas-map/src/lib/legend/legend.service.ts @@ -30,9 +30,8 @@ export class LegendService { public static buildColorLegend(colorExpression: string | any, visibleMode: boolean, legendData: Map, filter?: any, translate?: TranslateService): [Legend, string] { - return [undefined, ''] + return [undefined, '']; }; - public getCircleLegend(paint: any, visibileMode: boolean, legendData: Map, layer: any): CircleLegend { return undefined; diff --git a/projects/arlas-map/src/lib/legend/legend.tools.ts b/projects/arlas-map/src/lib/legend/legend.tools.ts index 4c2678c0..9d886e87 100644 --- a/projects/arlas-map/src/lib/legend/legend.tools.ts +++ b/projects/arlas-map/src/lib/legend/legend.tools.ts @@ -1,8 +1,27 @@ -import { HistogramData } from "arlas-d3/histograms/utils/HistogramUtils"; +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HistogramData } from 'arlas-d3/histograms/utils/HistogramUtils'; export function getMax(data: Array): number { return Math.max(...data.map(hd => +hd.value)); } export const MAX_CIRLE_RADIUS = 7; -export const MAX_LINE_WIDTH = 10; \ No newline at end of file +export const MAX_LINE_WIDTH = 10; diff --git a/projects/arlas-map/src/lib/map/model/controls.ts b/projects/arlas-map/src/lib/map/model/controls.ts index fedd3af0..29668840 100644 --- a/projects/arlas-map/src/lib/map/model/controls.ts +++ b/projects/arlas-map/src/lib/map/model/controls.ts @@ -17,7 +17,7 @@ * under the License. */ -import { marker } from "@biesbjerg/ngx-translate-extract-marker"; +import { marker } from '@biesbjerg/ngx-translate-extract-marker'; /** All the map controls configuration diff --git a/projects/arlas-map/src/lib/map/model/events.ts b/projects/arlas-map/src/lib/map/model/events.ts index e4166585..0a93d6ad 100644 --- a/projects/arlas-map/src/lib/map/model/events.ts +++ b/projects/arlas-map/src/lib/map/model/events.ts @@ -29,7 +29,7 @@ export interface MapLayerMouseEvent { } export interface MapMouseEvent { - type: string + type: string; point: ArlasPoint; lngLat: LngLat; } diff --git a/projects/arlas-map/src/lib/map/model/geometry.ts b/projects/arlas-map/src/lib/map/model/geometry.ts index 5475a51a..35abe706 100644 --- a/projects/arlas-map/src/lib/map/model/geometry.ts +++ b/projects/arlas-map/src/lib/map/model/geometry.ts @@ -21,7 +21,7 @@ export class ArlasPoint { public x: number; public y: number; - constructor(x: number, y: number) { + public constructor(x: number, y: number) { this.x = x; this.y = y; } diff --git a/projects/arlas-map/src/lib/map/model/map.ts b/projects/arlas-map/src/lib/map/model/map.ts index 0c0e9060..1b870565 100644 --- a/projects/arlas-map/src/lib/map/model/map.ts +++ b/projects/arlas-map/src/lib/map/model/map.ts @@ -19,29 +19,28 @@ export interface OnMoveResult { - zoom: number; - zoomStart: number; - center: Array; - centerWithOffset: Array; - extend: Array; - extendWithOffset: Array; - rawExtendWithOffset: Array; - extendForLoad: Array; - extendForTest: Array; - rawExtendForLoad: Array; - rawExtendForTest: Array; - xMoveRatio: number; - yMoveRatio: number; - visibleLayers: Set; + zoom: number; + zoomStart: number; + center: Array; + centerWithOffset: Array; + extend: Array; + extendWithOffset: Array; + rawExtendWithOffset: Array; + extendForLoad: Array; + extendForTest: Array; + rawExtendForLoad: Array; + rawExtendForTest: Array; + xMoveRatio: number; + yMoveRatio: number; + visibleLayers: Set; +} + +export class LngLat { + public lng: number; + public lat: number; + + public constructor(lng, lat) { + this.lng = lng; + this.lat = lat; } - - - export class LngLat { - lng: number; - lat: number; - - constructor(lng, lat) { - this.lng = lng; - this.lat = lat; - } - } \ No newline at end of file +} diff --git a/projects/arlas-map/src/lib/map/model/vector-style.ts b/projects/arlas-map/src/lib/map/model/vector-style.ts index 7029a1bd..8a5a3e9d 100644 --- a/projects/arlas-map/src/lib/map/model/vector-style.ts +++ b/projects/arlas-map/src/lib/map/model/vector-style.ts @@ -63,4 +63,4 @@ export abstract class VectorStyle { public abstract circle(layer: any); public abstract fill(layer: any); -} \ No newline at end of file +} diff --git a/projects/arlas-map/src/lib/map/service/arlas-map.service.ts b/projects/arlas-map/src/lib/map/service/arlas-map.service.ts index 2e025a2b..61d24d86 100644 --- a/projects/arlas-map/src/lib/map/service/arlas-map.service.ts +++ b/projects/arlas-map/src/lib/map/service/arlas-map.service.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; import { AbstractArlasMapGL, MapConfig } from '../AbstractArlasMapGL'; import { AbstractDraw } from '../../draw/AbstractDraw'; @@ -10,7 +29,7 @@ import { VectorStyle } from '../model/vector-style'; }) export abstract class ArlasMapService { - constructor() { } + public constructor() { } public abstract getInitTransformRequest(): Function; @@ -22,7 +41,6 @@ export abstract class ArlasMapService { public abstract boundsToString(bounds: any): string; - public abstract getPointFromScreen(e, container: HTMLElement); /** Sets `data` to a Geojson `source` of the map @@ -42,14 +60,14 @@ export abstract class ArlasMapService { public abstract addArlasDataLayer(map: AbstractArlasMapGL, layer: any, layersMap: Map, beforeId?: string); public abstract getLayersFromPattern(map: AbstractArlasMapGL, layersIdPattern: string): any[]; public abstract getAllLayers(map: AbstractArlasMapGL): any[]; - + public abstract hasLayer(map: AbstractArlasMapGL, layer: any); public abstract hasLayersFromPattern(map: AbstractArlasMapGL, layersIdPattern: string); public abstract moveLayer(map: AbstractArlasMapGL, layer: any, beforeId?: string); public abstract moveArlasDataLayer(map: AbstractArlasMapGL, layer: any, layersMap: Map, beforeId?: string); public abstract onLayerEvent(eventName: any, map: AbstractArlasMapGL, layer: any, fn: (e) => void); public abstract removeLayer(map: AbstractArlasMapGL, layer: any); - public abstract removeLayers(map: AbstractArlasMapGL, layers: any) + public abstract removeLayers(map: AbstractArlasMapGL, layers: any); public abstract removeLayersFromPattern(map: AbstractArlasMapGL, layersIdPattern: string); public abstract setLayerVisibility(layer: any, isVisible: boolean, map: AbstractArlasMapGL); public abstract isLayerVisible(layer: any): boolean; @@ -66,7 +84,7 @@ export abstract class ArlasMapService { public abstract addPopup(map: AbstractArlasMapGL, popup: any); public abstract createPopup(lng: number, lat: number, message: string); public abstract removePopup(map: AbstractArlasMapGL, popup: any); - + public abstract onMapEvent(eventName: any, map: AbstractArlasMapGL, fn: (e) => void); public abstract setMapCursor(map: AbstractArlasMapGL, cursor: string): void; public abstract flyTo(lat: number, lng: number, zoom: number, map: AbstractArlasMapGL); diff --git a/projects/arlas-map/src/lib/map/tools.ts b/projects/arlas-map/src/lib/map/tools.ts index 413e5ecb..0fb954bd 100644 --- a/projects/arlas-map/src/lib/map/tools.ts +++ b/projects/arlas-map/src/lib/map/tools.ts @@ -39,4 +39,4 @@ export function latLngToWKT(features) { wkt = wktType.replace('[###]', polygons); } return wkt; -} \ No newline at end of file +} diff --git a/projects/arlas-map/src/public-api.ts b/projects/arlas-map/src/public-api.ts index 8f70d894..cb9b2548 100644 --- a/projects/arlas-map/src/public-api.ts +++ b/projects/arlas-map/src/public-api.ts @@ -1,3 +1,22 @@ + +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /* * Public API Surface of arlas-map */ @@ -42,10 +61,11 @@ export { radiusCircleMode } from './lib/draw/modes/circles/radius.circle.mode'; export { createSupplementaryPointsForCircle, dragPan } from './lib/draw/modes/circles/utils'; export { stripDirectSelectMode } from './lib/draw/modes/strip/strip.direct.mode'; export { stripMode } from './lib/draw/modes/strip/strip.mode'; -export { AbstractArlasMapGL, ArlasMapOffset, CROSS_LAYER_PREFIX, +export { + AbstractArlasMapGL, ArlasMapOffset, CROSS_LAYER_PREFIX, BindLayerToEvent, ElementIdentifier, GEOJSON_SOURCE_TYPE, LAYER_SWITCHER_TOOLTIP, MapConfig, MapEventBinds, RESET_BEARING, ZOOM_IN, ZOOM_OUT - } from './lib/map/AbstractArlasMapGL'; +} from './lib/map/AbstractArlasMapGL'; export { MapInterface } from './lib/map/interface/map.interface'; export { ConfigControls, ControlButton, ControlPosition, ControlsOption, DrawConfigControl, @@ -59,11 +79,14 @@ export { } from './lib/map/model/layers'; export { ArlasMapSource } from './lib/map/model/sources'; export { VisualisationSetConfig } from './lib/map/model/visualisationsets'; -export { Legend, LegendData, PROPERTY_SELECTOR_SOURCE, CircleLegend, LineLegend, FillLegend, HeatmapLegend, LabelLegend } from './lib/legend/legend.config'; +export { + Legend, LegendData, PROPERTY_SELECTOR_SOURCE, CircleLegend, LineLegend, + FillLegend, HeatmapLegend, LabelLegend +} from './lib/legend/legend.config'; export { getMax, MAX_CIRLE_RADIUS, MAX_LINE_WIDTH } from './lib/legend/legend.tools'; export * as styles from './lib/draw/themes/default-theme'; export { ArlasMapComponent } from './lib/arlas-map.component'; export { ArlasMapService } from './lib/map/service/arlas-map.service'; -export { LngLat, OnMoveResult} from './lib/map/model/map'; +export { LngLat, OnMoveResult } from './lib/map/model/map'; export { VectorStyle, ArlasCircle, ArlasFill, VectorStyleEnum } from './lib/map/model/vector-style'; -export { ArlasMapFunctionalService } from './lib/arlas-map-logic.service'; \ No newline at end of file +export { MapLogicService } from './lib/arlas-map-logic.service'; diff --git a/projects/arlas-map/src/test.ts b/projects/arlas-map/src/test.ts index 5775317a..a3498fdb 100644 --- a/projects/arlas-map/src/test.ts +++ b/projects/arlas-map/src/test.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // This file is required by karma.conf.js and loads recursively all the .spec and framework files import 'zone.js'; diff --git a/projects/arlas-mapbox/karma.conf.js b/projects/arlas-mapbox/karma.conf.js index e0db555f..4f8a9f66 100644 --- a/projects/arlas-mapbox/karma.conf.js +++ b/projects/arlas-mapbox/karma.conf.js @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html diff --git a/projects/arlas-mapbox/src/lib/arlas-map-logic.service.ts b/projects/arlas-mapbox/src/lib/arlas-map-logic.service.ts index 5591441d..bd003648 100644 --- a/projects/arlas-mapbox/src/lib/arlas-map-logic.service.ts +++ b/projects/arlas-mapbox/src/lib/arlas-map-logic.service.ts @@ -1,5 +1,24 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; -import { ArlasMapFunctionalService } from 'arlas-map'; +import { MapLogicService as AbstractMapLogicService } from 'arlas-map'; import { ArlasMapboxService } from './arlas-mapbox.service'; import { FeatureCollection } from '@turf/helpers'; import { ArlasMapboxGL } from './map/ArlasMapboxGL'; @@ -14,10 +33,10 @@ import { VisualisationSetConfig } from 'arlas-map'; @Injectable({ providedIn: 'root' }) -export class MapLogicService extends ArlasMapFunctionalService{ +export class MapLogicService extends AbstractMapLogicService { public dataSources: GeoJSONSource[] = []; public layersMap: Map; - public constructor(public mapService: ArlasMapboxService) { + public constructor(public mapService: ArlasMapboxService) { super(mapService); } @@ -116,4 +135,4 @@ export class MapLogicService extends ArlasMapFunctionalService{ this.setLayersMap(mapLayers as MapLayers, layers); this.reorderLayers(visualisations, map); } -} \ No newline at end of file +} diff --git a/projects/arlas-mapbox/src/lib/arlas-mapbox.module.ts b/projects/arlas-mapbox/src/lib/arlas-mapbox.module.ts index 69b83f91..463feadf 100644 --- a/projects/arlas-mapbox/src/lib/arlas-mapbox.module.ts +++ b/projects/arlas-mapbox/src/lib/arlas-mapbox.module.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { NgModule } from '@angular/core'; import { ArlasMapboxService } from './arlas-mapbox.service'; import { MapboxBasemapService } from './basemaps/mapbox-basemap.service'; diff --git a/projects/arlas-mapbox/src/lib/arlas-mapbox.service.ts b/projects/arlas-mapbox/src/lib/arlas-mapbox.service.ts index 7238f064..3dc8f7b1 100644 --- a/projects/arlas-mapbox/src/lib/arlas-mapbox.service.ts +++ b/projects/arlas-mapbox/src/lib/arlas-mapbox.service.ts @@ -1,6 +1,31 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; -import { AbstractArlasMapGL, ARLAS_ID, ArlasMapService, CROSS_LAYER_PREFIX, FILLSTROKE_LAYER_PREFIX, LngLat, SCROLLABLE_ARLAS_ID } from 'arlas-map'; -import { AnyLayer, AnySourceData, GeoJSONSource, GeoJSONSourceOptions, GeoJSONSourceRaw, LngLatBounds, Point, Popup, RasterLayer, RasterSource, Source, SymbolLayer } from 'mapbox-gl'; +import { + ARLAS_ID, ArlasMapService, FILLSTROKE_LAYER_PREFIX, + LngLat, SCROLLABLE_ARLAS_ID +} from 'arlas-map'; +import { + AnyLayer, AnySourceData, GeoJSONSource, + GeoJSONSourceRaw, LngLatBounds, Point, Popup, RasterLayer, RasterSource, SymbolLayer +} from 'mapbox-gl'; import { ArlasMapboxConfig, ArlasMapboxGL } from './map/ArlasMapboxGL'; import { ArlasDraw } from './draw/ArlasDraw'; import { ArlasAnyLayer } from './map/model/layers'; @@ -11,7 +36,7 @@ import { ExternalEvent } from 'arlas-map'; @Injectable() export class ArlasMapboxService extends ArlasMapService { - constructor() { + public constructor() { super(); } @@ -99,7 +124,7 @@ export class ArlasMapboxService extends ArlasMapService { return { type: 'geojson', data - } + }; }; /** @@ -119,7 +144,7 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. - * Adds the given layer to the map instance, optionnaly before a layer. Otherwise it's added to the top. + * Adds the given layer to the map instance, optionnaly before a layer. Otherwise it's added to the top. * @param map Map * @param layer Layer to add to the map * @param before Identifier of an already added layer. The given Layer (second param) is added under this 'before' layer. @@ -135,10 +160,10 @@ export class ArlasMapboxService extends ArlasMapService { /** * Executes the 'fn' function on 'eventName' triggered from the given 'layer' of the 'map' instance. - * @param eventName - * @param map - * @param layer - * @param fn + * @param eventName Event name. + * @param map Map instance. + * @param layer Layer identifier. + * @param fn Function to execute on event of the given layer. */ public onLayerEvent(eventName: 'click' | 'mousemove' | 'mouseleave', map: ArlasMapboxGL, layer: string, fn: (e) => void): void { map.getMapProvider().on(eventName, layer, fn); @@ -147,9 +172,9 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. * Executes the 'fn' function on 'eventName' triggered from the 'map' instance. - * @param eventName - * @param map - * @param fn + * @param eventName Event. + * @param map Map instance. + * @param fn Function to execute on given event on the map. */ public onMapEvent(eventName: 'load' | 'moveend' | 'zoomend', map: ArlasMapboxGL, fn: (e) => void) { map.getMapProvider().on(eventName, fn); @@ -206,8 +231,8 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. * Removes the source from the map instance - * @param map - * @param source + * @param map Map instance + * @param source Source identifier. */ public removeSource(map: ArlasMapboxGL, source: string) { if (!!source && this.hasSource(map, source)) { @@ -216,7 +241,7 @@ export class ArlasMapboxService extends ArlasMapService { }; /** - * @override Mapbox implementation. + * @override Mapbox implementation. * Creates a popup at lng,lat with the given message. The popup is not yet added to the map. * @param lng Longitude. * @param lat Latitude. @@ -229,7 +254,7 @@ export class ArlasMapboxService extends ArlasMapService { closeOnClick: false }); return popup.setLngLat([lat, lng]) - .setHTML(message) + .setHTML(message); } /** @@ -274,12 +299,12 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. - * Checks if there are any layers respecting the given id patters + * Checks if there are any layers respecting the given id pattern * @param map Map instance. * @param layersIdPattern Identifiers pattern. - * @returns + * @returns true if any layer's id includes the given id pattern. */ - public hasLayersFromPattern(map: ArlasMapboxGL, layersIdPattern: string) { + public hasLayersFromPattern(map: ArlasMapboxGL, layersIdPattern: string): boolean { return map.getMapProvider().getStyle().layers.filter(l => l.id.includes(layersIdPattern)).length > 0; } @@ -301,7 +326,7 @@ export class ArlasMapboxService extends ArlasMapService { * @param maxZoom Maximal zoom to display the raster. * @param minZoom Minimal zoom to display the raster. * @param tileSize Size of the tiles fetched to display the raster (in pixels). Default to 256. - * @returns + * @returns a raster source instance. */ public createRasterSource(url: string, bounds: number[], maxZoom: number, minZoom: number, tileSize: number = 256): RasterSource { @@ -312,7 +337,7 @@ export class ArlasMapboxService extends ArlasMapService { maxzoom: maxZoom, minzoom: minZoom, tileSize: tileSize - } + }; } /** @@ -339,7 +364,7 @@ export class ArlasMapboxService extends ArlasMapService { layout: { visibility: 'visible' } - } + }; this.addLayer(map, iconLayer, beforeId); } @@ -352,7 +377,8 @@ export class ArlasMapboxService extends ArlasMapService { * @param iconSize The icon size * @param data Geojson data which features will be represented with the given icon. */ - public addIconLayer(map: ArlasMapboxGL, layerId: string, iconName: string, iconSize: number, data: GeoJSON.Feature | GeoJSON.FeatureCollection) { + public addIconLayer(map: ArlasMapboxGL, layerId: string, iconName: string, iconSize: number, + data: GeoJSON.Feature | GeoJSON.FeatureCollection) { const iconSource: GeoJSONSourceRaw = this.createGeojsonSource(data); const sourceId = layerId; this.setSource(sourceId, iconSource, map); @@ -365,7 +391,7 @@ export class ArlasMapboxService extends ArlasMapService { 'icon-size': iconSize, 'visibility': 'visible' } - } + }; this.addLayer(map, iconLayer); }; @@ -389,7 +415,7 @@ export class ArlasMapboxService extends ArlasMapService { layout: { 'visibility': 'visible' }, - } + }; style.applyStyle(geojsonLayer); this.addLayer(map, geojsonLayer); } @@ -435,10 +461,10 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. - * Checks if there are any layers respecting the given id patters + * Returns a list of layers whose ids include the the given id pattern. * @param map Map instance. * @param layersIdPattern Identifiers pattern. - * @returns + * @returns a list of layers whose ids include the the given id pattern. */ public getLayersFromPattern(map: ArlasMapboxGL, layersIdPattern: string): ArlasAnyLayer[] { return map.getMapProvider().getStyle().layers.filter(l => l.id.includes(layersIdPattern)) as ArlasAnyLayer[]; @@ -450,9 +476,9 @@ export class ArlasMapboxService extends ArlasMapService { /** * @override Mapbox implementation. - * Moves the given layer to the top in map instance OR optionnaly before a layer. - * @param map Map - * @param layer Layer to add to the map + * Moves the given layer to the top in map instance OR optionnaly before a layer. + * @param map Map instance. + * @param layer Layer to add to the map. * @param before Identifier of an already added layer. The given Layer (second param) is moved under this 'before' layer. */ public moveLayer(map: ArlasMapboxGL, layer: string, before?: string) { diff --git a/projects/arlas-mapbox/src/lib/basemaps/mapbox-basemap.service.ts b/projects/arlas-mapbox/src/lib/basemaps/mapbox-basemap.service.ts index d2d660ce..fca846b1 100644 --- a/projects/arlas-mapbox/src/lib/basemaps/mapbox-basemap.service.ts +++ b/projects/arlas-mapbox/src/lib/basemaps/mapbox-basemap.service.ts @@ -34,7 +34,6 @@ import { ArlasAnyLayer } from '../map/model/layers'; @Injectable() export class MapboxBasemapService extends BasemapService { - public constructor(protected http: HttpClient, protected mapService: ArlasMapboxService, private mapLogicService: MapLogicService @@ -63,7 +62,7 @@ export class MapboxBasemapService extends BasemapService { (selectedBasemap.styleFile as mapboxgl.Style).layers.forEach(l => { this.mapService.removeLayer(map, l.id); }); - this.mapService.removeSource(map, 'arlas_protomaps_source') + this.mapService.removeSource(map, 'arlas_protomaps_source'); } } @@ -118,7 +117,6 @@ export class MapboxBasemapService extends BasemapService { } } - public setBasemap(s: any, newBasemap: BasemapStyle, map: ArlasMapboxGL, mapSources: Array>) { const selectedBasemapLayersSet = new Set(); const layers: Array = this.mapService.getAllLayers(map); diff --git a/projects/arlas-mapbox/src/lib/basemaps/mapgl-basemap.component.ts b/projects/arlas-mapbox/src/lib/basemaps/mapgl-basemap.component.ts index 17eabc1d..45741872 100644 --- a/projects/arlas-mapbox/src/lib/basemaps/mapgl-basemap.component.ts +++ b/projects/arlas-mapbox/src/lib/basemaps/mapgl-basemap.component.ts @@ -22,7 +22,8 @@ import { BasemapComponent, ArlasMapSource } from 'arlas-map'; import { ArlasMapboxGL } from '../map/ArlasMapboxGL'; import { MapboxBasemapService } from './mapbox-basemap.service'; import { MapboxSourceType } from '../map/model/sources'; -import { ArlasMapFunctionalService } from 'arlas-map'; +import { MapLogicService } from '../arlas-map-logic.service'; +import { ArlasMapboxService } from '../arlas-mapbox.service'; @Component({ @@ -34,7 +35,7 @@ export class MapboxBasemapComponent extends BasemapComponent implements OnInit { @Input() public map: ArlasMapboxGL; @Input() public mapSources: Array>; - public constructor(protected basemapService: MapboxBasemapService, protected mapFunctionalService: ArlasMapFunctionalService) { - super(basemapService, mapFunctionalService); + public constructor(protected basemapService: MapboxBasemapService, protected mapLogicService: MapLogicService, protected mapService: ArlasMapboxService) { + super(basemapService, mapLogicService, mapService); } } diff --git a/projects/arlas-mapbox/src/lib/draw/ArlasDraw.ts b/projects/arlas-mapbox/src/lib/draw/ArlasDraw.ts index 53d97647..6530f696 100644 --- a/projects/arlas-mapbox/src/lib/draw/ArlasDraw.ts +++ b/projects/arlas-mapbox/src/lib/draw/ArlasDraw.ts @@ -17,8 +17,8 @@ * under the License. */ -import { AbstractDraw } from "arlas-map"; -import { ArlasMapboxGL } from "../map/ArlasMapboxGL"; +import { AbstractDraw } from 'arlas-map'; +import { ArlasMapboxGL } from '../map/ArlasMapboxGL'; import MapboxDraw from '@mapbox/mapbox-gl-draw'; diff --git a/projects/arlas-mapbox/src/lib/legend/legend.service.ts b/projects/arlas-mapbox/src/lib/legend/legend.service.ts index df53bedc..66fc1f2c 100644 --- a/projects/arlas-mapbox/src/lib/legend/legend.service.ts +++ b/projects/arlas-mapbox/src/lib/legend/legend.service.ts @@ -46,7 +46,7 @@ export const HEATMAP_DENSITY = 'Heatmap-density'; export class MapboxLegendService extends LegendService { public constructor(public translate: TranslateService) { - super() + super(); } public static filterLegend(colorLegendValues: Map, filter: any[], field: string) { @@ -213,7 +213,7 @@ export class MapboxLegendService extends LegendService { }; public static buildRadiusLegend(radiusExpression: string | any, legendData: Map): Legend { - const radiusLegend: Legend = {} + const radiusLegend: Legend = {}; const circleRadiusEvolution: Array = new Array(); if (Array.isArray(radiusExpression)) { if (radiusExpression.length >= 3) { @@ -241,14 +241,10 @@ export class MapboxLegendService extends LegendService { }); } radiusLegend.histogram = circleRadiusEvolution; - // if (!!this.circleRadiusLegend.interpolatedElement) { - // drawCircleSupportLine(this.circleRadiusLegend.interpolatedElement.nativeElement, circleRadiusEvolution, this.colorLegend, - // this.LEGEND_WIDTH, Math.min(this.MAX_CIRLE_RADIUS, maxCircleRadius) * 2); - // } } } } - return radiusLegend + return radiusLegend; }; @@ -328,7 +324,7 @@ export class MapboxLegendService extends LegendService { colorPalette: colors[1], strokeColor: strokeColors[0], strokeColorPalette: strokeColors[1], - }) + }); } diff --git a/projects/arlas-mapbox/src/lib/map/ArlasMapboxGL.ts b/projects/arlas-mapbox/src/lib/map/ArlasMapboxGL.ts index b32c95bf..2bbf462f 100644 --- a/projects/arlas-mapbox/src/lib/map/ArlasMapboxGL.ts +++ b/projects/arlas-mapbox/src/lib/map/ArlasMapboxGL.ts @@ -37,7 +37,7 @@ import mapboxgl, { import MapboxDraw from '@mapbox/mapbox-gl-draw'; import { MapLayers, ControlButton, ControlPosition, DrawControlsOption, - MapExtent, + MapExtent } from 'arlas-map'; import { ArlasAnyLayer } from './model/layers'; import { MapBoxControlButton, MapBoxPitchToggle } from './model/controls'; diff --git a/projects/arlas-mapbox/src/lib/map/model/controls.ts b/projects/arlas-mapbox/src/lib/map/model/controls.ts index 3811f0df..0b5a0f80 100644 --- a/projects/arlas-mapbox/src/lib/map/model/controls.ts +++ b/projects/arlas-mapbox/src/lib/map/model/controls.ts @@ -3,7 +3,7 @@ * license agreements. See the NOTICE.txt file distributed with * this work for additional information regarding copyright * ownership. Gisaïa licenses this file to you under - * the Apache License, Version 2.0 (the 'License'); you may + * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * @@ -11,7 +11,7 @@ * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. @@ -32,4 +32,4 @@ export class MapBoxControlButton extends ControlButton { this.btnClasses = ['mapboxgl-ctrl-icon', 'map__controls__icons', 'map__controls__icons--' + this.name]; this.containerClasses = ['mapboxgl-ctrl', 'mapboxgl-ctrl-group', 'mapboxgl-ctrl-group-' + this.name]; } -} \ No newline at end of file +} diff --git a/projects/arlas-mapbox/src/lib/map/model/sources.ts b/projects/arlas-mapbox/src/lib/map/model/sources.ts index 4d8c3fad..28629a2d 100644 --- a/projects/arlas-mapbox/src/lib/map/model/sources.ts +++ b/projects/arlas-mapbox/src/lib/map/model/sources.ts @@ -17,8 +17,8 @@ * under the License. */ -import mapboxgl from "mapbox-gl"; +import mapboxgl from 'mapbox-gl'; export type MapboxSourceType = mapboxgl.AnySourceData | mapboxgl.VectorSource | mapboxgl.RasterSource | mapboxgl.GeoJSONSource | mapboxgl.GeoJSONSourceRaw | -mapboxgl.CanvasSource | mapboxgl.ImageSource | mapboxgl.VideoSource; \ No newline at end of file +mapboxgl.CanvasSource | mapboxgl.ImageSource | mapboxgl.VideoSource; diff --git a/projects/arlas-mapbox/src/lib/map/model/vector-style.ts b/projects/arlas-mapbox/src/lib/map/model/vector-style.ts index cf968182..2972240b 100644 --- a/projects/arlas-mapbox/src/lib/map/model/vector-style.ts +++ b/projects/arlas-mapbox/src/lib/map/model/vector-style.ts @@ -40,4 +40,4 @@ export class MapboxVectorStyle extends VectorStyle { public fill(layer: FillLayer) { layer.paint = this.style as any; }; -} \ No newline at end of file +} diff --git a/projects/arlas-mapbox/src/public-api.ts b/projects/arlas-mapbox/src/public-api.ts index dc3353b5..f58f1cd9 100644 --- a/projects/arlas-mapbox/src/public-api.ts +++ b/projects/arlas-mapbox/src/public-api.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + /* * Public API Surface of arlas-mapbox */ @@ -6,4 +25,4 @@ export { MapboxLegendService } from './lib/legend/legend.service'; export * from './lib/arlas-mapbox.service'; export * from './lib/arlas-mapbox.module'; export { MapboxBasemapService } from './lib/basemaps/mapbox-basemap.service'; -export { MapLogicService } from './lib/arlas-map-logic.service'; \ No newline at end of file +export { MapLogicService } from './lib/arlas-map-logic.service'; diff --git a/projects/arlas-mapbox/src/test.ts b/projects/arlas-mapbox/src/test.ts index 5775317a..a3498fdb 100644 --- a/projects/arlas-mapbox/src/test.ts +++ b/projects/arlas-mapbox/src/test.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // This file is required by karma.conf.js and loads recursively all the .spec and framework files import 'zone.js'; diff --git a/projects/arlas-maplibre/karma.conf.js b/projects/arlas-maplibre/karma.conf.js index 8c806ea1..38273064 100644 --- a/projects/arlas-maplibre/karma.conf.js +++ b/projects/arlas-maplibre/karma.conf.js @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html diff --git a/projects/arlas-maplibre/src/lib/arlas-map-logic.service.ts b/projects/arlas-maplibre/src/lib/arlas-map-logic.service.ts index 2bc59950..223d1570 100644 --- a/projects/arlas-maplibre/src/lib/arlas-map-logic.service.ts +++ b/projects/arlas-maplibre/src/lib/arlas-map-logic.service.ts @@ -1,5 +1,24 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; -import { ArlasMapFunctionalService } from 'arlas-map'; +import { MapLogicService as AbstractMapLogicService } from 'arlas-map'; import { ArlasMaplibreService } from './arlas-maplibre.service'; import { FeatureCollection } from '@turf/helpers'; import { ArlasMaplibreGL } from './map/ArlasMaplibreGL'; @@ -13,10 +32,10 @@ import { VisualisationSetConfig } from 'arlas-map'; @Injectable({ providedIn: 'root' }) -export class MapLogicService extends ArlasMapFunctionalService{ +export class MapLogicService extends AbstractMapLogicService{ public dataSources: GeoJSONSourceSpecification[] = []; public layersMap: Map; - public constructor(public mapService: ArlasMaplibreService) { + public constructor(public mapService: ArlasMaplibreService) { super(mapService); } @@ -115,4 +134,4 @@ export class MapLogicService extends ArlasMapFunctionalService{ this.setLayersMap(mapLayers as MapLayers, layers); this.reorderLayers(visualisations, map); } -} \ No newline at end of file +} diff --git a/projects/arlas-maplibre/src/lib/arlas-maplibre.module.ts b/projects/arlas-maplibre/src/lib/arlas-maplibre.module.ts index d397e969..91e6c947 100644 --- a/projects/arlas-maplibre/src/lib/arlas-maplibre.module.ts +++ b/projects/arlas-maplibre/src/lib/arlas-maplibre.module.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { NgModule } from '@angular/core'; import { ArlasMaplibreService } from './arlas-maplibre.service'; import { MaplibreBasemapService } from './basemaps/maplibre-basemap.service'; diff --git a/projects/arlas-maplibre/src/lib/arlas-maplibre.service.ts b/projects/arlas-maplibre/src/lib/arlas-maplibre.service.ts index edf77187..2444e819 100644 --- a/projects/arlas-maplibre/src/lib/arlas-maplibre.service.ts +++ b/projects/arlas-maplibre/src/lib/arlas-maplibre.service.ts @@ -1,5 +1,24 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + import { Injectable } from '@angular/core'; -import { AbstractArlasMapGL, ARLAS_ID, ArlasMapService, FILLSTROKE_LAYER_PREFIX, SCROLLABLE_ARLAS_ID } from 'arlas-map'; +import { ARLAS_ID, ArlasMapService, FILLSTROKE_LAYER_PREFIX, SCROLLABLE_ARLAS_ID } from 'arlas-map'; import { AddLayerObject, CanvasSourceSpecification, GeoJSONSource, GeoJSONSourceSpecification, LayerSpecification, LngLatBounds, Point, Popup, @@ -9,7 +28,6 @@ import { import { ArlasMaplibreConfig, ArlasMaplibreGL } from './map/ArlasMaplibreGL'; import { ArlasDraw } from './draw/ArlasDraw'; import { LngLat } from 'arlas-map'; -import { LayerMetadata } from 'arlas-map'; import { FeatureCollection } from '@turf/helpers'; import { from } from 'rxjs'; import { MaplibreVectorStyle } from './map/model/vector-style'; @@ -77,9 +95,9 @@ export class ArlasMaplibreService extends ArlasMapService { } }, error: (err) => { - console.warn(errorMessage) + console.warn(errorMessage); } - }) + }); } @@ -110,7 +128,7 @@ export class ArlasMaplibreService extends ArlasMapService { return { type: 'geojson', data - } + }; }; /** @@ -135,7 +153,7 @@ export class ArlasMaplibreService extends ArlasMapService { /** * @override Maplibre implementation. - * Adds the given layer to the map instance, optionnaly before a layer. Otherwise it's added to the top. + * Adds the given layer to the map instance, optionnaly before a layer. Otherwise it's added to the top. * @param map Map * @param layer Layer to add to the map * @param before Identifier of an already added layer. The given Layer (second param) is added under this 'before' layer. @@ -165,10 +183,9 @@ export class ArlasMaplibreService extends ArlasMapService { } } - /** * @override Maplibre implementation. - * Moves the given layer to the top in map instance OR optionnaly before a layer. + * Moves the given layer to the top in map instance OR optionnaly before a layer. * @param map Map * @param layer Layer to add to the map * @param before Identifier of an already added layer. The given Layer (second param) is moved under this 'before' layer. @@ -228,21 +245,22 @@ export class ArlasMaplibreService extends ArlasMapService { /** * @override Maplibre implementation. * Executes the 'fn' function on 'eventName' triggered from the given 'layer' of the 'map' instance. - * @param eventName - * @param map - * @param layer - * @param fn + * @param eventName + * @param map + * @param layer + * @param fn */ - public onLayerEvent(eventName: 'click' | 'mousemove' | 'mouseleave' | 'mouseenter', map: ArlasMaplibreGL, layer: string, fn: (e) => void): void { + public onLayerEvent(eventName: 'click' | 'mousemove' | 'mouseleave' | 'mouseenter', + map: ArlasMaplibreGL, layer: string, fn: (e) => void): void { map.getMapProvider().on(eventName, layer, fn); } /** * @override Maplibre implementation. * Executes the 'fn' function on 'eventName' triggered from the 'map' instance. - * @param eventName - * @param map - * @param fn + * @param eventName event. + * @param map Map instance. + * @param fn Function to execute on map event. */ public onMapEvent(eventName: 'load' | 'moveend' | 'zoomend', map: ArlasMaplibreGL, fn: (e) => void) { map.getMapProvider().on(eventName, fn); @@ -308,8 +326,8 @@ export class ArlasMaplibreService extends ArlasMapService { /** * @override Maplibre implementation. * Removes the source from the map instance - * @param map - * @param source + * @param map Map Instance. + * @param source Source identifier. */ public removeSource(map: ArlasMaplibreGL, source: string) { if (!!source && this.hasSource(map, source)) { @@ -318,7 +336,7 @@ export class ArlasMaplibreService extends ArlasMapService { }; /** - * @override Maplibre implementation. + * @override Maplibre implementation. * Creates a popup at lng,lat with the given message. The popup is not yet added to the map. * @param lng Longitude. * @param lat Latitude. @@ -331,7 +349,7 @@ export class ArlasMaplibreService extends ArlasMapService { closeOnClick: false }); return popup.setLngLat([lat, lng]) - .setHTML(message) + .setHTML(message); } /** @@ -376,10 +394,10 @@ export class ArlasMaplibreService extends ArlasMapService { /** * @override Maplibre implementation. - * Checks if there are any layers respecting the given id patters + * Checks if there are any layers respecting the given id pattern. * @param map Map instance. * @param layersIdPattern Identifiers pattern. - * @returns + * @returns */ public hasLayersFromPattern(map: ArlasMaplibreGL, layersIdPattern: string) { return map.getMapProvider().getStyle().layers.filter(l => l.id.includes(layersIdPattern)).length > 0; @@ -387,10 +405,10 @@ export class ArlasMaplibreService extends ArlasMapService { /** * @override Maplibre implementation. - * Checks if there are any layers respecting the given id patters + * Return any layer respecting the given id pattern * @param map Map instance. * @param layersIdPattern Identifiers pattern. - * @returns + * @returns a list of layers respecting the given id pattern */ public getLayersFromPattern(map: ArlasMaplibreGL, layersIdPattern: string): AddLayerObject[] { return map.getMapProvider().getStyle().layers.filter(l => l.id.includes(layersIdPattern)); @@ -414,7 +432,7 @@ export class ArlasMaplibreService extends ArlasMapService { * @param maxZoom Maximal zoom to display the raster. * @param minZoom Minimal zoom to display the raster. * @param tileSize Size of the tiles fetched to display the raster (in pixels). Default to 256. - * @returns + * @returns a raster source instance. */ public createRasterSource(url: string, bounds: number[], maxZoom: number, minZoom: number, tileSize: number = 256): RasterSourceSpecification { @@ -424,7 +442,7 @@ export class ArlasMaplibreService extends ArlasMapService { bounds: bounds as [number, number, number, number], maxzoom: maxZoom, tileSize: tileSize - } + }; } /** @@ -450,7 +468,7 @@ export class ArlasMaplibreService extends ArlasMapService { layout: { visibility: 'visible' } - } + }; this.addLayer(map, iconLayer, beforeId); } @@ -474,7 +492,7 @@ export class ArlasMaplibreService extends ArlasMapService { layout: { 'visibility': 'visible' }, - } + }; style.applyStyle(geojsonLayer); this.addLayer(map, geojsonLayer); } @@ -488,7 +506,8 @@ export class ArlasMaplibreService extends ArlasMapService { * @param iconSize The icon size * @param data Geojson data which features will be represented with the given icon. */ - public addIconLayer(map: ArlasMaplibreGL, layerId: string, iconName: string, iconSize: number, data: GeoJSON.Feature | GeoJSON.FeatureCollection) { + public addIconLayer(map: ArlasMaplibreGL, layerId: string, iconName: string, + iconSize: number, data: GeoJSON.Feature | GeoJSON.FeatureCollection) { const iconSource: GeoJSONSourceSpecification = this.createGeojsonSource(data); const sourceId = layerId; this.setSource(sourceId, iconSource, map); @@ -501,7 +520,7 @@ export class ArlasMaplibreService extends ArlasMapService { 'icon-size': iconSize, 'visibility': 'visible' } - } + }; this.addLayer(map, iconLayer); }; diff --git a/projects/arlas-maplibre/src/lib/basemaps/mapgl-basemap.component.ts b/projects/arlas-maplibre/src/lib/basemaps/mapgl-basemap.component.ts index 6ef98857..01b0b294 100644 --- a/projects/arlas-maplibre/src/lib/basemaps/mapgl-basemap.component.ts +++ b/projects/arlas-maplibre/src/lib/basemaps/mapgl-basemap.component.ts @@ -23,8 +23,8 @@ import { ArlasMaplibreGL } from '../map/ArlasMaplibreGL'; import { MaplibreBasemapService } from './maplibre-basemap.service'; import { ArlasMapSource } from 'arlas-map'; import { MaplibreSourceType } from '../map/model/sources'; -import { ArlasMapFunctionalService } from 'arlas-map'; import { ArlasMaplibreService } from '../arlas-maplibre.service'; +import { MapLogicService } from '../arlas-map-logic.service'; @Component({ selector: 'arlas-maplibre-basemap', @@ -35,8 +35,8 @@ export class MaplibreBasemapComponent extends BasemapComponent implements OnInit @Input() public map: ArlasMaplibreGL; @Input() public mapSources: Array>; public constructor(protected basemapService: MaplibreBasemapService, - protected mapFunctionalService: ArlasMapFunctionalService, + protected mapLogicService: MapLogicService, protected mapService: ArlasMaplibreService) { - super(basemapService, mapFunctionalService, mapService); + super(basemapService, mapLogicService, mapService); } } diff --git a/projects/arlas-maplibre/src/lib/basemaps/maplibre-basemap.service.ts b/projects/arlas-maplibre/src/lib/basemaps/maplibre-basemap.service.ts index 38218b1b..3a9a5898 100644 --- a/projects/arlas-maplibre/src/lib/basemaps/maplibre-basemap.service.ts +++ b/projects/arlas-maplibre/src/lib/basemaps/maplibre-basemap.service.ts @@ -61,14 +61,14 @@ export class MaplibreBasemapService extends BasemapService { (selectedBasemap.styleFile as maplibre.StyleSpecification).layers.forEach(l => { this.mapService.removeLayer(map, l.id); }); - this.mapService.removeSource(map, 'arlas_protomaps_source') + this.mapService.removeSource(map, 'arlas_protomaps_source'); } } public declareProtomapProtocol(map: ArlasMaplibreGL) { const protocol = new pmtiles.Protocol(); - maplibre.addProtocol('pmtiles', (requestParameters: RequestParameters, abortController: AbortController) => { - return new Promise((res, rej) => { + maplibre.addProtocol('pmtiles', (requestParameters: RequestParameters, abortController: AbortController) => + new Promise((res, rej) => { protocol.tile(requestParameters, (error?: Error | null, data?: any | null, cacheControl?: string | null, expires?: string | null) => { if (error) { rej(error); @@ -79,8 +79,8 @@ export class MaplibreBasemapService extends BasemapService { data }); }); - }); - }); + }) + ); } public getInitStyle(selected: MapLibreBasemapStyle) { diff --git a/projects/arlas-maplibre/src/lib/legend/legend.service.ts b/projects/arlas-maplibre/src/lib/legend/legend.service.ts index 3ef39607..e2e33087 100644 --- a/projects/arlas-maplibre/src/lib/legend/legend.service.ts +++ b/projects/arlas-maplibre/src/lib/legend/legend.service.ts @@ -29,8 +29,10 @@ import { MAX_LINE_WIDTH } from 'arlas-map'; import { LayerMetadata } from 'arlas-map'; import { FillLegend, HeatmapLegend } from 'arlas-map'; import { LabelLegend, LegendService } from 'arlas-map'; -import { CirclePaintProps, FillPaintProps, HeatmapPaintProps, LayerSpecification, LinePaintProps, SymbolPaintProps, TypedStyleLayer } from 'maplibre-gl'; -import { MatFormFieldDefaultOptions } from '@angular/material/form-field'; +import { + CirclePaintProps, FillPaintProps, HeatmapPaintProps, + LinePaintProps, SymbolPaintProps, TypedStyleLayer +} from 'maplibre-gl'; export const GET = 'get'; export const MATCH = 'match'; @@ -41,323 +43,321 @@ export const NOT_IN = '!'; export const HEATMAP_DENSITY = 'Heatmap-density'; @Injectable({ - providedIn: 'root' + providedIn: 'root' }) export class MaplibreLegendService extends LegendService { - public constructor(public translate: TranslateService) { - super() - } + public constructor(public translate: TranslateService) { + super(); + } - public static filterLegend(colorLegendValues: Map, filter: any[], field: string) { - filter.forEach((f, idx) => { - if (idx !== 0 && idx !== filter.length - 1) { - switch (f[0]) { - case IN: { - if (f[1][1] === field) { - const valuesToKeep: Array = f[2][1]; - colorLegendValues.forEach((val, key) => { - if (!(valuesToKeep.includes(key))) { - colorLegendValues.delete(key); - } - }); - } - break; - } - case NOT_IN: { - if (f[1][0] === IN && f[1][1][1] === field) { - const valuesToExclude: Array = f[1][2][1]; - valuesToExclude.forEach(value => { - colorLegendValues.delete(value); - }); - } - break; - } + public static filterLegend(colorLegendValues: Map, filter: any[], field: string) { + filter.forEach((f, idx) => { + if (idx !== 0 && idx !== filter.length - 1) { + switch (f[0]) { + case IN: { + if (f[1][1] === field) { + const valuesToKeep: Array = f[2][1]; + colorLegendValues.forEach((val, key) => { + if (!(valuesToKeep.includes(key))) { + colorLegendValues.delete(key); } + }); } - }); - } + break; + } + case NOT_IN: { + if (f[1][0] === IN && f[1][1][1] === field) { + const valuesToExclude: Array = f[1][2][1]; + valuesToExclude.forEach(value => { + colorLegendValues.delete(value); + }); + } + break; + } + } + } + }); + } - public static buildColorLegend(colorExpression: string | any, visibleMode: boolean, legendData: Map, - filter?: any, translate?: TranslateService): [Legend, string] { + public static buildColorLegend(colorExpression: string | any, visibleMode: boolean, legendData: Map, + filter?: any, translate?: TranslateService): [Legend, string] { - const colorLegend: Legend = { visible: true }; - let colorPalette = ''; - if (typeof colorExpression === 'string') { - colorLegend.type = PROPERTY_SELECTOR_SOURCE.fix; - colorLegend.fixValue = colorExpression; - } else if (Array.isArray(colorExpression)) { - if (colorExpression.length === 2) { - /** color = ["get", "field"] ==> Generated or Provided */ - const field = colorExpression[1]; - colorLegend.title = field; - if (!Array.isArray(field)) { - if ((field as string).endsWith('_arlas__color')) { - colorLegend.type = PROPERTY_SELECTOR_SOURCE.generated; - } else { - colorLegend.type = PROPERTY_SELECTOR_SOURCE.provided; - } - colorLegend.manualValues = new Map(); - if (legendData && legendData.get(field)) { - const keysToColors = legendData.get(field).keysColorsMap; - const colorList = Array.from(keysToColors.keys()).map(k => [k, keysToColors.get(k)]).flat(); - for (let i = 0; i < colorList.length; i += 2) { - colorLegend.manualValues.set(translate ? translate.instant(colorList[i]) : colorList[i], colorList[i + 1]); - } - if (colorList.length === 0) { - colorLegend.manualValues.set('', '#eee'); - } - } else { - colorLegend.manualValues.set('', '#eee'); - } - - if (!!filter) { - MaplibreLegendService.filterLegend(colorLegend.manualValues, filter, - (field as string).endsWith('_arlas__color') ? (field as string).slice(0, -13) : field); - } - } - } else if (colorExpression.length >= 3) { - if (colorExpression[0] === MATCH) { - /** color = ["match", ["get", "field"], .... ]**/ - colorLegend.type = PROPERTY_SELECTOR_SOURCE.manual; - const colorsLength = colorExpression.length; - let hasDefaultColor = false; - if (colorsLength % 2 !== 0) { - hasDefaultColor = true; - } - const field = colorExpression[1].length === 2 ? colorExpression[1][1] : ''; - colorLegend.title = field; - colorLegend.manualValues = new Map(); - let keysToColors: Map; - if (legendData && legendData.get(field + '_color')) { - // If there is a legendData, use only the colors in the keysToColors - keysToColors = legendData.get(field + '_color').keysColorsMap; - } else { - // If no legendData for this field, use all the colors of colorExpression - keysToColors = new Map(); - for (let i = 2; i < colorExpression.length; i += 2) { - if (hasDefaultColor && i === colorsLength - 3) { - keysToColors.set(colorExpression[i] + '', colorExpression[i + 1]); - keysToColors.set(OTHER, colorExpression[i + 2]); - break; - } else { - keysToColors.set(colorExpression[i] + '', colorExpression[i + 1]); - } - } - } - for (let i = 2; i < colorExpression.length; i += 2) { - if (hasDefaultColor && i === colorsLength - 3) { - if (keysToColors.has(colorExpression[i] + '')) { - colorLegend.manualValues.set(translate ? translate.instant(colorExpression[i] + '') : colorExpression[i], - colorExpression[i + 1]); - } - colorLegend.manualValues.set(translate ? translate.instant(OTHER) : OTHER, colorExpression[i + 2]); - break; - } else { - if (keysToColors.has(colorExpression[i] + '')) { - colorLegend.manualValues.set(translate ? translate.instant(colorExpression[i] + '') : colorExpression[i], - colorExpression[i + 1]); - } - } - } - - if (!!filter) { - MaplibreLegendService.filterLegend(colorLegend.manualValues, filter, field); - } - } else if (colorExpression[0] === INTERPOLATE) { - colorLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; - /** color = ["interplate", ['linear'], ["get", "field"], 0, 1... ]**/ - // todo throw exception if interpolation is not linear - const field = colorExpression[2].length === 2 ? colorExpression[2][1] : HEATMAP_DENSITY; - colorLegend.title = field; - colorLegend.interpolatedValues = []; - const palette = []; - const colors = colorExpression.slice(3); - colors.forEach((c, i) => { - if (i % 2 === 0) { - palette.push({ - proportion: c, - value: colors[i + 1] - }); - } - }); - const minimum = palette[0].proportion; - const maximum = palette.slice(-1)[0].proportion; - palette.forEach(c => colorLegend.interpolatedValues.push(c.value)); - const colorValues = colorExpression.filter((c, i) => i > 2 && i % 2 !== 0); - if (legendData && legendData.get(field) && field !== 'count') { - colorLegend.minValue = legendData.get(field).minValue; - colorLegend.maxValue = legendData.get(field).maxValue; - // For heatmaps, the count is used to fetch data, so we use it for the legend - } else if (field === HEATMAP_DENSITY && legendData && legendData.get('count')) { - colorLegend.minValue = legendData.get('count').minValue; - colorLegend.maxValue = legendData.get('count').maxValue; - } else { - colorLegend.minValue = colorValues[0] + ''; - colorLegend.maxValue = colorValues[colorValues.length - 1] + ''; - } - if (!visibleMode) { - /** apply greyscale because the layer is not visible */ - colorLegend.interpolatedValues = colorLegend.interpolatedValues - .map((c) => tinycolor.default(c.toString()).greyscale().lighten(20).toHexString()); - palette.forEach(p => { - p.value = tinycolor.default(p.value.toString()).greyscale().lighten(20).toHexString(); - }); - } - colorPalette = palette.map(c => c.value + ' ' + (100 * (c.proportion - minimum) / (maximum - minimum)) + '%').join(','); - } - } + const colorLegend: Legend = { visible: true }; + let colorPalette = ''; + if (typeof colorExpression === 'string') { + colorLegend.type = PROPERTY_SELECTOR_SOURCE.fix; + colorLegend.fixValue = colorExpression; + } else if (Array.isArray(colorExpression)) { + if (colorExpression.length === 2) { + /** color = ["get", "field"] ==> Generated or Provided */ + const field = colorExpression[1]; + colorLegend.title = field; + if (!Array.isArray(field)) { + if ((field as string).endsWith('_arlas__color')) { + colorLegend.type = PROPERTY_SELECTOR_SOURCE.generated; + } else { + colorLegend.type = PROPERTY_SELECTOR_SOURCE.provided; + } + colorLegend.manualValues = new Map(); + if (legendData && legendData.get(field)) { + const keysToColors = legendData.get(field).keysColorsMap; + const colorList = Array.from(keysToColors.keys()).map(k => [k, keysToColors.get(k)]).flat(); + for (let i = 0; i < colorList.length; i += 2) { + colorLegend.manualValues.set(translate ? translate.instant(colorList[i]) : colorList[i], colorList[i + 1]); } - - colorLegend.visible = visibleMode; - return [colorLegend, colorPalette]; - }; - - public static buildRadiusLegend(radiusExpression: string | any, legendData: Map): Legend { - const radiusLegend: Legend = {} - const circleRadiusEvolution: Array = new Array(); - if (Array.isArray(radiusExpression)) { - if (radiusExpression.length >= 3) { - if (radiusExpression[0] === INTERPOLATE) { - const field = radiusExpression[2][1]; - radiusExpression.filter((w, i) => i >= 3).forEach((w, i) => { - if (i % 2 === 0) { - circleRadiusEvolution.push({ key: w, value: radiusExpression[i + 1 + 3] }); - } - }); - radiusLegend.title = field; - if (legendData && legendData.get(field)) { - radiusLegend.minValue = legendData.get(field).minValue; - radiusLegend.maxValue = legendData.get(field).maxValue; - } else { - radiusLegend.minValue = circleRadiusEvolution[0].key + ''; - radiusLegend.maxValue = circleRadiusEvolution[circleRadiusEvolution.length - 1].key + ''; - } - radiusLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; - const maxCircleRadius = getMax(circleRadiusEvolution); - if (maxCircleRadius > MAX_CIRLE_RADIUS) { - circleRadiusEvolution.map(lw => { - lw.value = lw.value * MAX_CIRLE_RADIUS / maxCircleRadius; - return lw; - }); - } - radiusLegend.histogram = circleRadiusEvolution; - // if (!!this.circleRadiusLegend.interpolatedElement) { - // drawCircleSupportLine(this.circleRadiusLegend.interpolatedElement.nativeElement, circleRadiusEvolution, this.colorLegend, - // this.LEGEND_WIDTH, Math.min(this.MAX_CIRLE_RADIUS, maxCircleRadius) * 2); - // } - } + if (colorList.length === 0) { + colorLegend.manualValues.set('', '#eee'); } - } - return radiusLegend + } else { + colorLegend.manualValues.set('', '#eee'); + } - }; + if (!!filter) { + MaplibreLegendService.filterLegend(colorLegend.manualValues, filter, + (field as string).endsWith('_arlas__color') ? (field as string).slice(0, -13) : field); + } + } + } else if (colorExpression.length >= 3) { + if (colorExpression[0] === MATCH) { + /** color = ["match", ["get", "field"], .... ]**/ + colorLegend.type = PROPERTY_SELECTOR_SOURCE.manual; + const colorsLength = colorExpression.length; + let hasDefaultColor = false; + if (colorsLength % 2 !== 0) { + hasDefaultColor = true; + } + const field = colorExpression[1].length === 2 ? colorExpression[1][1] : ''; + colorLegend.title = field; + colorLegend.manualValues = new Map(); + let keysToColors: Map; + if (legendData && legendData.get(field + '_color')) { + // If there is a legendData, use only the colors in the keysToColors + keysToColors = legendData.get(field + '_color').keysColorsMap; + } else { + // If no legendData for this field, use all the colors of colorExpression + keysToColors = new Map(); + for (let i = 2; i < colorExpression.length; i += 2) { + if (hasDefaultColor && i === colorsLength - 3) { + keysToColors.set(colorExpression[i] + '', colorExpression[i + 1]); + keysToColors.set(OTHER, colorExpression[i + 2]); + break; + } else { + keysToColors.set(colorExpression[i] + '', colorExpression[i + 1]); + } + } + } + for (let i = 2; i < colorExpression.length; i += 2) { + if (hasDefaultColor && i === colorsLength - 3) { + if (keysToColors.has(colorExpression[i] + '')) { + colorLegend.manualValues.set(translate ? translate.instant(colorExpression[i] + '') : colorExpression[i], + colorExpression[i + 1]); + } + colorLegend.manualValues.set(translate ? translate.instant(OTHER) : OTHER, colorExpression[i + 2]); + break; + } else { + if (keysToColors.has(colorExpression[i] + '')) { + colorLegend.manualValues.set(translate ? translate.instant(colorExpression[i] + '') : colorExpression[i], + colorExpression[i + 1]); + } + } + } - private static buildWidthLegend(lineWidth: number | any, - legendData: Map): Legend { - /** if the line width is fix then it is not added to the legend*/ - const widthLegend: Legend = {}; - if (Array.isArray(lineWidth)) { - if (lineWidth.length >= 3) { - if (lineWidth[0] === INTERPOLATE) { - const field = lineWidth[2][1]; - widthLegend.title = field; - if (legendData && legendData.get(field)) { - widthLegend.minValue = legendData.get(field).minValue; - widthLegend.maxValue = legendData.get(field).maxValue; - } - widthLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; - const lineWidthEvolution: Array = new Array(); - lineWidth.filter((w, i) => i >= 3).forEach((w, i) => { - if (i % 2 === 0) { - lineWidthEvolution.push({ key: w, value: lineWidth[i + 1 + 3] }); - } - }); - const maxLineWidth = getMax(lineWidthEvolution); - if (maxLineWidth > MAX_LINE_WIDTH) { - lineWidthEvolution.map(lw => { - lw.value = lw.value * MAX_LINE_WIDTH / maxLineWidth; - return lw; - }); - } - widthLegend.histogram = lineWidthEvolution; - } + if (!!filter) { + MaplibreLegendService.filterLegend(colorLegend.manualValues, filter, field); + } + } else if (colorExpression[0] === INTERPOLATE) { + colorLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; + /** color = ["interplate", ['linear'], ["get", "field"], 0, 1... ]**/ + // todo throw exception if interpolation is not linear + const field = colorExpression[2].length === 2 ? colorExpression[2][1] : HEATMAP_DENSITY; + colorLegend.title = field; + colorLegend.interpolatedValues = []; + const palette = []; + const colors = colorExpression.slice(3); + colors.forEach((c, i) => { + if (i % 2 === 0) { + palette.push({ + proportion: c, + value: colors[i + 1] + }); } + }); + const minimum = palette[0].proportion; + const maximum = palette.slice(-1)[0].proportion; + palette.forEach(c => colorLegend.interpolatedValues.push(c.value)); + const colorValues = colorExpression.filter((c, i) => i > 2 && i % 2 !== 0); + if (legendData && legendData.get(field) && field !== 'count') { + colorLegend.minValue = legendData.get(field).minValue; + colorLegend.maxValue = legendData.get(field).maxValue; + // For heatmaps, the count is used to fetch data, so we use it for the legend + } else if (field === HEATMAP_DENSITY && legendData && legendData.get('count')) { + colorLegend.minValue = legendData.get('count').minValue; + colorLegend.maxValue = legendData.get('count').maxValue; + } else { + colorLegend.minValue = colorValues[0] + ''; + colorLegend.maxValue = colorValues[colorValues.length - 1] + ''; + } + if (!visibleMode) { + /** apply greyscale because the layer is not visible */ + colorLegend.interpolatedValues = colorLegend.interpolatedValues + .map((c) => tinycolor.default(c.toString()).greyscale().lighten(20).toHexString()); + palette.forEach(p => { + p.value = tinycolor.default(p.value.toString()).greyscale().lighten(20).toHexString(); + }); + } + colorPalette = palette.map(c => c.value + ' ' + (100 * (c.proportion - minimum) / (maximum - minimum)) + '%').join(','); } - return widthLegend; - } - - public getCircleLegend(paint: CirclePaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): CircleLegend { - const p: CirclePaintProps = paint; - const colors = MaplibreLegendService.buildColorLegend(p['circle-color'], visibileMode, legendData, layer.filter, this.translate); - const strokeColors = MaplibreLegendService.buildColorLegend(p['circle-stroke-color'], visibileMode, legendData, - layer.filter, this.translate); - const radius = MaplibreLegendService.buildRadiusLegend(p['circle-radius'], legendData); - return ({ - color: colors[0], - colorPalette: colors[1], - strokeColor: strokeColors[0], - strokeColorPalette: strokeColors[1], - radius: radius - }); + } } + colorLegend.visible = visibleMode; + return [colorLegend, colorPalette]; + }; - public getLineLegend(paint: LinePaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): LineLegend { - const p: LinePaintProps = paint; - const colors = MaplibreLegendService.buildColorLegend(p['line-color'], visibileMode, legendData, layer.filter, this.translate); - const width = MaplibreLegendService.buildWidthLegend(p['line-width'], legendData); - return ({ - color: colors[0], - colorPalette: colors[1], - width: width, - //todo check dashes - dashes: p['line-dasharray'] as any - }); + public static buildRadiusLegend(radiusExpression: string | any, legendData: Map): Legend { + const radiusLegend: Legend = {}; + const circleRadiusEvolution: Array = new Array(); + if (Array.isArray(radiusExpression)) { + if (radiusExpression.length >= 3) { + if (radiusExpression[0] === INTERPOLATE) { + const field = radiusExpression[2][1]; + radiusExpression.filter((w, i) => i >= 3).forEach((w, i) => { + if (i % 2 === 0) { + circleRadiusEvolution.push({ key: w, value: radiusExpression[i + 1 + 3] }); + } + }); + radiusLegend.title = field; + if (legendData && legendData.get(field)) { + radiusLegend.minValue = legendData.get(field).minValue; + radiusLegend.maxValue = legendData.get(field).maxValue; + } else { + radiusLegend.minValue = circleRadiusEvolution[0].key + ''; + radiusLegend.maxValue = circleRadiusEvolution[circleRadiusEvolution.length - 1].key + ''; + } + radiusLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; + const maxCircleRadius = getMax(circleRadiusEvolution); + if (maxCircleRadius > MAX_CIRLE_RADIUS) { + circleRadiusEvolution.map(lw => { + lw.value = lw.value * MAX_CIRLE_RADIUS / maxCircleRadius; + return lw; + }); + } + radiusLegend.histogram = circleRadiusEvolution; + } + } } + return radiusLegend; - public getFillLegend(paint: FillPaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): FillLegend { - const p: FillPaintProps = paint; - const colors = MaplibreLegendService.buildColorLegend(p['fill-color'], visibileMode, legendData, layer.filter, this.translate); - const metadata = layer.metadata as LayerMetadata; - let strokeColors: [Legend, string] = [undefined, '']; - if (!!layer.metadata && !!metadata.stroke) { - strokeColors = MaplibreLegendService.buildColorLegend(metadata.stroke.color, visibileMode, legendData, - layer.filter, this.translate); + }; + private static buildWidthLegend(lineWidth: number | any, + legendData: Map): Legend { + /** if the line width is fix then it is not added to the legend*/ + const widthLegend: Legend = {}; + if (Array.isArray(lineWidth)) { + if (lineWidth.length >= 3) { + if (lineWidth[0] === INTERPOLATE) { + const field = lineWidth[2][1]; + widthLegend.title = field; + if (legendData && legendData.get(field)) { + widthLegend.minValue = legendData.get(field).minValue; + widthLegend.maxValue = legendData.get(field).maxValue; + } + widthLegend.type = PROPERTY_SELECTOR_SOURCE.interpolated; + const lineWidthEvolution: Array = new Array(); + lineWidth.filter((w, i) => i >= 3).forEach((w, i) => { + if (i % 2 === 0) { + lineWidthEvolution.push({ key: w, value: lineWidth[i + 1 + 3] }); + } + }); + const maxLineWidth = getMax(lineWidthEvolution); + if (maxLineWidth > MAX_LINE_WIDTH) { + lineWidthEvolution.map(lw => { + lw.value = lw.value * MAX_LINE_WIDTH / maxLineWidth; + return lw; + }); + } + widthLegend.histogram = lineWidthEvolution; } - return ({ - color: colors[0], - colorPalette: colors[1], - strokeColor: strokeColors[0], - strokeColorPalette: strokeColors[1], - }) + } } + return widthLegend; + } + public getCircleLegend(paint: CirclePaintProps, visibileMode: boolean, legendData: + Map, layer: TypedStyleLayer): CircleLegend { + const p: CirclePaintProps = paint; + const colors = MaplibreLegendService.buildColorLegend(p['circle-color'], visibileMode, + legendData, layer.filter, this.translate); + const strokeColors = MaplibreLegendService.buildColorLegend(p['circle-stroke-color'], visibileMode, legendData, + layer.filter, this.translate); + const radius = MaplibreLegendService.buildRadiusLegend(p['circle-radius'], legendData); + return ({ + color: colors[0], + colorPalette: colors[1], + strokeColor: strokeColors[0], + strokeColorPalette: strokeColors[1], + radius: radius + }); + } - public getHeatmapLegend(paint: HeatmapPaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): HeatmapLegend { - const p: HeatmapPaintProps = paint; - const colors = MaplibreLegendService.buildColorLegend(p['heatmap-color'], visibileMode, legendData, layer.filter, this.translate); - const radius = MaplibreLegendService.buildRadiusLegend(p['heatmap-radius'], legendData); - if (layer.source.toString().startsWith('feature-metric')) { - colors[0].visible = false; - } - return ({ - color: colors[0], - colorPalette: colors[1], - radius: radius - }); + public getLineLegend(paint: LinePaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): LineLegend { + const p: LinePaintProps = paint; + const colors = MaplibreLegendService.buildColorLegend(p['line-color'], visibileMode, legendData, layer.filter, this.translate); + const width = MaplibreLegendService.buildWidthLegend(p['line-width'], legendData); + return ({ + color: colors[0], + colorPalette: colors[1], + width: width, + // todo check dashes + dashes: p['line-dasharray'] as any + }); + } + + public getFillLegend(paint: FillPaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): FillLegend { + const p: FillPaintProps = paint; + const colors = MaplibreLegendService.buildColorLegend(p['fill-color'], visibileMode, legendData, layer.filter, this.translate); + const metadata = layer.metadata as LayerMetadata; + let strokeColors: [Legend, string] = [undefined, '']; + if (!!layer.metadata && !!metadata.stroke) { + strokeColors = MaplibreLegendService.buildColorLegend(metadata.stroke.color, visibileMode, legendData, + layer.filter, this.translate); } + return ({ + color: colors[0], + colorPalette: colors[1], + strokeColor: strokeColors[0], + strokeColorPalette: strokeColors[1], + }); + } - public getLabelLegend(paint: SymbolPaintProps, visibileMode: boolean, legendData: Map, layer: TypedStyleLayer): LabelLegend { - const p: SymbolPaintProps = paint; - const colors = MaplibreLegendService.buildColorLegend(p['text-color'], visibileMode, legendData, layer.filter, this.translate); - const size = MaplibreLegendService.buildWidthLegend(p['text-size'], legendData); - return ({ - color: colors[0], - colorPalette: colors[1], - size: size - }); + public getHeatmapLegend(paint: HeatmapPaintProps, visibileMode: boolean, legendData: Map, + layer: TypedStyleLayer): HeatmapLegend { + const p: HeatmapPaintProps = paint; + const colors = MaplibreLegendService.buildColorLegend(p['heatmap-color'], visibileMode, legendData, layer.filter, this.translate); + const radius = MaplibreLegendService.buildRadiusLegend(p['heatmap-radius'], legendData); + if (layer.source.toString().startsWith('feature-metric')) { + colors[0].visible = false; } + return ({ + color: colors[0], + colorPalette: colors[1], + radius: radius + }); + } + + + public getLabelLegend(paint: SymbolPaintProps, visibileMode: boolean, legendData: Map, + layer: TypedStyleLayer): LabelLegend { + const p: SymbolPaintProps = paint; + const colors = MaplibreLegendService.buildColorLegend(p['text-color'], visibileMode, legendData, layer.filter, this.translate); + const size = MaplibreLegendService.buildWidthLegend(p['text-size'], legendData); + return ({ + color: colors[0], + colorPalette: colors[1], + size: size + }); + } } diff --git a/projects/arlas-maplibre/src/lib/map/model/sources.ts b/projects/arlas-maplibre/src/lib/map/model/sources.ts index 01e2e6e3..8bdfdd61 100644 --- a/projects/arlas-maplibre/src/lib/map/model/sources.ts +++ b/projects/arlas-maplibre/src/lib/map/model/sources.ts @@ -1,2 +1,21 @@ + +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ export type MaplibreSourceType = maplibregl.VectorSourceSpecification | maplibregl.RasterSourceSpecification | -maplibregl.GeoJSONSourceSpecification; \ No newline at end of file +maplibregl.GeoJSONSourceSpecification; diff --git a/projects/arlas-maplibre/src/lib/map/model/vector-style.ts b/projects/arlas-maplibre/src/lib/map/model/vector-style.ts index b2cfa999..4e6ae05e 100644 --- a/projects/arlas-maplibre/src/lib/map/model/vector-style.ts +++ b/projects/arlas-maplibre/src/lib/map/model/vector-style.ts @@ -39,4 +39,4 @@ export class MaplibreVectorStyle extends VectorStyle { public fill(layer: FillLayerSpecification) { layer.paint = this.style as any; }; -} \ No newline at end of file +} diff --git a/projects/arlas-maplibre/src/public-api.ts b/projects/arlas-maplibre/src/public-api.ts index 9f93221d..e01f51ec 100644 --- a/projects/arlas-maplibre/src/public-api.ts +++ b/projects/arlas-maplibre/src/public-api.ts @@ -1,3 +1,21 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ /* * Public API Surface of arlas-maplibre */ @@ -6,5 +24,5 @@ export * from './lib/arlas-maplibre.service'; export * from './lib/arlas-maplibre.module'; export { MaplibreLegendService } from './lib/legend/legend.service'; export { MaplibreBasemapService } from './lib/basemaps/maplibre-basemap.service'; -export { MaplibreVectorStyle } from './lib/map/model/vector-style' -export { MapLogicService } from './lib/arlas-map-logic.service'; \ No newline at end of file +export { MaplibreVectorStyle } from './lib/map/model/vector-style'; +export { MapLogicService } from './lib/arlas-map-logic.service'; diff --git a/projects/arlas-maplibre/src/test.ts b/projects/arlas-maplibre/src/test.ts index 5775317a..a3498fdb 100644 --- a/projects/arlas-maplibre/src/test.ts +++ b/projects/arlas-maplibre/src/test.ts @@ -1,3 +1,22 @@ +/* + * Licensed to Gisaïa under one or more contributor + * license agreements. See the NOTICE.txt file distributed with + * this work for additional information regarding copyright + * ownership. Gisaïa licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + // This file is required by karma.conf.js and loads recursively all the .spec and framework files import 'zone.js';