From 3bfd83a0c29d38294dc1ca91278fc49f018c63ff Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sun, 1 Dec 2013 15:18:44 +0000 Subject: [PATCH] method to attempt to find a portal lat/lng from guid, even if the portal data isn't available (we can also search through links and fields) - minimal testing added note concerning unfinished/temporary nature of the portal details API --- code/portal_data.js | 40 ++++++++++++++++++++++++++++++++++++++++ code/portal_detail.js | 4 ++++ 2 files changed, 44 insertions(+) diff --git a/code/portal_data.js b/code/portal_data.js index 867bb464..cf5aa62b 100644 --- a/code/portal_data.js +++ b/code/portal_data.js @@ -39,3 +39,43 @@ window.getPortalFields = function(guid) { return fields; } + + +// find the lat/lon for a portal, using any and all available data +// (we have the list of portals, the cached portal details, plus links and fields as sources of portal locations) +window.findPortalLatLng = function(guid) { + if (window.portals[guid]) { + return window.portals[guid].getLatLng(); + } + + // not found in portals - try the cached (and possibly stale) details - good enough for location + var details = portalDetail.get(guid); + if (details) { + return L.latLng (details.locationE6.latE6/1E6, details.locationE6.lngE6/1E6); + } + + // now try searching through fields + for (var fguid in window.fields) { + var f = window.fields[fguid].options.data; + + for (var i in f.points) { + if (f.points[i].guid == guid) { + return L.latLng (f.points[i].latE6/1E6, f.points[i].lngE6/1E6); + } + } + } + + // and finally search through links + for (var lguid in window.links) { + var l = window.links[lguid].options.data; + if (l.oGuid == guid) { + return L.latLng (l.oLatE6/1E6, l.oLngE6/1E6); + } + if (l.dGuid == guid) { + return L.latLng (l.dLatE6/1E6, l.dLngE6/1E6); + } + } + + // no luck finding portal lat/lng + return undefined; +} diff --git a/code/portal_detail.js b/code/portal_detail.js index f33da496..e99d5b7a 100644 --- a/code/portal_detail.js +++ b/code/portal_detail.js @@ -1,6 +1,10 @@ /// PORTAL DETAIL ////////////////////////////////////// // code to retrieve the new potal detail data from the servers +// NOTE: the API for portal detailed information is NOT FINAL +// this is a temporary measure to get things working again after a major change to the intel map +// API. expect things to change here + // anonymous function wrapper for the code - any variables/functions not placed into 'window' will be private (function(){