Files
planet/frontend/public/earth/js/constants.js
T

692 lines
17 KiB
JavaScript

// constants.js - Global constants and configuration
// Scene configuration
export const CONFIG = {
defaultCameraZ: 300,
defaultViewZoom: 1.0,
minZoom: 0.22,
maxZoom: 5.0,
earthRadius: 100,
rotationSpeed: 0.0005,
minimumCameraAltitude: 10,
dragRotationFactorBase: 0.005,
dragRotationZoomExponent: 1.8,
dragRotationScaleMin: 0.12,
dragRotationScaleMax: 1.65,
};
export const ROTATION_MODE = {
ROTATE: "rotate",
CRUISE: "cruise",
MOTION: "motion",
};
export const CRUISE_MODULES = {
BGP: "bgp",
NEWS: "news",
COMPUTE_CENTERS: "computeCenters",
VESSELS: "vessels",
CABLES: "cables",
SATELLITES: "satellites",
};
export const DEFAULT_CRUISE_MODULES = [CRUISE_MODULES.BGP];
export const CRUISE_QUEUE_MODES = {
DEFAULT: "default",
REGION: "region",
RANDOM: "random",
};
export const DEFAULT_CRUISE_QUEUE_MODE = CRUISE_QUEUE_MODES.DEFAULT;
export const DEFAULT_CRUISE_REGION_ORDER = [
"americas",
"europe",
"middle-east-africa",
"asia-pacific",
"global",
];
export const SURFACE_HOVER_INFO_MODES = {
COUNTRY: "country",
POSITION: "position",
FULL: "full",
};
export const DEFAULT_SURFACE_HOVER_INFO_MODE =
SURFACE_HOVER_INFO_MODES.FULL;
export const CALLOUT_LINE_STYLES = {
THIN: "thin",
BOLD: "bold",
};
export const DEFAULT_CALLOUT_LINE_STYLE = CALLOUT_LINE_STYLES.THIN;
const EARTH_SURFACE_FILL_ALTITUDE_OFFSET = 0.32;
export const EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET = 0.48;
export const CRUISE_CONFIG = {
dwellMs: 7_000,
focusDurationMs: 1_400,
pollIntervalMs: 15_000,
maxPolledEvents: 200,
cardAnchorXRatio: 0.68,
cardAnchorYRatio: 0.24,
};
export const CONNECTOR_CONFIG = {
markerGapPx: 18,
panelGapPx: 12,
obstacleClearancePx: 8,
};
export const HUD_CONFIG = {
scaleReferenceWidth: 1920,
scaleReferenceHeight: 1080,
minScale: 0.7,
maxScale: 1,
brandLanguage: "zh",
};
// Earth coordinate constants
export const EARTH_CONFIG = {
tilt: 23.5, // earth tilt angle (degrees)
tiltRad: 23.5 * Math.PI / 180, // earth tilt angle (radians)
// hangzhou coordinates
chinaLat: 30.2741,
chinaLon: 120.1552,
chinaRotLon: 120.1552 - 270, // for rotation calculation (chinaLon - 270)
// view reset coefficient
latCoefficient: 0.5
};
export const CELESTIAL_CONFIG = {
enabled: true,
updateIntervalMs: 10_000,
skyRadius: 2600,
skyOpacity: 1,
skyBrightness: 2.0, // Default 200% starfield visibility
starMapUrl: "./assets/celestial/starmap_deep_8k.jpg",
brightStarsUrl: "./assets/celestial/bright-stars.json",
orientationEulerRad: {
x: 0.46,
y: 1.18,
z: -0.08,
},
followEarthRotation: {
enabled: true,
x: true,
y: true,
z: false,
invertX: true,
invertY: false,
invertZ: false,
},
sunDistance: 2150,
moonDistance: 2050,
sunScale: 78,
moonScale: 38,
sunHaloScale: 136,
moonHaloScale: 62,
brightStarDistance: 2350,
brightStarMinMag: 2.1,
brightStarMaxCount: 36,
brightStarMinScale: 2.4,
brightStarMaxScale: 6.8,
brightStarOpacity: 0.88,
sunLightDistance: 460,
sunLightIntensity: 1.02,
sunLightColor: 0xfff4df,
backLightIntensity: 0.3,
backLightColor: 0x2b4c78,
inspectionLighting: {
enabled: true,
ambientIntensity: 0.64,
ambientColor: 0x707070,
keyLightIntensity: 0.62,
keyLightColor: 0xfcfcfb,
keyLightDistance: 380,
keyLightOffset: { x: 0.42, y: 0.34, z: 0.84 },
backLightIntensity: 0.26,
backLightColor: 0x8f96a0,
backLightDistance: 260,
backLightOffset: { x: -0.52, y: -0.1, z: -0.62 },
pointLightIntensity: 0.12,
pointLightColor: 0xfafcff,
pointLightDistance: 320,
pointLightOffset: { x: 0.18, y: 0.52, z: 0.62 },
},
};
export const SCENE_LIGHT_CONFIG = {
ambient: {
color: 0x404060,
intensity: 1,
},
sun: {
color: 0xffffff,
intensity: 1.2,
position: { x: 5, y: 3, z: 5 },
},
back: {
color: 0x446688,
intensity: 0.3,
position: { x: -5, y: 0, z: -5 },
},
point: {
color: 0xffffff,
intensity: 0.4,
position: { x: 10, y: 10, z: 10 },
},
};
export const TERRAIN_CONFIG = {
enabled: true,
tileSize: 256,
baseZoom: 4,
geometryWidthSegments: 320,
geometryHeightSegments: 320,
baseRadiusOffset: 0.16,
exaggeration: 34,
landRevealFadeMeters: 220,
maxConcurrentRequests: 10,
batchRequestSize: 64,
opacity: 0.68,
color: 0x8aa884,
emissive: 0x030704,
specular: 0x000000,
shininess: 0,
urlTemplate:
"/api/v1/visualization/terrain/terrarium/{z}/{x}/{y}.png",
batchUrl: "/api/v1/visualization/terrain/terrarium/batch",
};
export const COUNTRY_BOUNDARY_CONFIG = {
// Verified China POV PMTiles artifacts are served by the backend (HTTP Range)
// so Web and the desktop client share one copy outside the Earth bundle.
tileManifestPath: "/api/v1/earth/boundaries/manifest",
tileFilesPath: "/api/v1/earth/boundaries/files/",
tileProvider: "auto",
mvtLayerNames: {
boundary: ["boundary_admin0", "boundary_disputed_internal", "coastline"],
admin1: ["boundary_admin1"],
claim: ["claim_line"],
},
// Compress 1x-5x into 4 clean tiers: NE admin0/admin1 saturate at z6 and overzoom above z6,
// while z8 refines OSM coastlines only. z9-z10 stay in PMTiles for future >5x zoom.
tileZoomThresholds: [
{ minViewZoom: 3.8, tileZoom: 8 },
{ minViewZoom: 2.3, tileZoom: 6 },
{ minViewZoom: 1.3, tileZoom: 4 },
{ minViewZoom: 0, tileZoom: 2 },
],
borderMaxZoom: 6,
tilePrefetchRing: 1,
tileDebounceMs: 180,
tileCacheLimit: 640,
// Admin-1 (province / state) lines fade in below the national borders.
admin1MinViewZoom: 2.0,
admin1FullViewZoom: 2.8,
admin1LineColor: 0x9fd0ff,
admin1LineOpacity: 0.26,
// Keep boundary/coastline strokes on the same shell as the high-res earth
// texture overlay. A lower or higher radius creates visible parallax while
// the globe rotates.
lineAltitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
hoverAltitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
claimLineAltitudeOffset: 0,
hoverMissStickyMs: 160,
lineColor: 0x7fc7ff,
lineOpacity: 0.58,
lineRenderOrder: 0.97,
dimmedLineOpacity: 0.18,
hoverLineColor: 0xff3b1f,
hoverLineOpacity: 1.0,
hoverLineRenderOrder: 0.99,
hoverGlowOpacity: 0.38,
hoverGlowLineWidth: 3,
hoverGlowRenderOrderOffset: 0.01,
hoverGlowRadiusOffset: 0,
// Tint and land fill share a depth-safe shell. Neither writes depth;
// renderOrder lets the loaded land fill replace the loading tint.
tintAltitudeOffset: EARTH_SURFACE_FILL_ALTITUDE_OFFSET,
tintColor: 0x0b1830,
tintRenderOrder: 0.2,
landColor: 0x080f1b,
landOpacity: 1.0,
landAltitudeOffset: EARTH_SURFACE_FILL_ALTITUDE_OFFSET,
landRenderOrder: 0.86,
landMaskWidth: 2048,
landMaskHeight: 1024,
};
export const GEO_LABEL_CONFIG = {
defaultEnabled: true,
maxVisibleDesktop: 28,
maxVisibleMobile: 14,
scanIntervalMs: 160,
occlusionRadiusFactor: 0.999,
altitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
tierFade: {
1: { minZoom: 1.7, fullZoom: 2.05 },
2: { minZoom: 2.75, fullZoom: 3.15 },
3: { minZoom: 3.75, fullZoom: 4.2 },
},
};
export const PATHS = {
cablesApi: '/api/v1/visualization/geo/cables',
landingPointsApi: '/api/v1/visualization/geo/landing-points',
computeCentersApi: '/api/v1/visualization/geo/compute-centers',
interactablesApi: '/api/v1/interactables/geojson',
vesselsApi: '/api/v1/vessels/snapshot',
vesselTrackApi: (mmsi) => `/api/v1/visualization/vessels/${encodeURIComponent(mmsi)}/track`,
bgpApi: '/api/v1/visualization/geo/bgp-anomalies',
bgpIncidentsApi: '/api/v1/visualization/geo/bgp-incidents',
bgpCollectorsApi: '/api/v1/visualization/geo/bgp-collectors',
earthSummaryApi: '/api/v1/visualization/geo/summary',
earthClientLogsApi: '/api/v1/system/logs/earth-client',
};
export const VESSEL_CONFIG = {
altitudeOffset: 0.2,
maxRenderedMarkers: 3000,
marker: {
baseScale: 7.5,
baseOpacity: 0.88,
hoverScale: 1.28,
lockedScale: 1.48,
dimmedScale: 0.78,
dimmedOpacity: 0.26,
},
colors: {
cargo: "#38bdf8",
tanker: "#f97316",
passenger: "#14b8a6",
fishing: "#f59e0b",
military: "#818cf8",
other: "#94a3b8",
},
sizeStabilization: {
min: 0.1,
max: 2.4,
},
track: {
altitudeOffset: 0.2,
color: 0x7dd3fc,
opacity: 0.82,
},
};
export const COMPUTE_CENTER_CONFIG = {
altitudeOffset: 0.48,
maxRenderedMarkers: 300,
overlapSpread: {
groupPrecision: 4,
minRadiusKm: 0.4,
maxRadiusKm: 6,
},
marker: {
baseOpacity: 0.88,
supercomputerScale: 12,
gpuClusterScale: 12,
hoverScale: 1.16,
lockedScale: 1.22,
dimmedScale: 0.82,
dimmedOpacity: 0.34,
pulseSpeed: 0.0038,
pulseAmplitude: 0.03,
},
colors: {
supercomputer: "#a855f7",
gpu_cluster: "#14b8a6",
data_center: "#818cf8",
cloud_center: "#38bdf8",
edge_node: "#f472b6",
infrastructure: "#14b8a6",
linked: "#f8fafc",
},
sizeStabilization: {
enabled: true,
min: 0.12,
max: 3.0,
},
};
// Cable colors mapping
export const CABLE_COLORS = {
'Americas II': 0xff4444,
'AU Aleutian A': 0x44ff44,
'AU Aleutian B': 0x4444ff,
'default': 0xffff44
};
export const CABLE_CONFIG = {
visual: {
normalTint: 0x328ebc,
sourceColorWeight: 0.38,
normalOpacity: 0.7,
pulseRepeats: 6,
pulseSpeed: 4.5,
},
lockedOpacityMin: 0.2,
lockedOpacityMax: 1.0,
otherOpacity: 0.5,
otherBrightness: 0.6,
pulseSpeed: 0.008,
pulseCoefficient: 0.4,
line: {
altitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
greatCircleSegments: 50,
nearPointThreshold: 0.01,
lineWidth: 1,
opacity: 1.0,
renderOrder: 1,
},
landingPoint: {
altitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
color: 0xf59e0b,
opacity: 1.0,
renderOrder: 1,
},
landingPointVisual: {
pulseSpeed: 0.003,
dimBrightness: 0.62,
related: {
haloScale: 1.65,
haloFalloff: 8,
},
dimmed: {
colorRGB: { r: 180, g: 116, b: 28 },
opacity: 0.78,
},
},
};
export const CABLE_STATE = {
NORMAL: 'normal',
HOVERED: 'hovered',
LOCKED: 'locked'
};
export const SATELLITE_CONFIG = {
workerStartupTimeoutMs: 10000,
maxCount: -1,
initialLoadCount: null,
hydrateFullAfterInitialLoad: false,
trailLength: 10,
trailSampleStepMs: 1400,
trailLineWidth: 2.4,
fallbackAltitudeOffset: 8,
altitudeCompressionKm: 1200,
defaultAltitudeCompression: 0,
maxDisplayAltitudeKm: 40000,
minRealAltitudeOffset: 4,
maxRealAltitudeOffset: 25,
maxTrueAltitudeOffset: 720,
frontFacingDotThreshold: 0.015,
occlusionRadiusFactor: 0.998,
overlayRenderOrder: 12,
dotBaseSize: 2.2,
labelMinZoom: 3.3,
labelMinZoomLowerBound: 2.5,
labelMinCount: 5,
labelDefaultCount: 16,
labelMaxCount: 36,
labelScanIntervalMs: 160,
footprintColor: 0x3399ff,
footprintOpacity: 0.34,
footprintDayVisibilityBoost: 1.65,
ringSize: 0.07,
apiPath: '/api/v1/visualization/geo/satellites',
breathingSpeed: 0.065,
defaultBreathingIntensity: 0.6,
minBreathingIntensity: 0.1,
maxBreathingIntensity: 1.0,
breathingScaleAmplitude: 0.22,
breathingOpacityMin: 0.34,
breathingOpacityMax: 0.9,
dotBreathingScaleAmplitude: 0.28,
dotOpacityMin: 0.72,
dotOpacityMax: 1.0
};
export const BGP_CONFIG = {
defaultFetchLimit: 200,
maxRenderedMarkers: 200,
altitudeOffset: 0.48,
collectorAltitudeOffset: 0.2,
marker: {
eventBaseScale: 6.2,
collectorBaseScale: 7.4,
hoverScale: 1.16,
dimmedScale: 0.92,
collectorStatusCoreBaseScale: 0.12,
collectorStatusCoreMinScale: 1.2,
},
pulse: {
eventSpeed: 0.0045,
collectorSpeed: 0.0024,
normalAmplitude: 0.03,
lockedAmplitude: 0.16,
},
regionScale: 11.5,
opacity: {
normal: 0.78,
hover: 1.0,
dimmed: 0.24,
collector: 0.62,
collectorHover: 0.9,
lockedMin: 0.65,
lockedMax: 1.0
},
severityColors: {
critical: 0xf43f5e,
high: 0xf97316,
medium: 0xf59e0b,
low: 0x38bdf8
},
severityScales: {
critical: 1.18,
high: 1.08,
medium: 1.0,
low: 0.94
},
collectorColor: 0x6db7ff,
collectorHeatColors: {
idle: 0x6db7ff,
low: 0x60a5fa,
medium: 0xfbbf24,
high: 0xfb923c,
hot: 0xff5f57
},
collectorIcon: {
ringStroke: "rgba(111, 160, 197, 0.34)",
ringLineWidth: 1.2,
ringRadius: 22,
pathStroke: "rgba(64, 106, 136, 0.74)",
pathLineWidth: 0.9,
pathFill: "rgba(214,224,233,0.88)",
centerFill: "rgba(222,231,239,0.72)",
centerRadius: 0.85,
idleBaseColor: 0xb7c4cf,
idleBlend: 0.56,
idleOpacity: 0.74,
hoverBlend: 0.42,
hoverNeutralColor: 0xc8d5e0,
lockedBlend: 0.48,
lockedNeutralColor: 0xd8e4ed,
dimmedColor: 0x7d8ca3,
},
regionColor: 0x2dd4bf,
ring: {
scaleA: 2.5,
scaleB: 3.4,
opacity: 0.5,
speed: 0.001,
},
halo: {
collectorScale: 11.5,
collectorPulseScale: 16.5,
collectorCoverageScale: 22.5,
tintNeutralColor: 0xffffff,
tintBlend: 0.72,
},
sizeStabilization: {
enabled: true,
collectorMin: 0.12,
collectorMax: 3.0,
eventMin: 0.12,
eventMax: 3.0,
},
};
export const GRID_CONFIG = {
radiusOffset: 0.14,
color: 0xc0e0ff,
opacity: 0.08,
lineWidth: 1,
renderOrder: 2.05,
latitudeStep: 15,
longitudeStep: 30,
segmentStep: 5,
};
export const CLOUD_LAYER_CONFIG = {
radiusOffset: 3,
shadowAltitudeOffset: 0.52,
widthSegments: 64,
heightSegments: 64,
opacity: 0.38,
shadowOpacity: 0.08,
textureUrl: "./assets/earth_clouds_2048.png",
};
export const DEFAULT_SURFACE_COLOR_GRADE = "classic-083";
export const SURFACE_COLOR_GRADES = Object.freeze({
"classic-083": Object.freeze({
id: "classic-083",
exposure: 0.92,
landSaturation: 0.88,
landGradeGain: 0.44,
landCoolBias: [0.004, 0.011, 0.028],
oceanAbsorption: 0.36,
oceanDeepColor: [0.004, 0.012, 0.032],
landReliefStrength: 0.10,
diffuseFloor: 0.78,
toneMapMode: 0,
}),
"fresh-natural": Object.freeze({
id: "fresh-natural",
exposure: 1.04,
landSaturation: 1.12,
landGradeGain: 1.0,
landCoolBias: [0.0, 0.0, 0.0],
oceanAbsorption: 0.56,
oceanDeepColor: [0.006, 0.018, 0.052],
landReliefStrength: 0.05,
diffuseFloor: 0.84,
toneMapMode: 1,
}),
"balanced-satellite": Object.freeze({
id: "balanced-satellite",
exposure: 1.0,
landSaturation: 0.96,
landGradeGain: 0.82,
landCoolBias: [0.001, 0.004, 0.01],
oceanAbsorption: 0.42,
oceanDeepColor: [0.004, 0.014, 0.038],
landReliefStrength: 0.06,
diffuseFloor: 0.82,
toneMapMode: 0,
}),
});
export function normalizeSurfaceColorGrade(id) {
return Object.prototype.hasOwnProperty.call(SURFACE_COLOR_GRADES, id)
? id
: DEFAULT_SURFACE_COLOR_GRADE;
}
export const EARTH_MATERIAL_CONFIG = {
// Base sphere sits below the country fill and high-res texture overlays.
// Keep it dark so a delayed overlay never flashes or reads as a white layer.
color: 0x010609,
specular: 0x000000,
shininess: 0,
emissive: 0x010609,
opacity: 1,
textureOverlayAltitudeOffset: EARTH_SURFACE_TEXTURE_ALTITUDE_OFFSET,
textureWidthSegments: 128,
textureHeightSegments: 128,
textureOverlayRenderOrder: 0.96,
// Depth-mask occluder keeps far-side objects hidden behind the earth
occluderRadiusFactor: 0.999,
occluderSegments: 48,
surface: {
colorGrade: DEFAULT_SURFACE_COLOR_GRADE,
exposure: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].exposure,
brightness: 1.0,
minBrightness: 0.65,
maxBrightness: 1.6,
brightnessStep: 0.05,
landSaturation: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].landSaturation,
landGradeGain: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].landGradeGain,
landCoolBias: [...SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].landCoolBias],
oceanAbsorption: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].oceanAbsorption,
oceanDeepColor: [...SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].oceanDeepColor],
diffuseFloor: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].diffuseFloor,
toneMapMode: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].toneMapMode,
// Independent night-side texture contrast and cool ambient, in linear RGB.
night: {
detailGamma: 0.55,
landTint: [0.07, 0.075, 0.08],
landAmbient: [0.003, 0.005, 0.008],
oceanTint: [0.008, 0.016, 0.024],
oceanAmbient: [0.0015, 0.004, 0.012],
},
terminator: [-0.14, 0.22],
oceanReflection: [0.025, 0.12, 0.32],
atmosphereColor: [0.08, 0.28, 0.65],
innerRimStrength: 0.28,
twilightWarmColor: [0.95, 0.38, 0.12],
twilightWarmStrength: 0.0,
sunglintStrength: 0.0,
landReliefStrength: SURFACE_COLOR_GRADES[DEFAULT_SURFACE_COLOR_GRADE].landReliefStrength,
},
atmosphere: {
radiusFactor: 1.025,
color: [0.18, 0.48, 0.88],
strength: 0.65,
mieColor: [0.92, 0.56, 0.30],
mieStrength: 0.18,
},
dayNight: {
enabled: true,
sunDirection: { x: 1, y: 0.2, z: 0.4 },
nightFloor: 0.24,
// Retain more contrast in source shadows without lifting their original color.
nightShadowFloor: 0.60,
nightShadowLuminance: 0.08,
twilightWidth: 0.12,
},
};
export const WEATHER_LAYER_DEFINITIONS = Object.freeze([
Object.freeze({ id: "clouds", label: "大气云图" }),
Object.freeze({ id: "wind", label: "全球风场" }),
]);
export const DEFAULT_WEATHER_LAYERS = Object.freeze({
clouds: true,
wind: true,
});