"use strict";const map01=new L.map("map01"),fg_shuttle=new L.FeatureGroup;document.addEventListener("alpine:init",(()=>{Alpine.data("mapData",(()=>({debug:!1,shuttle:{geofence:{long:4.4251,lat:51.9108},location:{long:null,lat:null,inside_geofence:!1,distance_to_tlc:null,distance_visible_on_map:135}},tlc:{location:{long:4.4251,lat:51.9108,radius:45}},marker_html:'\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ',init(){this.init_map(),this.$watch("shuttle.location.inside_geofence",(value=>{this.$dispatch("shuttle-inside-geofence-changed",{shuttle_inside_geofence:value,longitude:this.shuttle.location.long,latitude:this.shuttle.location.lat,radius:this.tlc.location.radius})})),this.debug&&setTimeout((()=>{this.tlc.location.radius=45}),2e4)},init_map(){const mapbox_token="pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw",mbAttr="© Mapbox © OpenStreetMap",mapbox_gray=L.tileLayer("https://api.mapbox.com/styles/v1/mapbox/light-v10/tiles/{z}/{x}/{y}?access_token="+mapbox_token,{attribution:mbAttr,tileSize:512,zoomOffset:-1}),mapbox_color=L.tileLayer("https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token="+mapbox_token,{attribution:mbAttr,tileSize:512,zoomOffset:-1}),pdok_lucht=L.tileLayer("https://service.pdok.nl/hwh/luchtfotorgb/wmts/v1_0/Actueel_orthoHR/EPSG:3857/{z}/{x}/{y}.jpeg",{attribution:'Kaartgegevens © Kadaster',tileSize:512,zoomOffset:-1}),base_layers={"Lucht":pdok_lucht,"Kleur":mapbox_color,"Grijs":mapbox_gray},lcontrol=new L.control.layers(base_layers,!0,{collapsed:!0,sortLayers:!0,hideSingleBase:!0});map01.setView([this.tlc.location.lat,this.tlc.location.long]),map01.setZoom(18),map01.setMinZoom(16),map01.addLayer(pdok_lucht),map01.addControl(lcontrol),lcontrol.addOverlay(fg_shuttle,"Vehicle"),map01.addLayer(fg_shuttle);L.circle([this.tlc.location.lat,this.tlc.location.long],{radius:this.tlc.location.radius}).addTo(map01);L.control.custom({position:"bottomleft",content:'\n
\n distance_tlc: \n \n
'}).addTo(map01),map01.locate({setView:!1,watch:!0,enableHighAccuracy:!0}).on("locationfound",(e=>{const long=e.longitude.toFixed(7),lat=e.latitude.toFixed(7);if(this.shuttle.location.lat===lat&&this.shuttle.location.long===long)return;if(!this.isShuttleInsideGeofence(e.latitude,e.longitude))return this.shuttle.location.lat=null,this.shuttle.location.long=null,this.shuttle.location.inside_geofence=!1,void(this.shuttle.location.distance_to_tlc>this.shuttle.location.distance_visible_on_map?fg_shuttle.clearLayers():(this.shuttle.location.long=long,this.shuttle.location.lat=lat,this.handleShuttlePositonOnMap(e.longitude,e.latitude)));this.shuttle.location.long=long,this.shuttle.location.lat=lat,this.shuttle.location.inside_geofence=!0,this.handleShuttlePositonOnMap(e.longitude,e.latitude),this.storeShuttlePosition(e.longitude,e.latitude)})).on("locationerror",(error=>{}))},toRad:value=>value*Math.PI/180,isShuttleInsideGeofence(lat,lon){const dLat=this.toRad(lat-this.shuttle.geofence.lat),dLon=this.toRad(lon-this.shuttle.geofence.long),lat1=this.toRad(this.shuttle.geofence.lat),lat2=this.toRad(lat),a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.sin(dLon/2)*Math.sin(dLon/2)*Math.cos(lat1)*Math.cos(lat2),c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a)),d=Math.round(6371*c*1e3);return this.shuttle.location.distance_to_tlc=d,d{if(200===response.status)return response.json()})).then((data=>{})).catch((error=>{console.error("Error:",error)}))}})))}));