// Load the map engine only for the approved realtime workspace. import '/workbench/drone-map.js'; // A separate, lazy map keeps configuration independent of the live receiver map. let settings, generation=0; window.ridMapSettings={ async open(p){const token=++generation;settings??=await import('./map-settings-adapter.js');if(token===generation)settings.open(p);}, close(){generation++;settings?.close();},refresh(){settings?.refresh();window.ridMap?.refresh();}, configure(p){settings?.configure(p);},setBasemap(v){settings?.setBasemap(v);}, tool(v){settings?.tool(v);},bounds(v){settings?.bounds(v);},current(){settings?.current();},metrics(){return settings?.metrics();} }; let fences,fenceGeneration=0; window.ridGeofences={ async open(p){const token=++fenceGeneration;try{fences??=await import('./geofence-map-adapter.js');if(token===fenceGeneration){fences.open(p);window.dispatchEvent(new Event('rid-fence-map-ready'));}}catch{window.dispatchEvent(new CustomEvent('rid-fence-map-error',{detail:{message:'围栏地图模块加载失败,可继续使用坐标编辑。'}}));}}, close(){fenceGeneration++;fences?.close();},render(p){fences?.render(p);},targets(p){fences?.targets(p);},tool(v){fences?.tool(v);},locate(){fences?.locate();},setBasemap(v){fences?.setBasemap(v);},metrics(){return fences?.metrics();} }; let history, historyGeneration = 0, historyPoints = [], historyIndex = 0, historyProgress = 0; let historyTarget, historyMapOptions; let playbackFrame, playbackTimestamp, playbackGeneration = 0; document.addEventListener('visibilitychange', () => { playbackTimestamp = undefined; }); function stopHistoryClock() { playbackGeneration += 1; if (playbackFrame !== undefined) cancelAnimationFrame(playbackFrame); playbackFrame = undefined; playbackTimestamp = undefined; } window.ridHistory = { async open(p) { const token = ++historyGeneration; try { history ??= await import('./history-map-adapter.js'); if (token === historyGeneration) { history.open({...p, ...historyMapOptions}); history.setPoints(historyPoints, historyTarget); history.setCursor(historyIndex, historyProgress); } } catch { window.dispatchEvent(new Event('rid-history-map-error')); } }, close() { historyGeneration += 1; stopHistoryClock(); history?.close(); }, prepareTrack(value) { return window.ridDroneMap.prepareTrack(value); }, setPoints(value, target) { historyPoints = Array.isArray(value) ? value : []; historyTarget = target; historyIndex = 0; historyProgress = 0; history?.setPoints(historyPoints, historyTarget); }, setMapOptions(value) { historyMapOptions = value; if (value) history?.setMapOptions(value); }, setCursor(index, progress) { historyIndex = index; historyProgress = progress; history?.setCursor(index, progress); }, startClock(tick) { stopHistoryClock(); const token = playbackGeneration; function frame(timestamp) { if (token !== playbackGeneration) return; const elapsed = playbackTimestamp === undefined ? 0 : Math.max(0, timestamp - playbackTimestamp); playbackTimestamp = timestamp; if (tick(elapsed) && token === playbackGeneration) { playbackFrame = requestAnimationFrame(frame); } } playbackFrame = requestAnimationFrame(frame); }, stopClock: stopHistoryClock, metrics() { return history?.metrics(); } }; if (location.pathname === '/realtime') await import('./map-adapter.js');