@stadiamaps/ferrostar-webcomponents 0.1.4 → 0.9.2
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 m,LitElement as v,html as u,unsafeCSS as I}from"lit";import N from
|
|
|
87
87
|
margin: 0 15px;
|
|
88
88
|
white-space: nowrap;
|
|
89
89
|
}
|
|
90
|
-
`],j([n()],O.prototype,"tripState",2),O=j([b("arrival-view")],O);class k{constructor(){this.simulationState=null,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=K(t,10),this.start()}async start(){for(;this.simulationState!==null;){await new Promise(l=>setTimeout(l,1/this.warpFactor*1e3));const t=this.simulationState,e=P(t);if(t===e)return;this.simulationState=e,this.lastLocation=e.current_location,this.updateCallback&&this.updateCallback()}}stop(){this.simulationState=null}}class G{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={coordinates:{lat:e.coords.latitude,lng:e.coords.longitude},horizontalAccuracy:e.coords.accuracy,courseOverGround:{degrees:Math.floor(e.coords.heading||0)},timestamp:e.timestamp,speed:
|
|
90
|
+
`],j([n()],O.prototype,"tripState",2),O=j([b("arrival-view")],O);class k{constructor(){this.simulationState=null,this.lastLocation=null,this.lastHeading=null,this.warpFactor=1,this.updateCallback=()=>{}}setSimulatedRoute(t){this.simulationState=K(t,10),this.start()}async start(){for(;this.simulationState!==null;){await new Promise(l=>setTimeout(l,1/this.warpFactor*1e3));const t=this.simulationState,e=P(t);if(t===e)return;this.simulationState=e,this.lastLocation=e.current_location,this.updateCallback&&this.updateCallback()}}stop(){this.simulationState=null}}class G{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=>{let l=null;e.coords.speed&&(l={value:e.coords.speed}),this.lastLocation={coordinates:{lat:e.coords.latitude,lng:e.coords.longitude},horizontalAccuracy:e.coords.accuracy,courseOverGround:{degrees:Math.floor(e.coords.heading||0)},timestamp:e.timestamp,speed:l},this.updateCallback&&this.updateCallback()},e=>alert(e.message),t)}}stop(){this.lastLocation=null,navigator.geolocation&&this.geolocationWatchId&&(navigator.geolocation.clearWatch(this.geolocationWatchId),this.geolocationWatchId=null)}}var y3=Object.defineProperty,A3=Object.getOwnPropertyDescriptor,g=(a,t,e,l)=>{for(var i=l>1?void 0:l?A3(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(l?o(t,e,i):o(i))||i);return l&&i&&y3(t,e,i),i};let s=class extends v{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.useIntegratedSearchBox=!1,this.useVoiceGuidance=!1,this.routeAdapter=null,this.map=null,this.searchBox=null,this.navigationController=null,this.currentLocationMapMarker=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.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}),this.useIntegratedSearchBox&&(this.searchBox=new W({onResultSelected:async a=>{await this.startNavigationFromSearch(a.geometry.coordinates)}}),this.map.addControl(this.searchBox,"top-left"))}async getRoutes(a,t){this.routeAdapter=new B(this.valhallaEndpointUrl,this.profile,JSON.stringify(this.costingOptions));const e=this.routeAdapter.generateRequest(a,t).get("body"),l=await this.httpClient(this.valhallaEndpointUrl,{method:"POST",body:new Uint8Array(e).buffer}),i=new Uint8Array(await l.arrayBuffer());return this.routeAdapter.parseResponse(i)}startNavigation(a,t){var l,i,r,o;this.useIntegratedSearchBox&&((l=this.map)==null||l.removeControl(this.searchBox)),this.navigationController=new Z(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(),(i=this.map)==null||i.addSource("route",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"LineString",coordinates:a.geometry.map(c=>[c.lng,c.lat])}}}),(r=this.map)==null||r.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.currentLocationMapMarker=new N.Marker().setLngLat(a.geometry[0]).addTo(this.map)}async startNavigationFromSearch(a){const t=[{coordinate:{lat:a[1],lng:a[0]},kind:"Break"}];for((!this.locationProvider||this.locationProvider instanceof k)&&(this.locationProvider=new G),this.locationProvider.start();!this.locationProvider.lastLocation;)await new Promise(i=>setTimeout(i,100));const e=(await this.getRoutes(this.locationProvider.lastLocation,t))[0],l={stepAdvance:{RelativeLineStringDistance:{minimumHorizontalAccuracy:25,automaticAdvanceDistance:10}},routeDeviationTracking:{StaticThreshold:{minimumHorizontalAccuracy:25,maxAcceptableDeviation:10}}};this.startNavigation(e,l)}async stopNavigation(){var a,t,e;this.clearMap(),(a=this.routeAdapter)==null||a.free(),this.routeAdapter=null,(t=this.navigationController)==null||t.free(),this.navigationController=null,this._tripState=null,this.locationProvider&&(this.locationProvider.updateCallback=null),this.useIntegratedSearchBox&&((e=this.map)==null||e.addControl(this.searchBox,"top-left"))}onLocationUpdated(){var a,t,e,l,i,r;this.navigationController&&(this._tripState=this.navigationController.updateUserLocation(this.locationProvider.lastLocation,this._tripState),(a=this.currentLocationMapMarker)==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((r=this._tripState.Navigating)==null?void 0:r.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.currentLocationMapMarker)==null||i.remove()}render(){return u`
|
|
91
91
|
<div id="map">
|
|
92
92
|
<instructions-view .tripState=${this._tripState}></instructions-view>
|
|
93
93
|
<div id="bottom-component">
|