@stadiamaps/ferrostar-webcomponents 0.32.0 → 0.32.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.
@@ -104,6 +104,15 @@
104
104
  margin: 0 15px;
105
105
  white-space: nowrap;
106
106
  }
107
+ @media (max-width: 600px) {
108
+ .progress-view-card {
109
+ padding: 10px;
110
+ }
111
+
112
+ .arrival-text {
113
+ margin: 0 5px;
114
+ }
115
+ }
107
116
  `],z([g()],N.prototype,"tripState",2),N=z([O("trip-progress-view")],N);function B(o){let t=null;return o.coords.speed&&(t={value:o.coords.speed}),{coordinates:{lat:o.coords.latitude,lng:o.coords.longitude},horizontalAccuracy:o.coords.accuracy,courseOverGround:{degrees:Math.floor(o.coords.heading||0)},timestamp:o.timestamp,speed:t}}class E{constructor(){this.simulationState=null,this.isRunning=!1,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=w.locationSimulationFromRoute(t,10,"None"),this.lastLocation=this.simulationState?.current_location,this.start()}async start(){if(!this.isRunning){for(this.isRunning=!0;this.simulationState!==null;){await new Promise(i=>setTimeout(i,1/this.warpFactor*1e3));const t=this.simulationState,e=w.advanceLocationSimulation(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 Jt{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=B(e),this.updateCallback&&this.updateCallback()},e=>{this.geolocationWatchId=null,alert(e.message)},t)}}getCurrentLocation(t){if(!navigator.geolocation)return new Promise((i,a)=>{a("This navigator does not support geolocation.")});const e=new Date().getTime()-t;return this.lastLocation&&this.lastLocation.timestamp>e?this.lastLocation:new Promise((i,a)=>{navigator.geolocation.getCurrentPosition(s=>{const r=B(s);this.lastLocation=r,i(r)},a)})}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var Xt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,v=(o,t,e,i)=>{for(var a=i>1?void 0:i?Qt(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(a=(i?r(t,e,a):r(a))||a);return i&&a&&Xt(t,e,a),a};l.FerrostarMap=class extends c.LitElement{constructor(){super(),this.valhallaEndpointUrl="",this.profile="",this.httpClient=fetch,this.options={},this._tripState=null,this.useVoiceGuidance=!1,this.geolocateOnLoad=!0,this.routeAdapter=null,this.geolocateControl=null,this.navigationController=null,this.simulatedLocationMarker=null,this.lastSpokenUtteranceId=null,this.httpClient===fetch&&(this.httpClient=this.httpClient.bind(window))}updated(t){t.has("locationProvider")&&this.locationProvider&&(this.locationProvider.updateCallback=this.onLocationUpdated.bind(this))}firstUpdated(){this.geolocateControl=new j.GeolocateControl({positionOptions:{enableHighAccuracy:!0},trackUserLocation:!0}),this.map.addControl(this.geolocateControl),this.map.on("load",t=>{this.geolocateOnLoad&&this.geolocateControl?.trigger()})}async getRoutes(t,e){this.routeAdapter=new w.RouteAdapter(this.valhallaEndpointUrl,this.profile,JSON.stringify(this.options));const i=this.routeAdapter.generateRequest(t,e),a=i.get("method");let s=new URL(i.get("url"));const r=i.get("body"),u=await this.httpClient(s,{method:a,body:new Uint8Array(r).buffer}),d=new Uint8Array(await u.arrayBuffer());try{return this.routeAdapter.parseResponse(d)}catch(n){throw console.error("Error parsing route response:",n),n}}startNavigation(t,e){this.locationProvider.start(),this.onNavigationStart&&this.map&&this.onNavigationStart(this.map),this.navigationController=new w.NavigationController(t,e),this.locationProvider.updateCallback=this.onLocationUpdated.bind(this);const i=this.locationProvider.lastLocation?this.locationProvider.lastLocation:{coordinates:t.geometry[0],horizontalAccuracy:0,courseOverGround:null,timestamp:Date.now(),speed:null};this.tripStateUpdate(this.navigationController.getInitialState(i)),this.clearMap(),this.map?.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t.geometry.map(a=>[a.lng,a.lat])}}}),this.map?.addLayer({id:"route",type:"line",source:"route",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#3478f6","line-width":8}}),this.map?.addLayer({id:"route-border",type:"line",source:"route",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#FFFFFF","line-width":13}},"route"),this.map?.flyTo({center:t.geometry[0]}),this.locationProvider instanceof E&&(this.simulatedLocationMarker=new j.Marker({color:"green"}).setLngLat(t.geometry[0]).addTo(this.map))}async stopNavigation(){this.routeAdapter?.free(),this.routeAdapter=null,this.navigationController?.free(),this.navigationController=null,this.tripStateUpdate(null),this.clearMap(),this.locationProvider&&(this.locationProvider.updateCallback=null),this.onNavigationStop&&this.map&&this.onNavigationStop(this.map)}tripStateUpdate(t){this._tripState=t,this.onTripStateChange?.(t)}onLocationUpdated(){if(!this.navigationController)return;const t=this.navigationController.updateUserLocation(this.locationProvider.lastLocation,this._tripState);this.tripStateUpdate(t),this.simulatedLocationMarker?.setLngLat(this.locationProvider.lastLocation.coordinates),this.map?.easeTo({center:this.locationProvider.lastLocation.coordinates,bearing:this.locationProvider.lastLocation.courseOverGround.degrees||0});const e=this._tripState;this.useVoiceGuidance&&e!=null&&typeof e=="object"&&"Navigating"in e&&e.Navigating?.spokenInstruction&&e.Navigating?.spokenInstruction.utteranceId!==this.lastSpokenUtteranceId&&(this.lastSpokenUtteranceId=e.Navigating?.spokenInstruction.utteranceId,window.speechSynthesis.cancel(),window.speechSynthesis.speak(new SpeechSynthesisUtterance(e.Navigating?.spokenInstruction.text)))}clearMap(){this.map?.getLayer("route")&&this.map?.removeLayer("route"),this.map?.getLayer("route-border")&&this.map?.removeLayer("route-border"),this.map?.getSource("route")&&this.map?.removeSource("route"),this.simulatedLocationMarker?.remove()}render(){return c.html`
