mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
added local storage for map hash, will now load last used map hash for user on map init
This commit is contained in:
@@ -8,7 +8,7 @@ import { modeSelect } from '../modes/select';
|
||||
import { utilDisplayLabel, utilObjectOmit, utilQsString, utilStringQs } from '../util';
|
||||
import { utilArrayIdentical } from '../util/array';
|
||||
import { t } from '../core/localizer';
|
||||
|
||||
import { prefs } from '../core/preferences';
|
||||
|
||||
export function behaviorHash(context) {
|
||||
|
||||
@@ -28,7 +28,7 @@ export function behaviorHash(context) {
|
||||
var newParams = {};
|
||||
|
||||
delete oldParams.id;
|
||||
var selected = context.selectedIDs().filter(function(id) {
|
||||
var selected = context.selectedIDs().filter(function (id) {
|
||||
return context.hasEntity(id);
|
||||
});
|
||||
if (selected.length) {
|
||||
@@ -53,12 +53,12 @@ export function behaviorHash(context) {
|
||||
var changeCount;
|
||||
var titleID;
|
||||
|
||||
var selected = context.selectedIDs().filter(function(id) {
|
||||
var selected = context.selectedIDs().filter(function (id) {
|
||||
return context.hasEntity(id);
|
||||
});
|
||||
if (selected.length) {
|
||||
var firstLabel = utilDisplayLabel(context.entity(selected[0]), context.graph());
|
||||
if (selected.length > 1 ) {
|
||||
if (selected.length > 1) {
|
||||
contextual = t('title.labeled_and_more', {
|
||||
labeled: firstLabel,
|
||||
count: selected.length - 1
|
||||
@@ -109,11 +109,17 @@ export function behaviorHash(context) {
|
||||
|
||||
// set the title we want displayed for the browser tab/window
|
||||
updateTitle(true /* includeChangeCount */);
|
||||
|
||||
//save last used map hash/location for future
|
||||
const mapHash = latestHash.split("map=");
|
||||
if (mapHash.length == 2) {
|
||||
prefs("map-hash", mapHash[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _throttledUpdate = _throttle(updateHashIfNeeded, 500);
|
||||
var _throttledUpdateTitle = _throttle(function() {
|
||||
var _throttledUpdateTitle = _throttle(function () {
|
||||
updateTitle(true /* includeChangeCount */);
|
||||
}, 500);
|
||||
|
||||
@@ -140,7 +146,7 @@ export function behaviorHash(context) {
|
||||
context.map().centerZoom([mapArgs[2], Math.min(_latitudeLimit, Math.max(-_latitudeLimit, mapArgs[1]))], mapArgs[0]);
|
||||
|
||||
if (q.id && mode) {
|
||||
var ids = q.id.split(',').filter(function(id) {
|
||||
var ids = q.id.split(',').filter(function (id) {
|
||||
return context.hasEntity(id);
|
||||
});
|
||||
if (ids.length &&
|
||||
@@ -181,8 +187,8 @@ export function behaviorHash(context) {
|
||||
|
||||
if (q.id) {
|
||||
//if (!context.history().hasRestorableChanges()) {
|
||||
// targeting specific features: download, select, and zoom to them
|
||||
context.zoomToEntity(q.id.split(',')[0], !q.map);
|
||||
// targeting specific features: download, select, and zoom to them
|
||||
context.zoomToEntity(q.id.split(',')[0], !q.map);
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -193,6 +199,21 @@ export function behaviorHash(context) {
|
||||
if (q.map) {
|
||||
behavior.hadHash = true;
|
||||
}
|
||||
else if (prefs("map-hash")) {
|
||||
//user has existing map location hash, set hash & map to location
|
||||
const mapHash = prefs("map-hash");
|
||||
let currentHash = computedHash();
|
||||
|
||||
currentHash = currentHash.substring(0, currentHash.indexOf("map=")) + "map=" + mapHash;
|
||||
|
||||
window.history.replaceState(null, computedTitle(false /* includeChangeCount */), currentHash);
|
||||
const mapArgs = mapHash.split('/').map(Number);
|
||||
context.map().centerZoom([mapArgs[2], Math.min(_latitudeLimit, Math.max(-_latitudeLimit, mapArgs[1]))], mapArgs[0]);
|
||||
|
||||
_cachedHash = window.location.hash;
|
||||
|
||||
behavior.hadHash = true;
|
||||
}
|
||||
|
||||
hashchange();
|
||||
|
||||
@@ -200,7 +221,7 @@ export function behaviorHash(context) {
|
||||
}
|
||||
}
|
||||
|
||||
behavior.off = function() {
|
||||
behavior.off = function () {
|
||||
_throttledUpdate.cancel();
|
||||
_throttledUpdateTitle.cancel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user