diff --git a/docs/mockup_assembler.html b/docs/mockup_assembler.html index 65de1d9..50af554 100644 --- a/docs/mockup_assembler.html +++ b/docs/mockup_assembler.html @@ -447,6 +447,52 @@ function render(id) { } } +// ── GPS: прибытие на объект сборки ──────────────────────────────────────────── +var _ASM_GPS_RADIUS = 300; // метров — у клиента адрес уличный, допуск больше чем у салона +var _ASM_JOBS = { + 'А-2847': {addr:'ул. Ленина, 45', lat:59.9548, lng:30.3158}, + 'А-2851': {addr:'пр. Победы, 88', lat:59.8695, lng:30.2867} +}; +window._ASM_GPS = {}; // jobId → null | 'loading' | {ok,dist,forced} +window._ASM_GPS_DEMO = 'near'; // 'near' | 'far' + +function _asmGpsDist(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 _asmFmt(m){ return m<1000?(m+' м'):(m/1000).toFixed(1)+' км'; } +function _asmGpsResult(jobId,dist){ + var ok=dist<=_ASM_GPS_RADIUS; + window._ASM_GPS[jobId]={ok:ok,dist:dist}; + document.getElementById('screen').innerHTML=render('asm_detail'); +} +function _asmGpsRequest(jobId){ + window._ASM_GPS[jobId]='loading'; + document.getElementById('screen').innerHTML=render('asm_detail'); + var job=_ASM_JOBS[jobId]; + function onGot(lat,lng){ _asmGpsResult(jobId,_asmGpsDist(lat,lng,job.lat,job.lng)); } + function onFail(){ _asmGpsResult(jobId, window._ASM_GPS_DEMO==='near'?62:1380); } + 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 _asmGpsForce(jobId){ + var prev=window._ASM_GPS[jobId]; + window._ASM_GPS[jobId]={ok:false,dist:prev&&prev.dist||0,forced:true}; + document.getElementById('screen').innerHTML=render('asm_detail'); +} +function _asmGpsCancelCheck(jobId){ + window._ASM_GPS[jobId]=null; + document.getElementById('screen').innerHTML=render('asm_detail'); +} + /* ─── BOTTOM SHEET ─── */ function showSheet(d) { const existing = document.getElementById('bottomSheet'); @@ -650,13 +696,43 @@ function screenAsmDetail() {
-