Leaflet/debug/tests/add_remove_layers.html

72 lines
2.2 KiB
HTML
Raw Normal View History

2013-01-13 05:55:13 +08:00
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="../../dist/leaflet.css" />
<link rel="stylesheet" href="../css/screen.css" />
<script type="text/javascript" src="../../build/deps.js"></script>
<script src="../leaflet-include.js"></script>
</head>
<body>
<div id="map"></div>
<div id="buttons">
<button type="button" id="b1"> Add Layer</button>
<button type="button" id="b2"> Remove Layer</button>
</div>
2013-01-13 05:55:13 +08:00
<script>
var map;
var myLayerGroup = new L.LayerGroup();
2013-01-13 05:55:13 +08:00
// set up the map
map = new L.Map('map', {preferCanvas: true});
2013-01-13 05:55:13 +08:00
// create the tile layer with correct attribution
var osmUrl = 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib = 'Map data © OpenStreetMap contributors';
var osm = new L.TileLayer(osmUrl, { minZoom: 1, maxZoom: 17, attribution: osmAttrib, detectRetina: true });
map.addLayer(osm);
map.fitBounds(new L.LatLngBounds([51,7],[51,7]));
drawTestLine();
2013-01-13 05:55:13 +08:00
function drawTestLine() {
var lat = 51;
var long = 7;
for (var i = 0; i < 50; i++) {
var myCircle = new L.Circle(new L.LatLng(lat, long),3);
myCircle.on('click',
function (e) {
popup = new L.Popup();
popup.setLatLng(this.getLatLng());
2013-01-13 05:55:13 +08:00
var popuptxt = "Hello!";
alert("I am the click function");
popup.setContent(popuptxt);
map.openPopup(popup);
});
myLayerGroup.addLayer(myCircle);
lat = lat + 0.0001;
long = long + 0.0001;
2013-01-13 05:55:13 +08:00
}
2013-01-13 05:55:13 +08:00
map.addLayer(myLayerGroup);
};
2013-01-13 05:55:13 +08:00
L.DomEvent.on(L.DomUtil.get('b1'), 'click', function () {
map.addLayer(myLayerGroup);
});
L.DomEvent.on(L.DomUtil.get('b2'), 'click', function () {
map.removeLayer(myLayerGroup);
2013-01-13 05:55:13 +08:00
});
</script>
</body>
</html>