From 2626ffe8bb803db68dffbf02d6cac4801af3442c Mon Sep 17 00:00:00 2001 From: zdenevuk <zdenko.vuk@ijs.si> Date: Tue, 29 Nov 2022 14:44:53 +0100 Subject: [PATCH] This is a combination of 2 commits. added getMapInfo, but currently getting a cors error corrected url --- .../results-map/results-map.component.ts | 29 ++++++++++--------- .../utils/services/network.service.ts | 10 +++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/app/pages/simulation-wizard/results-map/results-map.component.ts b/src/app/pages/simulation-wizard/results-map/results-map.component.ts index bb280c98..e9e99148 100644 --- a/src/app/pages/simulation-wizard/results-map/results-map.component.ts +++ b/src/app/pages/simulation-wizard/results-map/results-map.component.ts @@ -5,6 +5,7 @@ import * as MapColors from "./map-colors-local"; import { legendInverted, ratiosBetweenGrades } from "./results-map-settings"; import { NbToastrService, NbDialogService } from "@nebular/theme"; import { Simulation } from "../utils/data/simulation"; +import { NetworkService } from "../utils/services/network.service"; @Component({ selector: "ngx-results-map", @@ -39,13 +40,18 @@ export class ResultsMapComponent implements OnChanges { constructor( private simulationService: SimulationService, private toastrService: NbToastrService, - private dialogService: NbDialogService + private dialogService: NbDialogService, + private networkService: NetworkService ) {} onMapReady(map: L.Map) { this.map = map; this.grayscaleChange(); setTimeout(() => { this.map.invalidateSize(); + this.networkService.getMapInfo().subscribe((res) => { + console.log("🚀☢ ~ res", res); + this.setMapPositionAndZoom(res) + }); }, 50); // setTimeout(() => { // console.log( @@ -72,7 +78,7 @@ export class ResultsMapComponent implements OnChanges { onLoadClick(selectedKpi: string) { this.selectedGeojson = selectedKpi; this.resetLayersAndButton(); - this.setMapZoomAndLoadGeojsons(); + this.setLoadGeojsons(); if (this.radioButtonLayersControl) this.radioButtonLayersControl.remove(this.map); @@ -613,10 +619,9 @@ export class ResultsMapComponent implements OnChanges { el.style.filter = "grayscale(" + (100 - this.grayscale) + "%)"; } - setMapZoomAndLoadGeojsons() { + setLoadGeojsons() { if (this.selectedSimulation != undefined) { if (this.selectedSimulation["city"]["cityId"] == "amsterdam") { - this.map.setView(new L.LatLng(52.4, 4.9), 9); this.loadGeojsons = [ { response: undefined, @@ -640,7 +645,6 @@ export class ResultsMapComponent implements OnChanges { }, ]; } else if (this.selectedSimulation["city"]["cityId"] == "bilbao") { - this.map.setView(new L.LatLng(43.3, -2.9), 9); console.log( "%c buttons set might not be the right ones for bilbao", "background: indianred; font-weight: bold; color: black; font-family: serif; padding: 0 10px;" @@ -668,10 +672,6 @@ export class ResultsMapComponent implements OnChanges { }, ]; } else if (this.selectedSimulation["city"]["cityId"] == "helsinki") { - this.map.setView( - new L.LatLng(60.16005488265436, 24.920971999284017), - 13 - ); this.loadGeojsons = [ { response: undefined, @@ -695,10 +695,6 @@ export class ResultsMapComponent implements OnChanges { }, ]; } else if (this.selectedSimulation["city"]["cityId"] == "messina") { - this.map.setView( - new L.LatLng(38.10119097299323, 15.491646372349038), - 9 - ); console.log( "%c buttons set might not be the right ones for messina", "background: magenta; font-weight: bold; color: black; font-family: serif; padding: 0 10px;" @@ -765,6 +761,11 @@ export class ResultsMapComponent implements OnChanges { entry[1]["response"] = undefined; }); - this.setMapZoomAndLoadGeojsons(); + this.setLoadGeojsons(); + } + + setMapPositionAndZoom(res: Object) { + console.log("🚀☢ ~ res", res) + this.map.setView(new L.LatLng(0, 0), 7); } } diff --git a/src/app/pages/simulation-wizard/utils/services/network.service.ts b/src/app/pages/simulation-wizard/utils/services/network.service.ts index 9d5a0db7..649eab47 100644 --- a/src/app/pages/simulation-wizard/utils/services/network.service.ts +++ b/src/app/pages/simulation-wizard/utils/services/network.service.ts @@ -81,4 +81,14 @@ export class NetworkService { }) ); } + + getMapInfo(): Observable<any> { + return this.httpClient.get(`${this.dssUrl}/map-info`).pipe( + map((res) => { + return res; + }), + tapDebugApi, + catchError(this.handleError) + ); + } } -- GitLab