Skip to content

Commit

Permalink
utils_misc.js: window.makePermalink: improve func signature
Browse files Browse the repository at this point in the history
pass options' object with named properties
(instead of unclear boolean positional parameters)
  • Loading branch information
johndoe committed Nov 18, 2019
1 parent e33e5d8 commit 1b3098a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion code/smartphone.js
Expand Up @@ -181,7 +181,7 @@ window.runOnSmartphonesAfterBoot = function() {
window.setAndroidPermalink = function() {
var p = window.selectedPortal && window.portals[window.selectedPortal];
var href = $('<a>')
.prop('href', window.makePermalink(p && p.getLatLng(), true))
.prop('href', window.makePermalink(p && p.getLatLng(), {includeMapView: true}))
.prop('href'); // to get absolute URI
android.setPermalink(href);
}
Expand Down
19 changes: 12 additions & 7 deletions code/utils_misc.js
Expand Up @@ -477,25 +477,30 @@ window.clampLatLngBounds = function(bounds) {
return new L.LatLngBounds ( clampLatLng(bounds.getSouthWest()), clampLatLng(bounds.getNorthEast()) );
}

// @function makePermalink(latlng?: LatLng, mapView?: Boolean, absolute?: Boolean): String
// Makes the permalink for the portal with specified latlng, possibly incluging current map view
// (at least one of two parameters have to be present).
// By default generate relative link, but absolute (full) also can be requested.
window.makePermalink = function(latlng, mapView, absolute) {
// @function makePermalink(latlng?: LatLng, options?: Object): String
// Makes the permalink for the portal with specified latlng, possibly including current map view.
// Portal latlng can be omitted to create mapview-only permalink.
// @option: includeMapView: Boolean = null
// Use to add zoom level and latlng of current map center.
// @option: fullURL: Boolean = null
// Use to make absolute fully qualified URL (default: relative link).
window.makePermalink = function(latlng, options) {//mapView, absolute
options = options || {}

function ll2str (ll) { return ll[0] + ',' + ll[1]; }
function round (ll) { // ensures that lat,lng are with same precision as in stock intel permalinks
return ll.map(function (n) { return Math.trunc(n*1e6)/1e6; });
}
var args = [];
if (mapView) {
if (!latlng || options.includeMapView) {
var c = window.map.getCenter();
args.push('ll='+ll2str(round([c.lat,c.lng])), 'z='+window.map.getZoom())
}
if (latlng) {
if ('lat' in latlng) { latlng = [latlng.lat, latlng.lng]; }
args.push('pll='+ll2str(latlng));
}
var url = absolute ? 'https://intel.ingress.com/' : '/';
var url = options.fullURL ? 'https://intel.ingress.com/' : '/';
return url + '/?' + args.join('&');
};

Expand Down
5 changes: 4 additions & 1 deletion plugins/draw-tools.user.js
Expand Up @@ -342,7 +342,10 @@ window.plugin.drawTools.optCopy = function() {
stockLinks.push([latLngs[latLngs.length-1].lat,latLngs[latLngs.length-1].lng,latLngs[0].lat,latLngs[0].lng]);
}
});
var stockUrl = window.makePermalink(false,true,true)+'&pls='+stockLinks.map(function(link){return link.join(',');}).join('_');
var stockUrl = window.makePermalink(null, {
includeMapView: true,
fullURL: true
}) + '&pls='+stockLinks.map(function(link){return link.join(',');}).join('_');
var stockWarnTexts = [];
if (stockWarnings.polyAsLine) stockWarnTexts.push('Note: polygons are exported as lines');
if (stockLinks.length>40) stockWarnTexts.push('Warning: Stock intel may not work with more than 40 line segments - there are '+stockLinks.length);
Expand Down

0 comments on commit 1b3098a

Please sign in to comment.