68 lines
1.6 KiB
JavaScript
Raw Normal View History

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
var userPositionIsReal = false;
var userposition = {
coords: {
latitude: 46.595,
longitude: -112.019,
accuracy: 10000
}
};
var leafletmap = L.map('map', {
2019-03-29 14:37:06 -06:00
minZoom: 12,
maxZoom: 20
});
2019-03-29 14:37:06 -06:00
leafletmap.attributionControl.setPrefix("");
2019-03-28 18:03:26 -06:00
var leafletgllayer = L.mapboxGL({
2019-03-29 14:37:06 -06:00
attribution: "© OpenMapTiles © OpenStreetMap contributors",
accessToken: 'none',
style: SETTINGS["map_style_json"],
2019-03-28 18:03:26 -06:00
pitch: 0
});
leafletgllayer.addTo(leafletmap);
function recenterMapPosition() {
var zoom = 13;
2019-03-31 14:48:57 -06:00
if (userposition.coords.accuracy < 1000) {
zoom = 15;
}
leafletmap.setView([userposition.coords.latitude, userposition.coords.longitude], zoom);
}
function recenterMapToUserPosition() {
if (userPositionIsReal == false) {
getLocation(function (position) {
userposition = position;
userPositionIsReal = true;
recenterMapPosition();
});
} else {
recenterMapPosition();
}
}
// Attempt to get user location
watchLocation(function (position) {
userposition = position;
if (userPositionIsReal == false) {
recenterMapPosition();
userPositionIsReal = true;
}
});
// Set map to default position
recenterMapPosition();
// Load nearby
updateMap();
// Watch for map moving
leafletmap.on("moveend", function () {
updateMap();
});