mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 21:28:11 +02:00
Don't exit drawing mode on hashchange unless the user has moved a lot
(Switching background while drawing a line was causing the line to get cancelled because of returning to browse mode) (closes #4099)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as d3 from 'd3';
|
||||
import _ from 'lodash';
|
||||
import { geoSphericalDistance } from '../geo';
|
||||
import { modeBrowse } from '../modes';
|
||||
import { utilQsString, utilStringQs } from '../util';
|
||||
|
||||
@@ -12,13 +13,21 @@ export function behaviorHash(context) {
|
||||
var parser = function(map, s) {
|
||||
var q = utilStringQs(s);
|
||||
var args = (q.map || '').split('/').map(Number);
|
||||
|
||||
if (args.length < 3 || args.some(isNaN)) {
|
||||
return true; // replace bogus hash
|
||||
} else if (s !== formatter(map).slice(1)) {
|
||||
var mode = context.mode();
|
||||
if (mode && mode.id.match(/^draw/) !== null) {
|
||||
|
||||
} else if (s !== formatter(map).slice(1)) { // hash has changed
|
||||
var mode = context.mode(),
|
||||
dist = geoSphericalDistance(map.center(), [args[2], args[1]]),
|
||||
maxdist = 500;
|
||||
|
||||
// Don't allow the hash location to change too much while drawing
|
||||
// This can happen if the user accidently hit the back button. #3996
|
||||
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]);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user