From 4ab20b05eb35f2f03c505e058b50d6aaabbe37a4 Mon Sep 17 00:00:00 2001
From: "ext.sopra.ncastejon" <castejon.nicolas@gmail.com>
Date: Mon, 17 Feb 2020 09:54:48 +0100
Subject: [PATCH] Use an url for the map style, instead of local files.

---
 src/app/core/services/app-config.service.ts | 1 +
 src/app/map/components/map.component.ts     | 4 ++--
 src/app/map/services/map.service.ts         | 2 +-
 src/app/map/settings.ts                     | 6 ++++--
 src/assets/config/config.json               | 3 ++-
 5 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/app/core/services/app-config.service.ts b/src/app/core/services/app-config.service.ts
index d733ce6a..c869cc21 100644
--- a/src/app/core/services/app-config.service.ts
+++ b/src/app/core/services/app-config.service.ts
@@ -17,6 +17,7 @@ export class AppConfig {
     wms: string;
     mvt: string;
     seo: string;
+    openMapTiles: string;
   };
   theFunctionalitiesInterruptor: {
     credits: boolean;
diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts
index a4ebce86..42f4e1a4 100644
--- a/src/app/map/components/map.component.ts
+++ b/src/app/map/components/map.component.ts
@@ -59,7 +59,7 @@ export class MapComponent implements OnInit, OnDestroy {
     }
 
     this.initilizeLanguage();
-    // this.initAvailableLayers();
+
     this.constructMap();
   }
 
@@ -197,7 +197,7 @@ export class MapComponent implements OnInit, OnDestroy {
         mapboxOptions['bounds'] = bounds;
       }
 
-      mapboxOptions['style'] = `assets/mapbox-gl-styles/${this.selectedBaseLayer.fileName}`;
+      mapboxOptions['style'] = this.selectedBaseLayer.urlJson;
 
       // Create the map with the associated style Mapbox file
       // tslint:disable-next-line: max-line-length
diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts
index 5941abd2..eddc0f07 100644
--- a/src/app/map/services/map.service.ts
+++ b/src/app/map/services/map.service.ts
@@ -433,7 +433,7 @@ fpc_fond_plan_communaut.fpctoit&map.imagetype=mvt&tilemode=gmap&tile={x}+{y}+{z}
     }
     this._map.setMaxZoom(this.selectedBaseLayer.maxzoom);
 
-    this._map.setStyle(`assets/mapbox-gl-styles/${this.selectedBaseLayer.fileName}`);
+    this._map.setStyle(this.selectedBaseLayer.urlJson);
   }
 
   setSelectedFeature(selectedFeature) {
diff --git a/src/app/map/settings.ts b/src/app/map/settings.ts
index b08e25ec..ea88d0b5 100644
--- a/src/app/map/settings.ts
+++ b/src/app/map/settings.ts
@@ -1,3 +1,5 @@
+import { APP_CONFIG } from '../core/services/app-config.service';
+
 export const settings = {
 
   // Map
@@ -6,7 +8,7 @@ export const settings = {
     {
       id: 2,
       maxzoom: 21,
-      fileName: 'vector.json',
+      urlJson: `${APP_CONFIG.backendUrls.openMapTiles}/styles/vector/style.json`,
       labels: {
         fr: 'Carte',
         en: 'Map',
@@ -15,7 +17,7 @@ export const settings = {
     {
       id: 4,
       maxzoom: 21,
-      fileName: 'satellite.json',
+      urlJson: `${APP_CONFIG.backendUrls.openMapTiles}/styles/aerial/style.json`,
       labels: {
         fr: 'Satellite',
         en: 'Satellite',
diff --git a/src/assets/config/config.json b/src/assets/config/config.json
index 914e53c2..4005b293 100644
--- a/src/assets/config/config.json
+++ b/src/assets/config/config.json
@@ -14,7 +14,8 @@
     "wms": "https://data-reloaded-dev.alpha.grandlyon.com/api/services/wms",
     "mvt": "https://data-reloaded-dev.alpha.grandlyon.com/api/services/mvt",
     "geocoder": "https://download.data.grandlyon.com/geocoding/photon",
-    "seo": "/share"
+    "seo": "/share",
+    "openMapTiles": "https://openmaptiles.recette.data.grandlyon.com"
   },
   "theFunctionalitiesInterruptor": {
     "credits": true,
-- 
GitLab