Advertisement
MarkUa

Untitled

Apr 10th, 2020
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.02 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.  
  7. </head>
  8. <body>
  9. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  10. <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" >
  11. <script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
  12.  
  13. <script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-modal.js"></script>
  14. <script src="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet/0.0.1-beta.5/esri-leaflet.js"></script>
  15. <script src="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet-geocoder/0.0.1-beta.5/esri-leaflet-geocoder.js"></script>
  16. <link rel="stylesheet" type="text/css" href="https://cdn-geoweb.s3.amazonaws.com/esri-leaflet-geocoder/0.0.1-beta.5/esri-leaflet-geocoder.css">
  17. <link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" >
  18. <link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" >
  19.    <script src = "leaflet-search.js"></script>
  20.      <link rel="stylesheet" href="leaflet-search.css" />
  21.  
  22. <a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal
  23. </a>
  24.  
  25. <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  26.     <div class="modal-header">
  27.     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  28.     <h3 id="myModalLabel">Modal header</h3>
  29.     </div>
  30.     <div class="modal-body">
  31.     <p><div id="map" style="height:380px"></div></p>
  32.     </div>
  33.     <div class="modal-footer">
  34.     <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  35.     <button class="btn btn-primary" onclick="saveLocation()">Save changes</button>
  36.     </div>
  37.     </div>
  38.  
  39.  
  40. <script>
  41.  
  42.   var map = L.map('map', {
  43.     // Set latitude and longitude of the map center (required)
  44.     center: [50.7833, 30.4167],
  45.     // Set the initial zoom level, values 0-18, where 0 is most zoomed-out (required)
  46.     zoom: 12,
  47.     minZoom: 3,
  48. }).on('click', function(e) {
  49.     if (marker)
  50.             map.removeLayer(marker);
  51.     marker = L.marker([e.latlng.lat, e.latlng.lng]).addTo(map);
  52.     map.panTo(e.latlng);
  53. });
  54.  
  55. L.control.scale().addTo(map);
  56.  
  57.  L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
  58.   attribution: ''
  59. }).addTo(map);
  60.  
  61. var marker;
  62.  
  63. map.on('click', function(e) {
  64.     if( !marker ) {
  65.  
  66.         marker = L.marker(e.latlng).addTo(map);
  67.  
  68.     }
  69. });
  70.  
  71.  
  72.  
  73.   var searchControl = new L.esri.Controls.Geosearch().addTo(map);
  74.  
  75.   var results = new L.LayerGroup().addTo(map);
  76.  
  77.  
  78.  
  79.  
  80.   searchControl.on('results', function(data){
  81.     if(marker) {
  82.         map.removeLayer(marker);
  83.     }
  84.     results.clearLayers();
  85.     for (var i = data.results.length - 1; i >= 0; i--) {
  86.         marker = L.marker([data.results[i].latlng.lat, data.results[i].latlng.lng]).addTo(map);
  87.        map.panTo(data.results[i].latlng);
  88.         //  map.flyTo([data.results[i].latlng.lat, data.results[i].latlng.lng],100);
  89.         break;
  90.     }
  91.  
  92.   });
  93.  
  94. $('#myModal').on('shown',function(){
  95.     L.Util.requestAnimFrame(map.invalidateSize,map,!1,map._container);
  96.       plotCurrentLocation(map);
  97. });
  98.  
  99. $('#myModal').on('hidden',function(){
  100.     if( marker ) {
  101.         map.removeLayer(marker);
  102.         marker = null;
  103.     }
  104. });
  105.  
  106.  
  107.  
  108. function plotCurrentLocation(map) {
  109.    if (navigator.geolocation) {
  110.       navigator.geolocation.getCurrentPosition(function(position) {
  111.          var currLocation = new L.latLng(position.coords.latitude,position.coords.longitude);
  112.  
  113.         if (marker)
  114.             map.removeLayer(marker);
  115.         marker = L.marker([position.coords.latitude,position.coords.longitude],{}).addTo(map);
  116.          map.panTo(currLocation);
  117.       });
  118.    }
  119. }
  120.  
  121. function saveLocation(){
  122.     //alert(marker.getLatLng().lat);
  123.     $('#myModal').modal('hide');
  124. }
  125.  
  126.    $(document).ready(function() {
  127.          plotCurrentLocation(map);
  128.    })
  129.  
  130.  
  131. </script>
  132.  
  133.  
  134. </body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement