@stadiamaps/ferrostar-webcomponents 0.17.0 → 0.18.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.
- package/dist/ferrostar-map.d.ts +3 -3
- package/dist/ferrostar-map.d.ts.map +1 -1
- package/dist/ferrostar-webcomponents.js +1 -1
- package/dist/ferrostar-webcomponents.js.map +1 -1
- package/dist/ferrostar-webcomponents.umd.cjs +1 -1
- package/dist/ferrostar-webcomponents.umd.cjs.map +1 -1
- package/package.json +2 -2
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
margin: 0 15px;
|
|
88
88
|
white-space: nowrap;
|
|
89
89
|
}
|
|
90
|
-
`],R([n()],y.prototype,"tripState",2),y=R([f("arrival-view")],y);function H(l){let t=null;return l.coords.speed&&(t={value:l.coords.speed}),{coordinates:{lat:l.coords.latitude,lng:l.coords.longitude},horizontalAccuracy:l.coords.accuracy,courseOverGround:{degrees:Math.floor(l.coords.heading||0)},timestamp:l.timestamp,speed:t}}class j{constructor(){this.simulationState=null,this.isRunning=!1,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=u.locationSimulationFromRoute(t,10),this.lastLocation=this.simulationState?.current_location,this.start()}async start(){if(!this.isRunning){for(this.isRunning=!0;this.simulationState!==null;){await new Promise(a=>setTimeout(a,1/this.warpFactor*1e3));const t=this.simulationState,e=u.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 G1{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=H(e),this.updateCallback&&this.updateCallback()},e=>{this.geolocationWatchId=null,alert(e.message)},t)}}getCurrentLocation(t){if(!navigator.geolocation)return new Promise((a,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((a,i)=>{navigator.geolocation.getCurrentPosition(o=>{const r=H(o);this.lastLocation=r,a(r)},i)})}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var W1=Object.defineProperty,K1=Object.getOwnPropertyDescriptor,g=(l,t,e,a)=>{for(var i=a>1?void 0:a?K1(t,e):t,o=l.length-1,r;o>=0;o--)(r=l[o])&&(i=(a?r(t,e,i):r(i))||i);return a&&i&&W1(t,e,i),i};s.FerrostarMap=class extends c.LitElement{constructor(){super(),this.valhallaEndpointUrl="",this.styleUrl="",this.profile="",this.center=null,this.pitch=60,this.zoom=6,this.httpClient=fetch,this.options={},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.
|
|
90
|
+
`],R([n()],y.prototype,"tripState",2),y=R([f("arrival-view")],y);function H(l){let t=null;return l.coords.speed&&(t={value:l.coords.speed}),{coordinates:{lat:l.coords.latitude,lng:l.coords.longitude},horizontalAccuracy:l.coords.accuracy,courseOverGround:{degrees:Math.floor(l.coords.heading||0)},timestamp:l.timestamp,speed:t}}class j{constructor(){this.simulationState=null,this.isRunning=!1,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=u.locationSimulationFromRoute(t,10),this.lastLocation=this.simulationState?.current_location,this.start()}async start(){if(!this.isRunning){for(this.isRunning=!0;this.simulationState!==null;){await new Promise(a=>setTimeout(a,1/this.warpFactor*1e3));const t=this.simulationState,e=u.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 G1{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=H(e),this.updateCallback&&this.updateCallback()},e=>{this.geolocationWatchId=null,alert(e.message)},t)}}getCurrentLocation(t){if(!navigator.geolocation)return new Promise((a,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((a,i)=>{navigator.geolocation.getCurrentPosition(o=>{const r=H(o);this.lastLocation=r,a(r)},i)})}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var W1=Object.defineProperty,K1=Object.getOwnPropertyDescriptor,g=(l,t,e,a)=>{for(var i=a>1?void 0:a?K1(t,e):t,o=l.length-1,r;o>=0;o--)(r=l[o])&&(i=(a?r(t,e,i):r(i))||i);return a&&i&&W1(t,e,i),i};s.FerrostarMap=class extends c.LitElement{constructor(){super(),this.valhallaEndpointUrl="",this.styleUrl="",this.profile="",this.center=null,this.pitch=60,this.zoom=6,this.httpClient=fetch,this.options={},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.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)),this.map&&(t.has("styleUrl")&&this.map.setStyle(this.styleUrl),t.has("center")&&(t.get("center")===null&&this.center!==null?this.map.jumpTo({center:this.center}):this.center!==null&&(this.map.getCenter().distanceTo(_.LngLat.convert(this.center))>5e5?this.map.jumpTo({center:this.center}):this.map.flyTo({center:this.center}))),t.has("pitch")&&this.map.setPitch(this.pitch),t.has("zoom")&&this.map.setZoom(this.zoom))}firstUpdated(){this.map=new _.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 _.GeolocateControl({positionOptions:{enableHighAccuracy:!0},trackUserLocation:!0}),this.map.addControl(this.geolocateControl),this.map.on("load",t=>{this.geolocateOnLoad&&this.geolocateControl?.trigger(),this.configureMap!==void 0&&this.configureMap(t.target)})}async getRoutes(t,e){this.routeAdapter=new u.RouteAdapter(this.valhallaEndpointUrl,this.profile,JSON.stringify(this.options));const a=this.routeAdapter.generateRequest(t,e),i=a.get("method");let o=new URL(a.get("url"));const r=a.get("body"),h=await this.httpClient(o,{method:i,body:new Uint8Array(r).buffer}),v=new Uint8Array(await h.arrayBuffer());return this.routeAdapter.parseResponse(v)}startNavigation(t,e){this.locationProvider.start(),this.onNavigationStart&&this.map&&this.onNavigationStart(this.map),this.navigationController=new u.NavigationController(t,e),this.locationProvider.updateCallback=this.onLocationUpdated.bind(this);const a=this.locationProvider.lastLocation?this.locationProvider.lastLocation:{coordinates:t.geometry[0],horizontalAccuracy:0,courseOverGround:null,timestamp:Date.now(),speed:null};this._tripState=this.navigationController.getInitialState(a),this.clearMap(),this.map?.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t.geometry.map(i=>[i.lng,i.lat])}}}),this.map?.addLayer({id:"route",type:"line",source:"route",layout:{"line-join":"round","line-cap":"round"},paint:{"line-color":"#3700B3","line-width":8}}),this.map?.setCenter(t.geometry[0]),this.locationProvider instanceof j&&(this.simulatedLocationMarker=new _.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._tripState=null,this.clearMap(),this.locationProvider&&(this.locationProvider.updateCallback=null),this.onNavigationStop&&this.map&&this.onNavigationStop(this.map)}onLocationUpdated(){if(!this.navigationController)return;this._tripState=this.navigationController.updateUserLocation(this.locationProvider.lastLocation,this._tripState),this.simulatedLocationMarker?.setLngLat(this.locationProvider.lastLocation.coordinates),this.map?.easeTo({center:this.locationProvider.lastLocation.coordinates,bearing:this.locationProvider.lastLocation.courseOverGround.degrees||0});const t=this._tripState;this.useVoiceGuidance&&t!=null&&typeof t=="object"&&"Navigating"in t&&t.Navigating?.spokenInstruction&&t.Navigating?.spokenInstruction.utteranceId!==this.lastSpokenUtteranceId&&(this.lastSpokenUtteranceId=t.Navigating?.spokenInstruction.utteranceId,window.speechSynthesis.cancel(),window.speechSynthesis.speak(new SpeechSynthesisUtterance(t.Navigating?.spokenInstruction.text)))}clearMap(){this.map?.getLayer("route")&&this.map?.removeLayer("route"),this.map?.getSource("route")&&this.map?.removeSource("route"),this.simulatedLocationMarker?.remove()}render(){return c.html`
|
|
91
91
|
<style>
|
|
92
92
|
${this.customStyles}
|
|
93
93
|
</style>
|