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) {