Skip to content

Commit

Permalink
Merge pull request #773 from modos189/feature/iitc_utils
Browse files Browse the repository at this point in the history
IITC.utils API
  • Loading branch information
modos189 authored Nov 9, 2024
2 parents 6462fbe + f46cfdf commit e4f2084
Show file tree
Hide file tree
Showing 11 changed files with 1,409 additions and 647 deletions.
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ Parts imported from other projects remain under their respective licenses:
- [**delaunay.js**](https://github.com/ironwallaby/delaunay) © [_Jay LaPorte_](http://ironwallaby.github.io/): [[CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/)]
- [**s2-geometry-javascript**](https://github.com/jonatkins/s2-geometry-javascript) © _Jon Atkins_: [LICENSE: same as IITC]
- [**ulog**](https://github.com/Download/ulog) © [_Stijn de Witt_](http://StijnDeWitt.com/): [[CC-BY-4.0](https://github.com/Download/ulog/blob/master/LICENSE.md)]
- [**pnpoly**](https://wrfranklin.org/Research/Short_Notes/pnpoly.html) © [_W Randolph Franklin (WRF)_](http://wrfranklin.org/nikola/pages/index.html): [[MIT with Attribution](https://wrfranklin.org/Research/Short_Notes/pnpoly.html)] used in: utils.js (isPointInPolygon)
12 changes: 12 additions & 0 deletions core/code/_deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,15 @@ window.findPortalLatLng = function (guid) {
// no luck finding portal lat/lng
return undefined;
};

// to be ovewritten in app.js
/**
* Finds the latitude and longitude for a portal using all available data sources.
* This includes the list of portals, cached portal details, and information from links and fields.
*
* @deprecated
* @function androidCopy
*/
window.androidCopy = function () {
return true; // i.e. execute other actions
};
46 changes: 46 additions & 0 deletions core/code/portal_data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global L -- eslint */

/**
* @file Contain misc functions to get portal info
* @module portal_data
Expand Down Expand Up @@ -73,6 +75,50 @@ window.getPortalFieldsCount = function (guid) {
return fields.length;
};

/**
* Zooms the map to a specific portal and shows its details if available.
*
* @function zoomToAndShowPortal
* @param {string} guid - The globally unique identifier of the portal.
* @param {L.LatLng|number[]} latlng - The latitude and longitude of the portal.
*/
window.zoomToAndShowPortal = function (guid, latlng) {
window.map.setView(latlng, window.DEFAULT_ZOOM);
// if the data is available, render it immediately. Otherwise defer
// until it becomes available.
if (window.portals[guid]) window.renderPortalDetails(guid);
else window.urlPortal = guid;
};

/**
* Selects a portal by its latitude and longitude.
*
* @function selectPortalByLatLng
* @param {number|Array|L.LatLng} lat - The latitude of the portal
* or an array or L.LatLng object containing both latitude and longitude.
* @param {number} [lng] - The longitude of the portal.
*/
window.selectPortalByLatLng = function (lat, lng) {
if (lng === undefined && lat instanceof Array) {
lng = lat[1];
lat = lat[0];
} else if (lng === undefined && lat instanceof L.LatLng) {
lng = lat.lng;
lat = lat.lat;
}
for (var guid in window.portals) {
var latlng = window.portals[guid].getLatLng();
if (latlng.lat === lat && latlng.lng === lng) {
window.renderPortalDetails(guid);
return;
}
}

// not currently visible
window.urlPortalLL = [lat, lng];
window.map.setView(window.urlPortalLL, window.DEFAULT_ZOOM);
};

(function () {
var cache = {};
var cache_level = 0;
Expand Down
59 changes: 59 additions & 0 deletions core/code/portal_detail_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,62 @@ window.selectPortal = function (guid) {
window.runHooks('portalSelected', { selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid });
return update;
};

/**
* Changes the coordinates and map scale to show the range for portal links.
*
* @function rangeLinkClick
*/
window.rangeLinkClick = function () {
if (window.portalRangeIndicator) window.map.fitBounds(window.portalRangeIndicator.getBounds());
if (window.isSmartphone()) window.show('map');
};

/**
* Creates a link to open a specific portal in Ingress Prime.
*
* @function makePrimeLink
* @param {string} guid - The globally unique identifier of the portal.
* @param {number} lat - The latitude of the portal.
* @param {number} lng - The longitude of the portal.
* @returns {string} The Ingress Prime link for the portal
*/
window.makePrimeLink = function (guid, lat, lng) {
return `https://link.ingress.com/?link=https%3A%2F%2Fintel.ingress.com%2Fportal%2F${guid}&apn=com.nianticproject.ingress&isi=576505181&ibi=com.google.ingress&ifl=https%3A%2F%2Fapps.apple.com%2Fapp%2Fingress%2Fid576505181&ofl=https%3A%2F%2Fintel.ingress.com%2Fintel%3Fpll%3D${lat}%2C${lng}`;
};

/**
* Generates a permalink URL based on the specified latitude and longitude and additional options.
*
* @param {L.LatLng|number[]} [latlng] - The latitude and longitude for the permalink.
* Can be omitted to create mapview-only permalink.
* @param {Object} [options] - Additional options for permalink generation.
* @param {boolean} [options.includeMapView] - Include current map view in the permalink.
* @param {boolean} [options.fullURL] - Generate a fully qualified URL (default: relative link).
* @returns {string} The generated permalink URL.
*/
window.makePermalink = function (latlng, options) {
options = options || {};

function round(l) {
// ensures that lat,lng are with same precision as in stock intel permalinks
return Math.floor(l * 1e6) / 1e6;
}
var args = [];
if (!latlng || options.includeMapView) {
var c = window.map.getCenter();
args.push('ll=' + [round(c.lat), round(c.lng)].join(','), 'z=' + window.map.getZoom());
}
if (latlng) {
if ('lat' in latlng) {
latlng = [latlng.lat, latlng.lng];
}
args.push('pll=' + latlng.join(','));
}
var url = '';
if (options.fullURL) {
url += new URL(document.baseURI).origin;
}
url += '/';
return url + '?' + args.join('&');
};
24 changes: 24 additions & 0 deletions core/code/portal_detail_display_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,27 @@ window.getMitigationText = function (d, linkCount) {

return ['shielding', mitigationShort, title];
};

/**
* Displays a dialog with links to show the specified location on various map services.
*
* @function showPortalPosLinks
* @param {number} lat - Latitude of the location.
* @param {number} lng - Longitude of the location.
* @param {string} name - Name of the location.
*/
window.showPortalPosLinks = function (lat, lng, name) {
var encoded_name = encodeURIComponent(name);
var qrcode = '<div id="qrcode"></div>';
var script = "<script>$('#qrcode').qrcode({text:'GEO:" + lat + ',' + lng + "'});</script>";
var gmaps = '<a href="https://maps.google.com/maps?ll=' + lat + ',' + lng + '&q=' + lat + ',' + lng + '%20(' + encoded_name + ')">Google Maps</a>';
var bingmaps =
'<a href="https://www.bing.com/maps/?v=2&cp=' + lat + '~' + lng + '&lvl=16&sp=Point.' + lat + '_' + lng + '_' + encoded_name + '___">Bing Maps</a>';
var osm = '<a href="https://www.openstreetmap.org/?mlat=' + lat + '&mlon=' + lng + '&zoom=16">OpenStreetMap</a>';
var latLng = '<span>' + lat + ',' + lng + '</span>';
window.dialog({
html: '<div style="text-align: center;">' + qrcode + script + gmaps + '; ' + bingmaps + '; ' + osm + '<br />' + latLng + '</div>',
title: name,
id: 'poslinks',
});
};
Loading

0 comments on commit e4f2084

Please sign in to comment.