plugin: distance-to-portal
new plugin: manually set your location, then the distance to the selected portal is shown intended to aid key management when at home (select a portal, find key in inventory by distance rather than name)
This commit is contained in:
parent
9efc2fb508
commit
9397171030
117
plugins/distance-to-portal.user.js
Normal file
117
plugins/distance-to-portal.user.js
Normal file
@ -0,0 +1,117 @@
|
||||
// ==UserScript==
|
||||
// @id iitc-plugin-distance-to-portal@jonatkins
|
||||
// @name IITC plugin: Distance to portal
|
||||
// @category Info
|
||||
// @version 0.1.0.@@DATETIMEVERSION@@
|
||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||
// @updateURL @@UPDATEURL@@
|
||||
// @downloadURL @@DOWNLOADURL@@
|
||||
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Allows your current location to be set manually, then shows the distance to the selected portal. Useful when managing portal keys.
|
||||
// @include https://www.ingress.com/intel*
|
||||
// @include http://www.ingress.com/intel*
|
||||
// @match https://www.ingress.com/intel*
|
||||
// @match http://www.ingress.com/intel*
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
@@PLUGINSTART@@
|
||||
|
||||
// PLUGIN START ////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// use own namespace for plugin
|
||||
window.plugin.distanceToPortal = function() {};
|
||||
|
||||
|
||||
|
||||
window.plugin.distanceToPortal.addDistance = function(info) {
|
||||
|
||||
var ll = info.portal.getLatLng();
|
||||
|
||||
var text;
|
||||
|
||||
if (window.plugin.distanceToPortal.currentLoc) {
|
||||
var dist = window.plugin.distanceToPortal.currentLoc.distanceTo(ll);
|
||||
|
||||
if (dist >= 10000) {
|
||||
dist = Math.round(dist/1000)+'km';
|
||||
} else if (dist >= 1000) {
|
||||
dist = Math.round(dist/100)/10+'km';
|
||||
} else {
|
||||
dist = Math.round(dist)+'m';
|
||||
}
|
||||
|
||||
text = 'Distance: '+dist;
|
||||
} else {
|
||||
text = 'Location not set';
|
||||
}
|
||||
|
||||
var div = $('<div>').addClass('portal-distance').text(text).attr('title','Double-click to set/change current location').on('dblclick',window.plugin.distanceToPortal.setLocation);
|
||||
|
||||
$('#resodetails').after(div);
|
||||
|
||||
};
|
||||
|
||||
|
||||
window.plugin.distanceToPortal.setLocation = function() {
|
||||
if (window.plugin.distanceToPortal.currentLocMarker) {
|
||||
map.removeLayer(window.plugin.distanceToPortal.currentLocMarker);
|
||||
window.plugin.distanceToPortal.currentLocMarker = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!window.plugin.distanceToPortal.currentLoc) {
|
||||
window.plugin.distanceToPortal.currentLoc = map.getCenter();
|
||||
}
|
||||
|
||||
|
||||
var markerTemplate = '@@INCLUDESTRING:images/marker-icon.svg.template@@';
|
||||
window.plugin.distanceToPortal.currentLocMarker = L.marker(window.plugin.distanceToPortal.currentLoc,{
|
||||
icon: L.divIcon({
|
||||
iconSize: new L.Point(25, 41),
|
||||
iconAnchor: new L.Point(12, 41),
|
||||
html: markerTemplate.replace(/%COLOR%/g, '#444'),
|
||||
className: 'leaflet-iitc-distance-to-portal-location'
|
||||
}),
|
||||
draggable: true,
|
||||
});
|
||||
|
||||
window.plugin.distanceToPortal.currentLocMarker.on('dragend', function(e) {
|
||||
window.plugin.distanceToPortal.currentLoc = window.plugin.distanceToPortal.currentLocMarker.getLatLng();
|
||||
|
||||
localStorage['plugin-distance-to-portal'] = JSON.stringify({lat:window.plugin.distanceToPortal.currentLoc.lat, lng:window.plugin.distanceToPortal.currentLoc.lng});
|
||||
|
||||
// bit nasty, but easiest way of refreshing the distance after marker is moved
|
||||
if (selectedPortal) renderPortalDetails(selectedPortal);
|
||||
});
|
||||
|
||||
map.addLayer(window.plugin.distanceToPortal.currentLocMarker);
|
||||
};
|
||||
|
||||
|
||||
window.plugin.distanceToPortal.setup = function() {
|
||||
|
||||
try {
|
||||
window.plugin.distanceToPortal.currentLoc = L.latLng(JSON.parse(localStorage['plugin-distance-to-portal']));
|
||||
} catch(e) {
|
||||
window.plugin.distanceToPortal.currentLoc = null;
|
||||
}
|
||||
|
||||
window.plugin.distanceToPortal.currentLocMarker = null;
|
||||
|
||||
|
||||
$('head').append(
|
||||
'<style>'+
|
||||
'div.portal-distance { text-align: center; }'+
|
||||
'</style>'
|
||||
);
|
||||
|
||||
addHook('portalDetailsUpdated', window.plugin.distanceToPortal.addDistance);
|
||||
};
|
||||
|
||||
var setup = window.plugin.distanceToPortal.setup;
|
||||
|
||||
// PLUGIN END //////////////////////////////////////////////////////////
|
||||
|
||||
@@PLUGINEND@@
|
Loading…
x
Reference in New Issue
Block a user