UNPKG

@arcgis/map-components

Version:
4 lines • 14.8 kB
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. v4.33.13 */ import{a as D}from"./THGY6EBD.js";import d from"./4RFCEGOP.js";import"./KW27SA4Q.js";import c from"./HXOMZNNJ.js";import{a as R}from"./MZHKSD55.js";import{a as v}from"./HA5P4MAX.js";import b from"./MX24TT2G.js";import a from"./2WKS6ZFG.js";import{e as L}from"./4TYQGSWG.js";import"./JDUE7Q24.js";import"./DXCYBWXJ.js";import{B as g,E as P,P as O,Q as w,S as N,U as T,a as S,j as C,k as h}from"./HX57SHRL.js";export default $arcgis.t(([{watch:A},{property:n,subclass:F},u,{onLocaleChange:W},X,B,Z,G,Y,$,y,I,{geographicToWebMercator:ee},te,{project:oe},ie,,,U,{a:x,c:b}])=>{var re=C`@layer{arcgis-locate{display:block}}`,k=!1,ae={maximumAge:0,timeout:15e3,enableHighAccuracy:!0};function se(){let t="geolocation"in navigator;return t||console.warn("geolocation-unsupported","Geolocation unsupported."),t}function ne(){let t=window.isSecureContext;return t||k||(k=!0,console.warn("insecure-context","Geolocation requires a secure origin.")),t}function le(){return se()&&ne()}function ce(t){return t??=ae,new Promise((e,o)=>{setTimeout(()=>o(new u("geolocation:timeout","getting the current geolocation position timed out")),t?.timeout??15e3),navigator.geolocation.getCurrentPosition(e,o,t??void 0)})}function pe(t,e){let{position:o,view:r}=t,i=de(o)?.coords;if(!i)throw new u("geometry-service:no-coords","Geolocation has no coordinates");let a=ue(i);return he(a,r,e)}function de(t){let e=t?.coords||{},o={accuracy:e.accuracy,altitude:e.altitude,altitudeAccuracy:e.altitudeAccuracy,heading:e.heading,latitude:e.latitude,longitude:e.longitude,speed:e.speed,toJSON(){return{}}};return t&&{coords:o,timestamp:t.timestamp,toJSON(){return{}}}}function ue({longitude:t,latitude:e,altitude:o}){return new $({longitude:t,latitude:e,z:o||void 0,spatialReference:{wkid:4326}})}async function he(t,e,o){if(!e)return await Promise.resolve(t);let r=e.spatialReference;return r.isWGS84?await Promise.resolve(t):r.isWebMercator?await Promise.resolve(ee(t)):y.isLoaded()?await Promise.resolve(y.execute(t,r)):await me(o).then(async i=>{if(!i)throw new u("geometry-service:missing-url","Geometry service URL is missing");let a=new ie({geometries:[t],outSpatialReference:r});return(await oe(i,a,o))[0]})}async function me(t){if(I.geometryServiceUrl)return await Promise.resolve(I.geometryServiceUrl);let e=te.getDefault();try{await e.load(t)}catch{}return e.helperServices?.geometry?.url}var ge=Object.defineProperty,ye=Object.getOwnPropertyDescriptor,p=(t,e,o,r)=>{for(var i=r>1?void 0:r?ye(e,o):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(i=(r?s(e,o,i):s(i))||i);return r&&i&&ge(e,o,i),i},fe=2500;function Q(t){let e={type:"CIMVectorMarker",enable:!0,anchorPoint:{x:0,y:0},anchorPointUnits:"Relative",dominantSizeAxis3D:"Y",size:t==="background"?16:14,billboardMode3D:"FaceNearPlane",frame:{xmin:0,ymin:0,xmax:17,ymax:17},markerGraphics:[{type:"CIMMarkerGraphic",geometry:{rings:[[[8.5,0],[7.02,.13],[5.59,.51],[4.25,1.14],[3.04,1.99],[1.99,3.04],[1.14,4.25],[.51,5.59],[.13,7.02],[0,8.5],[.13,9.98],[.51,11.41],[1.14,12.75],[1.99,13.96],[3.04,15.01],[4.25,15.86],[5.59,16.49],[7.02,16.87],[8.5,17],[9.98,16.87],[11.41,16.49],[12.75,15.86],[13.96,15.01],[15.01,13.96],[15.86,12.75],[16.49,11.41],[16.87,9.98],[17,8.5],[16.87,7.02],[16.49,5.59],[15.86,4.25],[15.01,3.04],[13.96,1.99],[12.75,1.14],[11.41,.51],[9.98,.13],[8.5,0]]]},symbol:{type:"CIMPolygonSymbol",symbolLayers:[{type:"CIMSolidStroke",enable:!0,capStyle:"Round",joinStyle:"Round",lineStyle3D:"Strip",miterLimit:10,width:t==="background"?0:2,color:[255,255,255,255]},{type:"CIMSolidFill",enable:!0,color:t==="background"?[0,0,0,66]:[0,122,194,255]}]}}],scaleSymbolsProportionally:!0,respectFrame:!0};return t==="background"&&(e.offsetX=0,e.offsetY=-1),e}var H={type:"CIMPictureMarker",primitiveName:"headingOverride",enable:!0,anchorPoint:{x:0,y:-.5},anchorPointUnits:"Relative",dominantSizeAxis3D:"Y",size:36,billboardMode3D:"FaceNearPlane",invertBackfaceTexture:!0,scaleX:1,textureFilter:"Picture",url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAkCAYAAACe0YppAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAYaSURBVHgBvVfNb1VFFD/nzP16xRYJKYREEiJoDLLShQkrSNzoHv8I2QgxwY8FJWHhxoVxISEu2AordWNiQjAxEBeEsKAmhCCwkPDRAn1t33v33jnH37n3Fam0pa8kTjOde+/MnN/5+J0z85jW08yYTpxgfzx0bS+fO0R0YHqyeb9w7YEtLTv+9rSdOH7ciNleJJJX/Do1JQ3AltdlT35fiN6gG8kD8akdmzO+6w/zM7wdw725rUY78DBXtmATA6PZntFgm9Kjm6o/HFJpdi5Xhp+16sDBC+H+gUmZfjIXHKC+35U42ZHZfpe30BZS7okNFnhu8wTRk2ek5LEV2q+N8nEj6yuNVRjHddftrt4ahyJbOxF+Uppi/Rf47NlA05Pp9vkyRNkkD8sqUJHwOGfSpYFQFXhTJryQBaZSeAxbFus+U1K0gJm2oy3QKwuZzqeuSK5kpW6BEsE6+nCsAHDXQWuaOljzU8uP/ToxUW4KcwKg8QzOSdFL6Swm0hurAC7N2qIW7ncwNgYKF4la3/w7RnzrUK29KseXWqmTKXGl45Zrd9CLrsSjr96fcw4kS46mTsJznSTrVBR6VQJQdDbpZTWexxgCYCFz30cquD8oYVQgtUAUzfo8wGtqGoNRFmFZ1KKulJMQu3Vpm/I8Pup3ekvES57GaabXo4lsszEA6zrkhcmAAkBNshi59O9wVsokBLZUCQAxllXVBkyCDRQuTlLLiL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EDwXKwCzncdFg+PJeVf1m3uPUupLR7Hq6tHNyLhw1TCmdGbm0BmaUjr63LzaMBH943D9f+yO5uZ7HfcLktqdwqMU0jtPUDN6vDOfzgKFrXtta6q83vfHU4M5KoURbT4W3zsPIqrgQFO8GozV8ocZGOTN4dRdRowN6CnOLmKkk5t7H1i+HPNGJj2kj7buYajoRXh2+36eOt+2nENrrF3ozODEmFC0D4hjbQNgYc+DSYjd9qqGSJXqL/tZ16/DWdfvw9bbCt41hcpYn9RAEX9Q22fwC74ny5v9iplQAAAABJRU5ErkJggg=="},we=Q("layer"),ve=Q("background"),be=new Y({data:{type:"CIMSymbolReference",symbol:{type:"CIMPointSymbol",symbolLayers:[we,ve,H],angleAlignment:"Map"},primitiveOverrides:[{type:"CIMPrimitiveOverride",primitiveName:"headingOverride",propertyName:"Rotation",valueExpressionInfo:{type:"CIMExpressionInfo",title:"Rotation override",expression:"360 - $feature.heading",returnType:"Default"}},{type:"CIMPrimitiveOverride",primitiveName:"headingOverride",propertyName:"TintColor",valueExpressionInfo:{type:"CIMExpressionInfo",title:"TintColor override",expression:"IIF(IsEmpty($feature.heading), [255, 255, 255, 0], [255, 255, 255, 1])",returnType:"Default"}}]}}),l=class extends Z{constructor(){super(...arguments),this._geolocationUsable=!0,this.goToLocationEnabled=!0,this.graphic=new G({symbol:be}),this.rotationEnabled=!0}initialize(){le()||(this._geolocationUsable=!1),this.addHandles([A(()=>this.view?.type,()=>this._handleViewTypeChange(),{initial:!0})])}destroy(){this._clearGraphic(),this.view=void 0}_clearGraphic(){let{view:t,graphic:e}=this;t&&e&&t.graphics.remove(e)}_addGraphic(){let{view:t,graphic:e}=this;!t?.graphics||!e||t.graphics.includes(e)||t.graphics.push(e)}_handleViewTypeChange(){H.enable=this.view?.type==="2d"}_getScaleWithinConstraints(t,e){if(!e)return t;if(e.type==="2d"){let{effectiveMaxScale:o,effectiveMinScale:r}=e.constraints;return Math.min(r,Math.max(o,t))}return t}_getScale(t){let{scale:e}=this,o=typeof e=="number"?e:fe;return this._getScaleWithinConstraints(o,t)}_getHeading(t,e){let o=e?.spatialReference,r=o?.isWebMercator||o?.isGeographic,i=t.coords?.heading;return!r||typeof i!="number"||Number.isNaN(i)||i<0||i>360?null:i}_addHeading(t){let{heading:e,target:o,view:r}=t;if(!(!r||e===null)){if(r.type==="3d"){o.heading=e;return}r.type==="2d"&&(o.rotation=360-e)}}async _animatePoint(t,e,o,r){let{view:i}=this;if(!this.goToLocationEnabled||!i)return;let a={target:t,scale:e};this.rotationEnabled&&this._addHeading({heading:o,target:a,view:i});let s={signal:r.signal};x(s),this.goToOverride&&i&&this.goToOverride(i,{target:a,options:s}),await i.goTo(a,s)}async updatePosition(t,e){try{let o=this.view,r=await pe({position:t,view:o},{signal:e.signal}),{graphic:i}=this,{timestamp:a,coords:s}=t,{accuracy:f,altitude:m,altitudeAccuracy:K,latitude:V,longitude:J,speed:_}=s,E=this._getHeading(t,o),j={timestamp:a,accuracy:f,altitude:m,altitudeAccuracy:K,heading:E,latitude:V,longitude:J,speed:_};i&&(i.geometry=r,i.attributes=j);let q=this._getScale(o);await this._animatePoint(r,q,E,e)}catch(o){if(!b(o))throw new u("geolocation-positioning:invalid-point","Cannot position invalid point",{error:o})}return t}};p([n()],l.prototype,"_geolocationUsable",2);p([n()],l.prototype,"geolocationOptions",2);p([n()],l.prototype,"goToLocationEnabled",2);p([n()],l.prototype,"goToOverride",2);p([n({type:G})],l.prototype,"graphic",2);p([n()],l.prototype,"scale",2);p([n()],l.prototype,"rotationEnabled",2);p([n()],l.prototype,"view",2);l=p([F("map-components.geolocation.GeolocationPositioning")],l);var Ae=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,d=(t,e,o,r)=>{for(var i=r>1?void 0:r?Me(e,o):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(i=(r?s(e,o,i):s(i))||i);return r&&i&&Ae(e,o,i),i},Ee=new B({icon:"trash",id:"remove-selected-feature",title:"{messages.remove}",className:"esri-icon-trash"});function Se(t){return new X({title:t.currentLocation,fieldInfos:[{fieldName:"timestamp",label:t.timestamp,format:{dateFormat:"short-date-short-time"}},{fieldName:"latitude",label:t.latitude,format:{places:4,digitSeparator:!0}},{fieldName:"longitude",label:t.longitude,format:{places:4,digitSeparator:!0}},{fieldName:"accuracy",label:t.accuracy,format:{places:0,digitSeparator:!0}},{fieldName:"altitude",label:t.altitude,format:{places:0,digitSeparator:!0}},{fieldName:"altitudeAccuracy",label:t.altitudeAccuracy,format:{places:0,digitSeparator:!0}},{fieldName:"heading",label:t.heading,format:{places:0,digitSeparator:!0}},{fieldName:"speed",label:t.speed,format:{places:0,digitSeparator:!0}}],actions:[Ee.clone()],content:[{type:"fields"}]})}var c=class extends l{constructor(t){super(t),this._locateController=null,this.currentPosition=null,this.error=void 0,this.messages=null,this.popupEnabled=!0,this.locate=this.locate.bind(this)}initialize(){this.addHandles([W(()=>{let{graphic:t,view:e}=this;t&&e?.graphics?.includes(t)&&this._updatePopupTemplate(t)})])}destroy(){this.cancelLocate()}get state(){return this._geolocationUsable?this.view?.ready?this._locateController?"locating":this.error!=null?"error":"ready":"disabled":"feature-unsupported"}async locate(){if(this.cancelLocate(),this.state==="disabled")throw new u("locate:disabled-state","Cannot locate when disabled.");if(this.state==="feature-unsupported")throw new u("locate:feature-unsupported-state","Cannot locate in unsecure domain.");let t=new AbortController;this._locateController=t,this.error=void 0;try{let e=await ce(this.geolocationOptions);if(await this.updatePosition(e,t),this._locateController!==t)return null;let{graphic:o}=this;return o&&this._updatePopupTemplate(o),this._addGraphic(),this.currentPosition=e,this._locateController=null,e}catch(e){if(b(e))return null;throw t===this._locateController&&(this._locateController=null),this.error=e,e}}cancelLocate(){this._clearGraphic(),this._locateController&&this._locateController.abort(),this._locateController=null}_updatePopupTemplate(t){if(!this.popupEnabled)return;let e=Se(this.messages),o=t!==this.graphic;this.destroyed||o||(t.popupTemplate=e)}};d([n()],c.prototype,"_locateController",2);d([n()],c.prototype,"currentPosition",2);d([n()],c.prototype,"error",2);d([n()],c.prototype,"messages",2);d([n()],c.prototype,"popupEnabled",2);d([n({readOnly:!0})],c.prototype,"state",1);c=d([F("map-components.locate.LocateViewModel")],c);var Ce={base:"esri-locate"},z="gps-off",Pe=U(c),M=class extends O{constructor(){super(...arguments),this.messages=R(),this.viewModel=Pe(this),this.autoDestroyDisabled=!1,this.geolocationOptions=this.viewModel.geolocationOptions,this.goToLocationDisabled=this.viewModel.goToLocationEnabled,this.goToOverride=this.viewModel.goToOverride,this.graphic=this.viewModel.graphic,this.icon=z,this.popupDisabled=this.viewModel.popupEnabled,this.position="top-left",this.scale=this.viewModel.scale,this.state=this.viewModel.state,this.arcgisError=g(),this.arcgisPropertyChange=L()("state"),this.arcgisReady=g(),this.arcgisSuccess=g()}static{this.properties={autoDestroyDisabled:5,geolocationOptions:0,goToLocationDisabled:7,goToOverride:0,graphic:0,icon:1,label:1,messageOverrides:0,popupDisabled:5,position:3,referenceElement:1,scale:9,state:3}}static{this.shadowRootOptions=P}static{this.styles=re}async cancelLocate(){this.viewModel.cancelLocate()}async destroy(){await this.manager.destroy()}async locate(){return await this.viewModel.locate()}loaded(){this.viewModel.messages={...this.messages,...this.messageOverrides},this.manager.onLifecycle(()=>[A(()=>this.viewModel.error,e=>{this.arcgisError.emit({error:e})}),A(()=>this.viewModel.currentPosition,e=>{this.arcgisSuccess.emit({position:e})})])}_localizeError(e){if(e instanceof GeolocationPositionError)return e.code===GeolocationPositionError.PERMISSION_DENIED?this.messages?.permissionError:e.code===GeolocationPositionError.TIMEOUT?this.messages?.timeoutError:this.messages?.positionUnavailable;if(e instanceof Error)return e.message}_locate(){let{viewModel:e}=this;e.state==="locating"?e.cancelLocate():e.locate().catch(()=>{})}render(){let{viewModel:e,icon:o}=this,{state:r}=e,i=r==="locating",a=i?this.messages.cancel:this.messages.title,s=r==="feature-unsupported",f=D===void 0?z:void 0,m=this._localizeError(this.viewModel?.error);return h`<div class=${w(S(Ce.base,v.widget))}>${!s&&h`<calcite-button class=${w(v.widgetButton)} .disabled=${r==="disabled"} .iconStart=${i?void 0:o??f} kind=neutral .label=${a} @click=${this._locate} title=${a??N}>${i?h`<calcite-loader inline label></calcite-loader>`:null}</calcite-button>`||""}${m?h`<calcite-tooltip open overlay-positioning=fixed .referenceElement=${this.el}>${m}</calcite-tooltip>`:null}</div>`}};T("arcgis-locate",M);return M},"core/reactiveUtils","core/accessorSupport/decorators","core/Error","intl","PopupTemplate","support/actions/ActionButton","core/Accessor","Graphic","symbols/CIMSymbol","geometry/Point","geometry/operators/projectOperator","config","geometry/support/webMercatorUtils","portal/Portal","rest/geometryService","rest/support/ProjectParameters",a,b,c,d)