|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Leaflet debug page</title> |
| 5 | + |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
| 7 | + |
| 8 | + <link rel="stylesheet" href="../../dist/leaflet.css" /> |
| 9 | + <!--[if lte IE 8]><link rel="stylesheet" href="../../dist/leaflet.ie.css" /><![endif]--> |
| 10 | + |
| 11 | + <link rel="stylesheet" href="../css/screen.css" /> |
| 12 | + <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.0.js'></script> |
| 13 | + |
| 14 | + <script> |
| 15 | + L_PREFER_CANVAS = true; |
| 16 | + $(document).ready(function() { |
| 17 | + var map; |
| 18 | + var myLayerGroup = new L.LayerGroup(); |
| 19 | + |
| 20 | + initmap(); |
| 21 | + |
| 22 | + |
| 23 | + function initmap() { |
| 24 | + |
| 25 | + // set up the map |
| 26 | + map = new L.Map('map'); |
| 27 | + |
| 28 | + // create the tile layer with correct attribution |
| 29 | + var osmUrl = 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png'; |
| 30 | + var osmAttrib = 'Map data © OpenStreetMap contributors'; |
| 31 | + var osm = new L.TileLayer(osmUrl, { minZoom: 1, maxZoom: 17, attribution: osmAttrib, detectRetina: true }); |
| 32 | + map.addLayer(osm); |
| 33 | + map.fitBounds(new L.LatLngBounds([51,7],[51,7])); |
| 34 | + drawTestLine(); |
| 35 | + |
| 36 | + |
| 37 | + }; |
| 38 | + |
| 39 | + function drawTestLine() { |
| 40 | + var lat = 51; |
| 41 | + var long = 7; |
| 42 | + for (var i = 0; i < 50; i++) { |
| 43 | + |
| 44 | + var myCircle = new L.Circle(new L.LatLng(lat, long),3); |
| 45 | + myCircle.on('click', |
| 46 | + function (e) { |
| 47 | + popup = new L.Popup(); |
| 48 | + popup.setLatLng(this.getLatLng()); |
| 49 | + |
| 50 | + var popuptxt = "Hello!"; |
| 51 | + alert("I am the click function"); |
| 52 | + popup.setContent(popuptxt); |
| 53 | + |
| 54 | + map.openPopup(popup); |
| 55 | + |
| 56 | + |
| 57 | + }); |
| 58 | + myLayerGroup.addLayer(myCircle); |
| 59 | + lat = lat + 0.0001; |
| 60 | + long = long + 0.0001; |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + map.addLayer(myLayerGroup); |
| 65 | + |
| 66 | + }; |
| 67 | + |
| 68 | + $("#b1").click(function() { |
| 69 | + map.addLayer(myLayerGroup); |
| 70 | + }); |
| 71 | + |
| 72 | + $("#b2").click(function() { |
| 73 | + map.removeLayer(myLayerGroup); |
| 74 | + }); |
| 75 | + |
| 76 | + }); |
| 77 | + </script> |
| 78 | + |
| 79 | + <script src="../leaflet-include.js"></script> |
| 80 | +</head> |
| 81 | +<body> |
| 82 | + <div id="map"></div> |
| 83 | + <div id="buttons"> |
| 84 | + <button type="button" id="b1"> Add Layer</button> |
| 85 | + <button type="button" id="b2"> Remove Layer</button> |
| 86 | + </div> |
| 87 | +</body> |
| 88 | +</html> |
0 commit comments