@stadiamaps/ferrostar-webcomponents 0.13.2 → 0.14.0

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.
@@ -87,7 +87,7 @@ import{css as v,LitElement as u,html as b,unsafeCSS as W}from"lit";import N,{Lng
87
87
  margin: 0 15px;
88
88
  white-space: nowrap;
89
89
  }
90
- `],j([n()],S.prototype,"tripState",2),S=j([f("arrival-view")],S);function k(a){let t=null;return a.coords.speed&&(t={value:a.coords.speed}),{coordinates:{lat:a.coords.latitude,lng:a.coords.longitude},horizontalAccuracy:a.coords.accuracy,courseOverGround:{degrees:Math.floor(a.coords.heading||0)},timestamp:a.timestamp,speed:t}}class G{constructor(){this.simulationState=null,this.isRunning=!1,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=B(t,10),this.start()}async start(){if(!this.isRunning){for(this.isRunning=!0;this.simulationState!==null;){await new Promise(l=>setTimeout(l,1/this.warpFactor*1e3));const t=this.simulationState,e=Z(t);if(t===e)return;this.simulationState=e,this.lastLocation=e.current_location,this.updateCallback&&this.updateCallback()}this.isRunning=!1}}stop(){this.simulationState=null}}class A3{constructor(){this.geolocationWatchId=null,this.lastLocation=null,this.lastHeading=null,this.updateCallback=()=>{}}start(){if(navigator.geolocation&&!this.geolocationWatchId){const t={enableHighAccuracy:!0};this.geolocationWatchId=navigator.geolocation.watchPosition(e=>{this.lastLocation=k(e),this.updateCallback&&this.updateCallback()},e=>{this.geolocationWatchId=null,alert(e.message)},t)}}getCurrentLocation(t){if(!navigator.geolocation)return new Promise((l,i)=>{i("This navigator does not support geolocation.")});const e=new Date().getTime()-t;return this.lastLocation&&this.lastLocation.timestamp>e?this.lastLocation:new Promise((l,i)=>{navigator.geolocation.getCurrentPosition(o=>{const r=k(o);this.lastLocation=r,l(r)},i)})}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var C3=Object.defineProperty,L3=Object.getOwnPropertyDescriptor,c=(a,t,e,l)=>{for(var i=l>1?void 0:l?L3(t,e):t,o=a.length-1,r;o>=0;o--)(r=a[o])&&(i=(l?r(t,e,i):r(i))||i);return l&&i&&C3(t,e,i),i};let s=class extends u{constructor(){super(),this.valhallaEndpointUrl="",this.styleUrl="",this.profile="",this.center=null,this.pitch=60,this.zoom=6,this.httpClient=fetch,this.costingOptions={},this._tripState=null,this.useVoiceGuidance=!1,this.geolocateOnLoad=!0,this.routeAdapter=null,this.map=null,this.geolocateControl=null,this.navigationController=null,this.simulatedLocationMarker=null,this.lastSpokenInstructionText=null,this.httpClient===fetch&&(this.httpClient=this.httpClient.bind(window))}updated(a){a.has("locationProvider")&&this.locationProvider&&(this.locationProvider.updateCallback=this.onLocationUpdated.bind(this)),this.map&&(a.has("styleUrl")&&this.map.setStyle(this.styleUrl),a.has("center")&&(a.get("center")===null&&this.center!==null?this.map.jumpTo({center:this.center}):this.center!==null&&(this.map.getCenter().distanceTo(K.convert(this.center))>5e5?this.map.jumpTo({center:this.center}):this.map.flyTo({center:this.center}))),a.has("pitch")&&this.map.setPitch(this.pitch),a.has("zoom")&&this.map.setZoom(this.zoom))}firstUpdated(){this.map=new N.Map({container:this.shadowRoot.getElementById("map"),style:this.styleUrl?this.styleUrl:"https://demotiles.maplibre.org/style.json",center:this.center??[0,0],pitch:this.pitch,bearing:0,zoom:this.zoom,attributionControl:{compact:!0}}),this.geolocateControl=new P({positionOptions:{enableHighAccuracy:!0},trackUserLocation:!0}),this.map.addControl(this.geolocateControl),this.map.on("load",a=>{var t;this.geolocateOnLoad&&((t=this.geolocateControl)==null||t.trigger()),this.configureMap!==void 0&&this.configureMap(a.target)})}async getRoutes(a,t){this.routeAdapter=new T(this.valhallaEndpointUrl,this.profile,JSON.stringify(this.costingOptions));const e=this.routeAdapter.generateRequest(a,t),l=e.get("method");let i=new URL(e.get("url"));const o=e.get("body"),r=await this.httpClient(i,{method:l,body:new Uint8Array(o).buffer}),g=new Uint8Array(await r.arrayBuffer());return this.routeAdapter.parseResponse(g)}startNavigation(a,t){var l,i,o;this.locationProvider.start(),this.onNavigationStart&&this.map&&this.onNavigationStart(this.map),this.navigationController=new $(a,t),this.locationProvider.updateCallback=this.onLocationUpdated.bind(this);const e=this.locationProvider.lastLocation?this.locationProvider.lastLocation:{coordinates:a.geometry[0],horizontalAccuracy:0,courseOverGround:null,timestamp:Date.now(),speed:null};this._tripState=this.navigationController.getInitialState(e),this.clearMap(),(l=this.map)==null||l.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:a.geometry.map(r=>[r.lng,r.lat])}}}),(i=this.map)==null||i.addLayer({id:"route",type:"line",source:"route",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#3700B3","line-width":8}}),(o=this.map)==null||o.setCenter(a.geometry[0]),this.locationProvider instanceof G&&(this.simulatedLocationMarker=new N.Marker({color:"green"}).setLngLat(a.geometry[0]).addTo(this.map))}async stopNavigation(){var a,t;(a=this.routeAdapter)==null||a.free(),this.routeAdapter=null,(t=this.navigationController)==null||t.free(),this.navigationController=null,this._tripState=null,this.clearMap(),this.locationProvider&&(this.locationProvider.updateCallback=null),this.onNavigationStop&&this.map&&this.onNavigationStop(this.map)}onLocationUpdated(){var a,t,e,l,i,o;this.navigationController&&(this._tripState=this.navigationController.updateUserLocation(this.locationProvider.lastLocation,this._tripState),(a=this.simulatedLocationMarker)==null||a.setLngLat(this.locationProvider.lastLocation.coordinates),(t=this.map)==null||t.easeTo({center:this.locationProvider.lastLocation.coordinates,bearing:this.locationProvider.lastLocation.courseOverGround.degrees||0}),this.useVoiceGuidance&&((e=this._tripState.Navigating)!=null&&e.spokenInstruction)&&((l=this._tripState.Navigating)==null?void 0:l.spokenInstruction.text)!==this.lastSpokenInstructionText&&(this.lastSpokenInstructionText=(i=this._tripState.Navigating)==null?void 0:i.spokenInstruction.text,window.speechSynthesis.cancel(),window.speechSynthesis.speak(new SpeechSynthesisUtterance((o=this._tripState.Navigating)==null?void 0:o.spokenInstruction.text))))}clearMap(){var a,t,e,l,i;(a=this.map)!=null&&a.getLayer("route")&&((t=this.map)==null||t.removeLayer("route")),(e=this.map)!=null&&e.getSource("route")&&((l=this.map)==null||l.removeSource("route")),(i=this.simulatedLocationMarker)==null||i.remove()}render(){return b`
90
+ `],j([n()],S.prototype,"tripState",2),S=j([f("arrival-view")],S);function k(a){let t=null;return a.coords.speed&&(t={value:a.coords.speed}),{coordinates:{lat:a.coords.latitude,lng:a.coords.longitude},horizontalAccuracy:a.coords.accuracy,courseOverGround:{degrees:Math.floor(a.coords.heading||0)},timestamp:a.timestamp,speed:t}}class G{constructor(){this.simulationState=null,this.isRunning=!1,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){var e;this.simulationState=B(t,10),this.lastLocation=(e=this.simulationState)==null?void 0:e.current_location,this.start()}async start(){if(!this.isRunning){for(this.isRunning=!0;this.simulationState!==null;){await new Promise(l=>setTimeout(l,1/this.warpFactor*1e3));const t=this.simulationState,e=Z(t);if(t===e)return;this.simulationState=e,this.lastLocation=e.current_location,this.updateCallback&&this.updateCallback()}this.isRunning=!1}}stop(){this.simulationState=null}}class A3{constructor(){this.geolocationWatchId=null,this.lastLocation=null,this.lastHeading=null,this.updateCallback=()=>{}}start(){if(navigator.geolocation&&!this.geolocationWatchId){const t={enableHighAccuracy:!0};this.geolocationWatchId=navigator.geolocation.watchPosition(e=>{this.lastLocation=k(e),this.updateCallback&&this.updateCallback()},e=>{this.geolocationWatchId=null,alert(e.message)},t)}}getCurrentLocation(t){if(!navigator.geolocation)return new Promise((l,i)=>{i("This navigator does not support geolocation.")});const e=new Date().getTime()-t;return this.lastLocation&&this.lastLocation.timestamp>e?this.lastLocation:new Promise((l,i)=>{navigator.geolocation.getCurrentPosition(o=>{const r=k(o);this.lastLocation=r,l(r)},i)})}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var C3=Object.defineProperty,L3=Object.getOwnPropertyDescriptor,c=(a,t,e,l)=>{for(var i=l>1?void 0:l?L3(t,e):t,o=a.length-1,r;o>=0;o--)(r=a[o])&&(i=(l?r(t,e,i):r(i))||i);return l&&i&&C3(t,e,i),i};let s=class extends u{constructor(){super(),this.valhallaEndpointUrl="",this.styleUrl="",this.profile="",this.center=null,this.pitch=60,this.zoom=6,this.httpClient=fetch,this.costingOptions={},this._tripState=null,this.useVoiceGuidance=!1,this.geolocateOnLoad=!0,this.routeAdapter=null,this.map=null,this.geolocateControl=null,this.navigationController=null,this.simulatedLocationMarker=null,this.lastSpokenInstructionText=null,this.httpClient===fetch&&(this.httpClient=this.httpClient.bind(window))}updated(a){a.has("locationProvider")&&this.locationProvider&&(this.locationProvider.updateCallback=this.onLocationUpdated.bind(this)),this.map&&(a.has("styleUrl")&&this.map.setStyle(this.styleUrl),a.has("center")&&(a.get("center")===null&&this.center!==null?this.map.jumpTo({center:this.center}):this.center!==null&&(this.map.getCenter().distanceTo(K.convert(this.center))>5e5?this.map.jumpTo({center:this.center}):this.map.flyTo({center:this.center}))),a.has("pitch")&&this.map.setPitch(this.pitch),a.has("zoom")&&this.map.setZoom(this.zoom))}firstUpdated(){this.map=new N.Map({container:this.shadowRoot.getElementById("map"),style:this.styleUrl?this.styleUrl:"https://demotiles.maplibre.org/style.json",center:this.center??[0,0],pitch:this.pitch,bearing:0,zoom:this.zoom,attributionControl:{compact:!0}}),this.geolocateControl=new P({positionOptions:{enableHighAccuracy:!0},trackUserLocation:!0}),this.map.addControl(this.geolocateControl),this.map.on("load",a=>{var t;this.geolocateOnLoad&&((t=this.geolocateControl)==null||t.trigger()),this.configureMap!==void 0&&this.configureMap(a.target)})}async getRoutes(a,t){this.routeAdapter=new T(this.valhallaEndpointUrl,this.profile,JSON.stringify(this.costingOptions));const e=this.routeAdapter.generateRequest(a,t),l=e.get("method");let i=new URL(e.get("url"));const o=e.get("body"),r=await this.httpClient(i,{method:l,body:new Uint8Array(o).buffer}),g=new Uint8Array(await r.arrayBuffer());return this.routeAdapter.parseResponse(g)}startNavigation(a,t){var l,i,o;this.locationProvider.start(),this.onNavigationStart&&this.map&&this.onNavigationStart(this.map),this.navigationController=new $(a,t),this.locationProvider.updateCallback=this.onLocationUpdated.bind(this);const e=this.locationProvider.lastLocation?this.locationProvider.lastLocation:{coordinates:a.geometry[0],horizontalAccuracy:0,courseOverGround:null,timestamp:Date.now(),speed:null};this._tripState=this.navigationController.getInitialState(e),this.clearMap(),(l=this.map)==null||l.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:a.geometry.map(r=>[r.lng,r.lat])}}}),(i=this.map)==null||i.addLayer({id:"route",type:"line",source:"route",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#3700B3","line-width":8}}),(o=this.map)==null||o.setCenter(a.geometry[0]),this.locationProvider instanceof G&&(this.simulatedLocationMarker=new N.Marker({color:"green"}).setLngLat(a.geometry[0]).addTo(this.map))}async stopNavigation(){var a,t;(a=this.routeAdapter)==null||a.free(),this.routeAdapter=null,(t=this.navigationController)==null||t.free(),this.navigationController=null,this._tripState=null,this.clearMap(),this.locationProvider&&(this.locationProvider.updateCallback=null),this.onNavigationStop&&this.map&&this.onNavigationStop(this.map)}onLocationUpdated(){var a,t,e,l,i,o;this.navigationController&&(this._tripState=this.navigationController.updateUserLocation(this.locationProvider.lastLocation,this._tripState),(a=this.simulatedLocationMarker)==null||a.setLngLat(this.locationProvider.lastLocation.coordinates),(t=this.map)==null||t.easeTo({center:this.locationProvider.lastLocation.coordinates,bearing:this.locationProvider.lastLocation.courseOverGround.degrees||0}),this.useVoiceGuidance&&((e=this._tripState.Navigating)!=null&&e.spokenInstruction)&&((l=this._tripState.Navigating)==null?void 0:l.spokenInstruction.text)!==this.lastSpokenInstructionText&&(this.lastSpokenInstructionText=(i=this._tripState.Navigating)==null?void 0:i.spokenInstruction.text,window.speechSynthesis.cancel(),window.speechSynthesis.speak(new SpeechSynthesisUtterance((o=this._tripState.Navigating)==null?void 0:o.spokenInstruction.text))))}clearMap(){var a,t,e,l,i;(a=this.map)!=null&&a.getLayer("route")&&((t=this.map)==null||t.removeLayer("route")),(e=this.map)!=null&&e.getSource("route")&&((l=this.map)==null||l.removeSource("route")),(i=this.simulatedLocationMarker)==null||i.remove()}render(){return b`
91
91
  <style>
92
92
  ${this.customStyles}
93
93
  </style>