release: bump version to 0.53.0
This commit is contained in:
@@ -259,9 +259,10 @@ const vesselIconLayer = createInteractableLayer({
|
||||
});
|
||||
|
||||
const DEFAULT_VESSEL_VIEWPORT = {
|
||||
bbox: [-180, -90, 180, 90],
|
||||
zoom: 2,
|
||||
bbox: [-10, 50, 35, 75],
|
||||
zoom: 4,
|
||||
};
|
||||
const MAX_VESSEL_SUBSCRIPTION_BBOX_AREA = 2500;
|
||||
|
||||
export function getVesselMarkers() {
|
||||
return vesselIconLayer.getMarkers();
|
||||
@@ -353,8 +354,34 @@ export async function loadVessels(_scene, earth, options = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export function startVesselRealtime(earth, { onUpdate } = {}) {
|
||||
function normalizeVesselViewportOptions(options = {}) {
|
||||
const bbox = Array.isArray(options.bbox) && options.bbox.length === 4
|
||||
? options.bbox.map(Number)
|
||||
: DEFAULT_VESSEL_VIEWPORT.bbox;
|
||||
const [lonA, latA, lonB, latB] = bbox;
|
||||
const normalizedBbox = [
|
||||
Math.max(-180, Math.min(lonA, lonB)),
|
||||
Math.max(-90, Math.min(latA, latB)),
|
||||
Math.min(180, Math.max(lonA, lonB)),
|
||||
Math.min(90, Math.max(latA, latB)),
|
||||
];
|
||||
const area = (normalizedBbox[2] - normalizedBbox[0]) * (normalizedBbox[3] - normalizedBbox[1]);
|
||||
const safeBbox = Number.isFinite(area) && area <= MAX_VESSEL_SUBSCRIPTION_BBOX_AREA
|
||||
? normalizedBbox
|
||||
: DEFAULT_VESSEL_VIEWPORT.bbox;
|
||||
const zoom = Number.isFinite(Number(options.zoom))
|
||||
? Number(options.zoom)
|
||||
: DEFAULT_VESSEL_VIEWPORT.zoom;
|
||||
return {
|
||||
bbox: safeBbox,
|
||||
zoom: Math.max(1, Math.min(20, Math.round(zoom))),
|
||||
limit: options.limit ?? VESSEL_CONFIG.maxRenderedMarkers,
|
||||
};
|
||||
}
|
||||
|
||||
export function startVesselRealtime(earth, { onUpdate, bbox, zoom, limit } = {}) {
|
||||
if (vesselStreamSocket || typeof WebSocket === "undefined") return;
|
||||
const subscriptionOptions = normalizeVesselViewportOptions({ bbox, zoom, limit });
|
||||
const connect = () => {
|
||||
if (!showVessels || vesselStreamSocket) return;
|
||||
const socket = new WebSocket(getVesselStreamUrl());
|
||||
@@ -369,9 +396,9 @@ export function startVesselRealtime(earth, { onUpdate } = {}) {
|
||||
type: "subscribe",
|
||||
data: {
|
||||
channel: "vessels",
|
||||
bbox: DEFAULT_VESSEL_VIEWPORT.bbox,
|
||||
zoom: DEFAULT_VESSEL_VIEWPORT.zoom,
|
||||
limit: VESSEL_CONFIG.maxRenderedMarkers,
|
||||
bbox: subscriptionOptions.bbox,
|
||||
zoom: subscriptionOptions.zoom,
|
||||
limit: subscriptionOptions.limit,
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user