Add public GeoJSON features API and load public 3D objects on maps.
CI / test (push) Successful in 3s
CI / test (push) Successful in 3s
Expose GET /v1/features/public (optional kind filter) and update Leaflet/MapLibre demos to render all public 3D assets globally, while still merging owner collections after login. Made-with: Cursor
This commit is contained in:
+28
-12
@@ -41,6 +41,10 @@ function setStatus(message) {
|
||||
statusEl.textContent = message;
|
||||
}
|
||||
|
||||
function currentApiBase() {
|
||||
return apiBaseEl.value.trim().replace(/\/+$/g, "");
|
||||
}
|
||||
|
||||
function extFromFilename(name) {
|
||||
const idx = name.lastIndexOf(".");
|
||||
if (idx <= 0) return "";
|
||||
@@ -248,20 +252,31 @@ function renderAssets(features) {
|
||||
}
|
||||
|
||||
async function refreshFeatures() {
|
||||
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 publicResp = await fetch(`${currentApiBase()}/v1/features/public?kind=3d`);
|
||||
if (!publicResp.ok) {
|
||||
throw new Error(`Failed to load public features: HTTP ${publicResp.status}`);
|
||||
}
|
||||
const publicData = await publicResp.json();
|
||||
const byID = new Map((publicData.features || []).map((feature) => [feature.id, feature]));
|
||||
|
||||
if (accessToken) {
|
||||
const { collections } = await client.listCollections();
|
||||
if (!collectionId && collections.length > 0) {
|
||||
collectionId = collections[0].id;
|
||||
collectionInfoEl.textContent = `${collections[0].name} (${collections[0].id})`;
|
||||
}
|
||||
const ownFeatureSets = await Promise.all(
|
||||
collections.map(async (collection) => {
|
||||
const { features } = await client.listFeatures(collection.id);
|
||||
return features;
|
||||
})
|
||||
);
|
||||
for (const feature of ownFeatureSets.flat()) {
|
||||
byID.set(feature.id, feature);
|
||||
}
|
||||
}
|
||||
|
||||
const featureSets = await Promise.all(
|
||||
collections.map(async (collection) => {
|
||||
const { features } = await client.listFeatures(collection.id);
|
||||
return features;
|
||||
})
|
||||
);
|
||||
const features = featureSets.flat();
|
||||
const features = Array.from(byID.values());
|
||||
clearFeatureMeshes();
|
||||
for (const feature of features) {
|
||||
const coords = feature.geometry?.coordinates;
|
||||
@@ -384,6 +399,7 @@ map.on("load", () => {
|
||||
threeLayer = createThreeLayer();
|
||||
map.addLayer(threeLayer);
|
||||
renderSharedAssetFromQuery();
|
||||
refreshFeatures().catch((error) => setStatus(error.message));
|
||||
});
|
||||
|
||||
map.on("click", (event) => {
|
||||
|
||||
Reference in New Issue
Block a user