Spaces:
Sleeping
Sleeping
Fix: EV chargers now load on selecting Électrique (lower zoom gate to 9, auto-zoom in, paginate + dedupe by location)
Browse files- static/app.js +29 -6
- static/sw.js +1 -1
static/app.js
CHANGED
|
@@ -67,7 +67,7 @@ let thermCar = null; // { label, fuel, cons } chosen combustion model
|
|
| 67 |
let stopMarkers = []; // recharge-stop markers on the map
|
| 68 |
let routeLine = null, depPin = null, arrPin = null;
|
| 69 |
let depCoord = null, arrCoord = null; // coords from a picked city suggestion
|
| 70 |
-
let chargersOn = false, chargerTimer = null;
|
| 71 |
|
| 72 |
// ===================== Utilities =====================
|
| 73 |
function esc(t) {
|
|
@@ -286,6 +286,9 @@ function selectElectric() {
|
|
| 286 |
map.removeLayer(cluster);
|
| 287 |
togglePriceLegend(false);
|
| 288 |
toggleChargers(true);
|
|
|
|
|
|
|
|
|
|
| 289 |
}
|
| 290 |
|
| 291 |
function togglePriceLegend(showPrice) {
|
|
@@ -635,16 +638,36 @@ function chargerMarker(c) {
|
|
| 635 |
}
|
| 636 |
async function loadChargersInView() {
|
| 637 |
if (!chargersOn) return;
|
| 638 |
-
if (map.getZoom() <
|
| 639 |
const b = map.getBounds();
|
| 640 |
const where = bboxWhere(b.getSouth(), b.getWest(), b.getNorth(), b.getEast());
|
| 641 |
-
const
|
|
|
|
|
|
|
| 642 |
try {
|
| 643 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
chargerCluster.clearLayers();
|
| 645 |
-
const ms = (j.results || []).filter(c => c.consolidated_latitude != null).map(chargerMarker);
|
| 646 |
chargerCluster.addLayers(ms);
|
| 647 |
-
chargerMsg(
|
|
|
|
|
|
|
| 648 |
} catch (e) { chargerMsg("Bornes indisponibles."); }
|
| 649 |
}
|
| 650 |
function toggleChargers(on) {
|
|
|
|
| 67 |
let stopMarkers = []; // recharge-stop markers on the map
|
| 68 |
let routeLine = null, depPin = null, arrPin = null;
|
| 69 |
let depCoord = null, arrCoord = null; // coords from a picked city suggestion
|
| 70 |
+
let chargersOn = false, chargerTimer = null, loadSeq = 0;
|
| 71 |
|
| 72 |
// ===================== Utilities =====================
|
| 73 |
function esc(t) {
|
|
|
|
| 286 |
map.removeLayer(cluster);
|
| 287 |
togglePriceLegend(false);
|
| 288 |
toggleChargers(true);
|
| 289 |
+
// The national layer is too dense to show country-wide, so zoom in to where
|
| 290 |
+
// chargers load (the moveend then triggers the fetch around the current centre).
|
| 291 |
+
if (map.getZoom() < 9) map.setView(map.getCenter(), 9);
|
| 292 |
}
|
| 293 |
|
| 294 |
function togglePriceLegend(showPrice) {
|
|
|
|
| 638 |
}
|
| 639 |
async function loadChargersInView() {
|
| 640 |
if (!chargersOn) return;
|
| 641 |
+
if (map.getZoom() < 9) { chargerCluster.clearLayers(); chargerMsg("Zoomez pour afficher les bornes ⚡"); return; }
|
| 642 |
const b = map.getBounds();
|
| 643 |
const where = bboxWhere(b.getSouth(), b.getWest(), b.getNorth(), b.getEast());
|
| 644 |
+
const base = `${IRVE_URL}?limit=100&select=${IRVE_SELECT}&where=${encodeURIComponent(where)}`;
|
| 645 |
+
const myseq = ++loadSeq; // ignore this result if a newer view starts loading
|
| 646 |
+
chargerMsg("Chargement des bornes…");
|
| 647 |
try {
|
| 648 |
+
let all = [], total = 0;
|
| 649 |
+
for (let offset = 0; offset < 300; offset += 100) { // up to 300 (API caps 100/req)
|
| 650 |
+
const j = await (await fetch(`${base}&offset=${offset}`)).json();
|
| 651 |
+
total = j.total_count || 0;
|
| 652 |
+
const got = j.results || [];
|
| 653 |
+
all = all.concat(got);
|
| 654 |
+
if (got.length < 100) break;
|
| 655 |
+
}
|
| 656 |
+
if (myseq !== loadSeq) return;
|
| 657 |
+
// Several charge points share one location; keep one marker per spot (max power).
|
| 658 |
+
const bySpot = new Map();
|
| 659 |
+
for (const c of all) {
|
| 660 |
+
if (c.consolidated_latitude == null) continue;
|
| 661 |
+
const k = c.consolidated_latitude + "," + c.consolidated_longitude;
|
| 662 |
+
const prev = bySpot.get(k);
|
| 663 |
+
if (!prev || (c.puissance_nominale || 0) > (prev.puissance_nominale || 0)) bySpot.set(k, c);
|
| 664 |
+
}
|
| 665 |
+
const ms = [...bySpot.values()].map(chargerMarker);
|
| 666 |
chargerCluster.clearLayers();
|
|
|
|
| 667 |
chargerCluster.addLayers(ms);
|
| 668 |
+
chargerMsg(!ms.length ? "Aucune borne dans cette zone"
|
| 669 |
+
: total > all.length ? `${ms.length} bornes affichées (zoomez pour plus)`
|
| 670 |
+
: `${ms.length} borne${ms.length > 1 ? "s" : ""}`);
|
| 671 |
} catch (e) { chargerMsg("Bornes indisponibles."); }
|
| 672 |
}
|
| 673 |
function toggleChargers(on) {
|
static/sw.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
* - The app shell, icons and CDN libraries are cached so the app boots offline.
|
| 5 |
* - Map tiles are cached with a bounded LRU-ish cap for offline revisits.
|
| 6 |
*/
|
| 7 |
-
const VERSION = "
|
| 8 |
const SHELL = "shell-" + VERSION;
|
| 9 |
const RUNTIME = "runtime-" + VERSION;
|
| 10 |
const TILES = "tiles-" + VERSION;
|
|
|
|
| 4 |
* - The app shell, icons and CDN libraries are cached so the app boots offline.
|
| 5 |
* - Map tiles are cached with a bounded LRU-ish cap for offline revisits.
|
| 6 |
*/
|
| 7 |
+
const VERSION = "v5";
|
| 8 |
const SHELL = "shell-" + VERSION;
|
| 9 |
const RUNTIME = "runtime-" + VERSION;
|
| 10 |
const TILES = "tiles-" + VERSION;
|