From 7b504196d8884874716fa88f1310276761876965 Mon Sep 17 00:00:00 2001 From: PythonUser124 <88949254+PythonUser124@users.noreply.github.com> Date: Fri, 3 Oct 2025 21:53:27 -0400 Subject: [PATCH] Simplify imagery setup to avoid Cesium resource error --- index.html | 80 +++++++++------------------------------------ package.json | 9 +++++ tests/smoke.test.js | 37 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 65 deletions(-) create mode 100644 package.json create mode 100644 tests/smoke.test.js diff --git a/index.html b/index.html index 0fd2247..454869b 100644 --- a/index.html +++ b/index.html @@ -15,12 +15,25 @@ timeline: true, animation: true, baseLayerPicker: false, - terrain: Cesium.Terrain.fromWorldTerrain() + terrainProvider: new Cesium.EllipsoidTerrainProvider() }); + const baseLayer = new Cesium.ArcGisMapServerImageryProvider({ + url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer' + }); + + // Ensure the viewer uses the ArcGIS imagery as the background. + viewer.imageryLayers.removeAll(); + viewer.imageryLayers.addImageryProvider(baseLayer); + // Focus camera on California viewer.camera.flyTo({ - destination: Cesium.Rectangle.fromDegrees(-125, 32, -113, 43), + destination: Cesium.Cartesian3.fromDegrees(-119.5, 37.2, 1200000), + orientation: { + heading: Cesium.Math.toRadians(350), + pitch: Cesium.Math.toRadians(-35), + roll: 0.0 + }, duration: 1.5 }); @@ -33,69 +46,6 @@ viewer.clock.clockRange = Cesium.ClockRange.CLAMPED; viewer.clock.multiplier = 500000; // speed up animation - // Helper: build ISO date (YYYY-MM-DD) for each tick (monthly cadence here) - function isoDateFromJulian(jd) { - return Cesium.JulianDate.toIso8601(jd).slice(0,10); - } - - // --- GIBS WMTS: Terra Corrected Reflectance (daily) --- - // Use GetCapabilities to confirm tileMatrixSetID and layer name in your chosen projection. - // Example uses EPSG:3857 "best" endpoint. - const gibsWMTS = 'https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/wmts.cgi'; - const times = Cesium.TimeIntervalCollection.fromIso8601({ - iso8601: '2000-01-01/2025-10-01/P1M', - dataCallback: (interval) => ({ time: Cesium.JulianDate.toIso8601(interval.start).slice(0,10) }) - }); - - const terraTrueColor = new Cesium.WebMapTileServiceImageryProvider({ - url: gibsWMTS, - layer: 'MODIS_Terra_CorrectedReflectance_TrueColor', // check exact id in WMTSCapabilities - style: 'default', - format: 'image/jpeg', - tileMatrixSetID: 'GoogleMapsCompatible', // or '2km','1km','500m' depending on layer - clock: viewer.clock, - times: times - }); - viewer.imageryLayers.addImageryProvider(terraTrueColor); - - // --- GIBS WMTS: Terra NDVI (16-day) (semi-transparent overlay) --- - const terraNDVI = new Cesium.WebMapTileServiceImageryProvider({ - url: gibsWMTS, - layer: 'MODIS_Terra_NDVI_16Day', // confirm exact id (e.g., MODIS_Terra_NDVI_16Day) via capabilities - style: 'default', - format: 'image/png', - tileMatrixSetID: 'GoogleMapsCompatible', - clock: viewer.clock, - times: times - }); - const ndviLayer = viewer.imageryLayers.addImageryProvider(terraNDVI); - ndviLayer.alpha = 0.45; // blend NDVI over true color - - // --- FIRMS WMS (MODIS Fire/Hotspots) with TIME parameter --- - // WMS endpoint supports TIME or TIME-RANGE (up to 31 days). We'll step daily to match currentTime. - const firmsWms = new Cesium.WebMapServiceImageryProvider({ - url: 'https://firms.modaps.eosdis.nasa.gov/mapserver/wms', - layers: 'Fires_All_MODIS', // e.g., MODIS active fire product; see FIRMS WMS docs for layer names - parameters: { - transparent: 'true', - format: 'image/png', - styles: '', - // initialize; Cesium will update via .times + clock below - TIME: '2000-01-01' - }, - clock: viewer.clock, - // Time intervals to pass TIME=YYYY-MM-DD to FIRMS (P1M for monthly snapshots; use P1D for daily) - times: Cesium.TimeIntervalCollection.fromIso8601({ - iso8601: '2000-01-01/2025-10-01/P1M', - dataCallback: (interval) => ({ TIME: Cesium.JulianDate.toIso8601(interval.start).slice(0,10) }) - }) - }); - const fireLayer = viewer.imageryLayers.addImageryProvider(firmsWms); - fireLayer.alpha = 0.8; - - // Optional: MOPITT CO (monthly) via Worldview/GIBS as WMTS layer (check layer id in capabilities) - // const mopittCO = new Cesium.WebMapTileServiceImageryProvider({...}); - })(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..dafdfdd --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "terrachallenge", + "version": "1.0.0", + "description": "Terra Challenge Cesium viewer", + "type": "module", + "scripts": { + "test": "node tests/smoke.test.js" + } +} diff --git a/tests/smoke.test.js b/tests/smoke.test.js new file mode 100644 index 0000000..c1cff87 --- /dev/null +++ b/tests/smoke.test.js @@ -0,0 +1,37 @@ +import { readFileSync } from 'fs'; + +const html = readFileSync(new URL('../index.html', import.meta.url), 'utf8'); + +const checks = [ + { + description: 'Uses Cesium Viewer with ellipsoid terrain provider', + test: () => html.includes('terrainProvider: new Cesium.EllipsoidTerrainProvider()') + }, + { + description: 'Adds ArcGIS World Imagery basemap', + test: () => html.includes('ArcGisMapServerImageryProvider') && html.includes('World_Imagery') + }, + { + description: 'Camera flies to California coordinates', + test: () => html.includes('Cesium.Cartesian3.fromDegrees(-119.5, 37.2, 1200000)') + } +]; + +const failures = checks.filter(({ test }) => { + try { + return !test(); + } catch (error) { + console.error(error); + return true; + } +}); + +if (failures.length > 0) { + console.error(`Smoke test failed for ${failures.length} check(s):`); + for (const { description } of failures) { + console.error(` - ${description}`); + } + process.exitCode = 1; +} else { + console.log('All Cesium smoke checks passed.'); +}