Add click listener on player markers to open up closest portal details
This commit is contained in:
parent
c7e94a1a25
commit
e45e694533
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @id iitc-plugin-player-tracker@breunigs
|
// @id iitc-plugin-player-tracker@breunigs
|
||||||
// @name IITC Plugin: Player tracker
|
// @name IITC Plugin: Player tracker
|
||||||
// @version 0.7.2.@@DATETIMEVERSION@@
|
// @version 0.8.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -31,9 +31,12 @@ window.plugin.playerTracker.setup = function() {
|
|||||||
plugin.playerTracker.drawnTraces = new L.LayerGroup();
|
plugin.playerTracker.drawnTraces = new L.LayerGroup();
|
||||||
window.layerChooser.addOverlay(plugin.playerTracker.drawnTraces, 'Player Tracker');
|
window.layerChooser.addOverlay(plugin.playerTracker.drawnTraces, 'Player Tracker');
|
||||||
map.addLayer(plugin.playerTracker.drawnTraces);
|
map.addLayer(plugin.playerTracker.drawnTraces);
|
||||||
window.plugin.playerTracker.oms = new OverlappingMarkerSpiderfier(map);
|
plugin.playerTracker.oms = new OverlappingMarkerSpiderfier(map);
|
||||||
window.plugin.playerTracker.oms.legColors = {'usual': '#FFFF00', 'highlighted': '#FF0000'};
|
plugin.playerTracker.oms.legColors = {'usual': '#FFFF00', 'highlighted': '#FF0000'};
|
||||||
window.plugin.playerTracker.oms.legWeight = 3.5;
|
plugin.playerTracker.oms.legWeight = 3.5;
|
||||||
|
plugin.playerTracker.oms.addListener('click', function(player) {
|
||||||
|
window.renderPortalDetails(player.options.referenceToPortal);
|
||||||
|
});
|
||||||
|
|
||||||
addHook('publicChatDataAvailable', window.plugin.playerTracker.handleData);
|
addHook('publicChatDataAvailable', window.plugin.playerTracker.handleData);
|
||||||
|
|
||||||
@ -91,7 +94,7 @@ window.plugin.playerTracker.processNewData = function(data) {
|
|||||||
if(json[1] < limit) return true;
|
if(json[1] < limit) return true;
|
||||||
|
|
||||||
// find player and portal information
|
// find player and portal information
|
||||||
var pguid, lat, lng, name;
|
var pguid, lat, lng, guid, name;
|
||||||
var skipThisMessage = false;
|
var skipThisMessage = false;
|
||||||
$.each(json[2].plext.markup, function(ind, markup) {
|
$.each(json[2].plext.markup, function(ind, markup) {
|
||||||
switch(markup[0]) {
|
switch(markup[0]) {
|
||||||
@ -114,16 +117,18 @@ window.plugin.playerTracker.processNewData = function(data) {
|
|||||||
// X.
|
// X.
|
||||||
lat = lat ? lat : markup[1].latE6/1E6;
|
lat = lat ? lat : markup[1].latE6/1E6;
|
||||||
lng = lng ? lng : markup[1].lngE6/1E6;
|
lng = lng ? lng : markup[1].lngE6/1E6;
|
||||||
|
guid = guid ? guid : markup[1].guid;
|
||||||
name = name ? name : markup[1].name;
|
name = name ? name : markup[1].name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// skip unusable events
|
// skip unusable events
|
||||||
if(!pguid || !lat || !lng || skipThisMessage) return true;
|
if(!pguid || !lat || !lng || !guid || skipThisMessage) return true;
|
||||||
|
|
||||||
var newEvent = {
|
var newEvent = {
|
||||||
latlngs: [[lat, lng]],
|
latlngs: [[lat, lng]],
|
||||||
|
guids: [guid],
|
||||||
time: json[1],
|
time: json[1],
|
||||||
name: name
|
name: name
|
||||||
};
|
};
|
||||||
@ -154,6 +159,7 @@ window.plugin.playerTracker.processNewData = function(data) {
|
|||||||
// this is multiple resos destroyed at the same time.
|
// this is multiple resos destroyed at the same time.
|
||||||
if(evts[cmp].time === json[1]) {
|
if(evts[cmp].time === json[1]) {
|
||||||
evts[cmp].latlngs.push([lat, lng]);
|
evts[cmp].latlngs.push([lat, lng]);
|
||||||
|
evts[cmp].guids.push(guid);
|
||||||
plugin.playerTracker.stored[pguid].events = evts;
|
plugin.playerTracker.stored[pguid].events = evts;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -239,9 +245,25 @@ window.plugin.playerTracker.drawData = function() {
|
|||||||
title += ago(ev.time, now) + minsAgo + ev.name + '\n';
|
title += ago(ev.time, now) + minsAgo + ev.name + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calculate the closest portal to the player
|
||||||
|
var eventPortal = []
|
||||||
|
var closestPortal;
|
||||||
|
var mostPortals = 0;
|
||||||
|
$.each(last.guids, function() {
|
||||||
|
if(eventPortal[this]) {
|
||||||
|
eventPortal[this]++;
|
||||||
|
} else {
|
||||||
|
eventPortal[this] = 1;
|
||||||
|
}
|
||||||
|
if(eventPortal[this] > mostPortals) {
|
||||||
|
mostPortals = eventPortal[this];
|
||||||
|
closestPortal = this;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// marker itself
|
// marker itself
|
||||||
var icon = playerData.team === 'ALIENS' ? new window.iconEnl() : new window.iconRes();
|
var icon = playerData.team === 'ALIENS' ? new window.iconEnl() : new window.iconRes();
|
||||||
var m = L.marker(gllfe(last), {title: title, icon: icon});
|
var m = L.marker(gllfe(last), {title: title, icon: icon, referenceToPortal: closestPortal});
|
||||||
// ensure tooltips are closed, sometimes they linger
|
// ensure tooltips are closed, sometimes they linger
|
||||||
m.on('mouseout', function() { $(this._icon).tooltip('close'); });
|
m.on('mouseout', function() { $(this._icon).tooltip('close'); });
|
||||||
m.addTo(layer);
|
m.addTo(layer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user