fetching data from triple store
davvalent

davvalent commited on 2023-03-15 16:56:41
Showing 1 changed files, with 57 additions and 23 deletions.

... ...
@@ -1,11 +1,19 @@
1 1
 /**
2 2
  * Plan interactif du Faubourg à m’lasse (PIFM)
3 3
  * 
4
- * Plan interactif du Faubourg à m’lasse (secteur Radio-Canada) intégrant des données
5
- * structurées, des photograpies d’archives, des cartes historiques et d’autres données.
4
+ * intégration des données structurées du projet QDMTL
5
+ * intégration des photograpies d’archives
6
+ * intégration du plan d’expropriation du Fabourg à m’lasse
6 7
  *
7 8
  * @requires module:leaflet
8 9
  * @author David Valentine <d@ntnlv.ca>
10
+ * @todo loading messages
11
+ * @todo error handling
12
+ * @todo ordre de chargement optimal des couches
13
+ * @todo english for code review
14
+ * @todo voir https://geojson.org/geojson-ld/
15
+ * @todo voir linked places format
16
+ * @todo protocole de geolocalisation : si geojson.io,, charger buildings.json
9 17
  */
10 18
 
11 19
 (async () => {
... ...
@@ -125,35 +133,61 @@
125 133
   pifm.createPane('fixed', document.querySelector("#map"));
126 134
 
127 135
   /** GeoJSON Layer */
128
-    geoJSON = L.geoJSON(geojsonFeatures, {
136
+  const geoJSON = L.geoJSON(geojsonFeaturesFromTripleStore, {
137
+
129 138
     onEachFeature: (feature, layer) => {
130
-        if (feature.properties) {
131 139
 
132
-          const popUpInformation = `
133
-            <div class="classe-ajoutée-dans-le-but-de-placer-limage-pricipale">
134
-              <h1>${feature.properties["appellation"]}</h1>
135
-              <ul>
136
-                <li>${feature.properties["appellation"]}</li>
137
-                <li>${feature.properties["rdfs:label"]}</li>
138
-                <li>${feature.properties["qdmtl:thoroughfare"]}</li>
139
-                <li>${feature.properties["inventoryNumber"]}</li>
140
-              </ul>
141
-            </div>
142
-          `,
143
-
144
-            popup = L.popup({
140
+      const popup = L.popup({
145 141
         pane: 'fixed',
146 142
         className: 'popup-fixed',
147
-              autoPan: false
148
-            }).setContent(popUpInformation);
143
+        autoPan: false,
144
+        maxWidth: 2000 // must be larger than 50% of the viewport
145
+      });
149 146
 
150 147
       layer.bindPopup(popup);
151 148
 
152 149
       layer.on("click", () => {
153
-            console.log("Message fired when clicking the geoJSON feature (the marker).");
150
+
151
+        let URI = feature.properties.URI;
152
+
153
+        if (dev()) {
154
+
155
+          console.log("Dev: Message fired when clicking the geoJSON feature (the marker).");
156
+
157
+          if (sessionStorage.getItem("onLineTripleStore") !== "true") {
158
+            URI = feature.properties.URI.replace("http://data.qdmtl.ca", sessionStorage.getItem("devTripleStoreUrl"));
159
+          }
160
+        }
161
+
162
+        /**
163
+         * Fetching the ressource
164
+         * Thenable since await is not allowed if not at top level
165
+         */
166
+        fetch(URI, {
167
+          method: "GET",
168
+          headers: {
169
+            "Accept": "application/ld+json",
170
+          }
171
+        })
172
+        .then((response) => response.json())
173
+        .then((jsonLD) => {
174
+
175
+          if (dev) {
176
+            console.log("Dev: Response from local server:", jsonLD);
177
+          }
178
+          
179
+          const popUpInformation = `
180
+            <h1>${feature.properties.URI}</h1>
181
+            <pre>${JSON.stringify(jsonLD, undefined, 2)}</pre>
182
+          `;
183
+
184
+          popup.setContent(popUpInformation);
185
+        },
186
+        (reason) => {
187
+            /* rejection handler */
188
+        });
154 189
         
155 190
         /**
156
-             * Trois prochaines instructions
157 191
          * Déplacement et centrage de la punaise
158 192
          */
159 193
         let targetLatLng = L.latLng(
... ...
@@ -182,8 +216,8 @@
182 216
     geoJSON.addTo(pifm);
183 217
 
184 218
   if (dev()) {
185
-    pifm.on("popupopen", () => console.log("Message fired on pop-up opening"));
186
-    console.log(pifm.getPanes());
219
+    pifm.on("popupopen", () => console.log("Dev: Message fired on pop-up opening"));
220
+    console.log("Dev:", pifm.getPanes());
187 221
   };
188 222
 
189 223
 })();
190 224