feat: Introduce GlobeView component with Google 3D Tiles and integrate various camera data sources including GDOT, Caltrans, and TFL.
This commit is contained in:
1 parent
6cfef39e1b
commit
c4f32ece18
11 files changed
+361
-7
No files matched your search
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user