@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 11 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../PopupTemplate.js";import r from"../request.js";import{ClonableMixin as 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{MultiOriginJSONSupportMixin as p}from"../core/MultiOriginJSONSupport.js";import{debounce as l,throwIfAbortError as m}from"../core/promiseUtils.js";import{property as d,subclass as c}from"../core/accessorSupport/decorators.js";import{Integer as u}from"../core/accessorSupport/ensureType.js";import y from"../geometry/Extent.js";import f from"../geometry/SpatialReference.js";import{featureGeometryTypeKebabDictionary as h}from"../geometry/support/typeUtils.js";import g from"../graphic/StreamGraphicOrigin.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 P}from"./mixins/ScaleRangeLayer.js";import{TemporalLayer as L}from"./mixins/TemporalLayer.js";import{TrackableLayer as U}from"./mixins/TrackableLayer.js";import{labelsVisible as O,legendEnabled as E,maxScale as k,minScale as D,popupEnabled as A,screenSizePerspectiveEnabled as C,url as N}from"./support/commonProperties.js";import{createDefaultRenderer as G}from"./support/featureLayerUtils.js";import _ from"./support/Field.js";import{defineFieldProperties as J}from"./support/fieldProperties.js";import{fixRendererFields as M,fixTimeInfoFields as V}from"./support/fieldUtils.js";import z from"./support/LabelClass.js";import{reader as q}from"./support/labelingInfo.js";import W from"./support/PurgeOptions.js";import{defaultStreamIdField as Q}from"./support/streamLayerUtils.js";import{read as B}from"../renderers/support/jsonUtils.js";import{loadStyleRenderer as H}from"../renderers/support/styleUtils.js";import{webSceneRendererTypes as K,rendererTypes as X}from"../renderers/support/typeUtils.js";import Y from"../rest/support/Query.js";import{createPopupTemplate as Z}from"../support/popupUtils.js";import $ from"../symbols/support/ElevationInfo.js";import{addLayerUnsupportedError as ee}from"../webdoc/support/unsupportedErrors.js";import{reader as te}from"../core/accessorSupport/decorators/reader.js";const re=J();let ie=class extends(S(x(I(w(L(U(P(F(v(R(T(p(b(i(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.graphicOrigin=new g(this),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 W,this.refreshInterval=0,this.screenSizePerspectiveEnabled=!0,this.sourceJSON=null,this.spatialReference=f.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 0:return i(this,t);case 1: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){M(e,this.fieldsIndex),this._set("renderer",e)}readRenderer(e,t,r){t=t.layerDefinition||t;const i=t.drawingInfo?.renderer;if(i){const e=B(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 G(t,r)}async connect(e){const[{createConnection:t}]=await Promise.all([import("./graphics/sources/connections/createConnection.js"),this.load()]),r=this.geometryType?h.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 Z(this,e)}createQuery(){const e=new Y;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(0,e)}async saveAs(e,t){return this._debouncedSaveOperations(1,t,e)}write(e,t){return this.webSocketUrl?(ee(t,this,"a custom websocket connection cannot be written to web scenes and web maps"),null):this.parsedUrl?super.write(e,t):(ee(t,this,"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 _({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}),M(this.renderer,this.fieldsIndex),V(this.timeInfo,this.fieldsIndex),this.objectIdField||(this.objectIdField=Q),H(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:$})],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(re.fields)],ie.prototype,"fields",void 0),e([d(re.fieldsIndex)],ie.prototype,"fieldsIndex",void 0),e([d({type:y,json:{name:"layerDefinition.definitionGeometry",write:!0}})],ie.prototype,"geometryDefinition",void 0),e([d({type:h.apiValues,json:{read:{reader:h.read}}})],ie.prototype,"geometryType",void 0),e([d({readOnly:!0,clonable:!1})],ie.prototype,"graphicOrigin",void 0),e([d(O)],ie.prototype,"labelsVisible",void 0),e([d({type:[z],json:{name:"layerDefinition.drawingInfo.labelingInfo",read:{reader:q},write:!0}})],ie.prototype,"labelingInfo",void 0),e([d(E)],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:u})],ie.prototype,"maxReconnectionAttempts",void 0),e([d({type:u})],ie.prototype,"maxReconnectionInterval",void 0),e([d(k)],ie.prototype,"maxScale",void 0),e([d(D)],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(A)],ie.prototype,"popupEnabled",void 0),e([d({type:t,json:{name:"popupInfo",write:!0}})],ie.prototype,"popupTemplate",void 0),e([d({type:W})],ie.prototype,"purgeOptions",void 0),e([d({json:{read:!1,write:!1}})],ie.prototype,"refreshInterval",void 0),e([d({types:X,json:{origins:{service:{write:{target:"drawingInfo.renderer",enabled:!1}},"web-scene":{name:"layerDefinition.drawingInfo.renderer",types:K,write:!0}},write:{target:"layerDefinition.drawingInfo.renderer"}}})],ie.prototype,"renderer",null),e([te("service","renderer",["drawingInfo.renderer","defaultSymbol"]),te("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:f,json:{origins:{service:{read:{source:"spatialReference"}}}}})],ie.prototype,"spatialReference",void 0),e([d({json:{read:!1}})],ie.prototype,"type",void 0),e([d(N)],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([c("esri.layers.StreamLayer")],ie);const oe=ie;export{oe as default};