diff --git a/js/index.js b/js/index.js index 9d7ffde..eb69409 100644 --- a/js/index.js +++ b/js/index.js @@ -263,10 +263,18 @@ } }; + var onInvalidHashChangeCb = function(params) { + params = params.replace('zoom=', 'map='); + params = params.replace('&lat=', '/'); + params = params.replace('&lon=', '/'); + params = params.replace('&layer=', '/'); + return params; + }; + urlHash = new L.Hash(map, mapLayers, function() { var url = router.getUrl(routing.getWaypoints(), null); return "&" + url.substr('brouter?'.length + 1); - }, onHashChangeCb); + }, onHashChangeCb, onInvalidHashChangeCb); routingOptions.on('update', urlHash.updateHash, urlHash); nogos.on('update', urlHash.updateHash, urlHash); // waypoint add, move, delete (but last) diff --git a/js/plugin/leaflet-fullHash.js b/js/plugin/leaflet-fullHash.js index c3eb1a6..3ccd2de 100644 --- a/js/plugin/leaflet-fullHash.js +++ b/js/plugin/leaflet-fullHash.js @@ -5,10 +5,11 @@ (doc_mode === undefined || doc_mode > 7); })(); - L.Hash = function(map, layers, additionalCb, onHashChangeCb) { + L.Hash = function(map, layers, additionalCb, onHashChangeCb, onInvalidHashChangeCb) { this.onHashChange = L.Util.bind(this.onHashChange, this); this.additionalCb = additionalCb; this.onHashChangeCb = onHashChangeCb; + this.onInvalidHashChangeCb = onInvalidHashChangeCb; this.layers = layers; if (map) { this.init(map, layers); @@ -127,6 +128,16 @@ return; } var parsed = this.parseHash(hash); + if (!parsed) { + // migration from old hash style to new one + if (this.onInvalidHashChangeCb != null) { + var newHash = this.onInvalidHashChangeCb(hash); + if (newHash != null && newHash != hash) { + parsed = this.parseHash(newHash); + } + } + } + if (parsed) { this.isUpdatingHash = true;