(() => { function myAtr() { /*MAPset*/ var gsi = L.tileLayer('//cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', { attribution: '© <a href="https://maps.gsi.go.jp">国土地理院地図</a> contributors' }); var osm = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }); var BingAir = new L.BingLayer("AvRR1iCvcIBp2R9fSTjK7FSHYDT0zpGCWT9PoyO7gHt9nEFBOcROZuuTnXjhWOig", { type: "Aerial", culture: "ja" }); var gpsmap = L.map('seek').setView([38.892919, 139.818078], 16); osm.addTo(gpsmap); var baseMaps = { "OpenStreetMap" : osm, "地理院地図" : gsi, "BingMap航空写真" : BingAir }; L.control.layers(baseMaps).addTo(gpsmap); L.control.scale({ position: 'bottomright' }).addTo(gpsmap); gpsmap.on('mousemove', onMapMousemove) var laloinfo = L.control({ position: "bottomleft" }); laloinfo.onAdd = function (map) { this.ele = L.DomUtil.create('div', "infostyle"); this.ele.id = "latlondiv"; this.ele.style.visibility = "hidden"; this.ele.onmousemove = function (e) { e.stopPropagation() }; return this.ele; }; laloinfo.addTo(gpsmap); function onMapMousemove(e) { var box = document.getElementById("latlondiv"); var llnum = "緯度:" + e.latlng.lat.toFixed(6) + "<br>" + "経度:" + e.latlng.lng.toFixed(6); box.innerHTML = llnum; box.style.visibility = "visible"; }; /*Set-icon*/ //var opacitychange = document.getElementById("target"); var obj = L.icon({ iconSize: [30,30], iconUrl: '../map/pic/mark01.png', }); popIcon1 = L.marker([38.920325,139.850970], { icon:obj, opacity: 1.0 }).addTo(gpsmap); /*obj.onAdd = function (place) { this.ele.id = 'accesspoint'; this.ele.style.visibility = "hidden"; return this.ele; };*/ //popIcon1.document.getElementById('access'); //const displayOriginal = popicon1.style.display; //popicon1.style.display = 'none'; /*Palse-icon*/ var pulsingIcon = L.icon.pulse({ iconSize:[15,15], color:'#00ff00', fillColor:'#00ff00', heartbeat: 1 }); var gpsmarker = L.marker(gpsmap.getCenter(), {icon: pulsingIcon}).addTo(gpsmap); gpsmarker.bindPopup("捕捉中...").openPopup(); /*GPS-set*/ /*function interRupt() { console.log("timeId="+timeId); if (timeId != null) { navigator.geolocation.clearWatch(timeId); document.getElementById("title").textContent = "stop"; gpsmarker.setPopupContent("取得を停止しました"); } timeId = null; }*/ var repeat = 5000; var reTry = 5; var timeId = null; function getGPS() { //interRupt(); gpsmarker.setPopupContent("位置情報を取得中").openPopup() navigator.geolocation.getCurrentPosition( hitting, missing, { maximumAge: 0, timeout: 10000, enableHighAccuracy: true }); document.getElementById('title').textContent = "スタート!!"; } function hitting(pos){ var latlng = L.latLng([pos.coords.latitude, pos.coords.longitude]); gpsmap.flyTo(latlng); gpsmarker.setPopupContent( "現在地" ).openPopup().setLatLng(latlng); var ido = latlng.lat, kedo = latlng.lng; if (ido > 38.919787 && ido < 38.920901 && kedo > 139.850217 && kedo < 139.851665) { } } } function missing(error){ var attention = [ error.message, '位置情報の取得に失敗しました', 'あと'+(--reTry)+'回試行します。' ]; if (reTry > 0) { window.alert(attention[error.code]); timeId = setTimeout(getGPS, repeat); } else { var suspention = '<span style="color: red;">位置情報の取得を中断します。</span>'; window.alert(suspention); } } getGPS(); /*HTML-link document.getElementById("start").addEventListener("click", getGPS); document.getElementById("stop").addEventListener("click", interRupt); HTML-link*/ } document.addEventListener("DOMContentLoaded", myAtr, false); })();