0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

leafletを鍛える。その37

Posted at

概要

leafletを鍛えてみた。
OSMBuilding、見つけたのでやってみた。

参考にしたページ

写真

image.png

サンプルコード


const DEFAULT_POSITION = {
    latitude: 35.68997,
    longitude: 139.692461
};
function showLoading() {
    document.getElementById('loading').style.display = 'block';
}
function hideLoading() {
    document.getElementById('loading').style.display = 'none';
}
function initMap(position) {
    const map = new OSMBuildings({
        container: 'map',
        position: position,
        zoom: 10,
        minZoom: 8,
        maxZoom: 20,
        attribution: '© Data <a href="https://openstreetmap.org/copyright/">OpenStreetMap</a> © Map <a href="https://osmbuildings.org/copyright/">OSM Buildings</a>'
    });
    map.addMapTiles('https://tile-a.openstreetmap.fr/hot/{z}/{x}/{y}.png');
    map.addGeoJSONTiles('https://{s}.data.osmbuildings.org/0.2/59fcc2e8/tile/{z}/{x}/{y}.json');
}
function getCurrentLocationAndShowMap() {
    showLoading();
    if ("geolocation" in navigator) 
    {
        navigator.geolocation.getCurrentPosition(
            function(position) {
                hideLoading();
                initMap({
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude
                });
            },
            function(error) {
                console.error("位置情報の取得に失敗しました:", error);
                hideLoading();
                //alert("ng");
                initMap(DEFAULT_POSITION);
            },
            {
                enableHighAccuracy: true,
                timeout: 5000,
                maximumAge: 0
            }
        );
    } 
    else 
    {
        console.log("Geolocation APIがサポートされていません");
        hideLoading();
        initMap(DEFAULT_POSITION);
    }
}

getCurrentLocationAndShowMap();
    


成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?