From 1b3098a17d5604390cca8be6d4ff5462d72b4a00 Mon Sep 17 00:00:00 2001 From: johndoe Date: Mon, 18 Nov 2019 19:32:16 +0200 Subject: [PATCH] utils_misc.js: window.makePermalink: improve func signature pass options' object with named properties (instead of unclear boolean positional parameters) --- code/smartphone.js | 2 +- code/utils_misc.js | 19 ++++++++++++------- plugins/draw-tools.user.js | 5 ++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/code/smartphone.js b/code/smartphone.js index e27057378..de01e143a 100644 --- a/code/smartphone.js +++ b/code/smartphone.js @@ -181,7 +181,7 @@ window.runOnSmartphonesAfterBoot = function() { window.setAndroidPermalink = function() { var p = window.selectedPortal && window.portals[window.selectedPortal]; var href = $('') - .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); } diff --git a/code/utils_misc.js b/code/utils_misc.js index a99125669..cf2afc2a9 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -477,17 +477,22 @@ 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()) } @@ -495,7 +500,7 @@ window.makePermalink = function(latlng, mapView, absolute) { 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('&'); }; diff --git a/plugins/draw-tools.user.js b/plugins/draw-tools.user.js index aee9ba1df..8eeaf6e3b 100644 --- a/plugins/draw-tools.user.js +++ b/plugins/draw-tools.user.js @@ -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);