Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps #9

Open
wants to merge 44 commits into
base: maps
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
03fc27b
Use small icons and original Pokemon names
luke-jr Jul 17, 2016
cbe6046
gitignore stuff
luke-jr Jul 17, 2016
bdaed61
Show player on map
luke-jr Jul 17, 2016
5bde09d
Rename config.json to config.json.example
luke-jr Jul 17, 2016
b85ab8d
Make times reasonably accurate
luke-jr Jul 17, 2016
b182bc4
No need to clear data from previous session until we have done at lea…
luke-jr Jul 17, 2016
6c0f05f
Be more resilient to failures
luke-jr Jul 17, 2016
a6c99e4
Store expiry time rather than time left in data
luke-jr Jul 17, 2016
d4bdfa1
Use a hash to avoid duplicates of the same pokemon
luke-jr Jul 17, 2016
278cf7f
Load existing data at startup
luke-jr Jul 17, 2016
85d3bc6
Merge branch 'maps' of https://github.com/memelyfe/pokemongo-api-demo…
luke-jr Jul 17, 2016
eee29e3
Sort "Hide Pokemon" list
luke-jr Jul 17, 2016
594bce2
Break down days, hours, and minutes
luke-jr Jul 17, 2016
fd25da5
Don't delete and recreate markers for every refresh
luke-jr Jul 17, 2016
a44106e
Count number of pokemon seen on the map
luke-jr Jul 17, 2016
201f4fb
Show pokemon counts
luke-jr Jul 18, 2016
bc031b6
Retry heartbeat if it fails
luke-jr Jul 18, 2016
25fd49d
Atomically update data file
luke-jr Jul 18, 2016
32fa478
Avoid using title for HTML content
luke-jr Jul 18, 2016
f4b148f
Update details for existing markers so the timeleft counts down
luke-jr Jul 18, 2016
7b5ea8f
Change HTML page title
lalten Jul 18, 2016
342a1ac
Add app icon as favicon
lalten Jul 18, 2016
937fafb
Use Object for hidden_layers
luke-jr Jul 18, 2016
dc9ae40
Use pokemon id number for hidden_layers key
luke-jr Jul 18, 2016
2663290
Allow specifying default hidden_layers in config file
luke-jr Jul 18, 2016
d53ca57
Sort by and display pokedex number, and allow specifying ignored poke…
luke-jr Jul 18, 2016
ec267ba
Ensure pokemon icons are 25px and anchor in the middle-bottom
luke-jr Jul 18, 2016
c04681a
Prevent caching data
luke-jr Jul 18, 2016
23a665c
Make JS console logging more useful
luke-jr Jul 18, 2016
960fbd0
Resize legend
luke-jr Jul 18, 2016
ded73e4
Merge branch 'laltenpregoogle' into merging
Zeromark30 Jul 19, 2016
a6ff56f
Merge successful
Zeromark30 Jul 19, 2016
ab53878
tidy up for pull to memelyfe
Zeromark30 Jul 19, 2016
b426927
data.json
Zeromark30 Jul 19, 2016
5e0f56a
ignore data.json
Zeromark30 Jul 19, 2016
b25bf5f
Rename config.json.example to config.json
Zeromark30 Jul 19, 2016
a6dbc64
Merge remote-tracking branch 'freenode/maps' into merging
Zeromark30 Jul 19, 2016
a62c59b
further merging
Zeromark30 Jul 19, 2016
10ee267
merging
Zeromark30 Jul 19, 2016
519a3b3
Create data.json
Zeromark30 Jul 19, 2016
c6c2823
Create config.json
Zeromark30 Jul 19, 2016
42efa28
Merge branch 'maps' into merging
Zeromark30 Jul 19, 2016
2be3cd1
Merge pull request #1 from Zeromark30/merging
Zeromark30 Jul 19, 2016
1ca7700
remove minifiy
Zeromark30 Jul 19, 2016
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
data.json
config.json

data.json

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -91,3 +90,4 @@ ENV/

