Refactorisation
davvalent

davvalent commited on 2023-03-07 01:27:17
Showing 1 changed files, with 26 additions and 19 deletions.

... ...
@@ -87,7 +87,7 @@
87 87
     }),
88 88
 
89 89
     /** Instanciation du plan */
90
-    planDuFaubourg = L.map("map", {
90
+    pifm = L.map("map", {
91 91
       center: [45.51823567357893, -73.55085910368373],
92 92
       zoom: 17.5,
93 93
       minZoom: 15,
... ...
@@ -98,7 +98,7 @@
98 98
         baseLayer,
99 99
         faubourgLayer
100 100
       ]
101
-    }),
101
+    });
102 102
 
103 103
     /**
104 104
      * Créer un pane pour la fenêtre pop-up
... ...
@@ -106,7 +106,7 @@
106 106
      * "Panes are DOM elements used to control the ordering of layers on the map."
107 107
      * https://leafletjs.com/reference.html#map-pane
108 108
      */
109
-    informationPane = planDuFaubourg.createPane('fixed', document.querySelector("#map")),
109
+  pifm.createPane('fixed', document.querySelector("#map"));
110 110
 
111 111
     /** GeoJSON Layer */
112 112
     geoJSON = L.geoJSON(geojsonFeatures, {
... ...
@@ -147,11 +147,10 @@
147 147
             );
148 148
             const targetZoom = 20,
149 149
               popUpWidth = document.querySelector(".leaflet-popup").clientWidth,
150
-              targetPoint = planDuFaubourg.project(targetLatLng, targetZoom).subtract([popUpWidth / 2, 0]);
151
-            targetLatLng = planDuFaubourg.unproject(targetPoint, targetZoom);
152
-            planDuFaubourg.setView(targetLatLng, targetZoom);
153
-          })
154
-        }
150
+          targetPoint = pifm.project(targetLatLng, targetZoom).subtract([popUpWidth / 2, 0]);
151
+        targetLatLng = pifm.unproject(targetPoint, targetZoom);
152
+        pifm.setView(targetLatLng, targetZoom);
153
+      });
155 154
       }
156 155
     }),
157 156
 
... ...
@@ -159,18 +158,26 @@
159 158
     overlayMaps = {
160 159
       "<span class=\"controles\">Plan d'expropriation</span>": faubourgLayer,
161 160
       "<span class=\"controles\">Bâtiments</span>": geoJSON,
162
-    },
163
-
164
-    addLayerControl = L.control.layers(null, overlayMaps).addTo(planDuFaubourg),
165
-    addZoomControl = L.control.zoom({position:"topright"}).addTo(planDuFaubourg),
166
-    addScale = L.control.scale().addTo(planDuFaubourg),
167
-    addJsonLayer = geoJSON.addTo(planDuFaubourg);
161
+    };
168 162
 
169
-  planDuFaubourg.on("popupopen", () => {
170
-      console.log("Message fired on pop-up opening");
171
-    }
172
-  );
163
+    L.control.layers(null, overlayMaps).addTo(pifm);
164
+    L.control.zoom({position:"topright"}).addTo(pifm);
165
+    L.control.scale().addTo(pifm);
166
+    geoJSON.addTo(pifm);
173 167
 
174
-  console.log(planDuFaubourg.getPanes());
168
+  if (dev()) {
169
+    pifm.on("popupopen", () => console.log("Message fired on pop-up opening"));
170
+    console.log(pifm.getPanes());
171
+  };
175 172
 
176 173
 })();
174
+
175
+/**
176
+ * dev env tester
177
+ * @returns boolean
178
+ */
179
+function dev() {
180
+  return (location.host === "localhost" || location.host === "127.0.0.1")
181
+    ? true
182
+    : false;
183
+}
177 184
\ No newline at end of file
178 185