From b833c2ac6e38d420575be9882f3eb0f2691d994c Mon Sep 17 00:00:00 2001 From: Andriy Oblivantsev Date: Mon, 2 Mar 2026 22:17:04 +0000 Subject: [PATCH] Load all collections on map after login. Both map demos now fetch all user collections and render their features/assets immediately on login, including 3D objects, instead of only showing a single selected collection. Made-with: Cursor --- web/leaflet-demo.js | 26 +++++++++++++++++++++++--- web/maplibre-demo.js | 19 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/web/leaflet-demo.js b/web/leaflet-demo.js index bd76a45..47c1bb9 100644 --- a/web/leaflet-demo.js +++ b/web/leaflet-demo.js @@ -118,6 +118,7 @@ async function login() { if (!keys) await ensureKeys(); accessToken = await client.loginWithSignature(keys.publicKey, keys.privateKey); client.setAccessToken(accessToken); + await refreshFeatures(); } async function ensureCollection() { @@ -181,9 +182,28 @@ function renderAssets(features) { } } +function clearMarkers() { + for (const marker of markers.values()) { + map.removeLayer(marker); + } + markers.clear(); +} + async function refreshFeatures() { - if (!collectionId) return; - const { features } = await client.listFeatures(collectionId); + if (!accessToken) return; + const { collections } = await client.listCollections(); + if (!collectionId && collections.length > 0) { + collectionId = collections[0].id; + collectionInfoEl.textContent = `${collections[0].name} (${collections[0].id})`; + } + const featureSets = await Promise.all( + collections.map(async (collection) => { + const { features } = await client.listFeatures(collection.id); + return features; + }) + ); + const features = featureSets.flat(); + clearMarkers(); for (const feature of features) { const coords = feature.geometry?.coordinates; if (!coords || coords.length < 2) continue; @@ -271,7 +291,7 @@ document.getElementById("register").onclick = async () => { document.getElementById("login").onclick = async () => { try { await login(); - setStatus("Logged in."); + setStatus("Logged in. Loaded all collections on map."); } catch (error) { setStatus(error.message); } diff --git a/web/maplibre-demo.js b/web/maplibre-demo.js index 9156e20..60ba233 100644 --- a/web/maplibre-demo.js +++ b/web/maplibre-demo.js @@ -183,6 +183,7 @@ async function login() { if (!keys) await ensureKeys(); accessToken = await client.loginWithSignature(keys.publicKey, keys.privateKey); client.setAccessToken(accessToken); + await refreshFeatures(); } async function ensureCollection() { @@ -247,8 +248,20 @@ function renderAssets(features) { } async function refreshFeatures() { - if (!collectionId) return; - const { features } = await client.listFeatures(collectionId); + if (!accessToken) return; + const { collections } = await client.listCollections(); + if (!collectionId && collections.length > 0) { + collectionId = collections[0].id; + collectionInfoEl.textContent = `${collections[0].name} (${collections[0].id})`; + } + + const featureSets = await Promise.all( + collections.map(async (collection) => { + const { features } = await client.listFeatures(collection.id); + return features; + }) + ); + const features = featureSets.flat(); clearFeatureMeshes(); for (const feature of features) { const coords = feature.geometry?.coordinates; @@ -333,7 +346,7 @@ document.getElementById("register").onclick = async () => { document.getElementById("login").onclick = async () => { try { await login(); - setStatus("Logged in."); + setStatus("Logged in. Loaded all collections on map."); } catch (error) { setStatus(error.message); }