# Rope project settings
.ropeproject
run_private.bat
4 changes: 2 additions & 2 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[
{

]
}
Binary file added favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 119 additions & 56 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>PokeScanner</title>
<title>PokéScanner</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="icon" type="image/png" href="favicon.png" sizes="192x192">
<style>
html, body {
height: 100%;
Expand All @@ -19,11 +20,11 @@
margin: 5px;
font-size: 12px;
font-family: Arial, sans-serif;
height: 255px;
width: 150px;
height: 28em;
width: 28ex;
}
#legend div {
height: 210px;
height: 24em;
overflow: auto;
}
#legend li {
Expand Down Expand Up @@ -72,100 +73,160 @@
return (date.getUTCMinutes() > 0 ? date.getUTCMinutes() + "m " : "") + date.getUTCSeconds() + "s";
}

function getImage(p) {
var name = p.name;
if (p.name == "Nidoran F") {
name = "Nidoran";
}
else if (name == "Nidoran M") {
name = "Nidorano";
}
return "http://icons.iconarchive.com/icons/hektakun/pokemon/72/" + pad(p.id, 3) + "-" + cap(name) + "-icon.png";
}

function toggleLayer(checked, pkmn) {
if (checked) {
hidden_layers.push(pkmn);
hidden_layers[pkmn] = 1;
} else {
var index = hidden_layers.indexOf(pkmn);
if(index > -1){
hidden_layers.splice(index,1);
}
delete hidden_layers[pkmn];
Copy link

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Didn't realize that was a thing. I'll revert that.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

My fault. I did not see that you've changed hidden_layer from array to object.
delete is fine then.

}
refreshData();
};

function pkmn_label(pkmn) {
var elemname = "#" + pkmn.id + ". " + pkmn.name;
if (pkmn.id == -1) {
elemname = "(player)";
}
return elemname;
}


