add geolocation

This commit is contained in:
David 2017-03-26 22:57:03 -04:00
parent bdda5c11a7
commit 71d93f7e3d

View File

@ -137,6 +137,8 @@
} }
function loadMap(data) { function loadMap(data) {
var geolocate = new mapboxgl.GeolocateControl();
var points = []; var points = [];
$.each(data, function(key, value) { $.each(data, function(key, value) {
points.push({ points.push({
@ -167,6 +169,7 @@
} }
}) })
map.addControl(new mapboxgl.NavigationControl(), 'top-left'); map.addControl(new mapboxgl.NavigationControl(), 'top-left');
map.addControl(geolocate, 'top-right');
}); });
map.on('click', function (e) { map.on('click', function (e) {
@ -190,6 +193,13 @@
map.getCanvas().style.cursor = features.length ? 'pointer' : ''; map.getCanvas().style.cursor = features.length ? 'pointer' : '';
}); });
geolocate.on('geolocate', function (e) {
map.setZoom(14);
popup.setLngLat([e.coords.longitude, e.coords.latitude])
.setHTML('Current Location')
.addTo(map);
})
var template = $('#Table').html(); var template = $('#Table').html();
var rendered = Mustache.render(template, {rows: data}); var rendered = Mustache.render(template, {rows: data});
$('#Stores').html(rendered); $('#Stores').html(rendered);