alert("はじめは火山灰です。少しゆっくりだけど気をつけて!"); var piyo=L.icon({ iconUrl:'piyopiyo.gif', className:'piyoko', iconSize:[30, 41], iconAnchor:[19, 19], popupAnchor: [-6, -10] }); var piyo=L.icon({ iconUrl:'piyopiyo.gif', className:'piyoko', iconSize:[30, 41], iconAnchor:[19, 19], popupAnchor: [-6, -10] }); var piyoX=L.icon({ iconUrl:'emoji_xx.png', className:'piyoko', iconSize:[30, 41], iconAnchor:[19, 19], popupAnchor: [-6, -10] }); function timeStart(){ var res=confirm("okでゲームスタート!"); if( res == true ) { mk_cicle(); }else { timeStart(); } //clearTimeout(circles); }; function game(){ var timerInterval = 10000; // GPS失敗で何秒後に再取得か var tmId = null; var i = 0;//, countD = document.getElementById("countdown"); var point=L.marker(mymap.getCenter(),{icon:piyo,zIndexOffset:999}).addTo(mymap); point.bindPopup("僕を安全なところにつれてって!").openPopup(); var stop = document.getElementById("stp"); var gps=document.getElementById("str"); var nowTrying = null; var doflag=true; function tryGetGPS() { clearTimer(); //ser.textContent = "GPS取得..." nowTrying = navigator.geolocation.getCurrentPosition( onSuccess, onError,{ maximumAge: 0, timeout: 1000, enableHighAccuracy: true}) } function onemore() { if (nowTrying || tmId) { //info.textContent = "既にGPS取得試行or待機中です"; } else { startTimer(); //tm.textContent=""+naiyo[0]+""; } } function startTimer() { if (tmId==null && doflag){ tmId = setTimeout(tryGetGPS, 1000); //ser.textContent = "5秒後にGPS取得…"; //tme.textContent= "周りに注意して使用しましょう!"; } } function clearTimer() { if (tmId) { clearTimeout(tmId); //nowTrying=nil; } } function countDown(){ if (doflag){ alert("周りに注意して使用して下さい"); tryGetGPS(); timeStart(); } else{ tryGetGPS(); doflag=true; tmId=null; } } function stopCountDown() { doflag=false; location.href="./kazandeiryu.html" } function onSuccess(pos) { nowTrying = null; tmId=null; mymap.setZoom(18); var latlng = L.latLng([pos.coords.latitude, pos.coords.longitude]); point.setLatLng(latlng); mymap.panTo(latlng); var lat = latlng.lat, lng = latlng.lng; var g=1000000,d=0,i=0, come,name,near_point; var dist=latlng.distanceTo(circle); var panco=panko[panko.length-1]; if(panco<=dist && panco<=99){ onemore(); }else if(panco<=dist && 99<=panco){ point.bindPopup("助かったぴよー").openPopup(); stopCountDown(); }else{ point.setIcon(piyoX).bindPopup("灰で苦しいぴよー…").openPopup(); alert("追いつかれちゃった…"); stopCountDown(); } } function onError(err) { // 失敗時 nowTrying = null; //ser.textContent = "現在位置の取得失敗.10秒後にもう一回"; tmId = setTimeout(tryGetGPS, timerInterval); } gps.addEventListener("click", countDown, false); stop.addEventListener("click", stopCountDown, false); }; document.addEventListener("DOMContentLoaded", game, false);