日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Leaflet文档阅读笔记-Leaflet on Mobile笔记

發布時間:2025/3/15 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Leaflet文档阅读笔记-Leaflet on Mobile笔记 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

?

CSS和HTML改如何設置

定位功能


?

CSS和HTML改如何設置

如下的設置:

body {padding: 0;margin: 0; } html, body, #map {height: 100%;width: 100vw; }

這里還要設置禁止瀏覽器進行不必要的放縮

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

上面是官方的給出的,下面是本人個人的看法,css應該這么寫!

<style>html, body {height: 100%;margin: 0;}#map {width: 100%;height: 100%;}</style>

這樣,整個屏幕都是地圖了

?

定位功能

我先把官方代碼貼上了吧

<!DOCTYPE html> <html> <head><title>Mobile tutorial - Leaflet</title><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" /><link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/><script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js" integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og==" crossorigin=""></script><style>html, body {height: 100%;margin: 0;}#map {width: 600px;height: 400px;}</style><style>body { padding: 0; margin: 0; } #map { height: 100%; width: 100vw; }</style> </head> <body><div id='map'></div><script>var map = L.map('map').fitWorld();L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {maxZoom: 18,attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +'Imagery ? <a href="https://www.mapbox.com/">Mapbox</a>',id: 'mapbox.streets'}).addTo(map);function onLocationFound(e) {var radius = e.accuracy / 2;L.marker(e.latlng).addTo(map).bindPopup("You are within " + radius + " meters from this point").openPopup();L.circle(e.latlng, radius).addTo(map);}function onLocationError(e) {alert(e.message);}map.on('locationfound', onLocationFound);map.on('locationerror', onLocationError);map.locate({setView: true, maxZoom: 16}); </script></body> </html>

從中可以知道,當定位成功后,會觸發locationFound這個信號,當有問題時會觸發locationerror信號!

通過onLocationFound的參數,就能獲得位置坐標!

總結

以上是生活随笔為你收集整理的Leaflet文档阅读笔记-Leaflet on Mobile笔记的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。