Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const myModule = {
- async init() {
- let coords = await this.getCoords();
- console.log(coords);
- this.mymap = L.map('mapid').setView([coords.lat, coords.lng], 15);
- L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
- maxZoom: 18,
- attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
- '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
- 'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
- id: 'mapbox.streets'
- }).addTo(this.mymap);
- },
- getCoords: function() {
- return new Promise(resolve => {
- navigator.geolocation.getCurrentPosition(function(position) {
- const lat = position.coords.latitude;
- const lng = position.coords.longitude;
- resolve({ lat, lng })
- });
- });
- },
- async addMarker () {
- let coords = await this.getCoords();
- const marker = L.marker([coords.lat, coords.lng]).addTo(this.mymap);
- this.mymap.removeLayer(marker);
- console.log('test');
- }
- };
- window.onload = myModule.init();
- let timerId = setInterval(async () => {await myModule.addMarker()}, 1000);
Advertisement
Add Comment
Please, Sign In to add comment