Advertisement
MarkUa

Untitled

Apr 10th, 2020
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.13 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.  
  7.     <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.0/dist/leaflet.css" />
  8.     <script src = "https://unpkg.com/leaflet@1.3.0/dist/leaflet.js"> </script>
  9.     <link rel="stylesheet" href="../src/leaflet-search.css" />
  10.     <script src = "leaflet-search.js"></script>
  11.      <link rel="stylesheet" href="leaflet-search.css" />
  12.     <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
  13. <script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.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. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  18. </head>
  19.  
  20. <style>
  21.     body,
  22. html {
  23.   height: 100%;
  24.   font-family:Arial;
  25. }
  26.  
  27. #map {
  28.   width: 100%;
  29.   height: 100%;
  30.   z-index:100;
  31. }
  32. #mapSearchContainer{
  33.   position:fixed;
  34.   top:20px;
  35.   right: 40px;
  36.   height:30px;
  37.   width:180px;
  38.   z-index:110;
  39.   font-size:10pt;
  40.   color:#5d5d5d;
  41.   border:solid 1px #bbb;
  42.   background-color:#f8f8f8;
  43. }
  44. .pointer{
  45.   position:absolute;
  46.   top:86px;
  47.   left:60px;
  48.   z-index:99999;
  49. }
  50.     </style>
  51. <body>
  52.     <div id="map"></div>
  53. <div class='pointer'></div>
  54.  
  55. <script>
  56. // Initialize the map and assign it to a variable for later use
  57. var marker;
  58. var start;
  59. var map = L.map('map', {
  60.     // Set latitude and longitude of the map center (required)
  61.     center: [50.7833, 30.4167],
  62.     // Set the initial zoom level, values 0-18, where 0 is most zoomed-out (required)
  63.     zoom: 12,
  64.     minZoom: 3,
  65. }).on('click', function(e) {
  66.     if (marker)
  67.             map.removeLayer(marker);
  68.     marker = L.marker([e.latlng.lat, e.latlng.lng]).addTo(map);
  69.     map.panTo(e.latlng);
  70. });
  71.  
  72. function u(){
  73.     if (navigator.geolocation) {
  74.             navigator.geolocation.getCurrentPosition(displayLocationInfo);
  75.         }
  76.     return [50.7833, 30.4167];
  77. }
  78. L.control.scale().addTo(map);
  79.  
  80. // Create a Tile Layer and add it to the map
  81. //var tiles = new L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.png').addTo(map);
  82.  //L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  83.    //  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  84.  //}).addTo(map);
  85.  
  86.  L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
  87.   attribution: 'Tiles &copy; Esri &mdash; Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012'
  88. }).addTo(map);
  89.   var searchControl = new L.esri.Controls.Geosearch().addTo(map);
  90.  
  91.   var results = new L.LayerGroup().addTo(map);
  92.  
  93.     async function getLocation() {
  94.       if (navigator.geolocation) {
  95.          await navigator.geolocation.getCurrentPosition(await function (data) {
  96.              //alert("fwe")
  97.              start = [data.coords.latitude ,data.coords.longitude]});
  98.                // alert(start)
  99.       } else {
  100.           start = [41.575730,13.002411]
  101.       }
  102.     }
  103.  
  104.     function showPosition(position) {
  105.       start = [position.coords.latitude ,position.coords.longitude];
  106.     }
  107.  
  108.  
  109.   searchControl.on('results', function(data){
  110.     if(marker) {
  111.         map.removeLayer(marker);
  112.     }
  113.     results.clearLayers();
  114.     for (var i = data.results.length - 1; i >= 0; i--) {
  115.         marker = L.marker([data.results[i].latlng.lat, data.results[i].latlng.lng]).addTo(map);
  116.        map.panTo(data.results[i].latlng);
  117.         //  map.flyTo([data.results[i].latlng.lat, data.results[i].latlng.lng],100);
  118.         break;
  119.     }
  120.  
  121.      //alert(start)
  122.        // getLocation();
  123.       //  alert(start)
  124.    /* results.clearLayers();
  125.     for (var i = data.results.length - 1; i >= 0; i--) {
  126.       results.addLayer(L.marker(data.results[i].latlng));
  127.     }
  128.     alert(results.length)*/
  129.   });
  130.  
  131. function getPosition() {
  132.     return new Promise((res, rej) => {
  133.         navigator.geolocation.getCurrentPosition(res, rej)
  134.     });
  135. }
  136.  
  137.  
  138. function plotCurrentLocation(map) {
  139.    if (navigator.geolocation) {
  140.       navigator.geolocation.getCurrentPosition(function(position) {
  141.          var currLocation = new L.latLng(position.coords.latitude,position.coords.longitude);
  142.  
  143.          // plot the currLocation on Google Maps, or handle accordingly:
  144.  
  145.          //new google.maps.Marker({ title: 'Current Location',
  146.            //                       map: map,
  147.              //                     position: currLocation });
  148.         if (marker)
  149.             map.removeLayer(marker);
  150.         marker = L.marker([position.coords.latitude,position.coords.longitude],{}).addTo(map);
  151.          map.panTo(currLocation);
  152.       });
  153.    }
  154. }
  155.  
  156.    $(document).ready(function() {
  157.          plotCurrentLocation(map);
  158.    })
  159.  
  160. setTimeout(function(){$('.pointer').fadeOut('slow');},3400);
  161.  
  162.  
  163.  
  164.  
  165.     </script>
  166. </body>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement