Newer
Older
j2321-tanakai / js / iti.js
@Tanakai Fuga Tanakai Fuga on 20 Oct 1011 bytes Create iti.js
var map = L.map('map').setView([38.914544, 139.836720], 16, {
    scrollWheelZoom: false,
});

// OpenStreetMapのタイルレイヤーを地図に追加
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);

// パルスアニメーション付きアイコンの定義
var PulsingIcon = L.divIcon({
    className: 'leaflet-pulsing-icon'
});

// 現在地が取得できた場合の処理
function gpsSuccess(e) {
    L.marker(e.latlng, { icon: PulsingIcon }).addTo(map).bindPopup("あなた").openPopup();
}

// 現在地が取得できなかった場合の処理
function gpsError(e) {
    alert("現在地を取得できませんでした。" + e.message);
}

// 現在地の取得
map.locate({ setView: true, maxZoom: 13, timeout: 20000 });

// 成功した場合の処理
map.on('locationfound', gpsSuccess);

// 失敗した場合の処理
map.on('locationerror', gpsError);