diff --git a/www/index.html b/www/index.html index 1ac6a8fc..9e8a6221 100644 --- a/www/index.html +++ b/www/index.html @@ -873,6 +873,11 @@ Open all headings (for WikiMedia ZIMs: sets the state of collapsible headings on article load) + diff --git a/www/js/app.js b/www/js/app.js index 490ec45c..e34b6d31 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1608,6 +1608,11 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett } openAllSections(); }); + document.getElementById('useOSMCheck').addEventListener('click', function () { + params.mapsURI = this.checked ? 'https://www.openstreetmap.org/' : 'bingmaps:'; + settingsStore.setItem('mapsURI', params.mapsURI, Infinity); + params.themeChanged = true; + }); $('input:radio[name=useMathJax]').on('click', function (e) { params.useMathJax = /true/i.test(this.value); settingsStore.setItem('useMathJax', params.useMathJax, Infinity); @@ -3706,20 +3711,36 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett //Adapt German Wikivoyage POI data format var regexpGeoLocationDE = /([^<]+)[\s\S]+?longitude">([^<]+)<[\s\S]+?(]+?listing-name[^>]+>(?:]+>)?([^<]+))/ig; htmlArticle = htmlArticle.replace(regexpGeoLocationDE, function (match, latitude, longitude, href, id) { - return '\r\nMap marker\r\n' + href; + var html; + if (/bingmaps/.test(params.mapsURI)) { + html = '\r\n'; + } + if (/openstreetmap/.test(params.mapsURI)) { + html = '\r\n'; + } + html += 'Map marker\r\n' + href; + return html; }); //Adapt English Wikivoyage POI data format var regexpGeoLocationEN = /(href\s?=\s?")geo:([^,]+),([^"]+)("[^>]+?(?:data-zoom[^"]+"([^"]+))?[^>]+>)[^<]+(<\/a>[\s\S]+?]+listing-name)[\s\S]+?id\s?=\s?")([^"]+)/ig; - htmlArticle = htmlArticle.replace(regexpGeoLocationEN, function (match, p1, latitude, longitude, p4, p5, p6, id) { - return p1 + "bingmaps://?collection=point." + latitude + "_" + longitude + "_" + - encodeURIComponent(id.replace(/_/g, " ")).replace(/\.(\w\w)/g, "%$1") + - (p5 ? "\&lvl=" + p5 : "") + p4.replace(/style\s?="\s?background:[^"]+"\s?/i, "") + 'Map marker' + p6 + id; + htmlArticle = htmlArticle.replace(regexpGeoLocationEN, function (match, hrefAttr, latitude, longitude, p4, p5, p6, id) { + var html; + if (/bingmaps/.test(params.mapsURI)) { + html = hrefAttr + params.mapsURI + '?collection=point.' + latitude + '_' + longitude + '_' + + encodeURIComponent(id.replace(/_/g, ' ')).replace(/\.(\w\w)/g, '%$1') + + (p5 ? '\&lvl=' + p5 : '') + p4.replace(/style=["']\s?background:[^"']+["']/i, ''); + } + if (/openstreetmap/.test(params.mapsURI)) { + html = hrefAttr + params.mapsURI + '?mlat=' + latitude + '&mlon=' + longitude + '#map=18/' + latitude + '/' + longitude + + p4.replace(/style=["']\s?background:[^"']+["']/i, ''); + } + html += 'Map marker' + p6 + id; + return html; }); //Clean up remaining geo: links - htmlArticle = htmlArticle.replace(/href\s*=\s*"\s*geo:([\d.-]+),([\d.-]+)/ig, 'href="bingmaps://?collection=point.$1_$2_' + encodeURIComponent(dirEntry.getTitleOrUrl())); + htmlArticle = htmlArticle.replace(/href=['"]geo:([\d.-]+),([\d.-]+)[^'"]*/ig, 'href="bingmaps://?collection=point.$1_$2_' + encodeURIComponent(dirEntry.getTitleOrUrl())); // Process any app:// links (these are always from the app payload) to match the current protocol htmlArticle = htmlArticle.replace(/(['"])app:\/\//g, function (p0, p1) { diff --git a/www/js/init.js b/www/js/init.js index 9085e8e1..5a9ad746 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -94,6 +94,7 @@ params['allowInternetAccess'] = getSetting('allowInternetAccess'); params['windowOpener'] = getSetting('windowOpener'); // 'tab|window|false' A setting that determines whether right-click/long-press of a ZIM link opens a new window/tab params['rightClickType'] = getSetting('rightClickType'); // 'single|double|false' A setting that determines whether a single or double right-click is used to open a new window/tab params['navButtonsPos'] = getSetting('navButtonsPos') || 'bottom'; // 'top|bottom' A setting that determines where the back-forward nav buttons appear +params['mapsURI'] = getSetting('mapsURI') || 'bingmaps:'; // Protocol with colon ('bingmaps:') or URL with final slash ('https://www.openstreetmap.org/') //Do not touch these values unless you know what they do! Some are global variables, some are set programmatically params['imageDisplayMode'] = params.imageDisplay ? 'progressive' : 'manual'; @@ -206,6 +207,7 @@ document.getElementById('removePageMaxWidthCheck').indeterminate = params.remove document.getElementById('removePageMaxWidthCheck').readOnly = params.removePageMaxWidth == "auto"; document.getElementById('pageMaxWidthState').innerHTML = (params.removePageMaxWidth == "auto" ? "auto" : params.removePageMaxWidth ? "always" : "never"); document.getElementById('openAllSectionsCheck').checked = params.openAllSections; +document.getElementById('useOSMCheck').checked = /openstreetmap/.test(params.mapsURI); document.getElementById('cssUIDarkThemeCheck').checked = params.cssUITheme == "dark"; // Will be true, or false if light or auto document.getElementById('cssUIDarkThemeCheck').indeterminate = params.cssUITheme == "auto"; document.getElementById('cssUIDarkThemeCheck').readOnly = params.cssUITheme == "auto";