Guest User

Untitled

a guest
Oct 31st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const myModule = {
  2.     async init() {
  3.         let coords = await this.getCoords();
  4.         console.log(coords);
  5.  
  6.         this.mymap = L.map('mapid').setView([coords.lat, coords.lng], 15);
  7.  
  8.         L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  9.             maxZoom: 18,
  10.             attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
  11.                 '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
  12.                 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  13.             id: 'mapbox.streets'
  14.         }).addTo(this.mymap);
  15.     },
  16.  
  17.     getCoords: function() {
  18.         return new Promise(resolve => {
  19.             navigator.geolocation.getCurrentPosition(function(position) {
  20.                 const lat = position.coords.latitude;
  21.                 const lng = position.coords.longitude;
  22.                 resolve({ lat, lng })
  23.             });
  24.         });
  25.     },
  26.  
  27.     async addMarker () {
  28.  
  29.         let coords = await this.getCoords();
  30.         const marker = L.marker([coords.lat, coords.lng]).addTo(this.mymap);
  31.         this.mymap.removeLayer(marker);
  32.         console.log('test');
  33.     }
  34.  
  35.  
  36. };
  37.  
  38. window.onload = myModule.init();
  39. let timerId = setInterval(async () => {await myModule.addMarker()}, 1000);
Advertisement
Add Comment
Please, Sign In to add comment