mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Map stacks off the Cesium allow-list: providers move into the Cesium adapter
The map stacks' imagery, terrain and Google 3D factories move into the Cesium adapter (src/render/cesium/mapImagery.js, mapTerrain.js, google3d.js); the ./maps/imagery, ./maps/terrain and ./maps/3d exports point there. The catalog names its ion stacks by asset number, and the map source controller and default sources are Cesium-free: they build providers and switch imagery layers, terrain, tilesets and the globe's visibility through a map engine (src/maps/engine.js) that the Cesium adapter provides as it loads (mapEngine.js), through the application's renderer or the ./render/cesium/unbound export. The controller and createDefaultMapSources also take it as an `engine` option. src/maps/catalog.js, controller.js, imagery.js, terrain.js and google3d.js leave the allow-list.
This commit is contained in:
1 parent
aea5c3acc6
commit
a8a9cc73a4
31 files changed
+364
-140
No files matched your search
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @module render/cesium/mapImagery
|
||||
* @description The map stacks' imagery for the Cesium renderer: OSM, Esri
|
||||
* World Imagery and Cesium ion's world imagery (Bing over HTTPS).
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
export { ESRI_ATTRIBUTION_HTML } from '../../maps/attribution.js';
|
||||
|
||||
export function createOsmImagery() {
|
||||
return new Cesium.OpenStreetMapImageryProvider({
|
||||
url: 'https://tile.openstreetmap.org/',
|
||||
credit: '© OpenStreetMap contributors',
|
||||
});
|
||||
}
|
||||
|
||||
export function createEsriImagery() {
|
||||
return Cesium.ArcGisMapServerImageryProvider.fromUrl(
|
||||
'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer',
|
||||
{
|
||||
credit:
|
||||
'Powered by Esri — Source: Esri, Maxar, Earthstar Geographics, and the GIS User Community',
|
||||
enablePickFeatures: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function createIonImagery(style, accessToken) {
|
||||
accessToken = String(accessToken || '').trim();
|
||||
if (!accessToken) throw new Error('Ion imagery requires an explicit token');
|
||||
if (
|
||||
style === Cesium.IonWorldImageryStyle.AERIAL ||
|
||||
style === Cesium.IonWorldImageryStyle.AERIAL_WITH_LABELS
|
||||
) {
|
||||
return createBingIonImagery(style, accessToken);
|
||||
}
|
||||
return Cesium.IonImageryProvider.fromAssetId(style, { accessToken });
|
||||
}
|
||||
|
||||
async function createBingIonImagery(style, accessToken) {
|
||||
const endpoint = await new Cesium.Resource({
|
||||
url: `https://api.cesium.com/v1/assets/${style}/endpoint`,
|
||||
queryParameters: { access_token: accessToken },
|
||||
}).fetchJson();
|
||||
if (
|
||||
endpoint?.type !== 'IMAGERY' ||
|
||||
endpoint.externalType !== 'BING' ||
|
||||
typeof endpoint.options?.url !== 'string'
|
||||
) {
|
||||
throw new Error('Ion world imagery did not return a Bing imagery endpoint');
|
||||
}
|
||||
// Bing otherwise follows the page's HTTP scheme on localhost. Resolve its
|
||||
// ion-issued credentials through public APIs so tiles use HTTPS without
|
||||
// weakening CSP, changing SDK defaults or touching provider internals.
|
||||
const { url, ...options } = endpoint.options;
|
||||
const provider = await Cesium.BingMapsImageryProvider.fromUrl(url, {
|
||||
...options,
|
||||
tileProtocol: 'https',
|
||||
});
|
||||
const ionCredits = (endpoint.attributions ?? []).map(
|
||||
({ html, collapsible }) => new Cesium.Credit(html, collapsible === false),
|
||||
);
|
||||
const getTileCredits = provider.getTileCredits.bind(provider);
|
||||
provider.getTileCredits = (x, y, level) => [
|
||||
...ionCredits,
|
||||
...(getTileCredits(x, y, level) ?? []),
|
||||
];
|
||||
return provider;
|
||||
}
|
||||
Reference in new issue
Block a user