var preLength = -1;
var pkmn_size, pkmn_anchor;
function refreshData() {
getFile("data.json", true, function(response) {
getFile("data.json?t=" + (new Date()).getTime(), true, function(response) {
if ('undefined' == typeof pkmn_size) {
// Maps API might not be loaded before the first refresh
pkmn_size = new google.maps.Size(30, 30);
pkmn_anchor = new google.maps.Point(15, 15);
}

console.log("Refreshing data...");
var preLength = data.length;
data = JSON.parse(response);

if (preLength != data.length) {
if (preLength != response.length) {
preLength = response.length;
// Clear markers
for (var i = 0; i < markers.length; i++) {
listeners[i].a.remove();
listeners[i].b.remove();
markers[i].setMap(null);
for (var pokehash in markers) {
if (!markers.hasOwnProperty(pokehash)) {
continue;
}
if (data.hasOwnProperty(pokehash) && hidden_layers[data[pokehash].id] != 1) {
continue;
}
var marker = markers[pokehash];
marker.listeners[0].remove();
marker.listeners[1].remove();
marker.setMap(null);

delete markers[pokehash];
}
listeners = [];
markers = [];

// Add updated markers
for (var i = 0; i < data.length; i++) {
var p = data[i];
var numPkmnType = {};
for (var pokehash in data) {
if (!data.hasOwnProperty(pokehash)) {
// inherited, not interesting to us
continue;
}
var p = data[pokehash];
if (numPkmnType.hasOwnProperty(p.id)) {
numPkmnType[p.id] += 1;
} else {
numPkmnType[p.id] = 1;
}
if (!updated) {
map.setZoom(16);
map.panTo({lat: p.lat, lng: p.lng});
updated = true;
}

if(hidden_layers.indexOf(p.name) == -1){
if (layers.findIndex(function(v){ return v.id == p.id; }) == -1) {
console.log("Adding layer " + pkmn_label(p));
layers.push(p);
layers.sort(function(a, b){ return a.id - b.id; });
document.getElementById('pknum').innerHTML = " (" + (layers.length - 1) + ")";
}

if (hidden_layers[p.id] != 1) {
// Pokemon not hidden
if(layers.indexOf(p.name) == -1){
layers.push(p.name);

p.timeleft = p.expiry - p.timestamp;
timeleft_strify = p.timeleft
p.timeleft_str = ''
if (timeleft_strify > 86400) {
p.timeleft_str += Math.floor(timeleft_strify / 86400) + " days, ";
timeleft_strify %= 86400;
}
if (timeleft_strify > 3600) {
p.timeleft_str += Math.floor(timeleft_strify / 3600) + "h";
timeleft_strify %= 3600;
}
if (timeleft_strify > 60) {
p.timeleft_str += Math.floor(timeleft_strify / 60) + "m";
timeleft_strify %= 60;
}
console.log("Adding marker " + p.name);
p.timeleft_str += Math.floor(timeleft_strify) + "s";

detail_str = "<b>" + pkmn_label(p) + "</b><br>Time left: " + p.timeleft_str + "<br>Lat: " + p.lat + "<br>Long: " + p.lng;

if (markers.hasOwnProperty(pokehash)) {
markers[pokehash].details = detail_str;
continue;
}

console.log("Adding marker " + pkmn_label(p));

var infowindow = new google.maps.InfoWindow({
});

var image = getImage(p);
var image = "https://raw.githubusercontent.com/AHAAAAAAA/PokemonGo-Map/master/static/icons/" + p.id + ".png";
if (p.id == -1) {
//image = 'https://agents.farmers.com/images/walking.png';
image = null;
}

var marker = new google.maps.Marker({
map: map,
position: {lat: p.lat, lng: p.lng},
label: "",
title: "<b>"+p.name+"</b><br>Time left: " + formatSeconds(p.timeleft) + "<br>Lat: "+p.lat+"<br>Long: "+p.lng,
icon: image
details: detail_str,
icon: {
scaledSize: pkmn_size,
anchor: pkmn_anchor,
url: image
}
});

var listenerPair = {
a: google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(this.title);
var listenerPair = [
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.setContent(this.details);
infowindow.open(map, this);
}),

b: google.maps.event.addListener(marker, 'mouseout', function() {
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close(map, this);
})
};
];

listeners.push(listenerPair);
markers.push(marker);
marker.listeners = listenerPair;
markers[pokehash] = marker;
}
}

// Draw layer manager
var list = document.getElementById('legend-list');
var content = [];
for (var id in layers) {
var pkmn = layers[id];
var checked = hidden_layers.indexOf(pkmn) != -1 ? "checked": "";
content.push("<li><input type='checkbox' id='" + pkmn + "'" +
" onclick='toggleLayer(this.checked, this.id)' "+checked+"\/>" +
pkmn + "<\/li>");
for (var i = 0; i < layers.length; ++i) {
var pkmn = layers[i];
if (!numPkmnType.hasOwnProperty(pkmn.id)) {
numPkmnType[pkmn.id] = 0;
}
var checked = hidden_layers[pkmn.id] == 1 ? "checked": "";
var elemname = pkmn_label(pkmn);
content.push("<li><input type='checkbox' id='hide_" + pkmn.id + "'" +
" onclick='toggleLayer(this.checked, this.id.substr(5))' "+checked+"\/>" +
elemname + " (" + numPkmnType[pkmn.id] + ")" + "<\/li>");
}
list.innerHTML = content.join('');
}
Expand All @@ -174,17 +235,19 @@

data = {};
map = null;
markers = [];
listeners = [];
hidden_layers = [];
markers = {};
hidden_layers = {};
layers = [];
updated = false;


getFile("config.json", false, function(configData) {
config = JSON.parse(configData)
config = JSON.parse(configData);
console.log("Using api key: " + config.GOOGLE_MAPS_API_KEY);
loadScript("https://maps.googleapis.com/maps/api/js?key=" + config.GOOGLE_MAPS_API_KEY + "&libraries=drawing&callback=initMap");
for (var i = 0; i < config.hidden_pkmn.length; ++i) {
hidden_layers[config.hidden_pkmn[i]] = 1;
}
});

function initMap() {
Expand All @@ -198,7 +261,7 @@
var legend = document.createElement('div');
legend.id = 'legend';
var content = [];
content.push('<h3>Hide Pokemon</h3>');
content.push('<h3>Hide Pokemon<span id="pknum"></span></h3>');
content.push('<div id="legend-list"></div>');
legend.innerHTML = content.join('');
legend.index = 1;
Expand Down
Loading