Leaflet/examples/mobile-example.html

57 lines
1.4 KiB
HTML
Raw Normal View History

2011-04-27 22:11:24 +08:00
<!DOCTYPE html>
<html>
<head>
<title>Leaflet mobile example</title>
2012-02-14 23:02:29 +08:00
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
2011-04-27 22:11:24 +08:00
<link rel="stylesheet" href="../dist/leaflet.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="../dist/leaflet.ie.css" /><![endif]-->
2012-02-14 23:02:29 +08:00
2011-04-27 22:11:24 +08:00
<script src="../dist/leaflet.js"></script>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
2012-02-14 23:02:29 +08:00
</style>
2011-04-27 22:11:24 +08:00
</head>
<body>
<div id="map"></div>
<script>
var map = new L.Map('map');
2012-02-14 23:02:29 +08:00
2011-04-27 22:11:24 +08:00
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade',
cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});
2012-02-14 23:02:29 +08:00
2011-04-27 22:11:24 +08:00
map.addLayer(cloudmade);
2012-02-14 23:02:29 +08:00
2011-04-28 05:11:52 +08:00
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
2012-02-14 23:02:29 +08:00
2011-04-28 05:11:52 +08:00
map.locateAndSetView();
2012-02-14 23:02:29 +08:00
2011-04-28 05:11:52 +08:00
function onLocationFound(e) {
2011-05-19 22:29:37 +08:00
var radius = e.accuracy / 2;
2011-04-27 22:11:24 +08:00
var marker = new L.Marker(e.latlng);
map.addLayer(marker);
2011-05-19 22:29:37 +08:00
marker.bindPopup("You are within " + radius + " meters from this point").openPopup();
2012-02-14 23:02:29 +08:00
2011-05-19 22:29:37 +08:00
var circle = new L.Circle(e.latlng, radius);
map.addLayer(circle);
2011-04-28 05:11:52 +08:00
}
2012-02-14 23:02:29 +08:00
2011-04-28 05:11:52 +08:00
function onLocationError(e) {
2011-05-19 22:29:37 +08:00
alert(e.message);
2011-04-28 05:11:52 +08:00
}
2011-04-27 22:11:24 +08:00
</script>
</body>
2012-02-14 23:02:29 +08:00
</html>