Skip to content

Commit

Permalink
Externalise the map interface methods to an angular service
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedHamouGisaia committed Dec 12, 2024
1 parent 34ce9fe commit 64644f2
Show file tree
Hide file tree
Showing 23 changed files with 786 additions and 1,335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import { CommonModule } from '@angular/common';
import { GetValuePipe } from './get-value.pipe';
import { NgModule } from '@angular/core';

@NgModule({
imports: [
CommonModule
],
declarations: [
GetValuePipe
Expand Down
91 changes: 85 additions & 6 deletions projects/arlas-map/src/lib/arlas-map-logic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export abstract class ArlasMapFunctionalService {
public updateLabelSources(labelSourceId: string, data: FeatureCollection<GeoJSON.Geometry>, map: AbstractArlasMapGL) {
if (labelSourceId) {
const source = this.mapService.getSource(labelSourceId, map);
this.mapService.setDataToGeojsonSource(labelSourceId, source);
this.mapService.setDataToGeojsonSource(source, data);
}
}

Expand All @@ -76,7 +76,6 @@ export abstract class ArlasMapFunctionalService {
*/
public initVisualisationSet(visualisationSetsConfig: VisualisationSetConfig[]) {
if (visualisationSetsConfig) {
console.log('_initVisualisationSet');
visualisationSetsConfig.forEach(visu => {
this.visualisationsSets.visualisations.set(visu.name, new Set(visu.layers));
this.visualisationsSets.status.set(visu.name, visu.enabled);
Expand All @@ -86,7 +85,6 @@ export abstract class ArlasMapFunctionalService {

public initMapLayers(mapLayers: MapLayers<any>, map: AbstractArlasMapGL) {
if (mapLayers) {
console.log('init maplayers');
this.setLayersMap(mapLayers as MapLayers<any>);
}
}
Expand Down Expand Up @@ -117,7 +115,9 @@ export abstract class ArlasMapFunctionalService {
if (!!mapLayers.externalEventLayers) {
mapLayers.layers
.filter(layer => mapLayers.externalEventLayers.map(e => e.id).indexOf(layer.id) >= 0)
.forEach(l => this.mapService.addLayer(map, l.id));
.forEach(l => {
this.mapService.addLayer(map, l);
});
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export abstract class ArlasMapFunctionalService {
const isCollectionCompatible = (!collection || (!!collection && (fullLayer.source as string).includes(collection)));
if (isCollectionCompatible) {
const originalLayerId = layer.id.replace('arlas-' + visibilityEvent.toString() + '-', '');
const originalLayer = this.mapService.getLayer(map, originalLayerId);
const originalLayer = this.mapService.getAllLayers(map).find(l => l.id === originalLayerId);
if (!!originalLayer) {
originalLayerIsVisible = this.mapService.isLayerVisible(originalLayer);
}
Expand All @@ -180,7 +180,6 @@ export abstract class ArlasMapFunctionalService {
}
}


public selectFeatures(mapLayers: MapLayers<any>, map: AbstractArlasMapGL, elementToSelect: Array<ElementIdentifier>) {
if (elementToSelect) {
const ids = elementToSelect.length > 0 ?
Expand Down Expand Up @@ -214,4 +213,84 @@ export abstract class ArlasMapFunctionalService {
}


public updateLayoutVisibility(visualisationName: string, visualisationSetsConfig: VisualisationSetConfig[], map: AbstractArlasMapGL) {
const visuStatus = !this.visualisationsSets.status.get(visualisationName);
visualisationSetsConfig.find(v => v.name === visualisationName).enabled = visuStatus;
if (!visuStatus) {
const layersSet = new Set(this.visualisationsSets.visualisations.get(visualisationName));
this.visualisationsSets.visualisations.forEach((ls, v) => {
if (v !== visualisationName) {
ls.forEach(ll => {
if (layersSet && layersSet.has(ll)) {
layersSet.delete(ll);
}
});
}
});
layersSet.forEach(ll => {
this.mapService.setLayerVisibility(ll, false, map);
});
}
this.visualisationsSets.status.set(visualisationName, visuStatus);
const layers = new Set<string>();
this.visualisationsSets.visualisations.forEach((ls, v) => {
if (this.visualisationsSets.status.get(v)) {
ls.forEach(l => {
layers.add(l);
this.mapService.setLayerVisibility(l, true, map);
});
}
});
return layers;
}

public updateVisibility(visibilityStatus: Map<string, boolean>, visualisationSetsConfig: VisualisationSetConfig[], map: AbstractArlasMapGL) {
visibilityStatus.forEach((visibilityStatus, l) => {
let layerInVisualisations = false;
if (!visibilityStatus) {
visualisationSetsConfig.forEach(v => {
const ls = new Set(v.layers);
if (!layerInVisualisations) {
layerInVisualisations = ls.has(l);
}
});
if (layerInVisualisations) {
this.mapService.setLayerVisibility(l, false, map);
}
} else {
let oneVisualisationEnabled = false;
visualisationSetsConfig.forEach(v => {
const ls = new Set(v.layers);
if (!layerInVisualisations) {
layerInVisualisations = ls.has(l);
}
if (ls.has(l) && v.enabled) {
oneVisualisationEnabled = true;
this.mapService.setLayerVisibility(l, true, map);
}
});
if (!oneVisualisationEnabled && layerInVisualisations) {
this.mapService.setLayerVisibility(l, false, map);
}
}
});
}


public findVisualisationSetLayer(visuName: string, visualisationSetsConfig: VisualisationSetConfig[]) {
return visualisationSetsConfig.find(v => v.name === visuName).layers;
}
public setVisualisationSetLayers(visuName: string, layers: string[], visualisationSetsConfig: VisualisationSetConfig[]) {
const f = visualisationSetsConfig.find(v => v.name === visuName);
if (f) {
f.layers = layers;
}
}

public abstract updateMapStyle(map: AbstractArlasMapGL, l: any, ids: Array<string | number>, sourceName: string): void;

public abstract getVisibleIdsFilter(map: AbstractArlasMapGL, layer: any, ids: Array<string | number>);



}

Check failure on line 296 in projects/arlas-map/src/lib/arlas-map-logic.service.ts

View workflow job for this annotation

GitHub Actions / Lint, Build, Test & Documentation

Newline required at end of file but not found
4 changes: 2 additions & 2 deletions projects/arlas-map/src/lib/arlas-map.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<div cdkDragHandle class="map__visu-layer-drag">
<mat-icon>drag_indicator</mat-icon>
</div>
<arlas-legend [collection]="l | getCollection: map?.layersMap " [enabled]="visu.enabled"
[layer]="l | getValue: map?.layersMap " [zoom]="map?.zoom"
<arlas-legend [collection]="l | getCollection: mapFunctionalService.layersMap " [enabled]="visu.enabled"
[layer]="l | getValue: mapFunctionalService.layersMap " [zoom]="map?.zoom"
(visibilityStatus)="emitLegendVisibility(visu.name, l, $event)" [legendUpdater]="legendUpdater"
[visibilityUpdater]="visibilityUpdater"
(downloadSourceEmitter)="downloadLayerSource($event)"></arlas-legend>
Expand Down
Loading

0 comments on commit 64644f2

Please sign in to comment.