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.     init: function() {
  3.             const self = this;
  4.             var coords = this.getCoords();
  5.            
  6.      
  7.             self.mymap = L.map('mapid').setView([lat, lng], 15);
  8.            
  9.             L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
  10.                 maxZoom: 18,
  11.                 attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
  12.                     '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
  13.                     'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
  14.                 id: 'mapbox.streets'
  15.             }).addTo(self.mymap);
  16.     },
  17.  
  18.     getCoords: function(){
  19.             let lat; let lng;
  20.             navigator.geolocation.getCurrentPosition(function(position) {
  21.             lat = position.coords.latitude;
  22.             lng = position.coords.longitude;
  23.            
  24.  
  25.         });
  26.         console.log(lat);
  27.     },
  28.  
  29.     addMarker: function(){
  30.        
  31.         const marker = L.marker([lat, lng]).addTo(self.mymap);
  32.         mymap.removeLayer(marker)
  33.         console.log('test');
  34.     }
  35.  
  36.  
  37. };
  38.  
  39. window.onload = myModule.init();
  40.  
  41. //let timerId = setInterval(myModule.addMarker, 1000);
Advertisement
Add Comment
Please, Sign In to add comment