2011-06-21 16:43:31 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Leaflet debug page</title>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../../dist/leaflet.css" />
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
<link rel="stylesheet" href="../css/screen.css" />
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
<script src="../leaflet-include.js"></script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
|
2016-04-29 17:35:50 +08:00
|
|
|
<button onclick="group.removeLayer(path)">Remove path</button>
|
|
|
|
<button onclick="group.removeLayer(circle)">Remove circle</button>
|
|
|
|
<button onclick="group.clearLayers()">Remove all layers</button>
|
2011-07-28 18:58:40 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
|
|
|
|
<script src="route.js"></script>
|
|
|
|
<script>
|
2014-03-04 23:54:41 +08:00
|
|
|
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
|
|
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
|
|
|
|
osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib});
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
for (var i = 0, latlngs = [], len = route.length; i < len; i++) {
|
|
|
|
latlngs.push(new L.LatLng(route[i][0], route[i][1]));
|
|
|
|
}
|
2015-07-04 23:25:26 +08:00
|
|
|
var canvas = L.canvas();
|
|
|
|
var path = new L.Polyline(latlngs, {renderer: canvas});
|
2011-06-21 16:43:31 +08:00
|
|
|
|
2015-07-14 16:27:50 +08:00
|
|
|
var map = new L.Map('map', {layers: [osm], preferCanvas: true});
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-07-29 21:54:54 +08:00
|
|
|
var group = new L.LayerGroup();
|
2011-06-21 16:43:31 +08:00
|
|
|
|
|
|
|
map.fitBounds(new L.LatLngBounds(latlngs));
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
var circleLocation = new L.LatLng(51.508, -0.11),
|
|
|
|
circleOptions = {
|
2016-04-29 17:35:50 +08:00
|
|
|
color: 'red',
|
|
|
|
fillColor: 'yellow',
|
|
|
|
fillOpacity: 0.7,
|
|
|
|
renderer: canvas
|
2011-06-21 16:43:31 +08:00
|
|
|
};
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-22 17:26:03 +08:00
|
|
|
var circle = new L.Circle(circleLocation, 500000, circleOptions),
|
|
|
|
circleMarker = new L.CircleMarker(circleLocation, {fillColor: 'blue', fillOpacity: 1, stroke: false});
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-07-29 21:54:54 +08:00
|
|
|
group.addLayer(circle).addLayer(circleMarker);
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
circle.bindPopup('I am a circle');
|
2011-06-22 17:26:03 +08:00
|
|
|
circleMarker.bindPopup('I am a circle marker');
|
2012-07-30 17:31:09 +08:00
|
|
|
|
|
|
|
group.addLayer(path);
|
2011-06-21 19:04:35 +08:00
|
|
|
path.bindPopup('I am a polyline');
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
var p1 = latlngs[0],
|
2016-04-29 17:35:50 +08:00
|
|
|
p2 = latlngs[Math.round(len / 4)],
|
|
|
|
p3 = latlngs[Math.round(len / 3)],
|
|
|
|
p4 = latlngs[Math.round(len / 2)],
|
2011-06-21 16:43:31 +08:00
|
|
|
p5 = latlngs[len - 1],
|
|
|
|
polygonPoints = [p1, p2, p3, p4, p5];
|
|
|
|
|
|
|
|
var h1 = new L.LatLng(p1.lat, p1.lng),
|
|
|
|
h2 = new L.LatLng(p2.lat, p2.lng),
|
|
|
|
h3 = new L.LatLng(p3.lat, p3.lng),
|
|
|
|
h4 = new L.LatLng(p4.lat, p4.lng),
|
|
|
|
h5 = new L.LatLng(p5.lat, p5.lng);
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
h1.lng += 20;
|
|
|
|
h2.lat -= 5;
|
|
|
|
h3.lat -= 5;
|
|
|
|
h4.lng -= 10;
|
|
|
|
h5.lng -= 8;
|
|
|
|
h5.lat += 10;
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
var holePoints = [h5, h4, h3, h2, h1];
|
|
|
|
|
|
|
|
var polygon = new L.Polygon([polygonPoints, holePoints], {
|
2011-06-21 18:02:45 +08:00
|
|
|
fillColor: "#333",
|
2015-07-04 23:25:26 +08:00
|
|
|
color: 'green',
|
|
|
|
renderer: canvas
|
2011-06-21 16:43:31 +08:00
|
|
|
});
|
2011-07-29 21:54:54 +08:00
|
|
|
group.addLayer(polygon);
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2016-04-02 00:05:30 +08:00
|
|
|
var line = new L.Polyline([h1, h4, h5], {
|
|
|
|
dashArray: '5, 5'
|
|
|
|
});
|
|
|
|
group.addLayer(line);
|
|
|
|
|
2011-06-21 19:37:34 +08:00
|
|
|
polygon.bindPopup('I am a polygon');
|
2012-07-30 17:31:09 +08:00
|
|
|
|
2011-07-29 21:54:54 +08:00
|
|
|
map.addLayer(group);
|
2011-06-21 19:04:35 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
</script>
|
2011-07-24 20:55:49 +08:00
|
|
|
|
2011-06-21 16:43:31 +08:00
|
|
|
</body>
|
|
|
|
</html>
|