Skip to content

Instantly share code, notes, and snippets.

@AbdulKabia
Created March 28, 2018 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbdulKabia/20d33e0459c751f4a74ac2fcc7c210c1 to your computer and use it in GitHub Desktop.
Save AbdulKabia/20d33e0459c751f4a74ac2fcc7c210c1 to your computer and use it in GitHub Desktop.
init(lat, lng) {
let mapEl = document.createElement('div');
mapEl.id = 'map';
document.body.appendChild(mapEl);
// http://leafletjs.com/reference-1.3.0.html#map
let map = (this.map = leaflet.map(mapEl, this.options));
leaflet.tileLayer(tileUrl, { attribution }).addTo(map);
map.setView([lat, lng], defaultZoomLevel);
// http://leafletjs.com/reference-1.3.0.html#map-event
let onMapChange = () => this.emit('update', map.getBounds());
map.on('viewreset', onMapChange);
map.on('moveend', onMapChange);
// Show a marker at our current location
this.currentLocationMarker = leaflet
.marker([lat, lng], {
title: 'Current Location',
icon: svgMarker.location
})
.addTo(map);
log.info(`Map initialized with centre lat=${lat}, lng=${lng}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment