maplibre-gl-js-amplify 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -151,9 +151,13 @@
151
151
  yield core.jitteredExponentialRetry(this.refreshCredentials, [], MAX_DELAY_MS);
152
152
  // Refresh credentials on a timer because HubEvents do not trigger on credential refresh currently
153
153
  this.activeTimeout && clearTimeout(this.activeTimeout);
154
- const expiration = new Date(this.credentials.expiration);
155
- const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
156
- this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, timeout);
154
+ // Refresh credentials when expiration time is later than now
155
+ if (this.credentials.expiration.getTime() > (new Date()).getTime()) {
156
+ const expiration = new Date(this.credentials.expiration);
157
+ const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
158
+ this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, Math.min(timeout, 3600000) // Set timeout to an hour if we somehow don't have a value for timeout
159
+ );
160
+ }
157
161
  }
158
162
  catch (e) {
159
163
  console.error(`Failed to refresh credentials: ${e}`);
@@ -172,7 +176,7 @@
172
176
  }
173
177
  url = `https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${url}/style-descriptor`;
174
178
  }
175
- if (url.includes("amazonaws.com")) {
179
+ if (new URL(url).hostname.endsWith(".amazonaws.com")) {
176
180
  // only sign AWS requests (with the signature as part of the query string)
177
181
  const urlWithUserAgent = url +
178
182
  `?x-amz-user-agent=${encodeURIComponent(urlEncodePeriods(core.getAmplifyUserAgent()))}`;
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aws-amplify/core"),require("@aws-amplify/geo"),require("maplibre-gl"),require("@maplibre/maplibre-gl-geocoder"),require("@turf/along"),require("@turf/circle"),require("@turf/length"),require("@turf/helpers"),require("debounce"),require("@mapbox/mapbox-gl-draw"),require("maplibre-gl-draw-circle")):"function"==typeof define&&define.amd?define(["exports","@aws-amplify/core","@aws-amplify/geo","maplibre-gl","@maplibre/maplibre-gl-geocoder","@turf/along","@turf/circle","@turf/length","@turf/helpers","debounce","@mapbox/mapbox-gl-draw","maplibre-gl-draw-circle"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmplifyMapLibre={},e.aws_amplify_core,e.aws_amplify_geo,e.maplibregl,e.MaplibreGeocoder,e.along,e.circle,e.length,e.helpers,e.debounce,e.MapboxDraw,e.maplibreGlDrawCircle)}(this,(function(e,t,o,i,n,r,s,c,l,a,d,u){"use strict";function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=f(i),h=f(n),g=f(r),m=f(s),y=f(c),b=f(d);function v(e){return Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1]}function w(e){return v(e[0])}function G(e){return(t=e[0])&&Array.isArray(t.coordinates)&&"number"==typeof t.coordinates[0]&&"number"==typeof t.coordinates[1];var t}function C(e){return Array.isArray(e)&&((t=e[0])&&"string"==typeof t.geofenceId&&"object"==typeof t.geometry);var t}function _(e){return Array.isArray(e)&&(t=e[0],Array.isArray(t)&&w(t[0]));var t}const A=e=>"string"==typeof e&&e.length>0,L=e=>{let t;return t=w(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e},properties:{place_name:`Coordinates,${e}`}}))):G(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e.coordinates},properties:{title:e.title,address:e.address}}))):e,t};function E(e,t,o){const i=window.document.createElement(e);return void 0!==t&&(i.className=t),o&&o.appendChild(i),i}function x(e){e.parentNode&&e.parentNode.removeChild(e)}var I=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},M=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};class k{constructor(e,o){this.refreshCredentials=()=>I(this,void 0,void 0,(function*(){try{this.credentials=yield t.Credentials.get()}catch(e){throw console.error(`Failed to refresh credentials: ${e}`),e}})),this.refreshCredentialsWithRetry=()=>I(this,void 0,void 0,(function*(){try{const e=3e5;yield t.jitteredExponentialRetry(this.refreshCredentials,[],e),this.activeTimeout&&clearTimeout(this.activeTimeout);const o=new Date(this.credentials.expiration).getTime()-(new Date).getTime()-1e4;this.activeTimeout=window.setTimeout(this.refreshCredentialsWithRetry,o)}catch(e){console.error(`Failed to refresh credentials: ${e}`)}})),this.transformRequest=(e,o)=>{if("Style"===o&&!e.includes("://")){if(null==this.region)throw new Error("AWS region for map is undefined. Please verify that the region is set in aws-exports.js or that you are providing an AWS region parameter to createMap");e=`https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${e}/style-descriptor`}if(e.includes("amazonaws.com")){const o=e+`?x-amz-user-agent=${encodeURIComponent((i=t.getAmplifyUserAgent(),i.replace(/\./g,"%2E")))}`;return{url:t.Signer.signUrl(o,{access_key:this.credentials.accessKeyId,secret_key:this.credentials.secretAccessKey,session_token:this.credentials.sessionToken})}}var i},this.credentials=e,this.region=o,this.activeTimeout=null,this.refreshCredentialsWithRetry(),t.Hub.listen("auth",(e=>{switch(e.payload.event){case"signIn":case"signOut":case"tokenRefresh":this.refreshCredentialsWithRetry()}}))}}k.createMapLibreMap=e=>I(void 0,void 0,void 0,(function*(){const{region:n,mapConstructor:r=i.Map}=e,s=M(e,["region","mapConstructor"]),c=o.Geo.getDefaultMap(),l=new k(yield t.Credentials.get(),n||c.region).transformRequest;return new r(Object.assign(Object.assign({},s),{style:e.style||c.mapName,transformRequest:l}))}));const S="#fff",H="#000",P="#5d8aff",O="#2194f3",T="#003560",R="#FF9900",N="M24.8133 38.533C18.76 31.493 13 28.8264 13 20.8264C13.4827 14.9864 16.552 9.67169 21.368 6.33302C33.768 -2.26165 50.824 5.78902 52.0667 20.8264C52.0667 28.613 46.5733 31.6797 40.6533 38.373C32.4933 47.5464 35.4 63.093 32.4933 63.093C29.72 63.093 32.4933 47.5464 24.8133 38.533ZM32.4933 8.23969C26.5573 8.23969 21.7467 13.0504 21.7467 18.9864C21.7467 24.9224 26.5573 29.733 32.4933 29.733C38.4293 29.733 43.24 24.9224 43.24 18.9864C43.24 13.0504 38.4293 8.23969 32.4933 8.23969Z";var D;!function(e){e.ESRI_TOPOGRAPHIC="VectorEsriTopographic",e.ESRI_STREETS="VectorEsriStreets",e.ESRI_LIGHT_GRAY="VectorEsriLightGrayCanvas",e.ESRI_DARK_GRAY="VectorEsriDarkGrayCanvas",e.ESRI_NAVIGATION="VectorEsriNavigation",e.HERE_BERLIN="VectorHereBerlin"}(D||(D={}));const $={[D.ESRI_TOPOGRAPHIC]:"Noto Sans Regular",[D.ESRI_STREETS]:"Arial Regular",[D.ESRI_LIGHT_GRAY]:"Ubuntu Regular",[D.ESRI_DARK_GRAY]:"Ubuntu Regular",[D.ESRI_NAVIGATION]:"Arial Regular",[D.HERE_BERLIN]:"Fira GO Regular"};function B(e){const t=(null==e?void 0:e.fillColor)?e.fillColor:P,o=(null==e?void 0:e.strokeColor)?e.strokeColor:S,i=(null==e?void 0:e.lineWidth)?e.lineWidth:4;return{width:64,height:64,data:new Uint8Array(16384),onAdd:function(){const e=document.createElement("canvas");e.width=this.width,e.height=this.height,this.context=e.getContext("2d")},render:function(){const e=this.context,n=new Path2D(N);return e.stroke(n),e.fillStyle=t,e.strokeStyle=o,e.lineWidth=i,e.fill(n),this.data=e.getImageData(0,0,this.width,this.height).data,!0}}}var j=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const V="amplify-tip";function F(e,t,o){var{showMarkerPopup:n=!1}=o,r=j(o,["showMarkerPopup"]);const s=`${e}-layer-unclustered-point`;let c=null;function l(){null!==c&&(t.setLayoutProperty(s,"icon-image","inactive-marker"),c=null)}const a=r.popupRender?r.popupRender:function(e,{popupBackgroundColor:t="#fff",popupBorderColor:o="#0000001f",popupBorderWidth:i=2,popupFontColor:n="#000",popupPadding:r=20,popupBorderRadius:s=4,popupTitleFontWeight:c="bold"}){return l=>{let a,d;if(A(l.properties.place_name)){const e=l.properties.place_name.split(",");a=e[0],d=e.splice(1,e.length).join(",")}else A(l.properties.title)||A(l.properties.address)?(a=l.properties.title,d=l.properties.address):(a="Coordinates",d=l.geometry.coordinates);let u=`<div class="${e}-popup" style="background: ${t}; border: ${i}px solid ${o}; color: ${n}; border-radius: ${s}px; padding: ${r}px; word-wrap: break-word; margin: -10px -10px -15px;">`;return a&&(u+=`<div class="${e}-popup-title" style="font-weight: ${c};">${a}</div>`),d&&(u+=`<div class="${e}-popup-address">${d}</div>`),u+="</div>",u}}(s,r);!function(e,{selectedColor:t="#ff9900",selectedBorderColor:o="#fff",selectedBorderWidth:i=4,defaultBorderColor:n="#fff",defaultBorderWidth:r=4,defaultColor:s="#5d8aff",markerImageElement:c,activeMarkerImageElement:l}){const a=c||B({fillColor:s,strokeColor:n,lineWidth:r}),d=l||c||B({fillColor:t,strokeColor:o,lineWidth:i});e.addImage("inactive-marker",a,{pixelRatio:2}),e.addImage("active-marker",d,{pixelRatio:2})}(t,r);const d={id:s,type:"symbol",source:e,filter:["!",["has","point_count"]],layout:{"icon-image":"inactive-marker"}};if(t.addLayer(Object.assign({},d)),n){if(!document.getElementById(V)){const e=document.createElement("style");e.setAttribute("id",V),document.head.append(e),e.textContent=".mapboxgl-popup-tip { display: none; }"}}return t.on("click",(function(){l()})),t.on("click",s,(function(e){if("function"==typeof r.onClick&&r.onClick(e),c=e.features[0].id,t.setLayoutProperty(s,"icon-image",["match",["id"],c,"active-marker","inactive-marker"]),n){const o=e.features[0],n=o.geometry.coordinates;if(v(n)){(new i.Popup).setLngLat(n).setHTML(a(o)).setOffset(15).addTo(t).on("close",(function(){c===o.id&&l()}))}}})),t.on("mouseover",s,(function(){t.getCanvas().style.cursor="pointer"})),t.on("mouseleave",s,(()=>{t.getCanvas().style.cursor=""})),{unclusteredLayerId:s}}function Z(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path"),o=document.createElement("circle");return e.setAttribute("viewBox","0 0 64 64"),e.setAttribute("width","32"),e.setAttribute("height","32"),t.setAttribute("d",N),t.setAttribute("fill","#5d8aff"),o.setAttribute("fill","white"),o.setAttribute("cx","50%"),o.setAttribute("cy","50%"),o.setAttribute("r","5"),e.appendChild(o),e.appendChild(t),e}var W=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},q=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const z={forwardGeocode:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchByText(e.query,{biasPosition:e.bbox?void 0:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});i&&i.forEach((e=>{const{geometry:o}=e,i=q(e,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:o.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:o.point})}))}catch(e){console.error(`Failed to forwardGeocode with error: ${e}`)}return{features:t}})),reverseGeocode:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchByCoordinates(e.query,{maxResults:e.limit});if(i&&i.geometry){const{geometry:e}=i,o=q(i,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},o),place_name:o.label,text:o.label,center:e.point})}}catch(e){console.error(`Failed to reverseGeocode with error: ${e}`)}return{features:t}})),getSuggestions:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchForSuggestions(e.query,{biasPosition:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});t.push(...i)}catch(e){console.error(`Failed to get suggestions with error: ${e}`)}return{suggestions:t}})),searchByPlaceId:e=>W(void 0,void 0,void 0,(function*(){let t;try{const i=yield o.Geo.searchByPlaceId(e.query);if(i){const{geometry:e}=i,o=q(i,["geometry"]);t={type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},o),place_name:o.label,text:o.label,center:e.point}}}catch(e){console.error(`Failed to get place with error: ${e}`)}return{place:t}}))};const U=/^[-._\p{L}\p{N}]+$/iu,K=e=>({type:"Feature",geometry:{type:"MultiPolygon",coordinates:C(e)?e.map((e=>e.geometry.polygon)):e},properties:{}}),Y=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}}),J=(e,t,{bounds:o,radius:i})=>{if(!o&&!i)throw new Error("Circle requires a bounds or a radius");!function(e){const[t,o]=e;if(!Number.isFinite(t)||!Number.isFinite(o))throw new Error(`Invalid coordinates: [${t},${o}]`);if(o<-90||o>90){const e="Latitude must be between -90 and 90 degrees inclusive.";throw console.warn(e),new Error(e)}if(t<-180||t>180){const e="Longitude must be between -180 and 180 degrees inclusive.";throw console.warn(e),new Error(e)}}(t);const n=null!=i?i:Q(o)/8;return{id:e,type:"Feature",properties:{isCircle:!0,center:t,radius:n},geometry:{type:"Polygon",coordinates:m.default(t,n,{units:"miles"}).geometry.coordinates}}},Q=e=>{const t=e.getSouthWest().toArray(),o=e.getNorthEast().toArray(),i=e.getCenter().toArray(),n=l.lineString([t,i,o]);return y.default(n,{units:"miles"})},X=(e,t)=>((e,t)=>!!t[e])(e,t);function ee(e,t,o,i={}){var n,r,s,c,l,a,d,u;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");if(t.length>0&&!C(t)&&!_(t))throw new Error("Please pass in an array of Geofences or an array of Polygons");const f=`${e}`;o.addSource(f,{type:"geojson",data:K(t),generateId:!0});const p=null===(n=i.visible)||void 0===n||n?"visible":"none",h=`${e}-fill-layer`;o.addLayer({id:h,type:"fill",source:f,layout:{visibility:p},paint:{"fill-color":null!==(r=i.fillColor)&&void 0!==r?r:H,"fill-opacity":null!==(s=i.fillOpacity)&&void 0!==s?s:.3}});const g=`${e}-outline-layer`;o.addLayer({id:g,type:"line",source:f,layout:{visibility:p},paint:{"line-color":null!==(c=i.borderColor)&&void 0!==c?c:H,"line-opacity":null!==(l=i.borderOpacity)&&void 0!==l?l:.5,"line-width":null!==(a=i.borderWidth)&&void 0!==a?a:4,"line-offset":null!==(d=i.borderOffset)&&void 0!==d?d:(null!==(u=i.borderWidth)&&void 0!==u?u:4)/2*-1}});return{sourceId:f,outlineLayerId:g,fillLayerId:h,show:()=>{o.setLayoutProperty(h,"visibility","visible"),o.setLayoutProperty(g,"visibility","visible")},hide:()=>{o.setLayoutProperty(h,"visibility","none"),o.setLayoutProperty(g,"visibility","none")},isVisible:()=>"visible"===o.getLayoutProperty(h,"visibility"),setData:e=>{o.getSource(f).setData(e)}}}var te=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};function oe(e,t){let o,i,n,r,s,c,l,d,u,f,p,h,g,m;function y(t){f=E("div","geofence-ctrl-create-circle-mode-container",t);E("div","geofence-ctrl-create-circle-mode-title",f).innerHTML="Radius",m=E("input","geofence-ctrl-create-circle-mode-input",f),m.addEventListener("keydown",a.debounce(e.updateInputRadius,200))}function b(t){p=E("div","geofence-ctrl-create-polygon-mode-container",t);const o=E("div","geofence-ctrl-create-polygon-mode-info-container",p),i=E("div","geofence-ctrl-create-polygon-mode-icon",o);E("div","geofence-ctrl-create-polygon-mode-info-icon",i).innerHTML="i";E("div","geofence-ctrl-create-polygon-mode-title",o).innerHTML="How it works?";const n=E("div","geofence-ctrl-create-polygon-mode-reset-button geofence-ctrl-button",p);n.innerHTML="Reset",n.addEventListener("click",(()=>{e.resetGeofence()}));const r=function(e){const t=E("div","geofence-ctrl-create-polygon-mode-popup-container",e),o=E("div","geofence-ctrl-create-polygon-mode-popup",t);return v(o,"Move dots to desired position",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 38 38"),e.setAttribute("width","38"),e.setAttribute("height","38"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","circle");t.setAttribute("cx","19"),t.setAttribute("cy","18"),t.setAttribute("r","8"),t.setAttribute("fill","#FF9900");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d","M19 0L23.3302 7.5H14.6699L19 0Z"),o.setAttribute("fill","#003560");const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M19 36.5L14.6698 29H23.3301L19 36.5Z"),i.setAttribute("fill","#003560");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M0 18.33L7.5 13.9999L7.5 22.6602L0 18.33Z"),n.setAttribute("fill","#003560");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M37.5 18.3301L30 22.6603V14L37.5 18.3301Z"),r.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e.appendChild(n),e.appendChild(r),e}()),v(o,"Click on a border to create a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 42 27"),e.setAttribute("width","42"),e.setAttribute("height","27"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("y1","8"),t.setAttribute("x2","42"),t.setAttribute("y2","8"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("cx","21"),o.setAttribute("cy","8"),o.setAttribute("r","8"),o.setAttribute("fill","#FF9900");const i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M21 6.17822V22.488L24.6951 19.4356L27.172 26.1782L29.0399 25.3582L26.6035 18.57L31.4762 17.9322L21 6.17822Z"),i.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e}()),v(o,"Click into shape to move",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 32 32"),e.setAttribute("width","32"),e.setAttribute("height","32"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","1"),t.setAttribute("x","1"),t.setAttribute("width","30"),t.setAttribute("height","30"),t.setAttribute("fill","#2196F3"),t.setAttribute("fill-opacity","0.4"),t.setAttribute("stroke","#003560"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M11 6V22.3098L14.6951 19.2574L17.172 26L19.0399 25.18L16.6035 18.3918L21.4762 17.754L11 6Z"),o.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e}()),v(o,"Press delete to remove a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 64 20"),e.setAttribute("width","64"),e.setAttribute("height","20"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","0.5"),t.setAttribute("x","0.5"),t.setAttribute("width","63"),t.setAttribute("height","19"),t.setAttribute("rx","3.5"),t.setAttribute("stroke","#014478");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.4148 15C17.517 15 19.3118 13.076 19.3118 9.89418C19.3118 6.72727 17.517 4.81818 14.5192 4.81818H11.1186V15H14.4148ZM12.6548 13.6577V6.16051H14.4247C16.652 6.16051 17.8004 7.4929 17.8004 9.89418C17.8004 12.3054 16.652 13.6577 14.3303 13.6577H12.6548ZM24.394 15.1541C26.0595 15.1541 27.2377 14.3338 27.5758 13.0909L26.1689 12.8374C25.9004 13.5582 25.2541 13.9261 24.4089 13.9261C23.1362 13.9261 22.2811 13.1009 22.2413 11.6293H27.6703V11.1023C27.6703 8.34304 26.0197 7.2642 24.2896 7.2642C22.1618 7.2642 20.7598 8.88494 20.7598 11.2315C20.7598 13.603 22.1419 15.1541 24.394 15.1541ZM22.2463 10.5156C22.3059 9.43182 23.0914 8.49219 24.2995 8.49219C25.4529 8.49219 26.2086 9.3473 26.2136 10.5156H22.2463ZM30.8061 4.81818H29.3196V15H30.8061V4.81818ZM36.0971 15.1541C37.7626 15.1541 38.9409 14.3338 39.2789 13.0909L37.872 12.8374C37.6035 13.5582 36.9572 13.9261 36.112 13.9261C34.8393 13.9261 33.9842 13.1009 33.9444 11.6293H39.3734V11.1023C39.3734 8.34304 37.7228 7.2642 35.9927 7.2642C33.8649 7.2642 32.4629 8.88494 32.4629 11.2315C32.4629 13.603 33.845 15.1541 36.0971 15.1541ZM33.9494 10.5156C34.0091 9.43182 34.7946 8.49219 36.0027 8.49219C37.1561 8.49219 37.9118 9.3473 37.9167 10.5156H33.9494ZM44.5874 7.36364H43.0213V5.53409H41.5348V7.36364H40.4162V8.55682H41.5348V13.0661C41.5298 14.4531 42.5888 15.1243 43.7621 15.0994C44.2344 15.0945 44.5526 15.005 44.7266 14.9403L44.4581 13.7124C44.3587 13.7322 44.1747 13.777 43.9361 13.777C43.4538 13.777 43.0213 13.6179 43.0213 12.7578V8.55682H44.5874V7.36364ZM49.4409 15.1541C51.1064 15.1541 52.2846 14.3338 52.6227 13.0909L51.2157 12.8374C50.9473 13.5582 50.301 13.9261 49.4558 13.9261C48.1831 13.9261 47.3279 13.1009 47.2882 11.6293H52.7172V11.1023C52.7172 8.34304 51.0666 7.2642 49.3365 7.2642C47.2086 7.2642 45.8066 8.88494 45.8066 11.2315C45.8066 13.603 47.1887 15.1541 49.4409 15.1541ZM47.2931 10.5156C47.3528 9.43182 48.1383 8.49219 49.3464 8.49219C50.4998 8.49219 51.2555 9.3473 51.2605 10.5156H47.2931Z"),o.setAttribute("fill","black"),e.appendChild(t),e.appendChild(o),e}()),o}(i);o.addEventListener("click",(()=>{r.classList.toggle("show")}))}function v(e,t,o){const i=E("div","geofence-ctrl-create-polygon-mode-popup-step",e);E("div","geofence-ctrl-create-polygon-mode-popup-step-image",i).appendChild(o);E("div","geofence-ctrl-create-polygon-mode-popup-step-text",i).innerHTML=t}function w(){x(o),G(),u.style.display="flex"}function G(){g&&(x(g),g=void 0)}return{registerControlPosition:function(e,t){if(e._controlPositions[t])return;const o=document.createElement("div");o.className=`maplibregl-ctrl-${t}`,e._controlContainer.appendChild(o),e._controlPositions[t]=o},createElement:E,removeElement:x,createGeofenceCreateContainer:function(o){const i=E("div","geofence-ctrl-create-prompt-container",t);if(c=E("div","geofence-ctrl-create-prompt",i),o){const t=E("div","geofence-ctrl-create-prompt-buttons",c),o=E("div","geofence-ctrl-create-prompt-button-circle geofence-ctrl-create-prompt-button",t);o.addEventListener("click",(()=>{o.classList.add("geofence-ctrl-create-prompt-selected"),i.classList.remove("geofence-ctrl-create-prompt-selected"),p&&(x(p),p=void 0),f||y(c),e.changeMode("draw_circle")})),o.innerHTML="Circle";const i=E("div","geofence-ctrl-create-prompt-button-polygon geofence-ctrl-create-prompt-button",t);i.addEventListener("click",(()=>{e.changeMode("draw_polygon"),i.classList.add("geofence-ctrl-create-prompt-selected"),o.classList.remove("geofence-ctrl-create-prompt-selected"),f&&(x(f),f=void 0),p||b(c)})),i.innerHTML="Custom",o.classList.add("geofence-ctrl-create-prompt-selected"),y(c)}else b(c)},createGeofenceListContainer:function(){const i=E("div","geofence-ctrl-list-container",t);!function(t){const i=E("div","geofence-ctrl-list-header",t);l=E("div","geofence-ctrl-list-header-title",i),l.innerHTML="Geofences (0)",d=E("div","geofence-ctrl-list-header-checkbox-create-container",i),function(t){u=E("div","geofence-ctrl-list-checkbox-all-container",t),r=E("input","geofence-ctrl-list-checkbox-all",u),r.type="checkbox",r.addEventListener("click",(function(){r.checked?(e.displayAllGeofences(),i.innerHTML="Deselect All"):(e.hideAllGeofences(),i.innerHTML="Select All")}));const i=E("div","geofence-ctrl-list-checkbox-all-title",u);i.innerHTML="Select all",n=E("div","geofence-ctrl-list-header-add-button",u),n.innerHTML="+ Add",n.addEventListener("click",(()=>{!function(){u.style.display="none",o=E("div","geofence-ctrl-add-geofence-container",d);const t=E("div","geofence-ctrl-add-geofence",o),i=E("input","geofence-ctrl-add-geofence-input",t);i.placeholder="Enter name";const n=E("div","geofence-ctrl-add-geofence-buttons",t),r=E("div","geofence-ctrl-add-geofence-cancel-button geofence-ctrl-button ",n);r.innerHTML="Cancel",r.addEventListener("click",(()=>{w(),e.setEditingModeEnabled(!1)}));const s=E("div","geofence-ctrl-button geofence-ctrl-save-button",n);s.innerHTML="Save",s.addEventListener("click",(function(){return te(this,void 0,void 0,(function*(){G();(yield e.createGeofence(escape(i.value)))&&w()}))})),e.addEditableGeofence()}()}))}(d)}(i),s=E("div","geofence-ctrl-list",i),s.addEventListener("scroll",(()=>{const{scrollHeight:t,scrollTop:o,clientHeight:i}=s;o+i>=t-20&&e.loadMoreGeofences()}))},removeAddGeofenceContainer:w,createAddGeofencePromptError:function(e){if(g)return;g=E("div","geofence-ctrl-add-geofence-error",o),E("div","geofence-ctrl-add-geofence-error-icon",g).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 10"),e.setAttribute("width","12"),e.setAttribute("height","10"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M0 10H11.5789L5.78947 0L0 10ZM6.31579 8.42105H5.26316V7.36842H6.31579V8.42105ZM6.31579 6.31579H5.26316V4.21053H6.31579V6.31579Z"),t.setAttribute("fill","#FF5050"),e.appendChild(t),e}()),E("div","geofence-ctrl-add-geofence-error-text",g).innerHTML=e},renderListItem:function(o){const n=E("li","geofence-ctrl-list-item-container",s);n.id=`list-item-${o.geofenceId}`;const r=E("li","geofence-ctrl-list-item",n),c=E("div","geofence-ctrl-list-item-left-container",r),l=E("input","geofence-ctrl-list-item-checkbox",c);l.id=`list-item-checkbox-${o.geofenceId}`,l.type="checkbox",l.addEventListener("click",(function(){l.checked?(e.displayGeofence(o.geofenceId),e.fitGeofence(o.geofenceId)):e.hideGeofence(o.geofenceId)}));const a=E("div","geofence-ctrl-list-item-right-container",r),d=E("div","geofence-ctrl-list-item-title-container",a);d.addEventListener("mouseover",(function(){e.displayHighlightedGeofence(o.geofenceId)})),d.addEventListener("mouseout",(function(){e.hideHighlightedGeofence()})),E("div","geofence-ctrl-list-item-title",d).innerHTML=o.geofenceId;const u=E("div","geofence-ctrl-edit-button",d);u.addEventListener("click",(function(){e.editGeofence(o.geofenceId),function(o,n,r,s){const c=E("div","geofence-ctrl-list-item-controls",n),l=function(o,n){const r=E("div","geofence-ctrl-delete-button",o);return r.classList.add("geofence-ctrl-button"),r.addEventListener("click",(function(){!function(o){i=E("div","geofence-ctrl-delete-prompt-container",t);const n=E("div","geofence-ctrl-delete-prompt",i);E("div","geofence-ctrl-delete-geofence-title",n).innerHTML=`Are you sure you want to delete <strong>${o}</strong>?`,function(o,n){const r=E("div","geofence-ctrl-delete-geofence-buttons",o),s=E("div","geofence-ctrl-delete-geofence-cancel-button",r);s.innerHTML="Cancel",s.addEventListener("click",(()=>{x(i)}));const c=E("div","geofence-ctrl-delete-geofence-confirm-button",r);c.innerHTML="Delete",c.addEventListener("click",(function(){return te(this,void 0,void 0,(function*(){(yield e.deleteGeofence(n))&&(!function(e){h=E("div","geofence-ctrl-delete-popdown-container",t);const o=E("div","geofence-ctrl-delete-popdown",h),i=E("div","geofence-ctrl-delete-popdown-close-button",h);i.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M10.773 2.28762L9.71231 1.22696L6 4.93927L2.28769 1.22696L1.22703 2.28762L4.93934 5.99993L1.22703 9.71224L2.28769 10.7729L6 7.06059L9.71231 10.7729L10.773 9.71224L7.06066 5.99993L10.773 2.28762Z"),t.setAttribute("fill","white"),t.setAttribute("fill-rule","evenodd"),t.setAttribute("clip-rule","evenodd"),e.appendChild(t),e}()),i.addEventListener("click",(()=>{x(h)}));E("div","geofence-ctrl-delete-popdown-icon",o).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M6 0C2.688 0 0 2.688 0 6C0 9.312 2.688 12 6 12C9.312 12 12 9.312 12 6C12 2.688 9.312 0 6 0ZM6 10.8C3.354 10.8 1.2 8.646 1.2 6C1.2 3.354 3.354 1.2 6 1.2C8.646 1.2 10.8 3.354 10.8 6C10.8 8.646 8.646 10.8 6 10.8ZM8.754 3.348L4.8 7.302L3.246 5.754L2.4 6.6L4.8 9L9.6 4.2L8.754 3.348Z"),t.setAttribute("fill","white"),e.appendChild(t),e}());E("div","geofence-ctrl-delete-popdown-text",o).innerHTML=e?"Geofence was deleted successfully":"Geofence failed to delete"}(!0),x(i),e.setEditingModeEnabled(!1))}))}))}(n,o)}(n)})),r.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 12 16"),e.setAttribute("width","12"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M9.33317 5.5V13.8333H2.6665V5.5H9.33317ZM8.08317 0.5H3.9165L3.08317 1.33333H0.166504V3H11.8332V1.33333H8.9165L8.08317 0.5ZM10.9998 3.83333H0.999837V13.8333C0.999837 14.75 1.74984 15.5 2.6665 15.5H9.33317C10.2498 15.5 10.9998 14.75 10.9998 13.8333V3.83333Z"),t.setAttribute("fill","white"),e.appendChild(t),e}()),r}(r,s),a=()=>{o.classList.remove("geofence-ctrl-list-selected-item"),o.classList.add("geofence-ctrl-list-item"),x(c),x(l)},d=E("div","geofence-ctrl-cancel-button",c);d.classList.add("geofence-ctrl-button"),d.innerHTML="Cancel",d.addEventListener("click",(()=>{e.setEditingModeEnabled(!1),a()}));const u=E("div","geofence-ctrl-save-button geofence-ctrl-button",c);u.addEventListener("click",(()=>te(this,void 0,void 0,(function*(){yield e.saveGeofence(),a()})))),u.title="Save",u.innerHTML="Save"}(r,a,c,o.geofenceId),r.classList.remove("geofence-ctrl-list-item"),r.classList.add("geofence-ctrl-list-selected-item")})),u.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M0.5 12.375V15.5H3.625L12.8417 6.28333L9.71667 3.15833L0.5 12.375ZM2.93333 13.8333H2.16667V13.0667L9.71667 5.51667L10.4833 6.28333L2.93333 13.8333ZM15.2583 2.69167L13.3083 0.741667C13.1417 0.575 12.9333 0.5 12.7167 0.5C12.5 0.5 12.2917 0.583333 12.1333 0.741667L10.6083 2.26667L13.7333 5.39167L15.2583 3.86667C15.5833 3.54167 15.5833 3.01667 15.2583 2.69167Z"),t.setAttribute("fill","white"),e.appendChild(t),e}())},updateCheckbox:function(e,t){const o=document.getElementById(`list-item-checkbox-${e}`);o&&(o.checked=t)},removeGeofenceListItem:function(e){x(document.getElementById(`list-item-${e}`))},setGeofenceListEnabled:function(e){r.disabled=!e,e?n.classList.remove("geofence-ctrl-noHover"):n.classList.add("geofence-ctrl-noHover");const t=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");for(let o=0;o<t.length;o++)t.item(o).disabled=!e;const o=document.getElementsByClassName("geofence-ctrl-list-item-container");for(let t=0;t<o.length;t++)e?o.item(t).classList.remove("geofence-ctrl-noHover"):o.item(t).classList.add("geofence-ctrl-noHover")},getCheckboxAllValue:function(){return r.checked},removeGeofenceCreateContainer:function(){x(c),c=void 0,f=void 0,p=void 0},updateGeofenceCount:function(e){l.innerHTML=`Geofences (${e})`},updateGeofenceRadius:function(e){m&&(m.value=`${e}`)}}}class ie{constructor(e,t){this._mapBoxDraw=new b.default({displayControlsDefault:!1,defaultMode:"simple_select",userProperties:!0,controls:{trash:!0},modes:Object.assign(Object.assign({},b.default.modes),{draw_circle:u.CircleMode,direct_select:u.DirectMode,simple_select:u.SimpleSelectMode}),styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":O,"fill-outline-color":O,"fill-opacity":.3}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":R}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":T,"line-width":4}},{id:"gl-draw-polygon-and-line-vertex-active",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":8,"circle-color":R,"circle-stroke-color":T,"circle-stroke-width":1}}]}),this._map=e,this._ui=t,this.enable=this.enable.bind(this),this.disable=this.disable.bind(this),this.drawPolygonGeofence=this.drawPolygonGeofence.bind(this)}get(e){return this._mapBoxDraw.get(e)}add(e){const t=e.properties.isCircle;this.enable(t),this._mapBoxDraw.add(e),this._mapBoxDraw.changeMode("direct_select",{featureId:e.id})}delete(e){this._mapBoxDraw.delete(e)}disable(){this._map.hasControl(this._mapBoxDraw)&&this._map.removeControl(this._mapBoxDraw),this._ui.removeGeofenceCreateContainer()}enable(e){this._map.hasControl(this._mapBoxDraw)||(this._map.addControl(this._mapBoxDraw,"bottom-right"),this._ui.createGeofenceCreateContainer(e))}drawPolygonGeofence(e){const t=((e,t)=>{const o=t.getSouthWest().toArray(),i=t.getNorthEast().toArray(),n=t.getCenter().toArray(),r=l.lineString([o,n,i]),s=y.default(r,{units:"miles"}),c=g.default(r,s/4,{units:"miles"}).geometry.coordinates,a=g.default(r,s*(3/4),{units:"miles"}).geometry.coordinates;return{id:e,type:"Feature",geometry:{type:"Polygon",coordinates:[[a,[c[0],a[1]],c,[a[0],c[1]],a]]},properties:{}}})(e,this._map.getBounds());this.add(t)}drawCircularGeofence(e,t){const o=this._map.getBounds(),i=J(e,this._map.getCenter().toArray(),{bounds:o,radius:t});this.add(i),this._ui.updateGeofenceRadius(t||i.properties.radius.toFixed(2))}}var ne=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};const re={left:240};e.AmplifyGeocoderAPI=z,e.AmplifyGeofenceControl=class{constructor(e){this._geofenceCollectionId=null==e?void 0:e.geofenceCollectionId,this._loadedGeofences={},this._displayedGeofences=[],this.changeMode=this.changeMode.bind(this),this.loadInitialGeofences=this.loadInitialGeofences.bind(this),this.loadMoreGeofences=this.loadMoreGeofences.bind(this),this._loadGeofence=this._loadGeofence.bind(this),this.updateInputRadius=this.updateInputRadius.bind(this),this.saveGeofence=this.saveGeofence.bind(this),this.editGeofence=this.editGeofence.bind(this),this.deleteGeofence=this.deleteGeofence.bind(this),this.displayAllGeofences=this.displayAllGeofences.bind(this),this.hideAllGeofences=this.hideAllGeofences.bind(this),this.addEditableGeofence=this.addEditableGeofence.bind(this),this.setEditingModeEnabled=this.setEditingModeEnabled.bind(this),this.displayHighlightedGeofence=this.displayHighlightedGeofence.bind(this),this.hideHighlightedGeofence=this.hideHighlightedGeofence.bind(this),this.displayGeofence=this.displayGeofence.bind(this),this.hideGeofence=this.hideGeofence.bind(this),this.fitGeofence=this.fitGeofence.bind(this),this.fitAllGeofences=this.fitAllGeofences.bind(this)}getDefaultPosition(){return"full-screen"}onRemove(){this._ui.removeElement(this._container)}reorderMapLibreClassNames(){const e=document.getElementsByClassName("maplibregl-canvas").item(0);e&&(e.className="mapboxgl-canvas maplibregl-canvas")}onAdd(e){return this._map=e,this.reorderMapLibreClassNames(),this._container=E("div","geofence-ctrl maplibregl-ctrl"),this._ui=oe(this,this._container),this._amplifyDraw=new ie(e,this._ui),this._ui.registerControlPosition(e,"full-screen"),this._ui.createGeofenceListContainer(),this._map.once("load",function(){this._map.getSource("displayedGeofences")||(this._drawGeofencesOutput=ee("displayedGeofences",[],this._map,{fillColor:O,borderColor:T,borderOpacity:1}),this._highlightedGeofenceOutput=ee("highlightedGeofence",[],this._map,{fillColor:O,borderColor:T,borderOpacity:1,borderWidth:6}),this.loadInitialGeofences(),e.addControl(new p.default.NavigationControl({showCompass:!1}),"bottom-right"))}.bind(this)),this._map.on("draw.update",(()=>{const e=this._amplifyDraw._mapBoxDraw.getAll().features[0].geometry.coordinates[0],t=((e,t)=>{const o=l.lineString([e,t]);return y.default(o,{units:"miles"})})(e[0],e[Math.floor(e.length/2)])/2;this._ui.updateGeofenceRadius(t.toFixed(2))})),this._container}createGeofence(e){return ne(this,void 0,void 0,(function*(){if(e&&0!==e.length)if(e.match(U)){if(!X(e,this._loadedGeofences))return this.saveGeofence(e);this._ui.createAddGeofencePromptError("Geofence ID already exists.")}else this._ui.createAddGeofencePromptError("Geofence ID contains special characters.");else this._ui.createAddGeofencePromptError("Geofence ID is empty.")}))}saveGeofence(e){return ne(this,void 0,void 0,(function*(){const t=this._amplifyDraw.get(this._editingGeofenceId),i=e||this._editingGeofenceId,n=yield o.Geo.saveGeofences({geofenceId:i,geometry:{polygon:t.geometry.coordinates}});if(n.errors[0]){const e=n.errors[0];throw new Error(`There was an error saving geofence with id ${i}: ${e.error.code} - ${e.error.message}`)}const r={geofenceId:n.successes[0].geofenceId,geometry:{polygon:t.geometry.coordinates}};return this._loadGeofence(r),this.displayGeofence(r.geofenceId),this.setEditingModeEnabled(!1),r.geofenceId}))}loadInitialGeofences(){return ne(this,void 0,void 0,(function*(){try{const{entries:e,nextToken:t}=yield o.Geo.listGeofences();this._listGeofencesNextToken=t;const i=this._loadGeofence;e.forEach((e=>i(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}loadMoreGeofences(){return ne(this,void 0,void 0,(function*(){if(this._listGeofencesNextToken)try{const{entries:e,nextToken:t}=yield o.Geo.listGeofences({nextToken:this._listGeofencesNextToken});this._listGeofencesNextToken=t;const i=this._loadGeofence;e.forEach((e=>i(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}editGeofence(e){this.setEditingModeEnabled(!0);const t=this._loadedGeofences[e];if(!t)throw new Error(`Geofence with id ${e} does not exist`);const o=Y(t.geometry.polygon),i=Object.assign({id:t.geofenceId},o);this._amplifyDraw.add(i),this._editingGeofenceId=t.geofenceId}deleteGeofence(e){return ne(this,void 0,void 0,(function*(){const t=yield o.Geo.deleteGeofences(e);if(t.errors[0]){const o=t.errors[0].error;throw new Error(`There was an error deleting geofence with id ${e}: ${o.code} - ${o.message}`)}return this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e],this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length),this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),e}))}deleteSelectedGeofences(){this._displayedGeofences.map((e=>e.geofenceId)).forEach((e=>{this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e]})),this._displayedGeofences=[],this._updateDisplayedGeofences()}_loadGeofence(e){this._loadedGeofences[e.geofenceId]?this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e.geofenceId)):this._ui.renderListItem(e),this._loadedGeofences[e.geofenceId]=e,this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}displayGeofence(e){this._displayedGeofences.push(this._loadedGeofences[e]),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!0),this.fitAllGeofences()}displayAllGeofences(){this._displayedGeofences.push(...Object.values(this._loadedGeofences)),this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue())),this.fitAllGeofences()}fitGeofence(e){const t=this._map.getBounds();this._loadedGeofences[e].geometry.polygon[0].forEach((e=>{t.extend(e)})),this._map.fitBounds(t,{padding:re})}fitAllGeofences(){let e=!1;const t=this._map.getBounds();this._displayedGeofences.forEach((o=>{o.geometry.polygon[0].forEach((o=>{t.contains(o)||(t.extend(o),e=!0)}))})),e&&this._map.fitBounds(t,{padding:re})}hideGeofence(e){this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!1)}hideAllGeofences(){this._displayedGeofences=[],this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue()))}_updateDisplayedGeofences(){const e=K(this._displayedGeofences);this._drawGeofencesOutput.setData(e)}displayHighlightedGeofence(e){const t=this._loadedGeofences[e];if(!t)return void console.warn(`Geofence with id ${e} does not exist`);const o=Y(t.geometry.polygon);this._highlightedGeofenceOutput.setData(o),this._highlightedGeofenceOutput.show()}hideHighlightedGeofence(){this._highlightedGeofenceOutput.hide()}changeMode(e){this._amplifyDraw.delete(this._editingGeofenceId),"draw_circle"===e?this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}resetGeofence(){this._amplifyDraw.delete(this._editingGeofenceId),X(this._editingGeofenceId,this._loadedGeofences)?this.editGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}setEditingModeEnabled(e){e?this._amplifyDraw.enable():this._amplifyDraw.disable(),e?this._drawGeofencesOutput.hide():this._drawGeofencesOutput.show(),this._ui.setGeofenceListEnabled(!e)}updateInputRadius(e){const t=e.target.value,o=parseInt(t);isNaN(o)||this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId,o)}addEditableGeofence(){this._editingGeofenceId="tempGeofence",this._amplifyDraw.drawCircularGeofence("tempGeofence"),this.setEditingModeEnabled(!0)}},e.AmplifyMapLibreRequest=k,e.createAmplifyGeocoder=function(e){return new h.default(z,Object.assign({maplibregl:p.default,showResultMarkers:{element:Z()},marker:{element:Z()},showResultsWhileTyping:null==e?void 0:e.autocomplete},e))},e.createDefaultIcon=Z,e.createMap=e=>I(void 0,void 0,void 0,(function*(){return k.createMapLibreMap(e)})),e.drawGeofences=ee,e.drawPoints=function(e,t,i,{showCluster:n=!0,clusterOptions:r={},unclusteredOptions:s={},autoFit:c=!0}={},l){var a,d;if(!i||"function"!=typeof i.addSource||"function"!=typeof i.addLayer)throw new Error("Please use a maplibre map");const u=L(t),f=e;let p,h;i.addSource(f,{type:"geojson",data:{type:"FeatureCollection",features:u},cluster:n,clusterMaxZoom:null!==(a=r.clusterMaxZoom)&&void 0!==a?a:14,clusterRadius:null!==(d=r.smCircleSize)&&void 0!==d?d:60,generateId:!0}),n&&({clusterLayerId:p,clusterSymbolLayerId:h}=function(e,t,{fillColor:i="#5d8aff",smCircleSize:n=60,smThreshold:r=50,mdCircleSize:s=100,mdThreshold:c=100,lgCircleSize:l=140,lgThreshold:a=500,xlCircleSize:d=180,borderWidth:u=4,borderColor:f="#fff",clusterPaint:p,onClick:h,showCount:g,clusterCountLayout:m,fontColor:y="#fff"},b){const v=`${e}-layer-clusters`,w=`${e}-layer-cluster-count`,G=Object.assign({"circle-color":["step",["get","point_count"],i,r,i,c,i,a,i],"circle-radius":["step",["get","point_count"],n,r,s,c,l,a,d],"circle-stroke-width":u,"circle-stroke-color":f},p),C={id:v,type:"circle",source:e,filter:["has","point_count"],paint:G};if(t.addLayer(Object.assign({},C)),t.on("click",v,(function(o){"function"==typeof h&&h(o);const i=t.queryRenderedFeatures(o.point,{layers:[v]}),n=i[0].properties.cluster_id,r=t.getSource(e);(function(e){return"geojson"===e.type})(r)&&r.getClusterExpansionZoom(n,(function(e,o){e||t.easeTo({center:i[0].geometry.coordinates,zoom:o})}))})),g){const i={"text-field":"{point_count_abbreviated}","text-size":24},n=b||o.Geo.getDefaultMap().style;n&&(i["text-font"]=[$[n]]);const r=Object.assign(Object.assign({},i),m),s={id:w,type:"symbol",source:e,filter:["has","point_count"],layout:r,paint:{"text-color":y}};t.addLayer(Object.assign({},s))}return{clusterLayerId:v,clusterSymbolLayerId:w}}(f,i,r,l));const{unclusteredLayerId:g}=F(f,i,s||{});if(c){const e=i.getBounds();u.forEach((function(t){e.extend(t.geometry.coordinates)})),i.fitBounds(e)}return{sourceId:f,unclusteredLayerId:g,clusterLayerId:p,clusterSymbolLayerId:h,setData:e=>{const t=L(e);i.getSource(f).setData({type:"FeatureCollection",features:t})},show:()=>{i.setLayoutProperty(g,"visibility","visible"),p&&i.setLayoutProperty(p,"visibility","visible"),h&&i.setLayoutProperty(h,"visibility","visible")},hide:()=>{i.setLayoutProperty(g,"visibility","none"),p&&i.setLayoutProperty(p,"visibility","none"),h&&i.setLayoutProperty(h,"visibility","none")}}},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@aws-amplify/core"),require("@aws-amplify/geo"),require("maplibre-gl"),require("@maplibre/maplibre-gl-geocoder"),require("@turf/along"),require("@turf/circle"),require("@turf/length"),require("@turf/helpers"),require("debounce"),require("@mapbox/mapbox-gl-draw"),require("maplibre-gl-draw-circle")):"function"==typeof define&&define.amd?define(["exports","@aws-amplify/core","@aws-amplify/geo","maplibre-gl","@maplibre/maplibre-gl-geocoder","@turf/along","@turf/circle","@turf/length","@turf/helpers","debounce","@mapbox/mapbox-gl-draw","maplibre-gl-draw-circle"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AmplifyMapLibre={},e.aws_amplify_core,e.aws_amplify_geo,e.maplibregl,e.MaplibreGeocoder,e.along,e.circle,e.length,e.helpers,e.debounce,e.MapboxDraw,e.maplibreGlDrawCircle)}(this,(function(e,t,o,i,n,r,s,c,l,a,d,u){"use strict";function f(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=f(i),h=f(n),g=f(r),m=f(s),y=f(c),b=f(d);function v(e){return Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1]}function w(e){return v(e[0])}function G(e){return(t=e[0])&&Array.isArray(t.coordinates)&&"number"==typeof t.coordinates[0]&&"number"==typeof t.coordinates[1];var t}function C(e){return Array.isArray(e)&&((t=e[0])&&"string"==typeof t.geofenceId&&"object"==typeof t.geometry);var t}function _(e){return Array.isArray(e)&&(t=e[0],Array.isArray(t)&&w(t[0]));var t}const L=e=>"string"==typeof e&&e.length>0,A=e=>{let t;return t=w(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e},properties:{place_name:`Coordinates,${e}`}}))):G(e)?e.map((e=>({type:"Feature",geometry:{type:"Point",coordinates:e.coordinates},properties:{title:e.title,address:e.address}}))):e,t};function E(e,t,o){const i=window.document.createElement(e);return void 0!==t&&(i.className=t),o&&o.appendChild(i),i}function x(e){e.parentNode&&e.parentNode.removeChild(e)}var I=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},M=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};class k{constructor(e,o){this.refreshCredentials=()=>I(this,void 0,void 0,(function*(){try{this.credentials=yield t.Credentials.get()}catch(e){throw console.error(`Failed to refresh credentials: ${e}`),e}})),this.refreshCredentialsWithRetry=()=>I(this,void 0,void 0,(function*(){try{const e=3e5;if(yield t.jitteredExponentialRetry(this.refreshCredentials,[],e),this.activeTimeout&&clearTimeout(this.activeTimeout),this.credentials.expiration.getTime()>(new Date).getTime()){const e=new Date(this.credentials.expiration).getTime()-(new Date).getTime()-1e4;this.activeTimeout=window.setTimeout(this.refreshCredentialsWithRetry,Math.min(e,36e5))}}catch(e){console.error(`Failed to refresh credentials: ${e}`)}})),this.transformRequest=(e,o)=>{if("Style"===o&&!e.includes("://")){if(null==this.region)throw new Error("AWS region for map is undefined. Please verify that the region is set in aws-exports.js or that you are providing an AWS region parameter to createMap");e=`https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${e}/style-descriptor`}if(new URL(e).hostname.endsWith(".amazonaws.com")){const o=e+`?x-amz-user-agent=${encodeURIComponent((i=t.getAmplifyUserAgent(),i.replace(/\./g,"%2E")))}`;return{url:t.Signer.signUrl(o,{access_key:this.credentials.accessKeyId,secret_key:this.credentials.secretAccessKey,session_token:this.credentials.sessionToken})}}var i},this.credentials=e,this.region=o,this.activeTimeout=null,this.refreshCredentialsWithRetry(),t.Hub.listen("auth",(e=>{switch(e.payload.event){case"signIn":case"signOut":case"tokenRefresh":this.refreshCredentialsWithRetry()}}))}}k.createMapLibreMap=e=>I(void 0,void 0,void 0,(function*(){const{region:n,mapConstructor:r=i.Map}=e,s=M(e,["region","mapConstructor"]),c=o.Geo.getDefaultMap(),l=new k(yield t.Credentials.get(),n||c.region).transformRequest;return new r(Object.assign(Object.assign({},s),{style:e.style||c.mapName,transformRequest:l}))}));const S="#fff",H="#000",P="#5d8aff",O="#2194f3",T="#003560",R="#FF9900",N="M24.8133 38.533C18.76 31.493 13 28.8264 13 20.8264C13.4827 14.9864 16.552 9.67169 21.368 6.33302C33.768 -2.26165 50.824 5.78902 52.0667 20.8264C52.0667 28.613 46.5733 31.6797 40.6533 38.373C32.4933 47.5464 35.4 63.093 32.4933 63.093C29.72 63.093 32.4933 47.5464 24.8133 38.533ZM32.4933 8.23969C26.5573 8.23969 21.7467 13.0504 21.7467 18.9864C21.7467 24.9224 26.5573 29.733 32.4933 29.733C38.4293 29.733 43.24 24.9224 43.24 18.9864C43.24 13.0504 38.4293 8.23969 32.4933 8.23969Z";var D;!function(e){e.ESRI_TOPOGRAPHIC="VectorEsriTopographic",e.ESRI_STREETS="VectorEsriStreets",e.ESRI_LIGHT_GRAY="VectorEsriLightGrayCanvas",e.ESRI_DARK_GRAY="VectorEsriDarkGrayCanvas",e.ESRI_NAVIGATION="VectorEsriNavigation",e.HERE_BERLIN="VectorHereBerlin"}(D||(D={}));const $={[D.ESRI_TOPOGRAPHIC]:"Noto Sans Regular",[D.ESRI_STREETS]:"Arial Regular",[D.ESRI_LIGHT_GRAY]:"Ubuntu Regular",[D.ESRI_DARK_GRAY]:"Ubuntu Regular",[D.ESRI_NAVIGATION]:"Arial Regular",[D.HERE_BERLIN]:"Fira GO Regular"};function B(e){const t=(null==e?void 0:e.fillColor)?e.fillColor:P,o=(null==e?void 0:e.strokeColor)?e.strokeColor:S,i=(null==e?void 0:e.lineWidth)?e.lineWidth:4;return{width:64,height:64,data:new Uint8Array(16384),onAdd:function(){const e=document.createElement("canvas");e.width=this.width,e.height=this.height,this.context=e.getContext("2d")},render:function(){const e=this.context,n=new Path2D(N);return e.stroke(n),e.fillStyle=t,e.strokeStyle=o,e.lineWidth=i,e.fill(n),this.data=e.getImageData(0,0,this.width,this.height).data,!0}}}var j=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const V="amplify-tip";function F(e,t,o){var{showMarkerPopup:n=!1}=o,r=j(o,["showMarkerPopup"]);const s=`${e}-layer-unclustered-point`;let c=null;function l(){null!==c&&(t.setLayoutProperty(s,"icon-image","inactive-marker"),c=null)}const a=r.popupRender?r.popupRender:function(e,{popupBackgroundColor:t="#fff",popupBorderColor:o="#0000001f",popupBorderWidth:i=2,popupFontColor:n="#000",popupPadding:r=20,popupBorderRadius:s=4,popupTitleFontWeight:c="bold"}){return l=>{let a,d;if(L(l.properties.place_name)){const e=l.properties.place_name.split(",");a=e[0],d=e.splice(1,e.length).join(",")}else L(l.properties.title)||L(l.properties.address)?(a=l.properties.title,d=l.properties.address):(a="Coordinates",d=l.geometry.coordinates);let u=`<div class="${e}-popup" style="background: ${t}; border: ${i}px solid ${o}; color: ${n}; border-radius: ${s}px; padding: ${r}px; word-wrap: break-word; margin: -10px -10px -15px;">`;return a&&(u+=`<div class="${e}-popup-title" style="font-weight: ${c};">${a}</div>`),d&&(u+=`<div class="${e}-popup-address">${d}</div>`),u+="</div>",u}}(s,r);!function(e,{selectedColor:t="#ff9900",selectedBorderColor:o="#fff",selectedBorderWidth:i=4,defaultBorderColor:n="#fff",defaultBorderWidth:r=4,defaultColor:s="#5d8aff",markerImageElement:c,activeMarkerImageElement:l}){const a=c||B({fillColor:s,strokeColor:n,lineWidth:r}),d=l||c||B({fillColor:t,strokeColor:o,lineWidth:i});e.addImage("inactive-marker",a,{pixelRatio:2}),e.addImage("active-marker",d,{pixelRatio:2})}(t,r);const d={id:s,type:"symbol",source:e,filter:["!",["has","point_count"]],layout:{"icon-image":"inactive-marker"}};if(t.addLayer(Object.assign({},d)),n){if(!document.getElementById(V)){const e=document.createElement("style");e.setAttribute("id",V),document.head.append(e),e.textContent=".mapboxgl-popup-tip { display: none; }"}}return t.on("click",(function(){l()})),t.on("click",s,(function(e){if("function"==typeof r.onClick&&r.onClick(e),c=e.features[0].id,t.setLayoutProperty(s,"icon-image",["match",["id"],c,"active-marker","inactive-marker"]),n){const o=e.features[0],n=o.geometry.coordinates;if(v(n)){(new i.Popup).setLngLat(n).setHTML(a(o)).setOffset(15).addTo(t).on("close",(function(){c===o.id&&l()}))}}})),t.on("mouseover",s,(function(){t.getCanvas().style.cursor="pointer"})),t.on("mouseleave",s,(()=>{t.getCanvas().style.cursor=""})),{unclusteredLayerId:s}}function Z(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path"),o=document.createElement("circle");return e.setAttribute("viewBox","0 0 64 64"),e.setAttribute("width","32"),e.setAttribute("height","32"),t.setAttribute("d",N),t.setAttribute("fill","#5d8aff"),o.setAttribute("fill","white"),o.setAttribute("cx","50%"),o.setAttribute("cy","50%"),o.setAttribute("r","5"),e.appendChild(o),e.appendChild(t),e}var W=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))},q=function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(o[i[n]]=e[i[n]])}return o};const z={forwardGeocode:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchByText(e.query,{biasPosition:e.bbox?void 0:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});i&&i.forEach((e=>{const{geometry:o}=e,i=q(e,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:o.point},properties:Object.assign({},i),place_name:i.label,text:i.label,center:o.point})}))}catch(e){console.error(`Failed to forwardGeocode with error: ${e}`)}return{features:t}})),reverseGeocode:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchByCoordinates(e.query,{maxResults:e.limit});if(i&&i.geometry){const{geometry:e}=i,o=q(i,["geometry"]);t.push({type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},o),place_name:o.label,text:o.label,center:e.point})}}catch(e){console.error(`Failed to reverseGeocode with error: ${e}`)}return{features:t}})),getSuggestions:e=>W(void 0,void 0,void 0,(function*(){const t=[];try{const i=yield o.Geo.searchForSuggestions(e.query,{biasPosition:e.proximity,searchAreaConstraints:e.bbox,countries:e.countries,maxResults:e.limit});t.push(...i)}catch(e){console.error(`Failed to get suggestions with error: ${e}`)}return{suggestions:t}})),searchByPlaceId:e=>W(void 0,void 0,void 0,(function*(){let t;try{const i=yield o.Geo.searchByPlaceId(e.query);if(i){const{geometry:e}=i,o=q(i,["geometry"]);t={type:"Feature",geometry:{type:"Point",coordinates:e.point},properties:Object.assign({},o),place_name:o.label,text:o.label,center:e.point}}}catch(e){console.error(`Failed to get place with error: ${e}`)}return{place:t}}))};const U=/^[-._\p{L}\p{N}]+$/iu,K=e=>({type:"Feature",geometry:{type:"MultiPolygon",coordinates:C(e)?e.map((e=>e.geometry.polygon)):e},properties:{}}),Y=e=>({type:"Feature",geometry:{type:"Polygon",coordinates:e},properties:{}}),J=(e,t,{bounds:o,radius:i})=>{if(!o&&!i)throw new Error("Circle requires a bounds or a radius");!function(e){const[t,o]=e;if(!Number.isFinite(t)||!Number.isFinite(o))throw new Error(`Invalid coordinates: [${t},${o}]`);if(o<-90||o>90){const e="Latitude must be between -90 and 90 degrees inclusive.";throw console.warn(e),new Error(e)}if(t<-180||t>180){const e="Longitude must be between -180 and 180 degrees inclusive.";throw console.warn(e),new Error(e)}}(t);const n=null!=i?i:Q(o)/8;return{id:e,type:"Feature",properties:{isCircle:!0,center:t,radius:n},geometry:{type:"Polygon",coordinates:m.default(t,n,{units:"miles"}).geometry.coordinates}}},Q=e=>{const t=e.getSouthWest().toArray(),o=e.getNorthEast().toArray(),i=e.getCenter().toArray(),n=l.lineString([t,i,o]);return y.default(n,{units:"miles"})},X=(e,t)=>((e,t)=>!!t[e])(e,t);function ee(e,t,o,i={}){var n,r,s,c,l,a,d,u;if(!o||"function"!=typeof o.addSource||"function"!=typeof o.addLayer)throw new Error("Please use a maplibre map");if(t.length>0&&!C(t)&&!_(t))throw new Error("Please pass in an array of Geofences or an array of Polygons");const f=`${e}`;o.addSource(f,{type:"geojson",data:K(t),generateId:!0});const p=null===(n=i.visible)||void 0===n||n?"visible":"none",h=`${e}-fill-layer`;o.addLayer({id:h,type:"fill",source:f,layout:{visibility:p},paint:{"fill-color":null!==(r=i.fillColor)&&void 0!==r?r:H,"fill-opacity":null!==(s=i.fillOpacity)&&void 0!==s?s:.3}});const g=`${e}-outline-layer`;o.addLayer({id:g,type:"line",source:f,layout:{visibility:p},paint:{"line-color":null!==(c=i.borderColor)&&void 0!==c?c:H,"line-opacity":null!==(l=i.borderOpacity)&&void 0!==l?l:.5,"line-width":null!==(a=i.borderWidth)&&void 0!==a?a:4,"line-offset":null!==(d=i.borderOffset)&&void 0!==d?d:(null!==(u=i.borderWidth)&&void 0!==u?u:4)/2*-1}});return{sourceId:f,outlineLayerId:g,fillLayerId:h,show:()=>{o.setLayoutProperty(h,"visibility","visible"),o.setLayoutProperty(g,"visibility","visible")},hide:()=>{o.setLayoutProperty(h,"visibility","none"),o.setLayoutProperty(g,"visibility","none")},isVisible:()=>"visible"===o.getLayoutProperty(h,"visibility"),setData:e=>{o.getSource(f).setData(e)}}}var te=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};function oe(e,t){let o,i,n,r,s,c,l,d,u,f,p,h,g,m;function y(t){f=E("div","geofence-ctrl-create-circle-mode-container",t);E("div","geofence-ctrl-create-circle-mode-title",f).innerHTML="Radius",m=E("input","geofence-ctrl-create-circle-mode-input",f),m.addEventListener("keydown",a.debounce(e.updateInputRadius,200))}function b(t){p=E("div","geofence-ctrl-create-polygon-mode-container",t);const o=E("div","geofence-ctrl-create-polygon-mode-info-container",p),i=E("div","geofence-ctrl-create-polygon-mode-icon",o);E("div","geofence-ctrl-create-polygon-mode-info-icon",i).innerHTML="i";E("div","geofence-ctrl-create-polygon-mode-title",o).innerHTML="How it works?";const n=E("div","geofence-ctrl-create-polygon-mode-reset-button geofence-ctrl-button",p);n.innerHTML="Reset",n.addEventListener("click",(()=>{e.resetGeofence()}));const r=function(e){const t=E("div","geofence-ctrl-create-polygon-mode-popup-container",e),o=E("div","geofence-ctrl-create-polygon-mode-popup",t);return v(o,"Move dots to desired position",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 38 38"),e.setAttribute("width","38"),e.setAttribute("height","38"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","circle");t.setAttribute("cx","19"),t.setAttribute("cy","18"),t.setAttribute("r","8"),t.setAttribute("fill","#FF9900");const o=document.createElementNS("http://www.w3.org/2000/svg","path");o.setAttribute("d","M19 0L23.3302 7.5H14.6699L19 0Z"),o.setAttribute("fill","#003560");const i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M19 36.5L14.6698 29H23.3301L19 36.5Z"),i.setAttribute("fill","#003560");const n=document.createElementNS("http://www.w3.org/2000/svg","path");n.setAttribute("d","M0 18.33L7.5 13.9999L7.5 22.6602L0 18.33Z"),n.setAttribute("fill","#003560");const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d","M37.5 18.3301L30 22.6603V14L37.5 18.3301Z"),r.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e.appendChild(n),e.appendChild(r),e}()),v(o,"Click on a border to create a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 42 27"),e.setAttribute("width","42"),e.setAttribute("height","27"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","line");t.setAttribute("y1","8"),t.setAttribute("x2","42"),t.setAttribute("y2","8"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("cx","21"),o.setAttribute("cy","8"),o.setAttribute("r","8"),o.setAttribute("fill","#FF9900");const i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d","M21 6.17822V22.488L24.6951 19.4356L27.172 26.1782L29.0399 25.3582L26.6035 18.57L31.4762 17.9322L21 6.17822Z"),i.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e.appendChild(i),e}()),v(o,"Click into shape to move",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 32 32"),e.setAttribute("width","32"),e.setAttribute("height","32"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","1"),t.setAttribute("x","1"),t.setAttribute("width","30"),t.setAttribute("height","30"),t.setAttribute("fill","#2196F3"),t.setAttribute("fill-opacity","0.4"),t.setAttribute("stroke","#003560"),t.setAttribute("stroke-width","2");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M11 6V22.3098L14.6951 19.2574L17.172 26L19.0399 25.18L16.6035 18.3918L21.4762 17.754L11 6Z"),o.setAttribute("fill","#003560"),e.appendChild(t),e.appendChild(o),e}()),v(o,"Press delete to remove a dot",function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 64 20"),e.setAttribute("width","64"),e.setAttribute("height","20"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","rect");t.setAttribute("y","0.5"),t.setAttribute("x","0.5"),t.setAttribute("width","63"),t.setAttribute("height","19"),t.setAttribute("rx","3.5"),t.setAttribute("stroke","#014478");const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("d","M14.4148 15C17.517 15 19.3118 13.076 19.3118 9.89418C19.3118 6.72727 17.517 4.81818 14.5192 4.81818H11.1186V15H14.4148ZM12.6548 13.6577V6.16051H14.4247C16.652 6.16051 17.8004 7.4929 17.8004 9.89418C17.8004 12.3054 16.652 13.6577 14.3303 13.6577H12.6548ZM24.394 15.1541C26.0595 15.1541 27.2377 14.3338 27.5758 13.0909L26.1689 12.8374C25.9004 13.5582 25.2541 13.9261 24.4089 13.9261C23.1362 13.9261 22.2811 13.1009 22.2413 11.6293H27.6703V11.1023C27.6703 8.34304 26.0197 7.2642 24.2896 7.2642C22.1618 7.2642 20.7598 8.88494 20.7598 11.2315C20.7598 13.603 22.1419 15.1541 24.394 15.1541ZM22.2463 10.5156C22.3059 9.43182 23.0914 8.49219 24.2995 8.49219C25.4529 8.49219 26.2086 9.3473 26.2136 10.5156H22.2463ZM30.8061 4.81818H29.3196V15H30.8061V4.81818ZM36.0971 15.1541C37.7626 15.1541 38.9409 14.3338 39.2789 13.0909L37.872 12.8374C37.6035 13.5582 36.9572 13.9261 36.112 13.9261C34.8393 13.9261 33.9842 13.1009 33.9444 11.6293H39.3734V11.1023C39.3734 8.34304 37.7228 7.2642 35.9927 7.2642C33.8649 7.2642 32.4629 8.88494 32.4629 11.2315C32.4629 13.603 33.845 15.1541 36.0971 15.1541ZM33.9494 10.5156C34.0091 9.43182 34.7946 8.49219 36.0027 8.49219C37.1561 8.49219 37.9118 9.3473 37.9167 10.5156H33.9494ZM44.5874 7.36364H43.0213V5.53409H41.5348V7.36364H40.4162V8.55682H41.5348V13.0661C41.5298 14.4531 42.5888 15.1243 43.7621 15.0994C44.2344 15.0945 44.5526 15.005 44.7266 14.9403L44.4581 13.7124C44.3587 13.7322 44.1747 13.777 43.9361 13.777C43.4538 13.777 43.0213 13.6179 43.0213 12.7578V8.55682H44.5874V7.36364ZM49.4409 15.1541C51.1064 15.1541 52.2846 14.3338 52.6227 13.0909L51.2157 12.8374C50.9473 13.5582 50.301 13.9261 49.4558 13.9261C48.1831 13.9261 47.3279 13.1009 47.2882 11.6293H52.7172V11.1023C52.7172 8.34304 51.0666 7.2642 49.3365 7.2642C47.2086 7.2642 45.8066 8.88494 45.8066 11.2315C45.8066 13.603 47.1887 15.1541 49.4409 15.1541ZM47.2931 10.5156C47.3528 9.43182 48.1383 8.49219 49.3464 8.49219C50.4998 8.49219 51.2555 9.3473 51.2605 10.5156H47.2931Z"),o.setAttribute("fill","black"),e.appendChild(t),e.appendChild(o),e}()),o}(i);o.addEventListener("click",(()=>{r.classList.toggle("show")}))}function v(e,t,o){const i=E("div","geofence-ctrl-create-polygon-mode-popup-step",e);E("div","geofence-ctrl-create-polygon-mode-popup-step-image",i).appendChild(o);E("div","geofence-ctrl-create-polygon-mode-popup-step-text",i).innerHTML=t}function w(){x(o),G(),u.style.display="flex"}function G(){g&&(x(g),g=void 0)}return{registerControlPosition:function(e,t){if(e._controlPositions[t])return;const o=document.createElement("div");o.className=`maplibregl-ctrl-${t}`,e._controlContainer.appendChild(o),e._controlPositions[t]=o},createElement:E,removeElement:x,createGeofenceCreateContainer:function(o){const i=E("div","geofence-ctrl-create-prompt-container",t);if(c=E("div","geofence-ctrl-create-prompt",i),o){const t=E("div","geofence-ctrl-create-prompt-buttons",c),o=E("div","geofence-ctrl-create-prompt-button-circle geofence-ctrl-create-prompt-button",t);o.addEventListener("click",(()=>{o.classList.add("geofence-ctrl-create-prompt-selected"),i.classList.remove("geofence-ctrl-create-prompt-selected"),p&&(x(p),p=void 0),f||y(c),e.changeMode("draw_circle")})),o.innerHTML="Circle";const i=E("div","geofence-ctrl-create-prompt-button-polygon geofence-ctrl-create-prompt-button",t);i.addEventListener("click",(()=>{e.changeMode("draw_polygon"),i.classList.add("geofence-ctrl-create-prompt-selected"),o.classList.remove("geofence-ctrl-create-prompt-selected"),f&&(x(f),f=void 0),p||b(c)})),i.innerHTML="Custom",o.classList.add("geofence-ctrl-create-prompt-selected"),y(c)}else b(c)},createGeofenceListContainer:function(){const i=E("div","geofence-ctrl-list-container",t);!function(t){const i=E("div","geofence-ctrl-list-header",t);l=E("div","geofence-ctrl-list-header-title",i),l.innerHTML="Geofences (0)",d=E("div","geofence-ctrl-list-header-checkbox-create-container",i),function(t){u=E("div","geofence-ctrl-list-checkbox-all-container",t),r=E("input","geofence-ctrl-list-checkbox-all",u),r.type="checkbox",r.addEventListener("click",(function(){r.checked?(e.displayAllGeofences(),i.innerHTML="Deselect All"):(e.hideAllGeofences(),i.innerHTML="Select All")}));const i=E("div","geofence-ctrl-list-checkbox-all-title",u);i.innerHTML="Select all",n=E("div","geofence-ctrl-list-header-add-button",u),n.innerHTML="+ Add",n.addEventListener("click",(()=>{!function(){u.style.display="none",o=E("div","geofence-ctrl-add-geofence-container",d);const t=E("div","geofence-ctrl-add-geofence",o),i=E("input","geofence-ctrl-add-geofence-input",t);i.placeholder="Enter name";const n=E("div","geofence-ctrl-add-geofence-buttons",t),r=E("div","geofence-ctrl-add-geofence-cancel-button geofence-ctrl-button ",n);r.innerHTML="Cancel",r.addEventListener("click",(()=>{w(),e.setEditingModeEnabled(!1)}));const s=E("div","geofence-ctrl-button geofence-ctrl-save-button",n);s.innerHTML="Save",s.addEventListener("click",(function(){return te(this,void 0,void 0,(function*(){G();(yield e.createGeofence(escape(i.value)))&&w()}))})),e.addEditableGeofence()}()}))}(d)}(i),s=E("div","geofence-ctrl-list",i),s.addEventListener("scroll",(()=>{const{scrollHeight:t,scrollTop:o,clientHeight:i}=s;o+i>=t-20&&e.loadMoreGeofences()}))},removeAddGeofenceContainer:w,createAddGeofencePromptError:function(e){if(g)return;g=E("div","geofence-ctrl-add-geofence-error",o),E("div","geofence-ctrl-add-geofence-error-icon",g).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 10"),e.setAttribute("width","12"),e.setAttribute("height","10"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M0 10H11.5789L5.78947 0L0 10ZM6.31579 8.42105H5.26316V7.36842H6.31579V8.42105ZM6.31579 6.31579H5.26316V4.21053H6.31579V6.31579Z"),t.setAttribute("fill","#FF5050"),e.appendChild(t),e}()),E("div","geofence-ctrl-add-geofence-error-text",g).innerHTML=e},renderListItem:function(o){const n=E("li","geofence-ctrl-list-item-container",s);n.id=`list-item-${o.geofenceId}`;const r=E("li","geofence-ctrl-list-item",n),c=E("div","geofence-ctrl-list-item-left-container",r),l=E("input","geofence-ctrl-list-item-checkbox",c);l.id=`list-item-checkbox-${o.geofenceId}`,l.type="checkbox",l.addEventListener("click",(function(){l.checked?(e.displayGeofence(o.geofenceId),e.fitGeofence(o.geofenceId)):e.hideGeofence(o.geofenceId)}));const a=E("div","geofence-ctrl-list-item-right-container",r),d=E("div","geofence-ctrl-list-item-title-container",a);d.addEventListener("mouseover",(function(){e.displayHighlightedGeofence(o.geofenceId)})),d.addEventListener("mouseout",(function(){e.hideHighlightedGeofence()})),E("div","geofence-ctrl-list-item-title",d).innerHTML=o.geofenceId;const u=E("div","geofence-ctrl-edit-button",d);u.addEventListener("click",(function(){e.editGeofence(o.geofenceId),function(o,n,r,s){const c=E("div","geofence-ctrl-list-item-controls",n),l=function(o,n){const r=E("div","geofence-ctrl-delete-button",o);return r.classList.add("geofence-ctrl-button"),r.addEventListener("click",(function(){!function(o){i=E("div","geofence-ctrl-delete-prompt-container",t);const n=E("div","geofence-ctrl-delete-prompt",i);E("div","geofence-ctrl-delete-geofence-title",n).innerHTML=`Are you sure you want to delete <strong>${o}</strong>?`,function(o,n){const r=E("div","geofence-ctrl-delete-geofence-buttons",o),s=E("div","geofence-ctrl-delete-geofence-cancel-button",r);s.innerHTML="Cancel",s.addEventListener("click",(()=>{x(i)}));const c=E("div","geofence-ctrl-delete-geofence-confirm-button",r);c.innerHTML="Delete",c.addEventListener("click",(function(){return te(this,void 0,void 0,(function*(){(yield e.deleteGeofence(n))&&(!function(e){h=E("div","geofence-ctrl-delete-popdown-container",t);const o=E("div","geofence-ctrl-delete-popdown",h),i=E("div","geofence-ctrl-delete-popdown-close-button",h);i.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M10.773 2.28762L9.71231 1.22696L6 4.93927L2.28769 1.22696L1.22703 2.28762L4.93934 5.99993L1.22703 9.71224L2.28769 10.7729L6 7.06059L9.71231 10.7729L10.773 9.71224L7.06066 5.99993L10.773 2.28762Z"),t.setAttribute("fill","white"),t.setAttribute("fill-rule","evenodd"),t.setAttribute("clip-rule","evenodd"),e.appendChild(t),e}()),i.addEventListener("click",(()=>{x(h)}));E("div","geofence-ctrl-delete-popdown-icon",o).appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 12 12"),e.setAttribute("width","12"),e.setAttribute("height","12"),e.setAttribute("fill","none");const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d","M6 0C2.688 0 0 2.688 0 6C0 9.312 2.688 12 6 12C9.312 12 12 9.312 12 6C12 2.688 9.312 0 6 0ZM6 10.8C3.354 10.8 1.2 8.646 1.2 6C1.2 3.354 3.354 1.2 6 1.2C8.646 1.2 10.8 3.354 10.8 6C10.8 8.646 8.646 10.8 6 10.8ZM8.754 3.348L4.8 7.302L3.246 5.754L2.4 6.6L4.8 9L9.6 4.2L8.754 3.348Z"),t.setAttribute("fill","white"),e.appendChild(t),e}());E("div","geofence-ctrl-delete-popdown-text",o).innerHTML=e?"Geofence was deleted successfully":"Geofence failed to delete"}(!0),x(i),e.setEditingModeEnabled(!1))}))}))}(n,o)}(n)})),r.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 12 16"),e.setAttribute("width","12"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M9.33317 5.5V13.8333H2.6665V5.5H9.33317ZM8.08317 0.5H3.9165L3.08317 1.33333H0.166504V3H11.8332V1.33333H8.9165L8.08317 0.5ZM10.9998 3.83333H0.999837V13.8333C0.999837 14.75 1.74984 15.5 2.6665 15.5H9.33317C10.2498 15.5 10.9998 14.75 10.9998 13.8333V3.83333Z"),t.setAttribute("fill","white"),e.appendChild(t),e}()),r}(r,s),a=()=>{o.classList.remove("geofence-ctrl-list-selected-item"),o.classList.add("geofence-ctrl-list-item"),x(c),x(l)},d=E("div","geofence-ctrl-cancel-button",c);d.classList.add("geofence-ctrl-button"),d.innerHTML="Cancel",d.addEventListener("click",(()=>{e.setEditingModeEnabled(!1),a()}));const u=E("div","geofence-ctrl-save-button geofence-ctrl-button",c);u.addEventListener("click",(()=>te(this,void 0,void 0,(function*(){yield e.saveGeofence(),a()})))),u.title="Save",u.innerHTML="Save"}(r,a,c,o.geofenceId),r.classList.remove("geofence-ctrl-list-item"),r.classList.add("geofence-ctrl-list-selected-item")})),u.appendChild(function(){const e=document.createElementNS("http://www.w3.org/2000/svg","svg"),t=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("viewBox","0 0 16 16"),e.setAttribute("width","16"),e.setAttribute("height","16"),e.setAttribute("fill","none"),t.setAttribute("d","M0.5 12.375V15.5H3.625L12.8417 6.28333L9.71667 3.15833L0.5 12.375ZM2.93333 13.8333H2.16667V13.0667L9.71667 5.51667L10.4833 6.28333L2.93333 13.8333ZM15.2583 2.69167L13.3083 0.741667C13.1417 0.575 12.9333 0.5 12.7167 0.5C12.5 0.5 12.2917 0.583333 12.1333 0.741667L10.6083 2.26667L13.7333 5.39167L15.2583 3.86667C15.5833 3.54167 15.5833 3.01667 15.2583 2.69167Z"),t.setAttribute("fill","white"),e.appendChild(t),e}())},updateCheckbox:function(e,t){const o=document.getElementById(`list-item-checkbox-${e}`);o&&(o.checked=t)},removeGeofenceListItem:function(e){x(document.getElementById(`list-item-${e}`))},setGeofenceListEnabled:function(e){r.disabled=!e,e?n.classList.remove("geofence-ctrl-noHover"):n.classList.add("geofence-ctrl-noHover");const t=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");for(let o=0;o<t.length;o++)t.item(o).disabled=!e;const o=document.getElementsByClassName("geofence-ctrl-list-item-container");for(let t=0;t<o.length;t++)e?o.item(t).classList.remove("geofence-ctrl-noHover"):o.item(t).classList.add("geofence-ctrl-noHover")},getCheckboxAllValue:function(){return r.checked},removeGeofenceCreateContainer:function(){x(c),c=void 0,f=void 0,p=void 0},updateGeofenceCount:function(e){l.innerHTML=`Geofences (${e})`},updateGeofenceRadius:function(e){m&&(m.value=`${e}`)}}}class ie{constructor(e,t){this._mapBoxDraw=new b.default({displayControlsDefault:!1,defaultMode:"simple_select",userProperties:!0,controls:{trash:!0},modes:Object.assign(Object.assign({},b.default.modes),{draw_circle:u.CircleMode,direct_select:u.DirectMode,simple_select:u.SimpleSelectMode}),styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":O,"fill-outline-color":O,"fill-opacity":.3}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","$type","Point"],["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":R}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":T,"line-width":4}},{id:"gl-draw-polygon-and-line-vertex-active",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"],["!=","mode","static"]],paint:{"circle-radius":8,"circle-color":R,"circle-stroke-color":T,"circle-stroke-width":1}}]}),this._map=e,this._ui=t,this.enable=this.enable.bind(this),this.disable=this.disable.bind(this),this.drawPolygonGeofence=this.drawPolygonGeofence.bind(this)}get(e){return this._mapBoxDraw.get(e)}add(e){const t=e.properties.isCircle;this.enable(t),this._mapBoxDraw.add(e),this._mapBoxDraw.changeMode("direct_select",{featureId:e.id})}delete(e){this._mapBoxDraw.delete(e)}disable(){this._map.hasControl(this._mapBoxDraw)&&this._map.removeControl(this._mapBoxDraw),this._ui.removeGeofenceCreateContainer()}enable(e){this._map.hasControl(this._mapBoxDraw)||(this._map.addControl(this._mapBoxDraw,"bottom-right"),this._ui.createGeofenceCreateContainer(e))}drawPolygonGeofence(e){const t=((e,t)=>{const o=t.getSouthWest().toArray(),i=t.getNorthEast().toArray(),n=t.getCenter().toArray(),r=l.lineString([o,n,i]),s=y.default(r,{units:"miles"}),c=g.default(r,s/4,{units:"miles"}).geometry.coordinates,a=g.default(r,s*(3/4),{units:"miles"}).geometry.coordinates;return{id:e,type:"Feature",geometry:{type:"Polygon",coordinates:[[a,[c[0],a[1]],c,[a[0],c[1]],a]]},properties:{}}})(e,this._map.getBounds());this.add(t)}drawCircularGeofence(e,t){const o=this._map.getBounds(),i=J(e,this._map.getCenter().toArray(),{bounds:o,radius:t});this.add(i),this._ui.updateGeofenceRadius(t||i.properties.radius.toFixed(2))}}var ne=function(e,t,o,i){return new(o||(o=Promise))((function(n,r){function s(e){try{l(i.next(e))}catch(e){r(e)}}function c(e){try{l(i.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,c)}l((i=i.apply(e,t||[])).next())}))};const re={left:240};e.AmplifyGeocoderAPI=z,e.AmplifyGeofenceControl=class{constructor(e){this._geofenceCollectionId=null==e?void 0:e.geofenceCollectionId,this._loadedGeofences={},this._displayedGeofences=[],this.changeMode=this.changeMode.bind(this),this.loadInitialGeofences=this.loadInitialGeofences.bind(this),this.loadMoreGeofences=this.loadMoreGeofences.bind(this),this._loadGeofence=this._loadGeofence.bind(this),this.updateInputRadius=this.updateInputRadius.bind(this),this.saveGeofence=this.saveGeofence.bind(this),this.editGeofence=this.editGeofence.bind(this),this.deleteGeofence=this.deleteGeofence.bind(this),this.displayAllGeofences=this.displayAllGeofences.bind(this),this.hideAllGeofences=this.hideAllGeofences.bind(this),this.addEditableGeofence=this.addEditableGeofence.bind(this),this.setEditingModeEnabled=this.setEditingModeEnabled.bind(this),this.displayHighlightedGeofence=this.displayHighlightedGeofence.bind(this),this.hideHighlightedGeofence=this.hideHighlightedGeofence.bind(this),this.displayGeofence=this.displayGeofence.bind(this),this.hideGeofence=this.hideGeofence.bind(this),this.fitGeofence=this.fitGeofence.bind(this),this.fitAllGeofences=this.fitAllGeofences.bind(this)}getDefaultPosition(){return"full-screen"}onRemove(){this._ui.removeElement(this._container)}reorderMapLibreClassNames(){const e=document.getElementsByClassName("maplibregl-canvas").item(0);e&&(e.className="mapboxgl-canvas maplibregl-canvas")}onAdd(e){return this._map=e,this.reorderMapLibreClassNames(),this._container=E("div","geofence-ctrl maplibregl-ctrl"),this._ui=oe(this,this._container),this._amplifyDraw=new ie(e,this._ui),this._ui.registerControlPosition(e,"full-screen"),this._ui.createGeofenceListContainer(),this._map.once("load",function(){this._map.getSource("displayedGeofences")||(this._drawGeofencesOutput=ee("displayedGeofences",[],this._map,{fillColor:O,borderColor:T,borderOpacity:1}),this._highlightedGeofenceOutput=ee("highlightedGeofence",[],this._map,{fillColor:O,borderColor:T,borderOpacity:1,borderWidth:6}),this.loadInitialGeofences(),e.addControl(new p.default.NavigationControl({showCompass:!1}),"bottom-right"))}.bind(this)),this._map.on("draw.update",(()=>{const e=this._amplifyDraw._mapBoxDraw.getAll().features[0].geometry.coordinates[0],t=((e,t)=>{const o=l.lineString([e,t]);return y.default(o,{units:"miles"})})(e[0],e[Math.floor(e.length/2)])/2;this._ui.updateGeofenceRadius(t.toFixed(2))})),this._container}createGeofence(e){return ne(this,void 0,void 0,(function*(){if(e&&0!==e.length)if(e.match(U)){if(!X(e,this._loadedGeofences))return this.saveGeofence(e);this._ui.createAddGeofencePromptError("Geofence ID already exists.")}else this._ui.createAddGeofencePromptError("Geofence ID contains special characters.");else this._ui.createAddGeofencePromptError("Geofence ID is empty.")}))}saveGeofence(e){return ne(this,void 0,void 0,(function*(){const t=this._amplifyDraw.get(this._editingGeofenceId),i=e||this._editingGeofenceId,n=yield o.Geo.saveGeofences({geofenceId:i,geometry:{polygon:t.geometry.coordinates}});if(n.errors[0]){const e=n.errors[0];throw new Error(`There was an error saving geofence with id ${i}: ${e.error.code} - ${e.error.message}`)}const r={geofenceId:n.successes[0].geofenceId,geometry:{polygon:t.geometry.coordinates}};return this._loadGeofence(r),this.displayGeofence(r.geofenceId),this.setEditingModeEnabled(!1),r.geofenceId}))}loadInitialGeofences(){return ne(this,void 0,void 0,(function*(){try{const{entries:e,nextToken:t}=yield o.Geo.listGeofences();this._listGeofencesNextToken=t;const i=this._loadGeofence;e.forEach((e=>i(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}loadMoreGeofences(){return ne(this,void 0,void 0,(function*(){if(this._listGeofencesNextToken)try{const{entries:e,nextToken:t}=yield o.Geo.listGeofences({nextToken:this._listGeofencesNextToken});this._listGeofencesNextToken=t;const i=this._loadGeofence;e.forEach((e=>i(e))),this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}catch(e){throw new Error(`Error calling listGeofences: ${e}`)}}))}editGeofence(e){this.setEditingModeEnabled(!0);const t=this._loadedGeofences[e];if(!t)throw new Error(`Geofence with id ${e} does not exist`);const o=Y(t.geometry.polygon),i=Object.assign({id:t.geofenceId},o);this._amplifyDraw.add(i),this._editingGeofenceId=t.geofenceId}deleteGeofence(e){return ne(this,void 0,void 0,(function*(){const t=yield o.Geo.deleteGeofences(e);if(t.errors[0]){const o=t.errors[0].error;throw new Error(`There was an error deleting geofence with id ${e}: ${o.code} - ${o.message}`)}return this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e],this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length),this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),e}))}deleteSelectedGeofences(){this._displayedGeofences.map((e=>e.geofenceId)).forEach((e=>{this._ui.removeGeofenceListItem(e),delete this._loadedGeofences[e]})),this._displayedGeofences=[],this._updateDisplayedGeofences()}_loadGeofence(e){this._loadedGeofences[e.geofenceId]?this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e.geofenceId)):this._ui.renderListItem(e),this._loadedGeofences[e.geofenceId]=e,this._ui.updateGeofenceCount(Object.keys(this._loadedGeofences).length)}displayGeofence(e){this._displayedGeofences.push(this._loadedGeofences[e]),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!0),this.fitAllGeofences()}displayAllGeofences(){this._displayedGeofences.push(...Object.values(this._loadedGeofences)),this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue())),this.fitAllGeofences()}fitGeofence(e){const t=this._map.getBounds();this._loadedGeofences[e].geometry.polygon[0].forEach((e=>{t.extend(e)})),this._map.fitBounds(t,{padding:re})}fitAllGeofences(){let e=!1;const t=this._map.getBounds();this._displayedGeofences.forEach((o=>{o.geometry.polygon[0].forEach((o=>{t.contains(o)||(t.extend(o),e=!0)}))})),e&&this._map.fitBounds(t,{padding:re})}hideGeofence(e){this._displayedGeofences=this._displayedGeofences.filter((t=>t.geofenceId!==e)),this._updateDisplayedGeofences(),this._ui.updateCheckbox(e,!1)}hideAllGeofences(){this._displayedGeofences=[],this._updateDisplayedGeofences();const e=document.getElementsByClassName("geofence-ctrl-list-item-checkbox");Array.from(e).forEach((e=>e.checked=this._ui.getCheckboxAllValue()))}_updateDisplayedGeofences(){const e=K(this._displayedGeofences);this._drawGeofencesOutput.setData(e)}displayHighlightedGeofence(e){const t=this._loadedGeofences[e];if(!t)return void console.warn(`Geofence with id ${e} does not exist`);const o=Y(t.geometry.polygon);this._highlightedGeofenceOutput.setData(o),this._highlightedGeofenceOutput.show()}hideHighlightedGeofence(){this._highlightedGeofenceOutput.hide()}changeMode(e){this._amplifyDraw.delete(this._editingGeofenceId),"draw_circle"===e?this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}resetGeofence(){this._amplifyDraw.delete(this._editingGeofenceId),X(this._editingGeofenceId,this._loadedGeofences)?this.editGeofence(this._editingGeofenceId):this._amplifyDraw.drawPolygonGeofence(this._editingGeofenceId)}setEditingModeEnabled(e){e?this._amplifyDraw.enable():this._amplifyDraw.disable(),e?this._drawGeofencesOutput.hide():this._drawGeofencesOutput.show(),this._ui.setGeofenceListEnabled(!e)}updateInputRadius(e){const t=e.target.value,o=parseInt(t);isNaN(o)||this._amplifyDraw.drawCircularGeofence(this._editingGeofenceId,o)}addEditableGeofence(){this._editingGeofenceId="tempGeofence",this._amplifyDraw.drawCircularGeofence("tempGeofence"),this.setEditingModeEnabled(!0)}},e.AmplifyMapLibreRequest=k,e.createAmplifyGeocoder=function(e){return new h.default(z,Object.assign({maplibregl:p.default,showResultMarkers:{element:Z()},marker:{element:Z()},showResultsWhileTyping:null==e?void 0:e.autocomplete},e))},e.createDefaultIcon=Z,e.createMap=e=>I(void 0,void 0,void 0,(function*(){return k.createMapLibreMap(e)})),e.drawGeofences=ee,e.drawPoints=function(e,t,i,{showCluster:n=!0,clusterOptions:r={},unclusteredOptions:s={},autoFit:c=!0}={},l){var a,d;if(!i||"function"!=typeof i.addSource||"function"!=typeof i.addLayer)throw new Error("Please use a maplibre map");const u=A(t),f=e;let p,h;i.addSource(f,{type:"geojson",data:{type:"FeatureCollection",features:u},cluster:n,clusterMaxZoom:null!==(a=r.clusterMaxZoom)&&void 0!==a?a:14,clusterRadius:null!==(d=r.smCircleSize)&&void 0!==d?d:60,generateId:!0}),n&&({clusterLayerId:p,clusterSymbolLayerId:h}=function(e,t,{fillColor:i="#5d8aff",smCircleSize:n=60,smThreshold:r=50,mdCircleSize:s=100,mdThreshold:c=100,lgCircleSize:l=140,lgThreshold:a=500,xlCircleSize:d=180,borderWidth:u=4,borderColor:f="#fff",clusterPaint:p,onClick:h,showCount:g,clusterCountLayout:m,fontColor:y="#fff"},b){const v=`${e}-layer-clusters`,w=`${e}-layer-cluster-count`,G=Object.assign({"circle-color":["step",["get","point_count"],i,r,i,c,i,a,i],"circle-radius":["step",["get","point_count"],n,r,s,c,l,a,d],"circle-stroke-width":u,"circle-stroke-color":f},p),C={id:v,type:"circle",source:e,filter:["has","point_count"],paint:G};if(t.addLayer(Object.assign({},C)),t.on("click",v,(function(o){"function"==typeof h&&h(o);const i=t.queryRenderedFeatures(o.point,{layers:[v]}),n=i[0].properties.cluster_id,r=t.getSource(e);(function(e){return"geojson"===e.type})(r)&&r.getClusterExpansionZoom(n,(function(e,o){e||t.easeTo({center:i[0].geometry.coordinates,zoom:o})}))})),g){const i={"text-field":"{point_count_abbreviated}","text-size":24},n=b||o.Geo.getDefaultMap().style;n&&(i["text-font"]=[$[n]]);const r=Object.assign(Object.assign({},i),m),s={id:w,type:"symbol",source:e,filter:["has","point_count"],layout:r,paint:{"text-color":y}};t.addLayer(Object.assign({},s))}return{clusterLayerId:v,clusterSymbolLayerId:w}}(f,i,r,l));const{unclusteredLayerId:g}=F(f,i,s||{});if(c){const e=i.getBounds();u.forEach((function(t){e.extend(t.geometry.coordinates)})),i.fitBounds(e)}return{sourceId:f,unclusteredLayerId:g,clusterLayerId:p,clusterSymbolLayerId:h,setData:e=>{const t=A(e);i.getSource(f).setData({type:"FeatureCollection",features:t})},show:()=>{i.setLayoutProperty(g,"visibility","visible"),p&&i.setLayoutProperty(p,"visibility","visible"),h&&i.setLayoutProperty(h,"visibility","visible")},hide:()=>{i.setLayoutProperty(g,"visibility","none"),p&&i.setLayoutProperty(p,"visibility","none"),h&&i.setLayoutProperty(h,"visibility","none")}}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -5,7 +5,7 @@ import { Map as MaplibreMap, RequestParameters, MapOptions } from "maplibre-gl";
5
5
  * We keep the property optional here since we default to the map name for the maplibre style field and
6
6
  * it maintains backwards compatibility with the upgrade to maplibre v2.
7
7
  */
8
- interface CreateMapOptions extends Omit<MapOptions, 'style'>, Partial<Pick<MapOptions, 'style'>> {
8
+ interface CreateMapOptions extends Omit<MapOptions, "style">, Partial<Pick<MapOptions, "style">> {
9
9
  region?: string;
10
10
  mapConstructor?: typeof MaplibreMap;
11
11
  }
@@ -51,9 +51,13 @@ class AmplifyMapLibreRequest {
51
51
  yield (0, core_1.jitteredExponentialRetry)(this.refreshCredentials, [], MAX_DELAY_MS);
52
52
  // Refresh credentials on a timer because HubEvents do not trigger on credential refresh currently
53
53
  this.activeTimeout && clearTimeout(this.activeTimeout);
54
- const expiration = new Date(this.credentials.expiration);
55
- const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
56
- this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, timeout);
54
+ // Refresh credentials when expiration time is later than now
55
+ if (this.credentials.expiration.getTime() > (new Date()).getTime()) {
56
+ const expiration = new Date(this.credentials.expiration);
57
+ const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
58
+ this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, Math.min(timeout, 3600000) // Set timeout to an hour if we somehow don't have a value for timeout
59
+ );
60
+ }
57
61
  }
58
62
  catch (e) {
59
63
  console.error(`Failed to refresh credentials: ${e}`);
@@ -72,7 +76,7 @@ class AmplifyMapLibreRequest {
72
76
  }
73
77
  url = `https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${url}/style-descriptor`;
74
78
  }
75
- if (url.includes("amazonaws.com")) {
79
+ if (new URL(url).hostname.endsWith(".amazonaws.com")) {
76
80
  // only sign AWS requests (with the signature as part of the query string)
77
81
  const urlWithUserAgent = url +
78
82
  `?x-amz-user-agent=${encodeURIComponent((0, utils_1.urlEncodePeriods)((0, core_1.getAmplifyUserAgent)()))}`;
@@ -5,7 +5,7 @@ import { Map as MaplibreMap, RequestParameters, MapOptions } from "maplibre-gl";
5
5
  * We keep the property optional here since we default to the map name for the maplibre style field and
6
6
  * it maintains backwards compatibility with the upgrade to maplibre v2.
7
7
  */
8
- interface CreateMapOptions extends Omit<MapOptions, 'style'>, Partial<Pick<MapOptions, 'style'>> {
8
+ interface CreateMapOptions extends Omit<MapOptions, "style">, Partial<Pick<MapOptions, "style">> {
9
9
  region?: string;
10
10
  mapConstructor?: typeof MaplibreMap;
11
11
  }
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  var _a;
22
22
  import { Hub, Signer, jitteredExponentialRetry, getAmplifyUserAgent, Credentials, } from "@aws-amplify/core";
23
23
  import { Geo } from "@aws-amplify/geo";
24
- import { Map as MaplibreMap, } from "maplibre-gl";
24
+ import { Map as MaplibreMap } from "maplibre-gl";
25
25
  import { urlEncodePeriods } from "./utils";
26
26
  /**
27
27
  * An object for encapsulating an Amplify Geo transform request and Amplify credentials
@@ -48,9 +48,13 @@ export default class AmplifyMapLibreRequest {
48
48
  yield jitteredExponentialRetry(this.refreshCredentials, [], MAX_DELAY_MS);
49
49
  // Refresh credentials on a timer because HubEvents do not trigger on credential refresh currently
50
50
  this.activeTimeout && clearTimeout(this.activeTimeout);
51
- const expiration = new Date(this.credentials.expiration);
52
- const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
53
- this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, timeout);
51
+ // Refresh credentials when expiration time is later than now
52
+ if (this.credentials.expiration.getTime() > (new Date()).getTime()) {
53
+ const expiration = new Date(this.credentials.expiration);
54
+ const timeout = expiration.getTime() - new Date().getTime() - 10000; // Adds a 10 second buffer time before the next refresh
55
+ this.activeTimeout = window.setTimeout(this.refreshCredentialsWithRetry, Math.min(timeout, 3600000) // Set timeout to an hour if we somehow don't have a value for timeout
56
+ );
57
+ }
54
58
  }
55
59
  catch (e) {
56
60
  console.error(`Failed to refresh credentials: ${e}`);
@@ -69,7 +73,7 @@ export default class AmplifyMapLibreRequest {
69
73
  }
70
74
  url = `https://maps.geo.${this.region}.amazonaws.com/maps/v0/maps/${url}/style-descriptor`;
71
75
  }
72
- if (url.includes("amazonaws.com")) {
76
+ if (new URL(url).hostname.endsWith(".amazonaws.com")) {
73
77
  // only sign AWS requests (with the signature as part of the query string)
74
78
  const urlWithUserAgent = url +
75
79
  `?x-amz-user-agent=${encodeURIComponent(urlEncodePeriods(getAmplifyUserAgent()))}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maplibre-gl-js-amplify",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "MapLibre Plugin to Support Amplify Geo Integration",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",
@@ -106,5 +106,8 @@
106
106
  "@turf/line-slice": "^6.5.0",
107
107
  "debounce": "^1.2.1",
108
108
  "maplibre-gl-draw-circle": "^0.1.1"
109
+ },
110
+ "resolutions": {
111
+ "json5": "^2.2.2"
109
112
  }
110
113
  }