@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 11.2 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as e}from"../chunks/tslib.es6.js";import t from"../PopupTemplate.js";import r from"../request.js";import i from"../core/Clonable.js";import o from"../core/Error.js";import{handlesGroup as s}from"../core/handleUtils.js";import{clone as n}from"../core/lang.js";import a from"../core/Logger.js";import{MultiOriginJSONMixin as p}from"../core/MultiOriginJSONSupport.js";import{debounce as l,throwIfAbortError as m}from"../core/promiseUtils.js";import{property as d}from"../core/accessorSupport/decorators/property.js";import{Integer as c}from"../core/accessorSupport/ensureType.js";import{reader as u}from"../core/accessorSupport/decorators/reader.js";import{subclass as y}from"../core/accessorSupport/decorators/subclass.js";import f from"../geometry/Extent.js";import h from"../geometry/SpatialReference.js";import{featureGeometryTypeKebabDictionary as g}from"../geometry/support/typeUtils.js";import j from"./Layer.js";import{ArcGISService as v}from"./mixins/ArcGISService.js";import{BlendLayer as w}from"./mixins/BlendLayer.js";import{CustomParametersMixin as b}from"./mixins/CustomParametersMixin.js";import{DisplayFilteredLayer as S}from"./mixins/DisplayFilteredLayer.js";import{FeatureEffectLayer as I}from"./mixins/FeatureEffectLayer.js";import{FeatureReductionLayer as x}from"./mixins/FeatureReductionLayer.js";import{OperationalLayer as R}from"./mixins/OperationalLayer.js";import{PortalLayer as T}from"./mixins/PortalLayer.js";import{RefreshableLayer as F}from"./mixins/RefreshableLayer.js";import{ScaleRangeLayer as L}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as P}from"./mixins/TemporalLayer.js";import{TrackableLayer as U}from"./mixins/TrackableLayer.js";import{labelsVisible as E,legendEnabled as k,maxScale as A,minScale as O,popupEnabled as D,screenSizePerspectiveEnabled as C,url as _}from"./support/commonProperties.js";import{createDefaultRenderer as N}from"./support/featureLayerUtils.js";import V from"./support/Field.js";import{defineFieldProperties as M}from"./support/fieldProperties.js";import{fixRendererFields as G,fixTimeInfoFields as J}from"./support/fieldUtils.js";import z from"./support/LabelClass.js";import{reader as $}from"./support/labelingInfo.js";import q from"./support/PurgeOptions.js";import{defaultStreamIdField as W}from"./support/streamLayerUtils.js";import{read as Q}from"../renderers/support/jsonUtils.js";import{loadStyleRenderer as B}from"../renderers/support/styleUtils.js";import{webSceneRendererTypes as H,rendererTypes as K}from"../renderers/support/typeUtils.js";import X from"../rest/support/Query.js";import{createPopupTemplate as Y}from"../support/popupUtils.js";import Z from"../symbols/support/ElevationInfo.js";import{SaveOperationType as ee}from"../webdoc/interfaces.js";const te=M();function re(e,t){return new o("layer:unsupported",`Layer (${e.title}, ${e.id}) of type '${e.declaredClass}' ${t}`,{layer:e})}let ie=class extends(S(x(I(w(P(U(L(F(v(R(T(p(b(i.ClonableMixin(j))))))))))))))){constructor(...e){super(...e),this.copyright=null,this.definitionExpression=null,this.displayField=null,this.elevationInfo=null,this.fields=null,this.fieldsIndex=null,this.geometryDefinition=null,this.geometryType=null,this.labelsVisible=!0,this.labelingInfo=null,this.legendEnabled=!0,this.maxReconnectionAttempts=0,this.maxReconnectionInterval=20,this.maxScale=0,this.minScale=0,this.objectIdField=null,this.operationalLayerType="ArcGISStreamLayer",this.outFields=["*"],this.popupEnabled=!0,this.popupTemplate=null,this.purgeOptions=new q,this.refreshInterval=0,this.screenSizePerspectiveEnabled=!0,this.sourceJSON=null,this.spatialReference=h.WGS84,this.type="stream",this.url=null,this.updateInterval=300,this.useViewTime=!0,this.webSocketUrl=null,this._debouncedSaveOperations=l((async(e,t,r)=>{const{save:i,saveAs:o}=await import("./save/streamLayerUtils.js");switch(e){case ee.SAVE:return i(this,t);case ee.SAVE_AS:return o(this,r,t)}}))}normalizeCtorArgs(e,t){return"string"==typeof e?{url:e,...t}:e}load(e){if(!("WebSocket"in globalThis))return this.addResolvingPromise(Promise.reject(new o("stream-layer:websocket-unsupported","WebSocket is not supported in this browser. StreamLayer will not have real-time connection with the stream service."))),Promise.resolve(this);const t=null!=e?e.signal:null;return this.addResolvingPromise(this.loadFromPortal({supportedTypes:["Stream Service","Feed"]},e).catch(m).then((()=>this._fetchService(t)))),Promise.resolve(this)}get defaultPopupTemplate(){return this.createPopupTemplate()}set featureReduction(e){const t=this._normalizeFeatureReduction(e);this._set("featureReduction",t)}set renderer(e){G(e,this.fieldsIndex),this._set("renderer",e)}readRenderer(e,t,r){t=t.layerDefinition||t;const i=t.drawingInfo?.renderer;if(i){const e=Q(i,t,r)||void 0;return e||a.getLogger(this).error("Failed to create renderer",{rendererDefinition:t.drawingInfo.renderer,layer:this,context:r}),e}return N(t,r)}async connect(e){const[{createConnection:t}]=await Promise.all([import("./graphics/sources/connections/createConnection.js"),this.load()]),r=this.geometryType?g.toJSON(this.geometryType):null,{customParameters:i=null,definitionExpression:o=null,geometryDefinition:n=null,maxReconnectionAttempts:a=0,maxReconnectionInterval:p=20,spatialReference:l=this.spatialReference}=e||this.createConnectionParameters(),m=t(this.parsedUrl,this.spatialReference,l,r,o,n,a,p,i??void 0),d=s([this.on("send-message-to-socket",(e=>m.sendMessageToSocket(e))),this.on("send-message-to-client",(e=>m.sendMessageToClient(e)))]);return m.once("destroy",d.remove),m}createConnectionParameters(){return{spatialReference:this.spatialReference,customParameters:this.customParameters,definitionExpression:this.definitionExpression,geometryDefinition:this.geometryDefinition,maxReconnectionAttempts:this.maxReconnectionAttempts,maxReconnectionInterval:this.maxReconnectionInterval}}createPopupTemplate(e){return Y(this,e)}createQuery(){const e=new X;return e.returnGeometry=!0,e.outFields=["*"],e.where=this.definitionExpression||"1=1",e}getFieldDomain(e,t){if(!this.fields)return null;let r=null;return this.fields.some((t=>(t.name===e&&(r=t.domain),!!r))),r}getField(e){return this.fieldsIndex.get(e)}serviceSupportsSpatialReference(e){return!0}sendMessageToSocket(e){this.emit("send-message-to-socket",e)}sendMessageToClient(e){this.emit("send-message-to-client",e)}async save(e){return this._debouncedSaveOperations(ee.SAVE,e)}async saveAs(e,t){return this._debouncedSaveOperations(ee.SAVE_AS,t,e)}write(e,t){const r=t?.messages;return this.webSocketUrl?(r?.push(re(this,"using a custom websocket connection cannot be written to web scenes and web maps")),null):this.parsedUrl?super.write(e,t):(r?.push(re(this,"using a client-side only connection without a url cannot be written to web scenes and web maps")),null)}async _fetchService(e){if(!!!this.webSocketUrl&&this.parsedUrl){if(!this.sourceJSON){const{data:t}=await r(this.parsedUrl.path,{query:{f:"json",...this.customParameters,...this.parsedUrl.query},responseType:"json",signal:e});this.sourceJSON=t}}else{if(!this.timeInfo?.trackIdField)throw new o("stream-layer:missing-metadata","The stream layer trackIdField must be specified.");if(!this.objectIdField){const e=this.fields.find((e=>"oid"===e.type))?.name;if(!e)throw new o("stream-layer:missing-metadata","The stream layer objectIdField must be specified.");this.objectIdField=e}if(!this.fields)throw new o("stream-layer:missing-metadata","The stream layer fields must be specified.");if(this.fields.some((e=>e.name===this.objectIdField))||this.fields.push(new V({name:this.objectIdField,alias:this.objectIdField,type:"oid"})),!this.geometryType)throw new o("stream-layer:missing-metadata","The stream layer geometryType must be specified.");this.webSocketUrl&&(this.url=this.webSocketUrl)}return this.read(this.sourceJSON,{origin:"service",portalItem:this.portalItem,portal:this.portalItem?.portal,url:this.parsedUrl}),G(this.renderer,this.fieldsIndex),J(this.timeInfo,this.fieldsIndex),this.objectIdField||(this.objectIdField=W),B(this,{origin:"service"})}};e([d({type:String})],ie.prototype,"copyright",void 0),e([d({readOnly:!0})],ie.prototype,"defaultPopupTemplate",null),e([d({type:String,json:{name:"layerDefinition.definitionExpression",write:{enabled:!0,allowNull:!0}}})],ie.prototype,"definitionExpression",void 0),e([d({type:String})],ie.prototype,"displayField",void 0),e([d({type:Z})],ie.prototype,"elevationInfo",void 0),e([d({json:{origins:{"web-map":{read:!1,write:!1},"portal-item":{read:!1,write:!1},"web-scene":{read:!1,write:!1}}}})],ie.prototype,"featureReduction",null),e([d(te.fields)],ie.prototype,"fields",void 0),e([d(te.fieldsIndex)],ie.prototype,"fieldsIndex",void 0),e([d({type:f,json:{name:"layerDefinition.definitionGeometry",write:!0}})],ie.prototype,"geometryDefinition",void 0),e([d({type:g.apiValues,json:{read:{reader:g.read}}})],ie.prototype,"geometryType",void 0),e([d(E)],ie.prototype,"labelsVisible",void 0),e([d({type:[z],json:{name:"layerDefinition.drawingInfo.labelingInfo",read:{reader:$},write:!0}})],ie.prototype,"labelingInfo",void 0),e([d(k)],ie.prototype,"legendEnabled",void 0),e([d({type:["show","hide"],json:{origins:{"portal-item":{read:!1,write:!1}}}})],ie.prototype,"listMode",void 0),e([d({type:c})],ie.prototype,"maxReconnectionAttempts",void 0),e([d({type:c})],ie.prototype,"maxReconnectionInterval",void 0),e([d(A)],ie.prototype,"maxScale",void 0),e([d(O)],ie.prototype,"minScale",void 0),e([d({type:String})],ie.prototype,"objectIdField",void 0),e([d({value:"ArcGISStreamLayer",type:["ArcGISStreamLayer"]})],ie.prototype,"operationalLayerType",void 0),e([d({readOnly:!0})],ie.prototype,"outFields",void 0),e([d(D)],ie.prototype,"popupEnabled",void 0),e([d({type:t,json:{name:"popupInfo",write:!0}})],ie.prototype,"popupTemplate",void 0),e([d({type:q})],ie.prototype,"purgeOptions",void 0),e([d({json:{read:!1,write:!1}})],ie.prototype,"refreshInterval",void 0),e([d({types:K,json:{origins:{service:{write:{target:"drawingInfo.renderer",enabled:!1}},"web-scene":{name:"layerDefinition.drawingInfo.renderer",types:H,write:!0}},write:{target:"layerDefinition.drawingInfo.renderer"}}})],ie.prototype,"renderer",null),e([u("service","renderer",["drawingInfo.renderer","defaultSymbol"]),u("renderer",["layerDefinition.drawingInfo.renderer","layerDefinition.defaultSymbol"])],ie.prototype,"readRenderer",null),e([d((()=>{const e=n(C);return e.json.origins["portal-item"]={read:!1,write:!1},e})())],ie.prototype,"screenSizePerspectiveEnabled",void 0),e([d()],ie.prototype,"sourceJSON",void 0),e([d({type:h,json:{origins:{service:{read:{source:"spatialReference"}}}}})],ie.prototype,"spatialReference",void 0),e([d({json:{read:!1}})],ie.prototype,"type",void 0),e([d(_)],ie.prototype,"url",void 0),e([d({type:Number})],ie.prototype,"updateInterval",void 0),e([d({json:{read:!1,write:!1}})],ie.prototype,"useViewTime",void 0),e([d({type:String})],ie.prototype,"webSocketUrl",void 0),ie=e([y("esri.layers.StreamLayer")],ie);const oe=ie;export{oe as default};