Browse Source

Reduce frequency of map place updates

master
Skylar Ittner 2 years ago
parent
commit
739c277f67
  1. 23
      www/js/map.js

23
www/js/map.js

@ -6,6 +6,7 @@
var gotfirstfix = false;
var lastMapUpdateTimestamp = 0;
var playerPosition = {
coords: {
@ -29,15 +30,31 @@ if (gamemaptype == "leaflet") {
var map = mapboxMap();
}
// Make sure map places are refreshed even when location isn't
var mapRefreshInterval = setInterval(function () {
if (gotfirstfix) {
var currentTimestamp = Math.floor(Date.now() / 1000);
if (lastMapUpdateTimestamp < (currentTimestamp - 10)) {
updatePlaceLayer(playerPosition.coords.latitude, playerPosition.coords.longitude);
lastMapUpdateTimestamp = currentTimestamp;
}
}
}, 30 * 1000);
watchLocation(function (position) {
playerPosition = position;
if (gotfirstfix) {
setMapLocation(position.coords.latitude, position.coords.longitude);
updatePlaceLayer(position.coords.latitude, position.coords.longitude);
// Don't refresh map at an interval less than ten seconds
var currentTimestamp = Math.floor(Date.now() / 1000);
if (lastMapUpdateTimestamp < (currentTimestamp - 10)) {
updatePlaceLayer(position.coords.latitude, position.coords.longitude);
lastMapUpdateTimestamp = currentTimestamp;
}
} else {
animateMapIn(position.coords.latitude, position.coords.longitude, 16, position.coords.heading);
gotfirstfix = true;
}
playerPosition = position;
}, function (error) {
geoerrorcount++;
console.log("Geolocation error #" + geoerrorcount + ": ", error);
@ -65,7 +82,7 @@ function updatePlaceLayer(latitude, longitude) {
callAPI("nearbyplaces", {
latitude: latitude,
longitude: longitude,
radius: 1
radius: 2
}, function (data) {
map.updatePlaceLayer(data);
});

Loading…
Cancel
Save