108
117
  <style>
109
118
  ${this.customStyles}
@@ -190,5 +199,16 @@
190
199
  #stop-button:hover {
191
200
  background-color: #e0e0e0;
192
201
  }
202
+
203
+ @media (max-width: 600px) {
204
+ #stop-button {
205
+ padding: 14px;
206
+ }
207
+
208
+ #stop-button .icon {
209
+ width: 10px;
210
+ height: 10px;
211
+ }
212
+ }
193
213
  `],v([g()],l.FerrostarMap.prototype,"valhallaEndpointUrl",2),v([g()],l.FerrostarMap.prototype,"profile",2),v([g({attribute:!1})],l.FerrostarMap.prototype,"httpClient",2),v([g({type:Object,attribute:!1})],l.FerrostarMap.prototype,"locationProvider",2),v([g({type:Object,attribute:!1})],l.FerrostarMap.prototype,"options",2),v([o0()],l.FerrostarMap.prototype,"_tripState",2),v([g({type:Function,attribute:!1})],l.FerrostarMap.prototype,"onNavigationStart",2),v([g({type:Function,attribute:!1})],l.FerrostarMap.prototype,"onNavigationStop",2),v([g({type:Function,attribute:!0})],l.FerrostarMap.prototype,"onTripStateChange",2),v([g({type:Object,attribute:!1})],l.FerrostarMap.prototype,"customStyles",2),v([g({type:Boolean})],l.FerrostarMap.prototype,"useVoiceGuidance",2),v([g({type:Boolean})],l.FerrostarMap.prototype,"geolocateOnLoad",2),v([g({type:Object})],l.FerrostarMap.prototype,"map",2),l.FerrostarMap=v([O("ferrostar-map")],l.FerrostarMap),l.BrowserLocationProvider=Jt,l.SimulatedLocationProvider=E,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
194
214
  //# sourceMappingURL=ferrostar-webcomponents.umd.cjs.map