UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 10.8 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../request.js";import{createTask as r}from"../core/asyncUtils.js";import{clone as i}from"../core/lang.js";import{MultiOriginJSONSupportMixin as o}from"../core/MultiOriginJSONSupport.js";import{throwIfAbortError as s}from"../core/promiseUtils.js";import{urlToObject as l,addQueryParameters as a,isProtocolRelative as n,normalize as p}from"../core/urlUtils.js";import{property as y,subclass as u}from"../core/accessorSupport/decorators.js";import c from"../geometry/Extent.js";import m from"../geometry/SpatialReference.js";import h from"./Layer.js";import{APIKeyMixin as d}from"./mixins/APIKeyMixin.js";import{ArcGISCachedService as S}from"./mixins/ArcGISCachedService.js";import{ArcGISService as f}from"./mixins/ArcGISService.js";import{BlendLayer as g}from"./mixins/BlendLayer.js";import{CustomParametersMixin as v}from"./mixins/CustomParametersMixin.js";import{OperationalLayer as _}from"./mixins/OperationalLayer.js";import{PortalLayer as j}from"./mixins/PortalLayer.js";import{RefreshableLayer as w}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as b}from"./mixins/ScaleRangeLayer.js";import{url as I}from"./support/commonProperties.js";import{checkWebPSupport as T}from"./support/imageUtils.js";import x from"./support/SpriteSource.js";import U from"./support/TileInfo.js";import{TilemapCache as L}from"./support/TilemapCache.js";import{loadMetadata as P}from"./support/vectorTileLayerLoader.js";import{createForItemRead as R}from"../portal/support/jsonContext.js";import{parseKnownArcGISOnlineDomain as O}from"../portal/support/urlUtils.js";import{e as M}from"../chunks/persistableUrlUtils.js";import{areSchemasOverlapping as C,unionTileInfos as D}from"../views/2d/engine/vectorTiles/tileInfoUtils.js";import V from"../views/2d/engine/vectorTiles/style/StyleRepository.js";import{getWebGLCapabilities as E}from"../views/webgl/capabilities.js";import{addLayerUnsupportedError as N}from"../webdoc/support/unsupportedErrors.js";import{writer as k}from"../core/accessorSupport/decorators/writer.js";import{reader as K}from"../core/accessorSupport/decorators/reader.js";let B=class extends(g(b(w(S(f(_(j(v(d(o(h))))))))))){constructor(...e){super(...e),this._spriteSourceMap=new Map,this.currentStyleInfo=null,this.isReference=null,this.operationalLayerType="VectorTileLayer",this.path=null,this.refreshInterval=0,this.style=null,this.tilemapCache=null,this.type="vector-tile"}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}destroy(){if(this.sourceNameToSource)for(const e of Object.values(this.sourceNameToSource))e?.destroy();this.primarySource?.destroy(),this._spriteSourceMap.clear()}async prefetchResources(e){await this.loadSpriteSource(globalThis.devicePixelRatio||1,e)}load(e){const r=this.loadFromPortal({supportedTypes:["Vector Tile Service"],supportsData:!1},e).catch(s).then(async()=>{if(!this.portalItem?.id)return;const r=`${this.portalItem.itemCdnUrl}/resources/styles/root.json`;(await t(r,{...e,query:{f:"json",...this.customParameters,token:this.apiKey},authMode:this.portalItem.portal.authMode})).data&&this.read({url:r},R(this.portalItem,"portal-item"))}).catch(s).then(()=>this._loadStyle(e));return this.addResolvingPromise(r),Promise.resolve(this)}get apiKey(){return super.apiKey}set apiKey(e){super.apiKey=e}get portalItem(){return super.portalItem}set portalItem(e){super.portalItem=e}get attributionDataUrl(){const e=this.currentStyleInfo,t=e?.serviceUrl&&l(e.serviceUrl);if(!t)return null;const r=this._getDefaultAttribution(t.path);return r?a(r,{...this.customParameters,token:this.apiKey}):null}get capabilities(){const e=this.primarySource;return e?e.capabilities:{operations:{supportsExportTiles:!1,supportsTileMap:!1},exportTiles:null}}get fullExtent(){return this.primarySource?.fullExtent||null}get initialExtent(){return this.primarySource?.initialExtent||null}get parsedUrl(){return this.serviceUrl?l(this.serviceUrl):null}get serviceUrl(){return this.currentStyleInfo?.serviceUrl||null}get spatialReference(){return this.tileInfo?.spatialReference??null}get styleUrl(){return this.currentStyleInfo?.styleUrl||null}writeStyleUrl(e,t){e&&n(e)&&(e=`https:${e}`);const r=O(e);t.styleUrl=M(e,r)}get tileInfo(){const e=[];for(const r in this.sourceNameToSource)e.push(this.sourceNameToSource[r]);let t=this.primarySource?.tileInfo||new U;if(e.length>1)for(let r=0;r<e.length;r++)C(t,e[r].tileInfo)&&(t=D(t,e[r].tileInfo));return t}readTilemapCache(e,t){const r=t.capabilities?.includes("Tilemap");return r?new L({layer:this}):null}set url(e){if(!e)return void this._set("url",e);const t=l(e);this._set("url",t.path),t.query&&(this.customParameters={...this.customParameters,...t.query})}readVersion(e,t){return t.version?parseFloat(t.version):parseFloat(t.currentVersion)}async loadSpriteSource(e=1,t){if(!this._spriteSourceMap.has(e)){const r=E().maxTextureSize,i=this.currentStyleInfo?.spriteUrl?a(this.currentStyleInfo.spriteUrl,{...this.customParameters,token:this.apiKey}):null,o=new x({type:"url",spriteUrl:i,pixelRatio:e,spriteFormat:this.currentStyleInfo?.spriteFormat},r);await o.load(t),this._spriteSourceMap.set(e,o)}return this._spriteSourceMap.get(e)}async setSpriteSource(e,t){if(!e)return null;const r=E().maxTextureSize,i=e.spriteUrl,o=i?a(i,{...this.customParameters,token:this.apiKey}):null;if(!o&&"url"===e.type)return null;const l=new x(e,r);try{await l.load(t);const r=e.pixelRatio||1;return this._spriteSourceMap.clear(),this._spriteSourceMap.set(r,l),o&&this.currentStyleInfo&&(this.currentStyleInfo.spriteUrl=o),this.emit("spriteSource-change",{spriteSource:l}),l}catch(n){s(n)}return null}async loadStyle(e,t){const i=e||this.style||this.url;return this._loadingTask&&"string"==typeof i&&this.url===i||(this._loadingTask?.abort(),this._loadingTask=r(e=>(this._spriteSourceMap.clear(),this._getSourceAndStyle(i,{signal:e})),t)),this._loadingTask.promise}getStyleLayerId(e){return this.styleRepository.getStyleLayerId(e)}getStyleLayerIndex(e){return this.styleRepository.getStyleLayerIndex(e)}getPaintProperties(e){return i(this.styleRepository?.getPaintProperties(e))}setPaintProperties(e,t){const r=this.styleRepository.isPainterDataDriven(e);this.styleRepository.setPaintProperties(e,t);const i=this.styleRepository.isPainterDataDriven(e);this.emit("paint-change",{layer:e,paint:t,isDataDriven:r||i})}getStyleLayer(e){return i(this.styleRepository.getStyleLayer(e))}setStyleLayer(e,t){this.styleRepository.setStyleLayer(e,t),this.emit("style-layer-change",{layer:e,index:t})}deleteStyleLayer(e){this.styleRepository.deleteStyleLayer(e),this.emit("delete-style-layer",{layer:e})}getLayoutProperties(e){return i(this.styleRepository.getLayoutProperties(e))}setLayoutProperties(e,t){this.styleRepository.setLayoutProperties(e,t),this.emit("layout-change",{layer:e,layout:t})}setStyleLayerVisibility(e,t){this.styleRepository.setStyleLayerVisibility(e,t),this.emit("style-layer-visibility-change",{layer:e,visibility:t})}getStyleLayerVisibility(e){return this.styleRepository.getStyleLayerVisibility(e)}write(e,t){return t?.origin&&!this.styleUrl?(N(t,this,"style defined by JSON only are not supported"),null):super.write(e,t)}getTileUrl(e,t,r){return null}async _getSourceAndStyle(e,t){if(!e)throw new Error("invalid style!");const r=await P(e,{...t,query:{...this.customParameters,token:this.apiKey}});if("webp"===r.spriteFormat){await T("lossy")||(r.spriteFormat="png")}this._set("currentStyleInfo",{...r}),"string"==typeof e?(this.url=e,this.style=null):(this.url=null,this.style=e),this._set("sourceNameToSource",r.sourceNameToSource),this._set("primarySource",r.sourceNameToSource[r.primarySourceName]),this._set("styleRepository",new V(r.style,!1)),this.read(r.layerDefinition,{origin:"service"}),this.emit("load-style")}_getDefaultAttribution(e){const t=e.match(/^https?:\/\/(?:basemaps|basemapsbeta|basemapsdev)(?:-api)?\.arcgis\.com(\/[^/]+)?\/arcgis\/rest\/services\/([^/]+(\/[^/]+)*)\/vectortileserver/i),r=["OpenBasemap_v2","OpenBasemap_GCS_v2","OpenStreetMap_v2","OpenStreetMap_Daylight_v2","OpenStreetMap_Export_v2","OpenStreetMap_FTS_v2","OpenStreetMap_GCS_v2","World_Basemap","World_Basemap_v2","World_Basemap_Export_v2","World_Basemap_GCS_v2","World_Basemap_WGS84","World_Contours_v2","World_Hillshade_v2"];if(!t)return;const i=t[2]&&t[2].toLowerCase();if(!i)return;const o=t[1]||"";for(const s of r)if(s.toLowerCase().includes(i))return p(`//static.arcgis.com/attribution/Vector${o}/${s}`)}async _loadStyle(e){return this._loadingTask?.promise??this.loadStyle(null,e)}};e([y({readOnly:!0})],B.prototype,"attributionDataUrl",null),e([y({type:["show","hide"]})],B.prototype,"listMode",void 0),e([y({json:{read:!0,write:!0}})],B.prototype,"blendMode",void 0),e([y({readOnly:!0,json:{read:!1}})],B.prototype,"capabilities",null),e([y({readOnly:!0})],B.prototype,"currentStyleInfo",void 0),e([y({json:{read:!1},readOnly:!0,type:c})],B.prototype,"fullExtent",null),e([y({json:{read:!1},readOnly:!0,type:c})],B.prototype,"initialExtent",null),e([y({type:Boolean,json:{read:!1,write:{enabled:!0,overridePolicy:()=>({enabled:!1})}}})],B.prototype,"isReference",void 0),e([y({type:["VectorTileLayer"]})],B.prototype,"operationalLayerType",void 0),e([y({readOnly:!0})],B.prototype,"parsedUrl",null),e([y({type:String,json:{origins:{"web-scene":{read:!0,write:!0}},read:!1}})],B.prototype,"path",void 0),e([y({type:Number,json:{write:!1,origins:{"web-map":{write:!1},"web-scene":{write:!1},"portal-item":{write:!1}}}})],B.prototype,"refreshInterval",void 0),e([y()],B.prototype,"style",void 0),e([y({readOnly:!0})],B.prototype,"serviceUrl",null),e([y({type:m,readOnly:!0})],B.prototype,"spatialReference",null),e([y({readOnly:!0})],B.prototype,"styleRepository",void 0),e([y({readOnly:!0})],B.prototype,"sourceNameToSource",void 0),e([y({readOnly:!0})],B.prototype,"primarySource",void 0),e([y({type:String,readOnly:!0,json:{write:{ignoreOrigin:!0},origins:{"web-document":{write:{ignoreOrigin:!0,isRequired:!0}}}}})],B.prototype,"styleUrl",null),e([k(["portal-item","web-document"],"styleUrl")],B.prototype,"writeStyleUrl",null),e([y({json:{read:!1,origins:{service:{read:!1}}},readOnly:!0,type:U})],B.prototype,"tileInfo",null),e([y()],B.prototype,"tilemapCache",void 0),e([K("service","tilemapCache",["capabilities","tileInfo"])],B.prototype,"readTilemapCache",null),e([y({json:{read:!1},readOnly:!0,value:"vector-tile"})],B.prototype,"type",void 0),e([y({json:{origins:{"web-document":{read:{source:"styleUrl"}},"portal-item":{read:{source:"url"}}},write:!1,read:!1}}),y(I)],B.prototype,"url",null),e([y({readOnly:!0})],B.prototype,"version",void 0),e([K("version",["version","currentVersion"])],B.prototype,"readVersion",null),B=e([u("esri.layers.VectorTileLayer")],B);const A=B;export{A as default};