You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
2.6 KiB
JavaScript

"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[3085],{52984:function(e,t,n){var a=n(78284),o=n(5265),i=n(41376),r=n(79847),c=n(70492),d=n(42010),s=n(54354),g=n(12810),u=new s.ZP({center:(0,g.mi)([5.8713,45.6452]),zoom:19}),l=new d.Z({source:new r.Z}),m=new i.Z({layers:[l],target:"map",view:u}),h=document.getElementById("geolocation_marker"),p=new c.Z({positioning:"center-center",element:h,stopEvent:!1});m.addOverlay(p);var v=new o.Z([],"XYZM"),f=new a.Z({projection:u.getProjection(),trackingOptions:{maximumAge:1e4,enableHighAccuracy:!0,timeout:6e5}}),M=500;f.on("change",(function(){var e=f.getPosition(),t=f.getAccuracy(),n=f.getHeading()||0,a=f.getSpeed()||0;!function(e,t,n,a){var o=e[0],i=e[1],r=v.getCoordinates(),c=r[r.length-1],d=c&&c[2];if(d){var s=t-(d%(2*Math.PI)+2*Math.PI)%(2*Math.PI);if(Math.abs(s)>Math.PI)s=-(s>=0?1:-1)*(2*Math.PI-Math.abs(s));t=d+s}v.appendCoordinate([o,i,t,n]),v.setCoordinates(v.getCoordinates().slice(-20)),h.src=t&&a?"data/geolocation_marker_heading.png":"data/geolocation_marker.png"}(e,n,Date.now(),a);var o=v.getCoordinates(),i=o.length;i>=2&&(M=(o[i-1][3]-o[0][3])/(i-1));var r,c=["Position: "+e[0].toFixed(2)+", "+e[1].toFixed(2),"Accuracy: "+t,"Heading: "+Math.round((r=n,360*r/(2*Math.PI)))+"&deg;","Speed: "+(3.6*a).toFixed(1)+" km/h","Delta: "+Math.round(M)+"ms"].join("<br />");document.getElementById("info").innerHTML=c})),f.on("error",(function(){alert("geolocation error")}));var w=0;function k(){var e=Date.now()-1.5*M;e=Math.max(e,w),w=e;var t,n,a,o,i=v.getCoordinateAtM(e,!0);i&&(u.setCenter((t=i,n=-i[2],a=u.getResolution(),o=m.getSize()[1],[t[0]-Math.sin(n)*o*a*1/4,t[1]+Math.cos(n)*o*a*1/4])),u.setRotation(-i[2]),p.setPosition(i),m.render())}var P,y=document.getElementById("geolocate");y.addEventListener("click",(function(){f.setTracking(!0),l.on("postrender",k),m.render(),E()}),!1);var I=new XMLHttpRequest;I.open("GET","data/geolocation-orientation.json"),I.onload=function(){P=JSON.parse(I.responseText).data},I.send();var b=document.getElementById("simulate");function C(e){var t=e.coords;f.set("accuracy",t.accuracy),f.set("heading",t.heading*Math.PI*2/360);var n=(0,g.mi)([t.longitude,t.latitude]);f.set("position",n),f.set("speed",t.speed),f.changed()}function E(){y.disabled="disabled",b.disabled="disabled"}b.addEventListener("click",(function(){var e=P,t=e.shift();C(t);var n=t.timestamp;!function t(){var a=e.shift();if(a){var o=a.timestamp;C(a),window.setTimeout((function(){n=o,t()}),(o-n)/.5)}}(),l.on("postrender",k),m.render(),E()}),!1)}},function(e){var t=function(t){return e(e.s=t)};t(9877),t(52984)}]);
//# sourceMappingURL=geolocation-orientation.js.map