@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 6.61 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
import{__decorate as t}from"tslib";import{isSome as e}from"../../../core/arrayUtils.js";import r from"../../../core/Collection.js";import i from"../../../core/CollectionFlattener.js";import{makeHandle as s}from"../../../core/handleUtils.js";import{watch as o,syncAndInitial as a,initial as n}from"../../../core/reactiveUtils.js";import{property as h,subclass as p}from"../../../core/accessorSupport/decorators.js";import c from"../../../rest/support/DirectionLine.js";import l from"../../../rest/support/DirectionPoint.js";import u from"../../../rest/support/PointBarrier.js";import d from"../../../rest/support/PolygonBarrier.js";import _ from"../../../rest/support/PolylineBarrier.js";import m from"../../../rest/support/RouteInfo.js";import g from"../../../rest/support/Stop.js";import{LayerView2D as w}from"./LayerView2D.js";import y from"./graphics/GraphicContainer.js";import f from"./graphics/GraphicsView2D.js";import{RouteLayerInteractiveOptions as v}from"./support/RouteLayerInteractiveOptions.js";import k from"../../layers/LayerView.js";import{getHighlightName as M}from"../../support/highlightOptionsUtils.js";const F=["route-info","direction-line","direction-point","polygon-barrier","polyline-barrier","point-barrier","stop"],V={graphic:null,property:null,oldValue:null,newValue:null};function G(t){return t instanceof c||t instanceof l||t instanceof u||t instanceof d||t instanceof _||t instanceof m||t instanceof g}function I(t){return r.isCollection(t)&&t.length&&G(t.at(0))}function j(t){return Array.isArray(t)&&t.length>0&&G(t[0])}let P=class extends(w(k)){constructor(){super(...arguments),this._graphics=new r,this._networkFeatureMap=new Map,this._networkGraphicMap=new Map,this._interaction=null,this._loadInteractionPromise=null,this.interactive=!1,this.interactiveOptions=new v}get _routeItems(){return new i({getCollections:()=>this.layer&&!this.destroyed?[this.layer.routeInfo?new r([this.layer.routeInfo]):null,this.layer.directionLines,this.layer.directionPoints,this.layer.polygonBarriers,this.layer.polylineBarriers,this.layer.pointBarriers,this.layer.stops]:[]})}initialize(){this.addHandles(o(()=>{const{interactive:t,suspended:e}=this;return{interactive:t,suspended:e}},({interactive:t,suspended:e})=>{const r=t&&!e;r&&this._getInteractionLoadPromise().then(t=>{t.enabled=this.interactive&&!this.suspended}),this._interaction&&(this._interaction.enabled=r)},a)),this._updatingHandles.addOnCollectionChange(()=>this._routeItems,t=>this._routeItemsChanged(t),n)}destroy(){this._networkFeatureMap.clear(),this._networkGraphicMap.clear(),this._graphics.removeAll(),this._get("_routeItems")?.destroy()}attach(){this._createGraphicsView()}detach(){this._destroyGraphicsView(),this._interaction?.enabled&&(this._interaction.enabled=!1)}get selectedNetworkFeatures(){return this._interaction?.selectedNetworkFeatures??null}async create(t){return this._interaction?.create(t)}delete(){this._interaction?.delete()}async fetchPopupFeaturesAtLocation(t,e){return this._graphicsView.hitTest(t).filter(({popupTemplate:t})=>!!t)}highlight(t,r){let i;i=G(t)?[this._getNetworkFeatureUid(t)]:j(t)?t.map(t=>this._getNetworkFeatureUid(t)):I(t)?t.map(t=>this._getNetworkFeatureUid(t)).toArray():[t.uid];const o=i.filter(e);if(!o.length)return s();const a=M(r);return this._addHighlights(o,a),s(()=>this._removeHighlights(o,a))}async hitTest(t,r){if(this.suspended)return null;const i=this._graphicsView.hitTest(t).filter(e).map(t=>this._networkGraphicMap.get(t));if(!i.length)return null;const{layer:s}=this;return i.reverse().map(e=>({type:"route",layer:s,mapPoint:t,networkFeature:e}))}isUpdating(){return this._graphicsView.updating}moveEnd(){}remove(t){this._interaction?.remove(t)}update(t){this._graphicsView.processUpdate(t)}viewChange(){this._graphicsView.viewChange()}_createGraphic(t){const e=t.toGraphic();return e.layer=this.layer,e.sourceLayer=this.layer,e}_createGraphicsView(){const t=this.view,e=()=>this.requestUpdate(),r=new y(t.featuresTilingScheme);this._graphicsView=new f({container:r,graphics:this._graphics,requestUpdateCallback:e,view:t}),this.container.addChild(r),this._processHighlight()}_destroyGraphicsView(){this.container.removeChild(this._graphicsView.container),this._graphicsView.destroy()}_getDrawOrder(t){const e=this._networkGraphicMap.get(t);return F.indexOf(e.type)}_getInteractionLoadPromise(){return this._loadInteractionPromise||(this._loadInteractionPromise=this._loadInteraction(),this._updatingHandles.addPromise(this._loadInteractionPromise)),this._loadInteractionPromise}_getNetworkFeatureUid(t){return this._networkFeatureMap.has(t)?this._networkFeatureMap.get(t).uid:null}async _loadInteraction(){const{interactiveOptions:t,layer:e,view:r}=this,{RouteLayerInteraction:i}=await import("./support/RouteLayerInteraction.js");return this._interaction=new i({interactiveOptions:t,layer:e,view:r}),this._interaction}_routeItemsChanged(t){if(t.removed.length){this._graphics.removeMany(t.removed.map(t=>{const e=this._networkFeatureMap.get(t);return this._networkFeatureMap.delete(t),this._networkGraphicMap.delete(e),e}));for(const e of t.removed)this.removeHandles(e)}if(t.added.length){this._graphics.addMany(t.added.map(t=>{const e=this._createGraphic(t);return null==e.symbol?null:(this._networkFeatureMap.set(t,e),this._networkGraphicMap.set(e,t),e)}).filter(e));for(const e of t.added)this.addHandles([o(()=>e.geometry,(t,r)=>{this._updateGraphic(e,"geometry",t,r)}),o(()=>e.symbol,(t,r)=>{this._updateGraphic(e,"symbol",t,r)}),o(()=>e.popupTemplate,t=>{this._networkFeatureMap.has(e)&&(this._networkFeatureMap.get(e).popupTemplate=t)}),o(()=>e.toGraphic().attributes,t=>{this._networkFeatureMap.has(e)&&(this._networkFeatureMap.get(e).attributes=t)})],e);this._graphics.sort((t,e)=>this._getDrawOrder(t)-this._getDrawOrder(e))}}_updateGraphic(t,e,r,i){if(!this._networkFeatureMap.has(t)){const e=this._createGraphic(t);return this._networkFeatureMap.set(t,e),this._networkGraphicMap.set(e,t),void this._graphics.add(e)}const s=this._networkFeatureMap.get(t);s[e]=r,V.graphic=s,V.property=e,V.oldValue=i,V.newValue=r,this._graphicsView.graphicUpdateHandler(V)}_processHighlight(){const t=this._getHighlights();this._graphicsView?.setHighlight(t)}};t([h()],P.prototype,"_routeItems",null),t([h()],P.prototype,"_interaction",void 0),t([h()],P.prototype,"interactive",void 0),t([h({readOnly:!0})],P.prototype,"interactiveOptions",void 0),t([h({readOnly:!0})],P.prototype,"selectedNetworkFeatures",null),P=t([p("esri.views.2d.layers.RouteLayerView2D")],P);const b=P;export{b as default};