diff --git a/docs/mockup_measurer.html b/docs/mockup_measurer.html index ab9a7b1..7712af5 100644 --- a/docs/mockup_measurer.html +++ b/docs/mockup_measurer.html @@ -277,6 +277,51 @@ function render(id) { } } +// ── GPS: прибытие на объект замера ──────────────────────────────────────────── +var _MSR_GPS_RADIUS = 300; // метров +var _MSR_JOBS = { + 'З-1042': {addr:'ул. Рубинштейна, 7, кв. 18', lat:59.9295, lng:30.3426} +}; +window._MSR_GPS = {}; +window._MSR_GPS_DEMO = 'near'; + +function _msrGpsDist(la1,lo1,la2,lo2){ + var R=6371000,dL=(la2-la1)*Math.PI/180,dG=(lo2-lo1)*Math.PI/180; + var a=Math.sin(dL/2)*Math.sin(dL/2)+Math.cos(la1*Math.PI/180)*Math.cos(la2*Math.PI/180)*Math.sin(dG/2)*Math.sin(dG/2); + return Math.round(R*2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))); +} +function _msrFmt(m){ return m<1000?(m+' м'):(m/1000).toFixed(1)+' км'; } +function _msrGpsResult(jobId,dist){ + var ok=dist<=_MSR_GPS_RADIUS; + window._MSR_GPS[jobId]={ok:ok,dist:dist}; + document.getElementById('screen').innerHTML=render('order_detail'); +} +function _msrGpsRequest(jobId){ + window._MSR_GPS[jobId]='loading'; + document.getElementById('screen').innerHTML=render('order_detail'); + var job=_MSR_JOBS[jobId]; + function onGot(lat,lng){ _msrGpsResult(jobId,_msrGpsDist(lat,lng,job.lat,job.lng)); } + function onFail(){ _msrGpsResult(jobId, window._MSR_GPS_DEMO==='near'?54:1510); } + var tg=window.Telegram&&Telegram.WebApp; + if(tg&&tg.LocationManager&&tg.LocationManager.isInited){ + tg.LocationManager.getLocation(function(r){ r&&r.latitude?onGot(r.latitude,r.longitude):onFail(); }); + } else if(navigator.geolocation){ + navigator.geolocation.getCurrentPosition( + function(p){ onGot(p.coords.latitude,p.coords.longitude); }, + onFail,{timeout:8000,maximumAge:15000} + ); + } else { onFail(); } +} +function _msrGpsForce(jobId){ + var prev=window._MSR_GPS[jobId]; + window._MSR_GPS[jobId]={ok:false,dist:prev&&prev.dist||0,forced:true}; + document.getElementById('screen').innerHTML=render('order_detail'); +} +function _msrGpsCancelCheck(jobId){ + window._MSR_GPS[jobId]=null; + document.getElementById('screen').innerHTML=render('order_detail'); +} + /* ─── HOME ─── */ function screenHome() { return `