Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Displaying Pokestops + LuredPokestops #362

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion static/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function pad(num, size) {
document.getElementById('pokemon-checkbox').checked = getFromStorage("displayPokemons", "true");
document.getElementById('gyms-checkbox').checked = getFromStorage("displayGyms", "true");
document.getElementById('coverage-checkbox').checked = getFromStorage("displayCoverage", "true");
document.getElementById('pokestops-checkbox').checked = getFromStorage("displayPokestops", false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is still incorrect, shouldn't it be the "false" string instead of a boolean? Just basing off from the code above.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, line 45 looks fine to me Line 42, 43 and 44 should be true instead of "true".



$.getJSON("locale").done(function(data) {
Expand Down Expand Up @@ -275,10 +276,21 @@ function gymLabel(team_name, team_id, gym_points) {
return str;
}

function pokestopLabel(pokestop_id, lure_expiration, last_modified) {
var label = "Pokestop"

label += "<br>" + pokestop_id;
if (lure_expiration != null) {
var lure_ends = new Date(last_modified + 30 * 60 * 1000);
label += "<br>Lure module ends at " + pad(lure_ends.getHours()) + ":" + pad(lure_ends.getMinutes()) + ":" + pad(lure_ends.getSeconds());
}
return label;
}

var map_pokemons = {}; // dict containing all pokemons on the map.
var map_gyms = {};
var gym_types = [ "Uncontested", "Mystic", "Valor", "Instinct" ];
var map_pokestops = {};

function setupPokemonMarker(item) {
var myIcon = new google.maps.MarkerImage('static/icons/'+item.pokemon_id+'.png', null, null, null, new google.maps.Size(30,30));
Expand Down Expand Up @@ -317,6 +329,33 @@ function setupGymMarker(item) {
return marker;
}

function setupPokestopMarker(item) {
var marker = null;
var label = null;
var pic = null;
if (!item.isLured) {
label = pokestopLabel(item.pokestop_id, null, null);
pic = 'static/forts/Pstop.png';
} else {
label = pokestopLabel(item.pokestop_id, item.lure_expiration, item.last_modified);
pic = 'static/forts/PstopLured.png';
}

marker = new google.maps.Marker({
position: {lat: item.latitude, lng: item.longitude},
map: map,
icon: pic
});

marker.infoWindow = new google.maps.InfoWindow({
content: label,
disableAutoPan: true
});

addListeners(marker);
return marker;
}

function addListeners(marker){
marker.addListener('click', function() {
marker.infoWindow.open(map, marker);
Expand Down Expand Up @@ -463,7 +502,8 @@ function updateMap() {
url: "map-data",
type: 'GET',
data: {'pokemon': localStorage.displayPokemons,
'gyms': localStorage.displayGyms},
'gyms': localStorage.displayGyms,
'pokestops': localStorage.displayPokestops},
dataType: "json"
}).done(function(result) {
statusLabels(result["server_status"]);
Expand Down Expand Up @@ -515,6 +555,33 @@ function updateMap() {
}
});

$.each(result.pokestops, function(i, item) {
if (!document.getElementById('pokestops-checkbox').checked) {
return false; // in case the checkbox was unchecked in the meantime.
}

var lured = false;
if (item.lure_expiration != null) {
lured = item.last_modified + 30 * 60 * 1000 > new Date().getTime();
}

if (!(item.pokestop_id in map_pokestops)) {
item.isLured = lured;
item.marker = setupPokestopMarker(item);
map_pokestops[item.pokestop_id] = item;
} else {
if (item.pokestop_id in map_pokestops && map_pokestops[item.pokestop_id].isLured != lured) {
console.log("[" + item.pokestop_id + "] Lure changed to: " + lured);
map_pokestops[item.pokestop_id].marker.setMap(null);
delete map_pokestops[item.pokestop_id];

item.isLured = lured;
item.marker = setupPokestopMarker(item);
map_pokestops[item.pokestop_id] = item;
}
}
});

clearStaleMarkers();
}).fail(function() {
$lastRequestLabel.removeClass('label-success label-warning');
Expand Down Expand Up @@ -560,6 +627,18 @@ $('#coverage-checkbox').change(function() {
}, this);
});

$('#pokestops-checkbox').change(function() {
localStorage.displayPokestops = this.checked;
if (this.checked) {
updateMap();
} else {
$.each(map_pokestops, function(key, value) {
map_pokestops[key].marker.setMap(null);
});
map_pokestops = {}
}
});


// function displayCoverage() {
// // if (currentLocationMarker) currentLocationMarker.setMap(null);
Expand Down
11 changes: 5 additions & 6 deletions templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ <h1>Settings</h1>
<label for="pokemon-checkbox">Display Pokemon</label>
<br>
</div>
<!--
<div class="chckbox">
<input type="checkbox" id="pokestops-checkbox">
<label for="pokestops-checkbox">Display all Pokestops</label><br>
</div>

<div class="chckbox">
<input type="checkbox" id="pokestops-checkbox">
<label for="pokestops-checkbox">Display all Pokestops</label><br>
</div>
<!--
<div class="chckbox">
<input type="checkbox" id="pokestops-lured-checkbox">
<label for="pokestops-lured-checkbox">Display lured Pokestops</label><br>
Expand Down