UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.65 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{isSome as e}from"../../../core/arrayUtils.js";import t from"../../../core/Error.js";import{throwIfAborted as a}from"../../../core/promiseUtils.js";import{isTiledLayer as i,isBasemap3DSupportedLayer as r,isBasemapSupportedTiledLayer as n}from"../../../layers/support/layerUtils.js";import{stringFromViewingMode as s,ViewingMode as l}from"../../../views/ViewingMode.js";import{getTileInfoAndExtentFromWMTSLayer as o,checkIfTileInfoSupportedForView as p}from"../../../views/3d/terrain/terrainUtils.js";import{TilingScheme as c}from"../../../views/3d/terrain/TilingScheme.js";import{isSpatialReferenceSupported as m}from"../../../views/support/spatialReferenceSupport.js";async function f(e,t={}){const{basemap:i,view:r}=e;await i.load(t),y(i),await h(i,r,t),a(t)}async function u(t,r={}){const{basemap:n,view:s}=t;a(r);const l=n.baseLayers.find((e=>"unknown"===e.type))?.loadError;if(null!=l)throw l;if(!s||"spatialReferenceLocked"in s&&!s.spatialReferenceLocked)return;if(await n.load(r),a(r),0===n.baseLayers.length)return;const o=n.baseLayers.at(0);if(!i(o))return;if(n.spatialReference){if(s.spatialReference.equals(n.spatialReference))return;w()}await o.load(r),a(r);const p=(("supportedSpatialReferences"in o?o.supportedSpatialReferences:null)||["tileInfo"in o?o.tileInfo?.spatialReference:null]).filter(e);0!==p.length&&p.every((e=>!s.spatialReference.equals(e)))&&w()}function w(){throw new t("basemap-compatibility:incompatible-spatial-reference","Basemap spatial reference is not compatible with the view")}function y(e){if(0===e.baseLayers.length&&0===e.referenceLayers.length)return;const t=e.baseLayers.concat(e.referenceLayers).toArray().filter((e=>!r(e))).map((e=>b(e)));if(t.length)throw t[0]}function b(e){return new t("basemap-compatibility:unsupported-basemap-layer-type","Unsupported basemap layer type ${operationalLayerType}",{layer:e,operationalLayerType:e.operationalLayerType||"unknown"})}async function h(e,a,i){if(0===e.baseLayers.length)return;const r=e.baseLayers.at(0);if(n(r)){try{await r.load(i)}catch(s){const e="basemap-compatibility:unknown-error",a="Unknown basemap compatibility error",{name:i=e,message:r=a,details:n}=s;throw new t(i,r,n)}g(r,a)}}function g(e,a){const i=a.state.viewingMode;if(!i)return;let r,n;if("wmts"===e?.type){const s=o(e,a.spatialReference,i);if(null==s.tileInfo)throw new t("basemapgalleryitem:tiling-scheme-incompatible","Basemap tiling scheme is incompatible with the view");r=s.tileInfo,n=s.fullExtent}else r=e.tileInfo,n=e.fullExtent;if(null==r)return;if(!m(r.spatialReference,i))throw new t(`basemapgalleryitem:spatial-reference-unsupported-${s(i)}`,`Basemap spatial reference is unsupported in ${s(i)} mode`);const f="vector-tile"===e?.type?r.getCompatibleForVTL(256):null;if(i===l.Global){let a=p(r,n,null,i);if(a&&"vector-tile"===e?.type&&null!=n&&f&&!p(f,n,null,i)&&(a=null),a){const e=r.spatialReference.isWebMercator?"web-mercator":"wgs84";throw new t(`basemapgalleryitem:tiling-scheme-unsupported-${e}-global`,"Basemap tiling scheme is unsupported in global mode",{error:a})}}else if(c.checkUnsupported(r))throw new t("basemapgalleryitem:tiling-scheme-unsupported-local","Basemap tiling scheme is unsupported in local mode");const u=a.basemapTerrain?.tilingScheme;if(u&&!u.compatibleWith(r)&&("vector-tile"!==e?.type||!f||!u.compatibleWith(f)))throw new t("basemapgalleryitem:tiling-scheme-incompatible","Basemap tiling scheme is incompatible with the view")}export{u as default2DCompatibility,f as default3DCompatibility};