Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <title>Mobile - Leaflet</title>
  6.  
  7. <meta charset="utf-8" />
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9.  
  10. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
  11. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css" />
  12.  
  13. <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
  14. <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.2/dist/leaflet.css" />
  15. <link rel="stylesheet" href="css/leaflet.extra-markers.min.css">
  16. <link rel="stylesheet" href="css/MarkerCluster.css">
  17. <link rel="stylesheet" href="css/MarkerCluster.Default.css">
  18.  
  19. <script src="https://unpkg.com/leaflet@1.0.2/dist/leaflet.js"></script>
  20. <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  21. <script src="js/leaflet.extra-markers.min.js"></script>
  22. <script src="js/leaflet.markercluster-src.js"></script>
  23.  
  24. <script type="text/javascript">
  25. function log(str)
  26. {
  27. $('#result').text($('#result').text() + "-" + str);
  28. }
  29.  
  30. function Invoke(data) {
  31. try {
  32. log("Sending Data:" + data);
  33. //invokeCSharpAction(data);
  34. Native("dataCallback", data);
  35. }
  36. catch (err){
  37. log(err);
  38. }
  39. }
  40.  
  41. function click(item) {
  42. console.log(item, $(item));
  43.  
  44. groupClick($(item).attr("data-id"));
  45. }
  46. // The method which is called in the FAtaskpage.xaml.cs file to inject the markers in this this HTML javascript file
  47. function AddClusterGroup(data)
  48. {
  49. //Creates a list which will be filled with markers
  50. var markers = L.markerClusterGroup();
  51.  
  52. // Loopt through the JSon like list to retrieve the data from each object in the list.
  53. for (var i in data) {
  54. var item = data[i];
  55. var title = item[2];
  56. var description = item[4];
  57. // Creates a marker for every object with the retrieved long and lat coords
  58. var marker = L.marker(new L.LatLng(item[0], item[1]), { title: title });
  59. // Sets the popup content variable
  60. var popupcontent = '<p><b>' + item[2] + '</b> <br />' + item[4] + '</p>';
  61. // Sets the variable inside the popup which will be displayed when a marker is clicked. Inside the popup is the title and a description. With an onclick event
  62. marker.bindPopup($(popupcontent).click(function (item) {
  63. // Creates a list and adds the clicked task ID to the list
  64. var ids = [];
  65. ids.push(item[3]);
  66. //Creates a callback to the fataskpage.xaml.cs called "navigate" with the ID's list with the clicked ID in it.
  67. Native("navigate", ids);
  68.  
  69. }.bind(null, item))[0]);
  70. // Adds the marker to the markers list
  71. markers.addLayer(marker);
  72.  
  73. }
  74. /*
  75. for (var i = 0; i < data.length; i++)
  76. {
  77. var a = data[i];
  78. var title = a[2];
  79. var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title }).addEventListener("click", function(a) {
  80. groupClick(a[3]);
  81. }.bind(null, a), false);
  82. marker.bindPopup(title);
  83. markers.addLayer(marker);
  84.  
  85. }*/
  86. // Adds the markers list to the map
  87. map.addLayer(markers);
  88.  
  89. }
  90. function groupClick(id) {
  91.  
  92. var ids = [];
  93. ids.push(id);
  94. native("navigate", ids);
  95. }
  96. </script>
  97.  
  98.  
  99.  
  100. <style>
  101. #map {
  102. width: 600px;
  103. height: 400px;
  104. }
  105. </style>
  106.  
  107. <style>
  108. body {
  109. padding: 0;
  110. margin: 0;
  111. }
  112.  
  113. html, body, #map {
  114. height: 100vh;
  115. width: 100vw;
  116. }
  117. </style>
  118. </head>
  119. <body>
  120. <div id='result'></div>
  121. <div class="custom-popup" id='map' style="width:100%;height:100%;"></div>
  122. <button onclick="Invoke('Javascript')" title="click"></button>
  123. <script>
  124. var map = L.map('map' , { preferCanvas: true }).fitWorld();
  125. /*
  126. L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
  127. maxZoom: 18,
  128. attribution: '',
  129. id: 'mapbox.streets'
  130. }).addTo(map);
  131. */
  132. L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
  133. attribution: '',
  134. maxZoom: 20
  135. }).addTo(map);
  136.  
  137. function onLocationFound(e)
  138. {
  139. var radius = e.accuracy / 2;
  140.  
  141. L.marker(e.latlng).addTo(map)
  142. .bindPopup("You are within " + radius + " meters from this point").openPopup();
  143.  
  144. L.circle(e.latlng, radius).addTo(map);
  145. //invokeCSCode('JOHAN C#');
  146. }
  147.  
  148. function onLocationError(e)
  149. {
  150. alert(e.message);
  151. }
  152.  
  153. //map.on('locationfound', onLocationFound);
  154. //map.on('locationerror', onLocationError);
  155.  
  156. // map.locate({setView: true, maxZoom: 16});
  157. map.setView([52.528253, 4.839478], 4);
  158. </script>
  159.  
  160.  
  161.  
  162. </body>
  163. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement