From 91b67277bd5a3c817e1007580df9630954ea6dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Kr=C3=B3l?= Date: Tue, 14 Jan 2020 18:47:19 +0100 Subject: [PATCH 1/4] update document title --- modules/behavior/hash.js | 37 ++++++++++++++++++++++++++++++++++--- modules/ui/tools/save.js | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 853b8f42c..6fdbd2c0f 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -2,6 +2,7 @@ import _throttle from 'lodash-es/throttle'; import { select as d3_select } from 'd3-selection'; +import { utilDisplayLabel } from '../util'; import { geoSphericalDistance } from '../geo'; import { modeBrowse } from '../modes/browse'; import { utilObjectOmit, utilQsString, utilStringQs } from '../util'; @@ -29,7 +30,6 @@ export function behaviorHash(context) { if (mode && mode.id.match(/^draw/) !== null && dist > maxdist) { context.enter(modeBrowse(context)); } - map.centerZoom([args[2], Math.min(lat, Math.max(-lat, args[1]))], args[0]); } }; @@ -51,6 +51,7 @@ export function behaviorHash(context) { if (selected.length) { newParams.id = selected.join(','); } + updateTitle(selected); newParams.map = zoom.toFixed(2) + '/' + center[1].toFixed(precision) + @@ -59,6 +60,33 @@ export function behaviorHash(context) { return '#' + utilQsString(Object.assign(q, newParams), true); }; + function updateTitle(selected){ + var oldTitle = document.title; + var endIndex = oldTitle.indexOf("-"); + var oldIDStr = oldTitle.substring(endIndex+2); + if (selected.length === 1) { + if (endIndex === -1) { + oldTitle += " - " + utilDisplayLabel(context.entity(selected[0]), context); + } + else { + var newIDStr = utilDisplayLabel(context.entity(selected[0]), context); + oldTitle = oldTitle.replace(oldIDStr, newIDStr); + } + } + else if (selected.length > 1 ) { + var newIDStr = utilDisplayLabel(context.entity(selected[0]), context) + " and " + (selected.length-1).toString() + " more"; + oldTitle = oldTitle.replace(oldIDStr, newIDStr); + } + else{ + if(endIndex !== -1){ + var oldIDStr = oldTitle.substring(endIndex); + oldTitle = oldTitle.replace(oldIDStr, ""); + } + } + document.title = oldTitle; + + } + function update() { if (context.inIntro()) return; @@ -94,8 +122,11 @@ export function behaviorHash(context) { var q = utilStringQs(window.location.hash.substring(1)); if (q.id) { - context.zoomToEntity(q.id.split(',')[0], !q.map); - } + if (!context.history().hasRestorableChanges()) { + // targeting specific features: download, select, and zoom to them + context.zoomToEntities(q.id.split(',')); + } + } // Store these here instead of updating local storage since local // storage could be flushed if the user discards pending changes diff --git a/modules/ui/tools/save.js b/modules/ui/tools/save.js index 1e0c4a57a..ecfaafb4b 100644 --- a/modules/ui/tools/save.js +++ b/modules/ui/tools/save.js @@ -51,10 +51,29 @@ export function uiToolSave(context) { } } + function updateTitle(val) { + var oldTitle = document.title; + var endIndex = oldTitle.indexOf(")"); + var oldIDStr = oldTitle.substring(0, endIndex+1); + var newIDStr = "iD (" + val.toString() + ")"; + if(val === 0) { + oldTitle = oldTitle.replace(oldIDStr, "iD"); + } + else if(_numChanges !== 0){ + oldTitle = oldTitle.replace(oldIDStr, newIDStr); + } + else { + oldTitle = oldTitle.replace("iD", newIDStr); + } + document.title = oldTitle; + } function updateCount() { var val = history.difference().summary().length; if (val === _numChanges) return; + + updateTitle(val); + _numChanges = val; if (tooltipBehavior) { From 6286d1430f01ce030c7fab41bd74a85e0befbe2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Kr=C3=B3l?= Date: Wed, 15 Jan 2020 01:50:07 +0100 Subject: [PATCH 2/4] fix titles - single quotes --- modules/behavior/hash.js | 17 +++++++++-------- modules/ui/tools/save.js | 12 ++++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 6fdbd2c0f..e4d32a9ef 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -62,11 +62,11 @@ export function behaviorHash(context) { function updateTitle(selected){ var oldTitle = document.title; - var endIndex = oldTitle.indexOf("-"); + var endIndex = oldTitle.indexOf('-'); var oldIDStr = oldTitle.substring(endIndex+2); if (selected.length === 1) { if (endIndex === -1) { - oldTitle += " - " + utilDisplayLabel(context.entity(selected[0]), context); + oldTitle += ' - ' + utilDisplayLabel(context.entity(selected[0]), context); } else { var newIDStr = utilDisplayLabel(context.entity(selected[0]), context); @@ -74,13 +74,13 @@ export function behaviorHash(context) { } } else if (selected.length > 1 ) { - var newIDStr = utilDisplayLabel(context.entity(selected[0]), context) + " and " + (selected.length-1).toString() + " more"; + newIDStr = utilDisplayLabel(context.entity(selected[0]), context) + ' and ' + (selected.length-1).toString() + ' more'; oldTitle = oldTitle.replace(oldIDStr, newIDStr); } - else{ - if(endIndex !== -1){ - var oldIDStr = oldTitle.substring(endIndex); - oldTitle = oldTitle.replace(oldIDStr, ""); + else { + if (endIndex !== -1){ + oldIDStr = oldTitle.substring(endIndex); + oldTitle = oldTitle.replace(oldIDStr, ''); } } document.title = oldTitle; @@ -92,7 +92,8 @@ export function behaviorHash(context) { if (context.inIntro()) return; var s1 = formatter(context.map()); if (s0 !== s1) { - window.location.replace(s0 = s1); // don't recenter the map! + s0 = s1; + window.location.replace(s0); // don't recenter the map! } } diff --git a/modules/ui/tools/save.js b/modules/ui/tools/save.js index ecfaafb4b..2e7526bc4 100644 --- a/modules/ui/tools/save.js +++ b/modules/ui/tools/save.js @@ -53,17 +53,17 @@ export function uiToolSave(context) { function updateTitle(val) { var oldTitle = document.title; - var endIndex = oldTitle.indexOf(")"); + var endIndex = oldTitle.indexOf(')'); var oldIDStr = oldTitle.substring(0, endIndex+1); - var newIDStr = "iD (" + val.toString() + ")"; - if(val === 0) { - oldTitle = oldTitle.replace(oldIDStr, "iD"); + var newIDStr = 'iD (' + val.toString() + ')'; + if (val === 0) { + oldTitle = oldTitle.replace(oldIDStr, 'iD'); } - else if(_numChanges !== 0){ + else if (_numChanges !== 0){ oldTitle = oldTitle.replace(oldIDStr, newIDStr); } else { - oldTitle = oldTitle.replace("iD", newIDStr); + oldTitle = oldTitle.replace('iD', newIDStr); } document.title = oldTitle; } From 28ab9fe15072532ba53d5071a3d7a66d86204de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Kr=C3=B3l?= Date: Wed, 15 Jan 2020 02:03:50 +0100 Subject: [PATCH 3/4] remove counting changes in title --- modules/ui/tools/save.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/modules/ui/tools/save.js b/modules/ui/tools/save.js index 2e7526bc4..e6d62dbe8 100644 --- a/modules/ui/tools/save.js +++ b/modules/ui/tools/save.js @@ -51,28 +51,10 @@ export function uiToolSave(context) { } } - function updateTitle(val) { - var oldTitle = document.title; - var endIndex = oldTitle.indexOf(')'); - var oldIDStr = oldTitle.substring(0, endIndex+1); - var newIDStr = 'iD (' + val.toString() + ')'; - if (val === 0) { - oldTitle = oldTitle.replace(oldIDStr, 'iD'); - } - else if (_numChanges !== 0){ - oldTitle = oldTitle.replace(oldIDStr, newIDStr); - } - else { - oldTitle = oldTitle.replace('iD', newIDStr); - } - document.title = oldTitle; - } - function updateCount() { var val = history.difference().summary().length; if (val === _numChanges) return; - updateTitle(val); _numChanges = val; From 316872ef59e73b215c15b97b211e218afc50d7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katarzyna=20Kr=C3=B3l?= Date: Wed, 15 Jan 2020 02:42:50 +0100 Subject: [PATCH 4/4] map location in title --- modules/behavior/hash.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index e4d32a9ef..58bb0c8e0 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -51,16 +51,18 @@ export function behaviorHash(context) { if (selected.length) { newParams.id = selected.join(','); } - updateTitle(selected); - + newParams.map = zoom.toFixed(2) + '/' + center[1].toFixed(precision) + '/' + center[0].toFixed(precision); + updateTitle(selected, center[1].toFixed(precision), center[0].toFixed(precision)); + return '#' + utilQsString(Object.assign(q, newParams), true); }; - function updateTitle(selected){ + function updateTitle(selected, center1, center0){ + //selection var oldTitle = document.title; var endIndex = oldTitle.indexOf('-'); var oldIDStr = oldTitle.substring(endIndex+2); @@ -82,7 +84,10 @@ export function behaviorHash(context) { oldIDStr = oldTitle.substring(endIndex); oldTitle = oldTitle.replace(oldIDStr, ''); } + //map location + oldTitle += ' - (' + center1 + ',' + center0 + ')'; } + document.title = oldTitle; }