Skip to content

Commit

Permalink
Merge pull request #643 from xscreach/feature/range-display
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 authored Jul 9, 2023
2 parents c185b94 + 7efd7d6 commit d730856
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions core/code/portal_detail_display_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ window.getRangeText = function(d) {

if(!range.isLinkable) title += '\nPortal is missing resonators,\nno new links can be made';

return ['range',
'<a onclick="window.rangeLinkClick()"'
+ (range.isLinkable ? '' : ' style="text-decoration:line-through;"')
+ '>'
+ (range.range > 1000
? Math.floor(range.range/1000) + ' km'
: Math.floor(range.range) + ' m')
+ '</a>',
title];
return [
'range',
'<a onclick="window.rangeLinkClick()"' +
(range.isLinkable ? '' : ' style="text-decoration:line-through;"') +
'>' +
window.formatDistance(range.range) +
'</a>',
title,
];
}


Expand Down
3 changes: 3 additions & 0 deletions core/code/utils_misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ window.formatInterval = function(seconds,maxTerms) {
return terms.join(' ');
}

window.formatDistance = function (distance) {
return window.digits(distance > 10000 ? (distance / 1000).toFixed(2) + 'km' : Math.round(distance) + 'm');
};

window.rangeLinkClick = function() {
if(window.portalRangeIndicator)
Expand Down
16 changes: 8 additions & 8 deletions plugins/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// @version 0.4.2
// @description Save your favorite Maps and Portals and move the intel map with a click. Works with sync. Supports Multi-Project-Extension

/* global L -- eslint */

/* **********************************************************************
HOOKS:
Expand Down Expand Up @@ -865,22 +867,20 @@ window.plugin.bookmarks.loadStorageBox = function() {
var text = "You must select 2 or 3 portals!";
var color = "red";

function formatDistance(distance) {
var text = digits(distance > 10000 ? (distance/1000).toFixed(2) + "km" : (Math.round(distance) + "m"));
return distance >= 200000
? '<em title="Long distance link" class="help longdistance">'+text+'</em>'
: text;
}
function distanceElement(distance) {
var text = window.formatDistance(distance);
return distance >= 200000 ? '<em title="Long distance link" class="help longdistance">' + text + '</em>' : text;
}

if(latlngs.length == 2) {
var distance = L.latLng(latlngs[0]).distanceTo(latlngs[1]);
text = 'Distance between portals: ' + formatDistance(distance);
text = 'Distance between portals: ' + distanceElement(distance);
color = "";
} else if(latlngs.length == 3) {
var longdistance = false;
var distances = latlngs.map(function(ll1, i, latlngs) {
var ll2 = latlngs[(i+1)%3];
return formatDistance(L.latLng(ll1).distanceTo(ll2));
return distanceElement(L.latLng(ll1).distanceTo(ll2));
});
text = 'Distances: ' + distances.join(", ");
color = "";
Expand Down

0 comments on commit d730856

Please sign in to comment.