Guest User

Untitled

a guest
Sep 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title> Test Map</title>
  5.  
  6. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
  7. integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
  8. crossorigin=""/>
  9. <script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"
  10. integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA=="
  11. crossorigin=""></script>
  12. <script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
  13. <style>
  14. #map {
  15. height:800px;
  16. }
  17. </style>
  18.  
  19.  
  20. <script type = "text/javascript">
  21. function init(){
  22. var osmLink = "<a href='http://www.openstreetmap.org'>Open StreetMap</a>"
  23. var map = new L.map('map').setView([ -20.91, 142.70], 5);
  24. osmMap = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data &copy; ' + osmLink, maxZoom: 18,}).addTo(map);
  25. attrLink = 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'
  26. attrLinkToner = 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.';
  27. var terrainMap = L.tileLayer( 'http://{s}.tile.stamen.com/terrain/{z}/{x}/{y}.jpg',{
  28. attribution: attrLink,
  29. maxZoom: 18,
  30. }).addTo(map);
  31. var baseLayers = {
  32. "Open Street Map":osmMap, "Stamen Terrain": terrainMap
  33. };
  34.  
  35. L.control.layers(baseLayers).addTo(map);
  36.  
  37. showLayers(map);
  38.  
  39. function showLayers(map) {
  40.  
  41. var myIcon = L.icon({
  42. iconUrl: "./images/frog.png",
  43. iconSize: [24,24],
  44. iconAnchor: [12,24]
  45. });
  46.  
  47.  
  48. var controlLayers = L.control.layers().addTo(map);
  49.  
  50. $.getJSON("getData.php", function(data) {
  51. var geojsonLayer = L.geoJson(data, {
  52. style: function(feature) {
  53. return {
  54. 'weight': 0,
  55. 'fillColor': 'brown',
  56. 'fillOpacity': 1
  57. }
  58. },
  59. onEachFeature: function(feature, layer) {
  60. var popupText = "Popup Text";
  61. layer.bindPopup(popupText);
  62. }
  63. }).addTo(map);
  64. controlLayers.addOverlay(geojsonLayer, 'ExampleLayer');
  65. });
  66.  
  67.  
  68. } // end of function showLayers
  69.  
  70.  
  71. }// end of function init
  72. </script>
  73. </head>
  74. <h1>Page heading</h1>
  75. <body onload=init()>
  76. <div id = "map"> </div>
  77. </body>
  78. </html>
  79.  
  80. $.getJSON("getData.php",function(data){
  81. for (let i = 0; i< data.length; i++) {
  82. let location = new L.LatLng(data[i].siteLatitude, data[i].siteLongitude);
  83. let marker = new L.Marker(location, {
  84. icon: modelIcon,
  85. title: 'thetitle' });
  86.  
  87. let studyTitle = data[i].studyTitle
  88. let siteID = data[i].siteID;
  89.  
  90. let content = "<h2>" + studyTitle + "</h2>" + "<p>" + siteID + "</p>" + "<p> <b>" + "</b></p>";
  91. marker.bindPopup(content, {
  92. maxWidth: '400'
  93. });
  94. marker.addTo(map);
  95. }
  96. }
  97. )
Add Comment
Please, Sign In to add comment