feat: Introduce GlobeView component with Google 3D Tiles and integrate various camera data sources including GDOT, Caltrans, and TFL.

This commit is contained in:
silvertakana committed 2026-03-12 19:04:47 +13:00
1 parent 6cfef39e1b
commit c4f32ece18
11 files changed
+361 -7

No files matched your search

+1
View File
@@ -12,6 +12,7 @@
"@vercel/analytics": "^1.6.1",
"cesium": "^1.139.0",
"cheerio": "^1.2.0",
"hls.js": "^1.6.15",
"insecam-api": "^0.0.3",
"lucide-react": "^0.576.0",
"next": "16.1.6",
+1
View File
@@ -16,6 +16,7 @@
"@vercel/analytics": "^1.6.1",
"cesium": "^1.139.0",
"cheerio": "^1.2.0",
"hls.js": "^1.6.15",
"insecam-api": "^0.0.3",
"lucide-react": "^0.576.0",
"next": "16.1.6",
+1 -1
View File
@@ -1 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-83.74088,42.27756]},"properties":{"source":"cameras_json","stream":"http://173.167.10.225:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"Michigan","city":"Ann Arbor","timezone":"-04:00","preview_url":"http://insecam.org/static/thumb/252977.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-120.59073,35.11859]},"properties":{"source":"cameras_json","stream":"http://129.65.82.21:80/-wvhttp-01-/GetOneShot?image_size=640x480&frame_count=1000000000","country":"United States","country_code":null,"region":"California","city":"Arroyo Grande","timezone":"-08:00","preview_url":"http://insecam.org/static/thumb/689228.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-16.726,28.12271]},"properties":{"source":"cameras_json","stream":"http://212.170.102.212:80/webcapture.jpg?command=snap&channel=1?0","country":"Spain","country_code":null,"region":"Canarias","city":"Adeje","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/829971.jpg","is_iframe":false,"is_static":true,"is_popular":false,"categories":["traffic"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.56031,46.49142]},"properties":{"source":"cameras_json","stream":"http://109.164.252.213:8081/mjpg/video.mjpg","country":"Switzerland","country_code":null,"region":"Bern","city":"Adelboden","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/807248.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["mountains","other","airport"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.00162,65.67624]},"properties":{"source":"cameras_json","stream":"http://82.99.75.135:80/mjpg/video.mjpg","country":"Sweden","country_code":null,"region":"Norrbottens Lan","city":"Aelvsbyn","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/278111.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["nature"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[133.9,33.5]},"properties":{"source":"cameras_json","stream":"http://202.213.179.21:8001/jpg/image.jpg?0","country":"Japan","country_code":null,"region":"Kochi","city":"Aki","timezone":"+09:00","preview_url":"http://insecam.org/static/thumb/961703.jpg","is_iframe":false,"is_static":true,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[133.9,33.5]},"properties":{"source":"cameras_json","stream":"http://202.213.182.120:8001/jpg/image.jpg?0","country":"Japan","country_code":null,"region":"Kochi","city":"Aki","timezone":"+09:00","preview_url":"http://insecam.org/static/thumb/920219.jpg","is_iframe":false,"is_static":true,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-73.75623,42.65258]},"properties":{"source":"cameras_json","stream":"http://166.141.177.37:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albany","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/455398.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.19363,43.24645]},"properties":{"source":"cameras_json","stream":"http://72.43.65.9:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albion","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/722988.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.19363,43.24645]},"properties":{"source":"cameras_json","stream":"http://72.43.65.7:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albion","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/560424.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.23773,53.30393]},"properties":{"source":"cameras_json","stream":"http://81.133.30.194:82/mjpg/video.mjpg","country":"United Kingdom","country_code":null,"region":"England","city":"Alderley Edge","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/237453.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["rivers","marina"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-85.95365,42.97225]},"properties":{"source":"cameras_json","stream":"http://71.83.5.155:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"Michigan","city":"Allendale","timezone":"-04:00","preview_url":"http://insecam.org/static/thumb/238572.jpg","is_iframe":false,"is_static":falsLine truncated
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-83.74088,42.27756]},"properties":{"source":"cameras_json","stream":"http://173.167.10.225:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"Michigan","city":"Ann Arbor","timezone":"-04:00","preview_url":"http://insecam.org/static/thumb/252977.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-120.59073,35.11859]},"properties":{"source":"cameras_json","stream":"http://129.65.82.21:80/-wvhttp-01-/GetOneShot?image_size=640x480&frame_count=1000000000","country":"United States","country_code":null,"region":"California","city":"Arroyo Grande","timezone":"-08:00","preview_url":"http://insecam.org/static/thumb/689228.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[7.56031,46.49142]},"properties":{"source":"cameras_json","stream":"http://109.164.252.213:8081/mjpg/video.mjpg","country":"Switzerland","country_code":null,"region":"Bern","city":"Adelboden","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/807248.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["mountains","other","airport"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[21.00162,65.67624]},"properties":{"source":"cameras_json","stream":"http://82.99.75.135:80/mjpg/video.mjpg","country":"Sweden","country_code":null,"region":"Norrbottens Lan","city":"Aelvsbyn","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/278111.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["nature"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[133.9,33.5]},"properties":{"source":"cameras_json","stream":"http://202.213.179.21:8001/jpg/image.jpg?0","country":"Japan","country_code":null,"region":"Kochi","city":"Aki","timezone":"+09:00","preview_url":"http://insecam.org/static/thumb/961703.jpg","is_iframe":false,"is_static":true,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[133.9,33.5]},"properties":{"source":"cameras_json","stream":"http://202.213.182.120:8001/jpg/image.jpg?0","country":"Japan","country_code":null,"region":"Kochi","city":"Aki","timezone":"+09:00","preview_url":"http://insecam.org/static/thumb/920219.jpg","is_iframe":false,"is_static":true,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-73.75623,42.65258]},"properties":{"source":"cameras_json","stream":"http://166.141.177.37:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albany","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/455398.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.19363,43.24645]},"properties":{"source":"cameras_json","stream":"http://72.43.65.9:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albion","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/722988.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-78.19363,43.24645]},"properties":{"source":"cameras_json","stream":"http://72.43.65.7:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"New York","city":"Albion","timezone":"-05:00","preview_url":"http://insecam.org/static/thumb/560424.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-2.23773,53.30393]},"properties":{"source":"cameras_json","stream":"http://81.133.30.194:82/mjpg/video.mjpg","country":"United Kingdom","country_code":null,"region":"England","city":"Alderley Edge","timezone":"+01:00","preview_url":"http://insecam.org/static/thumb/237453.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["rivers","marina"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-85.95365,42.97225]},"properties":{"source":"cameras_json","stream":"http://71.83.5.155:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"Michigan","city":"Allendale","timezone":"-04:00","preview_url":"http://insecam.org/static/thumb/238572.jpg","is_iframe":false,"is_static":false,"is_popular":false,"categories":["other","rivers"]}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-85.95365,42.97225]},"properties":{"source":"cameras_json","stream":"http://71.83.5.157:80/mjpg/video.mjpg","country":"United States","country_code":null,"region":"Michigan","city":"Allendale","timezone":"-04:00","preview_url":"http://insecam.org/static/thumb/168157.jpg","is_iframe":false,"is_static":false,"is_Line truncated
@@ -0,0 +1,71 @@
/**
* Fetches all Caltrans CCTV cameras across all 12 California districts.
*
* API: https://cwwp2.dot.ca.gov/data/d{N}/cctv/cctvStatusD{NN}.json
* Free, no authentication required.
* Returns ~3,400 cameras with HLS streaming URLs and JPEG snapshots.
*/
import type { GdotCameraFeature } from "../gdot/gdotFetcher";
const DISTRICTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
function districtUrl(d: number): string {
const padded = String(d).padStart(2, "0");
return `https://cwwp2.dot.ca.gov/data/d${d}/cctv/cctvStatusD${padded}.json`;
}
function toGeoJsonFeature(raw: any): GdotCameraFeature | null {
const cam = raw.cctv;
if (!cam?.location) return null;
const lat = parseFloat(cam.location.latitude);
const lon = parseFloat(cam.location.longitude);
if (isNaN(lat) || isNaN(lon)) return null;
if (cam.inService === "false") return null;
const hls = cam.imageData?.streamingVideoURL || null;
const jpeg = cam.imageData?.static?.currentImageURL || "";
return {
type: "Feature",
geometry: { type: "Point", coordinates: [lon, lat] },
properties: {
stream: hls || jpeg,
hls,
country: "United States",
region: `District ${cam.location.district}, California`,
city: cam.location.nearbyPlace || "California",
source: "caltrans",
name: cam.location.locationName || "",
route: cam.location.route || "",
direction: cam.location.direction || "",
location_description: cam.location.locationName || "",
categories: ["traffic"],
},
};
}
/** Fetch all Caltrans cameras across all 12 districts in parallel. */
export async function fetchCaltransCameras(): Promise<GdotCameraFeature[]> {
const results = await Promise.allSettled(
DISTRICTS.map(async (d) => {
const res = await fetch(districtUrl(d), {
headers: { "User-Agent": "WorldWideView/1.0" },
});
if (!res.ok) return [];
const json = await res.json();
if (!Array.isArray(json.data)) return [];
const cameras: GdotCameraFeature[] = [];
for (const item of json.data) {
const f = toGeoJsonFeature(item);
if (f) cameras.push(f);
}
return cameras;
}),
);
return results
.filter((r): r is PromiseFulfilledResult<GdotCameraFeature[]> => r.status === "fulfilled")
.flatMap((r) => r.value);
}
+91
View File
@@ -0,0 +1,91 @@
/**
* Fetches all traffic camera data from the GDOT ArcGIS REST API.
*
* The API paginates at 2000 records, so we loop with `resultOffset`
* until all features are retrieved.
*/
const GDOT_BASE =
"https://services1.arcgis.com/2iUE8l8JKrP2tygQ/arcgis/rest/services" +
"/GDOT_Live_Traffic_Cameras/FeatureServer/0/query";
const PAGE_SIZE = 2000;
export interface GdotCameraFeature {
type: "Feature";
geometry: { type: "Point"; coordinates: [number, number] };
properties: {
stream: string;
hls: string | null;
country: string;
region: string;
city: string;
source: string;
name: string;
route: string;
direction: string;
location_description: string;
categories: string[];
};
}
/** Convert a raw ArcGIS feature into our GeoJSON format. */
function toGeoJsonFeature(raw: any): GdotCameraFeature | null {
const { attributes: a, geometry: g } = raw;
if (!g?.x || !g?.y) return null;
return {
type: "Feature",
geometry: { type: "Point", coordinates: [g.x, g.y] },
properties: {
stream: a.HLS || a.url || "",
hls: a.HLS || null,
country: "United States",
region: `${a.county || ""} County, Georgia`,
city: a.subdivision || "Georgia",
source: "gdot",
name: a.name || "",
route: a.route || "",
direction: a.dir || "",
location_description: a.location_description || "",
categories: ["traffic"],
},
};
}
/** Fetch all GDOT cameras, handling ArcGIS pagination. */
export async function fetchGdotCameras(): Promise<GdotCameraFeature[]> {
const all: GdotCameraFeature[] = [];
let offset = 0;
let hasMore = true;
while (hasMore) {
const params = new URLSearchParams({
where: "1=1",
outFields: "*",
outSR: "4326",
f: "json",
resultRecordCount: String(PAGE_SIZE),
resultOffset: String(offset),
});
const res = await fetch(`${GDOT_BASE}?${params}`, {
headers: { "User-Agent": "WorldWideView/1.0" },
});
if (!res.ok) throw new Error(`GDOT API returned ${res.status}`);
const json = await res.json();
const features = json.features || [];
for (const f of features) {
const converted = toGeoJsonFeature(f);
if (converted) all.push(converted);
}
hasMore = json.exceededTransferLimit === true;
offset += features.length;
}
return all;
}
+31
View File
@@ -0,0 +1,31 @@
import { NextResponse } from "next/server";
import { fetchGdotCameras, type GdotCameraFeature } from "./gdotFetcher";
/** In-memory cache with TTL. */
let cache: { data: GdotCameraFeature[]; expiry: number } | null = null;
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
export async function GET() {
try {
const now = Date.now();
if (cache && now < cache.expiry) {
return NextResponse.json({ cameras: cache.data, cached: true });
}
const cameras = await fetchGdotCameras();
cache = { data: cameras, expiry: now + CACHE_TTL_MS };
return NextResponse.json({ cameras, cached: false });
} catch (error: any) {
console.error("[GDOT API] Error:", error);
// Serve stale cache on error if available
if (cache) {
return NextResponse.json({ cameras: cache.data, cached: true, stale: true });
}
return NextResponse.json(
{ error: "Failed to fetch GDOT cameras", details: error.message },
{ status: 502 },
);
}
}
+66
View File
@@ -0,0 +1,66 @@
/**
* Fetches all TfL JamCams from the Transport for London API.
*
* API: https://api.tfl.gov.uk/Place/Type/JamCam
* Free, no authentication required.
* Returns ~900 cameras across London with JPEG and MP4 URLs.
*/
import type { GdotCameraFeature } from "../gdot/gdotFetcher";
const TFL_URL = "https://api.tfl.gov.uk/Place/Type/JamCam";
/** Extract a named property from TfL additionalProperties array. */
function getProp(props: any[], key: string): string {
const found = props?.find((p: any) => p.key === key);
return found?.value || "";
}
/** Convert a raw TfL JamCam place into our GeoJSON format. */
function toGeoJsonFeature(raw: any): GdotCameraFeature | null {
if (!raw.lat || !raw.lon) return null;
const imageUrl = getProp(raw.additionalProperties, "imageUrl");
const videoUrl = getProp(raw.additionalProperties, "videoUrl");
const available = getProp(raw.additionalProperties, "available");
if (available === "false") return null;
return {
type: "Feature",
geometry: { type: "Point", coordinates: [raw.lon, raw.lat] },
properties: {
stream: videoUrl || imageUrl || "",
hls: null,
country: "United Kingdom",
region: "London",
city: "London",
source: "tfl",
name: raw.commonName || raw.id || "",
route: getProp(raw.additionalProperties, "view"),
direction: "",
location_description: raw.commonName || "",
categories: ["traffic"],
},
};
}
/** Fetch all TfL JamCams. */
export async function fetchTflCameras(): Promise<GdotCameraFeature[]> {
const res = await fetch(TFL_URL, {
headers: { "User-Agent": "WorldWideView/1.0" },
});
if (!res.ok) throw new Error(`TfL API returned ${res.status}`);
const data = await res.json();
if (!Array.isArray(data)) return [];
const cameras: GdotCameraFeature[] = [];
for (const place of data) {
const feature = toGeoJsonFeature(place);
if (feature) cameras.push(feature);
}
return cameras;
}
+63
View File
@@ -0,0 +1,63 @@
import { NextResponse } from "next/server";
import { fetchGdotCameras, type GdotCameraFeature } from "../gdot/gdotFetcher";
import { fetchTflCameras } from "../tfl/tflFetcher";
import { fetchCaltransCameras } from "../caltrans/caltransFetcher";
/** In-memory cache for traffic cameras with 24h TTL. */
let cache: { data: GdotCameraFeature[]; expiry: number } | null = null;
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
/**
* Merge all traffic camera sources.
* Add new fetchers here as they are implemented.
*/
async function fetchAllTrafficCameras(): Promise<GdotCameraFeature[]> {
const results = await Promise.allSettled([
fetchGdotCameras(),
fetchTflCameras(),
fetchCaltransCameras(),
]);
const all: GdotCameraFeature[] = [];
for (const r of results) {
if (r.status === "fulfilled") all.push(...r.value);
}
return all;
}
export async function GET() {
try {
const now = Date.now();
if (cache && now < cache.expiry) {
return NextResponse.json({
cameras: cache.data,
total: cache.data.length,
cached: true,
});
}
const cameras = await fetchAllTrafficCameras();
cache = { data: cameras, expiry: now + CACHE_TTL_MS };
return NextResponse.json({
cameras,
total: cameras.length,
cached: false,
});
} catch (error: any) {
console.error("[TrafficCameras] Error:", error);
if (cache) {
return NextResponse.json({
cameras: cache.data,
total: cache.data.length,
cached: true,
stale: true,
});
}
return NextResponse.json(
{ error: "Failed to fetch traffic cameras", details: error.message },
{ status: 502 },
);
}
}
+2 -1
View File
@@ -122,7 +122,8 @@ export default function GlobeView() {
// Initialize Google Photorealistic 3D Tiles once
try {
const tileset = await createGooglePhotorealistic3DTileset({
key: process.env.GOOGLE_MAPS_API_KEY || undefined,
key: process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY || undefined,
onlyUsingWithGoogleGeocoder: true,
});
tileset.maximumScreenSpaceError = sceneSettings.maxScreenSpaceError;
viewer.scene.primitives.add(tileset);
+12 -3
View File
@@ -2,7 +2,7 @@
import React, { ChangeEvent } from "react";
import { useStore } from "@/core/state/store";
import { Upload, Link as LinkIcon, Database, RotateCcw } from "lucide-react";
import { Upload, Link as LinkIcon, Database, RotateCcw, TrafficCone } from "lucide-react";
import { pluginManager } from "@/core/plugins/PluginManager";
import { inputGroupStyle, labelStyle, inputStyle, loadButtonStyle, sourceTabStyle } from "./cameraSettingsStyles";
@@ -13,7 +13,7 @@ export const CameraSettings: React.FC<{ pluginId: string }> = ({ pluginId }) =>
const setHighlightLayerId = useStore((s) => s.setHighlightLayerId);
const [isLoading, setIsLoading] = React.useState(false);
const handleSourceTypeChange = (type: "default" | "url" | "file") => {
const handleSourceTypeChange = (type: "default" | "traffic" | "url" | "file") => {
updatePluginSettings(pluginId, { sourceType: type });
setHighlightLayerId(null);
};
@@ -64,7 +64,7 @@ export const CameraSettings: React.FC<{ pluginId: string }> = ({ pluginId }) =>
</div>
<div style={{ display: "flex", gap: "var(--space-xs)" }}>
{([["default", Database, "Default"], ["url", LinkIcon, "URL"], ["file", Upload, "File"]] as const).map(
{([["default", Database, "Default"], ["traffic", TrafficCone, "Traffic Cams"], ["url", LinkIcon, "URL"], ["file", Upload, "File"]] as const).map(
([type, Icon, label]) => (
<button key={type} onClick={() => handleSourceTypeChange(type as any)} style={sourceTabStyle(settings.sourceType === type)}>
<Icon size={14} />
@@ -83,6 +83,15 @@ export const CameraSettings: React.FC<{ pluginId: string }> = ({ pluginId }) =>
</div>
)}
{settings.sourceType === "traffic" && (
<div style={inputGroupStyle}>
<div style={{ fontSize: 11, color: "var(--text-secondary)" }}>DOT traffic cameras (GDOT + more)</div>
<button onClick={handleLoadData} disabled={isLoading} style={loadButtonStyle(isLoading)}>
{isLoading ? "Loading..." : settings.loaded ? "Reload" : "Load"}
</button>
</div>
)}
{settings.sourceType === "url" && (
<div style={inputGroupStyle}>
<label style={labelStyle}>URL</label>
+22 -2
View File
@@ -26,7 +26,7 @@ export class CameraPlugin implements WorldPlugin {
requiresConfiguration(settingsRaw: any): boolean {
const s = { sourceType: "default", ...(settingsRaw || {}) };
if (s.sourceType === "default") return false;
if (s.sourceType === "default" || s.sourceType === "traffic") return false;
if (s.sourceType === "url" && !s.customUrl) return true;
if (s.sourceType === "file" && !s.customData) return true;
return false;
@@ -45,7 +45,8 @@ export class CameraPlugin implements WorldPlugin {
return [];
}
const isAutoDefault = settings.sourceType === "default" && !this.lastActionId && !this.sourceBuckets["default"];
const isAutoDefault = (settings.sourceType === "default" || settings.sourceType === "traffic")
&& !this.lastActionId && !this.sourceBuckets["default"];
if (!isAutoDefault && (settings.action !== "load" || settings.actionId === this.lastActionId)) {
return this.getAllEntities();
}
@@ -54,6 +55,8 @@ export class CameraPlugin implements WorldPlugin {
try {
if (settings.sourceType === "default") {
await this.loadDefaultSource();
} else if (settings.sourceType === "traffic") {
await this.loadTrafficCameras();
} else if (settings.sourceType === "url") {
await this.loadUrlSource(settings);
} else if (settings.sourceType === "file") {
@@ -77,6 +80,23 @@ export class CameraPlugin implements WorldPlugin {
this.pushUpdate();
}
/** Load traffic cameras from the server-side cached API. */
private async loadTrafficCameras(): Promise<void> {
try {
const res = await fetch("/api/camera/traffic");
if (!res.ok) throw new Error(`API returned ${res.status}`);
const data = await res.json();
if (data.cameras && Array.isArray(data.cameras)) {
this.sourceBuckets["default"] = data.cameras.map(
(f: any, i: number) => mapGeoJsonFeature(f, i, "traffic"),
);
}
} catch (err) {
console.warn("[CameraPlugin] Traffic cameras API failed:", err);
}
this.pushUpdate();
}
private async loadUrlSource(settings: any): Promise<void> {
if (!settings.customUrl) return;
let url = settings.customUrl;