diff --git a/code/hooks.js b/code/hooks.js index 7cda12d0..17b15444 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -15,6 +15,8 @@ // required to successfully boot the plugin. // // 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 // mapDataRefreshEnd: called when we complete the map data load // portalAdded: called when a portal has been received and is about to @@ -45,6 +47,7 @@ window._hooks = {} window.VALID_HOOKS = [ + 'portalSelected', 'mapDataRefreshStart', 'mapDataRefreshEnd', 'portalAdded', 'portalDetailsUpdated', 'publicChatDataAvailable', 'factionChatDataAvailable', diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index f174628a..effd9fb1 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -3,16 +3,20 @@ // methods that highlight the portal in the map view. window.renderPortalDetails = function(guid) { + selectPortal(window.portals[guid] ? guid : null); + if(!window.portals[guid]) { - unselectOldPortal(); urlPortal = guid; + $('#portaldetails').html(''); + if(isSmartphone()) { + $('.fullimg').remove(); + $('#mobileinfo').html(''); + } return; } var d = window.portals[guid].options.details; - selectPortal(guid); - // collect some random data that’s not worth to put in an own method var links = {incoming: 0, outgoing: 0}; if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) { @@ -43,7 +47,6 @@ window.renderPortalDetails = function(guid) { var resoDetails = '' + getResonatorDetails(d) + '
'; - setPortalIndicators(d); var img = getPortalImageUrl(d); var lat = d.locationE6.latE6/1E6; var lng = d.locationE6.lngE6/1E6; @@ -89,7 +92,7 @@ window.renderPortalDetails = function(guid) { .attr('class', TEAM_TO_CSS[getTeam(d)]) .html('' + '

'+escapeHtmlSpecialChars(d.portalV2.descriptiveText.TITLE)+'

' - + 'X' + + 'X' // help cursor via ".imgpreview img" + '
' + ''+Math.floor(getPortalLevel(d))+'' @@ -117,64 +120,53 @@ window.renderPortalDetails = function(guid) { } // 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) { if(portalRangeIndicator) map.removeLayer(portalRangeIndicator); + portalRangeIndicator = null; + if(portalAccessIndicator) map.removeLayer(portalAccessIndicator); + portalAccessIndicator = null; + + if(d === null) return; + var range = getPortalRange(d); var coord = [d.locationE6.latE6/1E6, d.locationE6.lngE6/1E6]; portalRangeIndicator = (range > 0 ? L.geodesicCircle(coord, range, { fill: false, color: RANGE_INDICATOR_COLOR, weight: 3, clickable: false }) : L.circle(coord, range, { fill: false, stroke: false, clickable: false }) ).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() { - if(portalRangeIndicator) map.removeLayer(portalRangeIndicator); - portalRangeIndicator = null; - if(portalAccessIndicator) map.removeLayer(portalAccessIndicator); - portalAccessIndicator = null; + portalAccessIndicator = L.circle(coord, HACK_RANGE, + { fill: false, color: ACCESS_INDICATOR_COLOR, weight: 2, clickable: false } + ).addTo(map); } - // highlights portal with given GUID. Automatically clears highlights // on old selection. Returns false if the selected portal changed. // Returns true if it's still the same portal that just needs an // update. window.selectPortal = function(guid) { var update = selectedPortal === guid; - var oldPortal = portals[selectedPortal]; - if(!update && oldPortal) setMarkerStyle(oldPortal,false); - + var oldPortalGuid = selectedPortal; selectedPortal = guid; - if(portals[guid]) { -// resonatorsSetSelectStyle(guid); + var oldPortal = portals[oldPortalGuid]; + var newPortal = portals[guid]; - setMarkerStyle(portals[guid], true); + // Restore style of unselected portal + if(!update && oldPortal) setMarkerStyle(oldPortal,false); - if (map.hasLayer(portals[guid])) { - portals[guid].bringToFront(); + // Change style of selected portal + 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; } - - -window.unselectOldPortal = function() { - var oldPortal = portals[selectedPortal]; - if(oldPortal) setMarkerStyle(oldPortal,false); - selectedPortal = null; - $('#portaldetails').html(''); - if(isSmartphone()) { - $('.fullimg').remove(); - $('#mobileinfo').html(''); - } - clearPortalIndicators(); -} diff --git a/plugins/bookmarks-by-zaso.user.js b/plugins/bookmarks-by-zaso.user.js index efbb5f62..b4a647a1 100644 --- a/plugins/bookmarks-by-zaso.user.js +++ b/plugins/bookmarks-by-zaso.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-bookmarks@ZasoGD // @name IITC plugin: Bookmarks for maps and portals // @category Controls -// @version 0.2.3.@@DATETIMEVERSION@@ +// @version 0.2.4.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -841,7 +841,14 @@ $('#portaldetails').before(window.plugin.bookmarks.htmlBoxTrigger + window.plugin.bookmarks.htmlBkmrksBox); // Remove the star + window.addHook('portalSelected', function(data) { + if(data.selectedPortalGuid === null) { + $('.bkmrksStar').remove(); + } + }); + // in the future i hope in a 'portalClosed' hook + /* hook done window.unselectOldPortal = function() { var oldPortal = portals[selectedPortal]; if(oldPortal) portalResetColor(oldPortal); @@ -854,6 +861,7 @@ clearPortalIndicators(); $('.bkmrksStar').remove(); } + */ } $('#toolbox').append(window.plugin.bookmarks.htmlCallSetBox+window.plugin.bookmarks.htmlCalldrawBox);