Skip to content

Commit

Permalink
Adding exif parsing of location data to the logbook as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
magma1447 committed Dec 2, 2016
1 parent 1a0341d commit 1afe27a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Some (most) features are for paying members at Project-GC only.
* Autodecrypt hints.
* Add metres/feet above mean sea level.
* Add warning if the latest log is a DNF.
* Show exif location data for images in Gallery.
* Show exif location data for images in Gallery and Logbook.
* Adds button to map bookmark lists.

## Open source libraries used
Expand Down
146 changes: 89 additions & 57 deletions greasemonkey-geocaching-projectgc.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// @description Adds links and data to Geocaching.com to make it collaborate with PGC
// @include http://www.geocaching.com/*
// @include https://www.geocaching.com/*
// @version 1.6.0
// @version 1.6.1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=19641
// @grant GM_xmlhttpRequest
Expand Down Expand Up @@ -203,6 +203,69 @@
return distance;
}

function GetCoordinatesFromExif(exif) {
var GPSLatitudeRef = EXIF.getTag(exif, "GPSLatitudeRef");
var GPSLatitude = EXIF.getTag(exif, "GPSLatitude");
var GPSLongitudeRef = EXIF.getTag(exif, "GPSLongitudeRef");
var GPSLongitude = EXIF.getTag(exif, "GPSLongitude");

if(typeof(GPSLatitudeRef) == 'undefined') {
return false;
}

var coords = '';

coords += GPSLatitudeRef;
if(GPSLatitude[0] < 10) {
coords += '0' + GPSLatitude[0];
} else {
coords += GPSLatitude[0];
}
coords += ' ';
if(GPSLatitude[1] < 10) {
coords += '0' + GPSLatitude[1];
} else {
coords += GPSLatitude[1];
}
coords += '.';
var decimals = Math.round(GPSLatitude[2]/60*1000);
if(decimals < 10) {
coords += '00' + decimals;
} else if(decimals < 100) {
coords += '0' + decimals;
} else {
coords += decimals;
}

coords += ' ';

coords += GPSLongitudeRef;
if(GPSLongitude[0] < 10) {
coords += '00' + GPSLongitude[0];
} else if(GPSLongitude[0] < 100) {
coords += '0' + GPSLongitude[0];
} else {
coords += GPSLongitude[0];
}
coords += ' ';
if(GPSLongitude[1] < 10) {
coords += '0' + GPSLongitude[1];
} else {
coords += GPSLongitude[1];
}
coords += '.';
var decimals = Math.round(GPSLongitude[2]/60*1000);
if(decimals < 10) {
coords += '00' + decimals;
} else if(decimals < 100) {
coords += '0' + decimals;
} else {
coords += decimals;
}

return coords;
}

/**
* Check that we are authenticated at Project-GC.com, and that it's with the same username
*/
Expand Down Expand Up @@ -734,6 +797,29 @@
}
}

if(IsSettingEnabled('parseExifLocation')) {
$(jNode).find('table.LogImagesTable tr>td').each(function() {
var url = $(this).find('a.tb_images').attr('href');
var thumbnailUrl = url.replace('/img.geocaching.com/cache/log/large/', '/img.geocaching.com/cache/log/thumb/');

var imgElm = $(this).find('img');
$(imgElm).attr('src', thumbnailUrl);
$(imgElm).next().css('vertical-align', 'top');

$(imgElm).load(function() {
EXIF.getData($(imgElm)[0], function() {
// console.log(EXIF.pretty(this));
var coords = GetCoordinatesFromExif(this);
if(coords != false) {
$('<span style="color: #8c0b0b; font-weight: bold;">EXIF Location: ' + coords + '</span>').insertAfter($(imgElm).parent());
}
});
});

});
}


// Save to latest logs
if (latestLogs.length < 5) {
var node = $(jNode).find('div.HalfLeft.LogType strong img[src]'),
Expand Down Expand Up @@ -849,62 +935,8 @@
$('#ctl00_ContentBody_GalleryItems_DataListGallery img').each(function() {
EXIF.getData($(this)[0], function() {
// console.log(EXIF.pretty(this));
var GPSLatitudeRef = EXIF.getTag(this, "GPSLatitudeRef");
var GPSLatitude = EXIF.getTag(this, "GPSLatitude");
var GPSLongitudeRef = EXIF.getTag(this, "GPSLongitudeRef");
var GPSLongitude = EXIF.getTag(this, "GPSLongitude");

if(typeof(GPSLatitudeRef) != 'undefined') {
var coords = '';

coords += GPSLatitudeRef;
if(GPSLatitude[0] < 10) {
coords += '0' + GPSLatitude[0];
} else {
coords += GPSLatitude[0];
}
coords += ' ';
if(GPSLatitude[1] < 10) {
coords += '0' + GPSLatitude[1];
} else {
coords += GPSLatitude[1];
}
coords += '.';
var decimals = Math.round(GPSLatitude[2]/60*1000);
if(decimals < 10) {
coords += '00' + decimals;
} else if(decimals < 100) {
coords += '0' + decimals;
} else {
coords += decimals;
}

coords += ' ';

coords += GPSLongitudeRef;
if(GPSLongitude[0] < 10) {
coords += '00' + GPSLongitude[0];
} else if(GPSLongitude[0] < 100) {
coords += '0' + GPSLongitude[0];
} else {
coords += GPSLongitude[0];
}
coords += ' ';
if(GPSLongitude[1] < 10) {
coords += '0' + GPSLongitude[1];
} else {
coords += GPSLongitude[1];
}
coords += '.';
var decimals = Math.round(GPSLongitude[2]/60*1000);
if(decimals < 10) {
coords += '00' + decimals;
} else if(decimals < 100) {
coords += '0' + decimals;
} else {
coords += decimals;
}

var coords = GetCoordinatesFromExif(this);
if(coords != false) {
$('<span class="OldWarning">EXIF Location<br>' + coords + '</span>').insertAfter(this.parentNode);
}
});
Expand Down
Binary file added screenshots/LogbookExifLocations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1afe27a

Please sign in to comment.