Merge pull request #537 from Xelio/hook-select-portal
Refactor code of select/unselect portal. Add hook 'portalSeleted'.
This commit is contained in:
commit
1619ddfae5
@ -15,6 +15,8 @@
|
|||||||
// required to successfully boot the plugin.
|
// required to successfully boot the plugin.
|
||||||
//
|
//
|
||||||
// Here’s more specific information about each event:
|
// Here’s more specific information about each event:
|
||||||
|
// portalSelected: called when portal on map is selected/unselected.
|
||||||
|
// Provide guid of selected and unselected portal.
|
||||||
// mapDataRefreshStart: called when we start refreshing map data
|
// mapDataRefreshStart: called when we start refreshing map data
|
||||||
// mapDataRefreshEnd: called when we complete the map data load
|
// mapDataRefreshEnd: called when we complete the map data load
|
||||||
// portalAdded: called when a portal has been received and is about to
|
// portalAdded: called when a portal has been received and is about to
|
||||||
@ -45,6 +47,7 @@
|
|||||||
|
|
||||||
window._hooks = {}
|
window._hooks = {}
|
||||||
window.VALID_HOOKS = [
|
window.VALID_HOOKS = [
|
||||||
|
'portalSelected',
|
||||||
'mapDataRefreshStart', 'mapDataRefreshEnd',
|
'mapDataRefreshStart', 'mapDataRefreshEnd',
|
||||||
'portalAdded', 'portalDetailsUpdated',
|
'portalAdded', 'portalDetailsUpdated',
|
||||||
'publicChatDataAvailable', 'factionChatDataAvailable',
|
'publicChatDataAvailable', 'factionChatDataAvailable',
|
||||||
|
@ -3,16 +3,20 @@
|
|||||||
// methods that highlight the portal in the map view.
|
// methods that highlight the portal in the map view.
|
||||||
|
|
||||||
window.renderPortalDetails = function(guid) {
|
window.renderPortalDetails = function(guid) {
|
||||||
|
selectPortal(window.portals[guid] ? guid : null);
|
||||||
|
|
||||||
if(!window.portals[guid]) {
|
if(!window.portals[guid]) {
|
||||||
unselectOldPortal();
|
|
||||||
urlPortal = guid;
|
urlPortal = guid;
|
||||||
|
$('#portaldetails').html('');
|
||||||
|
if(isSmartphone()) {
|
||||||
|
$('.fullimg').remove();
|
||||||
|
$('#mobileinfo').html('');
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var d = window.portals[guid].options.details;
|
var d = window.portals[guid].options.details;
|
||||||
|
|
||||||
selectPortal(guid);
|
|
||||||
|
|
||||||
// collect some random data that’s not worth to put in an own method
|
// collect some random data that’s not worth to put in an own method
|
||||||
var links = {incoming: 0, outgoing: 0};
|
var links = {incoming: 0, outgoing: 0};
|
||||||
if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) {
|
if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) {
|
||||||
@ -43,7 +47,6 @@ window.renderPortalDetails = function(guid) {
|
|||||||
|
|
||||||
var resoDetails = '<table id="resodetails">' + getResonatorDetails(d) + '</table>';
|
var resoDetails = '<table id="resodetails">' + getResonatorDetails(d) + '</table>';
|
||||||
|
|
||||||
setPortalIndicators(d);
|
|
||||||
var img = getPortalImageUrl(d);
|
var img = getPortalImageUrl(d);
|
||||||
var lat = d.locationE6.latE6/1E6;
|
var lat = d.locationE6.latE6/1E6;
|
||||||
var lng = d.locationE6.lngE6/1E6;
|
var lng = d.locationE6.lngE6/1E6;
|
||||||
@ -89,7 +92,7 @@ window.renderPortalDetails = function(guid) {
|
|||||||
.attr('class', TEAM_TO_CSS[getTeam(d)])
|
.attr('class', TEAM_TO_CSS[getTeam(d)])
|
||||||
.html(''
|
.html(''
|
||||||
+ '<h3 class="title">'+escapeHtmlSpecialChars(d.portalV2.descriptiveText.TITLE)+'</h3>'
|
+ '<h3 class="title">'+escapeHtmlSpecialChars(d.portalV2.descriptiveText.TITLE)+'</h3>'
|
||||||
+ '<span class="close" onclick="unselectOldPortal();" title="Close">X</span>'
|
+ '<span class="close" onclick="renderPortalDetails(null);" title="Close">X</span>'
|
||||||
// help cursor via ".imgpreview img"
|
// help cursor via ".imgpreview img"
|
||||||
+ '<div class="imgpreview" '+imgTitle+' style="background-image: url('+img+')">'
|
+ '<div class="imgpreview" '+imgTitle+' style="background-image: url('+img+')">'
|
||||||
+ '<span id="level">'+Math.floor(getPortalLevel(d))+'</span>'
|
+ '<span id="level">'+Math.floor(getPortalLevel(d))+'</span>'
|
||||||
@ -117,64 +120,53 @@ window.renderPortalDetails = function(guid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draws link-range and hack-range circles around the portal with the
|
// draws link-range and hack-range circles around the portal with the
|
||||||
// given details.
|
// given details. Clear them if parameter 'd' is null.
|
||||||
window.setPortalIndicators = function(d) {
|
window.setPortalIndicators = function(d) {
|
||||||
if(portalRangeIndicator) map.removeLayer(portalRangeIndicator);
|
if(portalRangeIndicator) map.removeLayer(portalRangeIndicator);
|
||||||
|
portalRangeIndicator = null;
|
||||||
|
if(portalAccessIndicator) map.removeLayer(portalAccessIndicator);
|
||||||
|
portalAccessIndicator = null;
|
||||||
|
|
||||||
|
if(d === null) return;
|
||||||
|
|
||||||
var range = getPortalRange(d);
|
var range = getPortalRange(d);
|
||||||
var coord = [d.locationE6.latE6/1E6, d.locationE6.lngE6/1E6];
|
var coord = [d.locationE6.latE6/1E6, d.locationE6.lngE6/1E6];
|
||||||
portalRangeIndicator = (range > 0
|
portalRangeIndicator = (range > 0
|
||||||
? L.geodesicCircle(coord, range, { fill: false, color: RANGE_INDICATOR_COLOR, weight: 3, clickable: false })
|
? L.geodesicCircle(coord, range, { fill: false, color: RANGE_INDICATOR_COLOR, weight: 3, clickable: false })
|
||||||
: L.circle(coord, range, { fill: false, stroke: false, clickable: false })
|
: L.circle(coord, range, { fill: false, stroke: false, clickable: false })
|
||||||
).addTo(map);
|
).addTo(map);
|
||||||
if(!portalAccessIndicator)
|
|
||||||
portalAccessIndicator = L.circle(coord, HACK_RANGE,
|
|
||||||
{ fill: false, color: ACCESS_INDICATOR_COLOR, weight: 2, clickable: false }
|
|
||||||
).addTo(map);
|
|
||||||
else
|
|
||||||
portalAccessIndicator.setLatLng(coord);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.clearPortalIndicators = function() {
|
portalAccessIndicator = L.circle(coord, HACK_RANGE,
|
||||||
if(portalRangeIndicator) map.removeLayer(portalRangeIndicator);
|
{ fill: false, color: ACCESS_INDICATOR_COLOR, weight: 2, clickable: false }
|
||||||
portalRangeIndicator = null;
|
).addTo(map);
|
||||||
if(portalAccessIndicator) map.removeLayer(portalAccessIndicator);
|
|
||||||
portalAccessIndicator = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// highlights portal with given GUID. Automatically clears highlights
|
// highlights portal with given GUID. Automatically clears highlights
|
||||||
// on old selection. Returns false if the selected portal changed.
|
// on old selection. Returns false if the selected portal changed.
|
||||||
// Returns true if it's still the same portal that just needs an
|
// Returns true if it's still the same portal that just needs an
|
||||||
// update.
|
// update.
|
||||||
window.selectPortal = function(guid) {
|
window.selectPortal = function(guid) {
|
||||||
var update = selectedPortal === guid;
|
var update = selectedPortal === guid;
|
||||||
var oldPortal = portals[selectedPortal];
|
var oldPortalGuid = selectedPortal;
|
||||||
if(!update && oldPortal) setMarkerStyle(oldPortal,false);
|
|
||||||
|
|
||||||
selectedPortal = guid;
|
selectedPortal = guid;
|
||||||
|
|
||||||
if(portals[guid]) {
|
var oldPortal = portals[oldPortalGuid];
|
||||||
// resonatorsSetSelectStyle(guid);
|
var newPortal = portals[guid];
|
||||||
|
|
||||||
setMarkerStyle(portals[guid], true);
|
// Restore style of unselected portal
|
||||||
|
if(!update && oldPortal) setMarkerStyle(oldPortal,false);
|
||||||
|
|
||||||
if (map.hasLayer(portals[guid])) {
|
// Change style of selected portal
|
||||||
portals[guid].bringToFront();
|
if(newPortal) {
|
||||||
|
setMarkerStyle(newPortal, true);
|
||||||
|
|
||||||
|
if (map.hasLayer(newPortal)) {
|
||||||
|
newPortal.bringToFront();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPortalIndicators(newPortal ? newPortal.options.details : null);
|
||||||
|
|
||||||
|
runHooks('portalSelected', {selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid});
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
window.unselectOldPortal = function() {
|
|
||||||
var oldPortal = portals[selectedPortal];
|
|
||||||
if(oldPortal) setMarkerStyle(oldPortal,false);
|
|
||||||
selectedPortal = null;
|
|
||||||
$('#portaldetails').html('');
|
|
||||||
if(isSmartphone()) {
|
|
||||||
$('.fullimg').remove();
|
|
||||||
$('#mobileinfo').html('');
|
|
||||||
}
|
|
||||||
clearPortalIndicators();
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// @id iitc-plugin-bookmarks@ZasoGD
|
// @id iitc-plugin-bookmarks@ZasoGD
|
||||||
// @name IITC plugin: Bookmarks for maps and portals
|
// @name IITC plugin: Bookmarks for maps and portals
|
||||||
// @category Controls
|
// @category Controls
|
||||||
// @version 0.2.3.@@DATETIMEVERSION@@
|
// @version 0.2.4.@@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@@
|
||||||
@ -841,7 +841,14 @@
|
|||||||
$('#portaldetails').before(window.plugin.bookmarks.htmlBoxTrigger + window.plugin.bookmarks.htmlBkmrksBox);
|
$('#portaldetails').before(window.plugin.bookmarks.htmlBoxTrigger + window.plugin.bookmarks.htmlBkmrksBox);
|
||||||
|
|
||||||
// Remove the star
|
// Remove the star
|
||||||
|
window.addHook('portalSelected', function(data) {
|
||||||
|
if(data.selectedPortalGuid === null) {
|
||||||
|
$('.bkmrksStar').remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// in the future i hope in a 'portalClosed' hook
|
// in the future i hope in a 'portalClosed' hook
|
||||||
|
/* hook done
|
||||||
window.unselectOldPortal = function() {
|
window.unselectOldPortal = function() {
|
||||||
var oldPortal = portals[selectedPortal];
|
var oldPortal = portals[selectedPortal];
|
||||||
if(oldPortal) portalResetColor(oldPortal);
|
if(oldPortal) portalResetColor(oldPortal);
|
||||||
@ -854,6 +861,7 @@
|
|||||||
clearPortalIndicators();
|
clearPortalIndicators();
|
||||||
$('.bkmrksStar').remove();
|
$('.bkmrksStar').remove();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
$('#toolbox').append(window.plugin.bookmarks.htmlCallSetBox+window.plugin.bookmarks.htmlCalldrawBox);
|
$('#toolbox').append(window.plugin.bookmarks.htmlCallSetBox+window.plugin.bookmarks.htmlCalldrawBox);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user