From 631d459f56cc4abf7332e72efd25fcb7e32935a1 Mon Sep 17 00:00:00 2001 From: fkloft Date: Mon, 10 Aug 2015 22:16:09 +0200 Subject: [PATCH] [missions] fix mission permalinks not working if mission is not in cache fixed issue #1034 --- plugins/missions.user.js | 41 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/missions.user.js b/plugins/missions.user.js index 99dbc2db..63846503 100644 --- a/plugins/missions.user.js +++ b/plugins/missions.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-missions@jonatkins // @name IITC plugin: Missions // @category Info -// @version 0.1.1.@@DATETIMEVERSION@@ +// @version 0.1.2.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -228,13 +228,17 @@ window.plugin.missions = { }, zoomToMission: function(mission) { + map.fitBounds(this.getMissionBounds(mission), {maxZoom: 17}); + }, + + getMissionBounds: function(mission) { var latlngs = mission.waypoints.filter(function(waypoint) { return !!waypoint.portal; }).map(function(waypoint) { return [waypoint.portal.latE6/1E6, waypoint.portal.lngE6/1E6]; }); - map.fitBounds(L.latLngBounds(latlngs), {maxZoom: 17}); + return L.latLngBounds(latlngs); }, loadMissionsInBounds: function(bounds, callback, errorcallback) { @@ -857,10 +861,21 @@ window.plugin.missions = { }, // called after IITC and all plugin loaded - registerFieldForSyncing: function() { - if(!window.plugin.sync) return; - window.plugin.sync.registerMapForSync('missions', 'checkedMissions', this.syncCallback.bind(this), this.syncInitialed.bind(this)); - window.plugin.sync.registerMapForSync('missions', 'checkedWaypoints', this.syncCallback.bind(this), this.syncInitialed.bind(this)); + onIITCLoaded: function() { + var match = location.pathname.match(/\/mission\/([0-9a-z.]+)/); + if(match && match[1]) { + var mid = match[1]; + + this.loadMission(mid, function(mission) { + this.openMission(mid); + this.zoomToMission(mission); + }.bind(this)); + } + + if(window.plugin.sync) { + window.plugin.sync.registerMapForSync('missions', 'checkedMissions', this.syncCallback.bind(this), this.syncInitialed.bind(this)); + window.plugin.sync.registerMapForSync('missions', 'checkedWaypoints', this.syncCallback.bind(this), this.syncInitialed.bind(this)); + } }, // called after local or remote change uploaded @@ -962,12 +977,7 @@ window.plugin.missions = { // mission may be a cached mission or contain the full details if(mission.waypoints) { - var latlngs = mission.waypoints.filter(function(waypoint) { - return !!waypoint.portal; - }).map(function(waypoint) { - return [waypoint.portal.latE6/1E6, waypoint.portal.lngE6/1E6]; - }); - result.bounds = L.latLngBounds(latlngs) + result.bounds = this.getMissionBounds(mission); } if(mission.typeNum) { result.icon = this.missionTypeImages[mission.typeNum] || this.missionTypeImages[0]; @@ -1078,13 +1088,8 @@ window.plugin.missions = { window.addHook('plugin-missions-missions-refreshed', this.onMissionsRefreshed.bind(this)); window.addHook('plugin-missions-waypoint-changed', this.onWaypointChanged.bind(this)); window.addHook('plugin-missions-waypoints-refreshed', this.onWaypointsRefreshed.bind(this)); - window.addHook('iitcLoaded', this.registerFieldForSyncing.bind(this)); - var match = location.pathname.match(/\/mission\/([0-9a-z.]+)/); - if(match && match[1]) { - var mid = match[1]; - this.openMission(mid); - } + window.addHook('iitcLoaded', this.onIITCLoaded.bind(this)); } };