UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 7.94 kB
import{_ as e}from"../../../chunks/tslib.es6.js";import{version as i}from"../../../kernel.js";import t from"../../../core/Collection.js";import{abortMaybe as s,destroyMaybe as a,isSome as o,isNone as r}from"../../../core/maybe.js";import{watch as l}from"../../../core/reactiveUtils.js";import{queryToObject as n,objectToQuery as h}from"../../../core/urlUtils.js";import{property as p}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/accessorSupport/ensureType.js";import"../../../core/arrayUtils.js";import{subclass as m}from"../../../core/accessorSupport/decorators/subclass.js";import c from"../../../geometry/Extent.js";import{load as d,project as y}from"../../../geometry/projection.js";import g from"../../../geometry/SpatialReference.js";import{getGraphics as w,fetchService as u,parseKML as _}from"../../../layers/support/kmlUtils.js";import{parseUrl as b}from"../../../rest/utils.js";import{GraphicsCollection as V}from"../../../support/GraphicsCollection.js";import{Bitmap as f}from"../engine/Bitmap.js";import{BitmapContainer as v}from"../engine/BitmapContainer.js";import{LayerView2DMixin as S}from"./LayerView2D.js";import I from"./graphics/GraphicContainer.js";import x from"./graphics/GraphicsView2D.js";import C from"../../layers/LayerView.js";import{ImageReprojector as j}from"../../support/imageReprojection.js";class k{constructor(){this.allSublayers=new Map,this.allPoints=[],this.allPolylines=[],this.allPolygons=[],this.allMapImages=[]}}let P=class extends(S(C)){constructor(){super(...arguments),this._bitmapIndex=new Map,this._mapImageContainer=new v,this._kmlVisualData=new k,this._fetchController=null,this.allVisiblePoints=new V,this.allVisiblePolylines=new V,this.allVisiblePolygons=new V,this.allVisibleMapImages=new t}async hitTest(e,i){const t=this.layer;return[this._pointsView?.hitTest(e),this._polylinesView?.hitTest(e),this._polygonsView?.hitTest(e)].flat().filter(Boolean).map((i=>(i.layer=t,i.sourceLayer=t,{type:"graphic",graphic:i,layer:t,mapPoint:e})))}update(e){this._polygonsView&&this._polygonsView.processUpdate(e),this._polylinesView&&this._polylinesView.processUpdate(e),this._pointsView&&this._pointsView.processUpdate(e)}attach(){this._fetchController=new AbortController,this.container.addChild(this._mapImageContainer),this._polygonsView=new x({view:this.view,graphics:this.allVisiblePolygons,requestUpdateCallback:()=>this.requestUpdate(),container:new I(this.view.featuresTilingScheme)}),this.container.addChild(this._polygonsView.container),this._polylinesView=new x({view:this.view,graphics:this.allVisiblePolylines,requestUpdateCallback:()=>this.requestUpdate(),container:new I(this.view.featuresTilingScheme)}),this.container.addChild(this._polylinesView.container),this._pointsView=new x({view:this.view,graphics:this.allVisiblePoints,requestUpdateCallback:()=>this.requestUpdate(),container:new I(this.view.featuresTilingScheme)}),this.container.addChild(this._pointsView.container),this.addAttachHandles([this.allVisibleMapImages.on("change",(e=>{e.added.forEach((e=>this._addMapImage(e))),e.removed.forEach((e=>this._removeMapImage(e)))})),l((()=>this.layer.visibleSublayers),(e=>{for(const[i,t]of this._kmlVisualData.allSublayers)t.visibility=0;for(const i of e){const e=this._kmlVisualData.allSublayers.get(i.id);e&&(e.visibility=1)}this._refreshCollections()}))]),this.updatingHandles.addPromise(this._fetchService(this._fetchController.signal)),this._imageReprojector=new j}detach(){this._fetchController=s(this._fetchController),this._mapImageContainer.removeAllChildren(),this.container.removeAllChildren(),this._bitmapIndex.clear(),this._polygonsView=a(this._polygonsView),this._polylinesView=a(this._polylinesView),this._pointsView=a(this._pointsView),this._imageReprojector=a(this._imageReprojector)}moveStart(){}viewChange(){this._polygonsView.viewChange(),this._polylinesView.viewChange(),this._pointsView.viewChange()}moveEnd(){}isUpdating(){return this._pointsView.updating||this._polygonsView.updating||this._polylinesView.updating}_addMapImage(e){(this.view.spatialReference?.isWGS84||this.view.spatialReference?.isWebMercator)&&this._imageReprojector.loadAndReprojectBitmapData(e.href,c.fromJSON(e.extent),this.view.spatialReference).then((i=>{const t=new f(i.bitmapData,{immutable:!1,requestRenderOnSourceChangedEnabled:!0});t.x=i.extent.xmin,t.y=i.extent.ymax,t.resolution=i.extent.width/i.bitmapData.width,t.rotation=e.rotation,this._mapImageContainer.addChild(t),this._bitmapIndex.set(e,t)}))}async _getViewDependentUrl(e,t){const{viewFormat:s,viewBoundScale:a,httpQuery:l}=e;if(o(s)){if(r(t))throw new Error("Loading this network link requires a view state.");let p;if(await d(),o(a)&&1!==a){const e=new c(t.extent);e.expand(a),p=e}else p=t.extent;p=y(p,g.WGS84);const m=y(p,g.WebMercator),w=p.xmin,u=p.xmax,_=p.ymin,V=p.ymax,f=t.size[0]*t.pixelRatio,v=t.size[1]*t.pixelRatio,S=Math.max(m.width,m.height),I={"[bboxWest]":w.toString(),"[bboxEast]":u.toString(),"[bboxSouth]":_.toString(),"[bboxNorth]":V.toString(),"[lookatLon]":p.center.x.toString(),"[lookatLat]":p.center.y.toString(),"[lookatRange]":S.toString(),"[lookatTilt]":"0","[lookatHeading]":t.rotation.toString(),"[lookatTerrainLon]":p.center.x.toString(),"[lookatTerrainLat]":p.center.y.toString(),"[lookatTerrainAlt]":"0","[cameraLon]":p.center.x.toString(),"[cameraLat]":p.center.y.toString(),"[cameraAlt]":S.toString(),"[horizFov]":"60","[vertFov]":"60","[horizPixels]":f.toString(),"[vertPixels]":v.toString(),"[terrainEnabled]":"0","[clientVersion]":i,"[kmlVersion]":"2.2","[clientName]":"ArcGIS API for JavaScript","[language]":"en-US"},x=e=>{for(const i in e)for(const t in I)e[i]=e[i].replace(t,I[t])},C=n(s);x(C);let j={};o(l)&&(j=n(l),x(j));const k=b(e.href);k.query={...k.query,...C,...j};return`${k.path}?${h(C)}`}return e.href}async _fetchService(e){const i=new k;await this._loadVisualData(this.layer.url,i,e),this._kmlVisualData=i,this._refreshCollections()}_refreshCollections(){this.allVisiblePoints.removeAll(),this.allVisiblePolylines.removeAll(),this.allVisiblePolygons.removeAll(),this.allVisibleMapImages.removeAll(),this.allVisiblePoints.addMany(this._kmlVisualData.allPoints.filter((e=>this._isSublayerVisible(e.sublayerId))).map((({item:e})=>e))),this.allVisiblePolylines.addMany(this._kmlVisualData.allPolylines.filter((e=>this._isSublayerVisible(e.sublayerId))).map((({item:e})=>e))),this.allVisiblePolygons.addMany(this._kmlVisualData.allPolygons.filter((e=>this._isSublayerVisible(e.sublayerId))).map((({item:e})=>e))),this.allVisibleMapImages.addMany(this._kmlVisualData.allMapImages.filter((e=>this._isSublayerVisible(e.sublayerId))).map((({item:e})=>e)))}_isSublayerVisible(e){const i=this._kmlVisualData.allSublayers.get(e);return!!i?.visibility&&(-1===i.parentFolderId||this._isSublayerVisible(i.parentFolderId))}_loadVisualData(e,i,t){return this._fetchParsedKML(e,t).then((async e=>{for(const s of e.sublayers){i.allSublayers.set(s.id,s);const e=s.points?await w(s.points):[],a=s.polylines?await w(s.polylines):[],o=s.polygons?await w(s.polygons):[],r=s.mapImages||[];if(i.allPoints.push(...e.map((e=>({item:e,sublayerId:s.id})))),i.allPolylines.push(...a.map((e=>({item:e,sublayerId:s.id})))),i.allPolygons.push(...o.map((e=>({item:e,sublayerId:s.id})))),i.allMapImages.push(...r.map((e=>({item:e,sublayerId:s.id})))),s.networkLink){const e=await this._getViewDependentUrl(s.networkLink,this.view.state);await this._loadVisualData(e,i,t)}}}))}_fetchParsedKML(e,i){return u(e,this.layer.spatialReference,this.layer.refreshInterval,i).then((e=>_(e.data)))}_removeMapImage(e){const i=this._bitmapIndex.get(e);i&&(this._mapImageContainer.removeChild(i),this._bitmapIndex.delete(e))}};e([p()],P.prototype,"_pointsView",void 0),e([p()],P.prototype,"_polylinesView",void 0),e([p()],P.prototype,"_polygonsView",void 0),e([p()],P.prototype,"updating",void 0),P=e([m("esri.views.2d.layers.KMLLayerView2D")],P);const M=P;export{M as default};