Reduce changes with upstream
This commit is contained in:
parent
3d3dd376a4
commit
915189b171
2 changed files with 33 additions and 31 deletions
23
js/index.js
23
js/index.js
|
|
@ -71,7 +71,7 @@
|
||||||
if (result) {
|
if (result) {
|
||||||
routing.clear();
|
routing.clear();
|
||||||
onUpdate();
|
onUpdate();
|
||||||
urlHash.updateHash();
|
urlHash.onMapMove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -271,19 +271,24 @@
|
||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
urlHash = new L.Hash(map, mapLayers, function() {
|
urlHash = new L.Hash(map, mapLayers);
|
||||||
var url = router.getUrl(routing.getWaypoints(), null);
|
urlHash.additionalCb = function() {
|
||||||
return '&' + url.substr('brouter?'.length+1);
|
var url = router.getUrl(routing.getWaypoints(), null);
|
||||||
}, onHashChangeCb, onInvalidHashChangeCb);
|
return '&' + url.substr('brouter?'.length+1);
|
||||||
routingOptions.on('update', urlHash.updateHash, urlHash);
|
};
|
||||||
nogos.on('update', urlHash.updateHash, urlHash);
|
urlHash.onHashChangeCb = onHashChangeCb;
|
||||||
|
urlHash.onInvalidHashChangeCb = onInvalidHashChangeCb;
|
||||||
|
urlHash.layers = mapLayers;
|
||||||
|
|
||||||
|
routingOptions.on('update', urlHash.onMapMove, urlHash);
|
||||||
|
nogos.on('update', urlHash.onMapMove, urlHash);
|
||||||
// waypoint add, move, delete (but last)
|
// waypoint add, move, delete (but last)
|
||||||
routing.on('routing:routeWaypointEnd', urlHash.updateHash, urlHash);
|
routing.on('routing:routeWaypointEnd', urlHash.onMapMove, urlHash);
|
||||||
// delete last waypoint
|
// delete last waypoint
|
||||||
routing.on('waypoint:click', function (evt) {
|
routing.on('waypoint:click', function (evt) {
|
||||||
var r = evt.marker._routing;
|
var r = evt.marker._routing;
|
||||||
if (!r.prevMarker && !r.nextMarker) {
|
if (!r.prevMarker && !r.nextMarker) {
|
||||||
urlHash.updateHash();
|
urlHash.onMapMove();
|
||||||
}
|
}
|
||||||
}, urlHash);
|
}, urlHash);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,11 @@
|
||||||
(doc_mode === undefined || doc_mode > 7);
|
(doc_mode === undefined || doc_mode > 7);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
L.Hash = function(map, layers, additionalCb, onHashChangeCb, onInvalidHashChangeCb) {
|
L.Hash = function(map, options) {
|
||||||
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
||||||
this.additionalCb = additionalCb;
|
|
||||||
this.onHashChangeCb = onHashChangeCb;
|
|
||||||
this.onInvalidHashChangeCb = onInvalidHashChangeCb;
|
|
||||||
this.layers = layers;
|
|
||||||
if (map) {
|
if (map) {
|
||||||
this.init(map, layers);
|
this.init(map, options);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -49,8 +46,9 @@
|
||||||
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
|
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
|
||||||
layers = [];
|
layers = [];
|
||||||
|
|
||||||
|
//console.log(this.options);
|
||||||
var options = this.options;
|
var options = this.options;
|
||||||
//Check active layer
|
//Check active layers
|
||||||
for(var key in options) {
|
for(var key in options) {
|
||||||
if (options.hasOwnProperty(key)) {
|
if (options.hasOwnProperty(key)) {
|
||||||
if (map.hasLayer(options[key])) {
|
if (map.hasLayer(options[key])) {
|
||||||
|
|
@ -106,11 +104,11 @@
|
||||||
this.map = null;
|
this.map = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateHash: function() {
|
onMapMove: function() {
|
||||||
// bail if we're moving the map (updating from a hash),
|
// bail if we're moving the map (updating from a hash),
|
||||||
// or if the map is not yet loaded
|
// or if the map is not yet loaded
|
||||||
|
|
||||||
if (this.isUpdatingHash || !this.map._loaded) {
|
if (this.movingMap || !this.map._loaded) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,7 +119,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isUpdatingHash: false,
|
movingMap: false,
|
||||||
update: function() {
|
update: function() {
|
||||||
var hash = location.hash;
|
var hash = location.hash;
|
||||||
if (hash === this.lastHash) {
|
if (hash === this.lastHash) {
|
||||||
|
|
@ -139,16 +137,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsed) {
|
if (parsed) {
|
||||||
this.isUpdatingHash = true;
|
this.movingMap = true;
|
||||||
|
|
||||||
this.map.setView(parsed.center, parsed.zoom);
|
this.map.setView(parsed.center, parsed.zoom);
|
||||||
|
var layers = parsed.layers.length > 0 ? parsed.layers : [Object.keys(options)[0]],
|
||||||
if (this.onHashChangeCb != null) {
|
options = this.options,
|
||||||
this.onHashChangeCb(parsed.additional);
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = this.options,
|
|
||||||
layers = parsed.layers.length > 0 ? parsed.layers : [Object.keys(options)[0]],
|
|
||||||
that = this;
|
that = this;
|
||||||
//Add/remove layer
|
//Add/remove layer
|
||||||
this.map.eachLayer(function(layer) {
|
this.map.eachLayer(function(layer) {
|
||||||
|
|
@ -165,9 +158,13 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.isUpdatingHash = false;
|
if (this.onHashChangeCb != null) {
|
||||||
|
this.onHashChangeCb(parsed.additional);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.movingMap = false;
|
||||||
} else {
|
} else {
|
||||||
this.updateHash(this.map);
|
this.onMapMove(this.map);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -189,7 +186,7 @@
|
||||||
isListening: false,
|
isListening: false,
|
||||||
hashChangeInterval: null,
|
hashChangeInterval: null,
|
||||||
startListening: function() {
|
startListening: function() {
|
||||||
this.map.on("moveend layeradd layerremove", this.updateHash, this);
|
this.map.on("moveend layeradd layerremove", this.onMapMove, this);
|
||||||
|
|
||||||
if (HAS_HASHCHANGE) {
|
if (HAS_HASHCHANGE) {
|
||||||
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
|
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
|
||||||
|
|
@ -201,7 +198,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
stopListening: function() {
|
stopListening: function() {
|
||||||
this.map.off("moveend layeradd layerremove", this.updateHash, this);
|
this.map.off("moveend layeradd layerremove", this.onMapMove, this);
|
||||||
|
|
||||||
if (HAS_HASHCHANGE) {
|
if (HAS_HASHCHANGE) {
|
||||||
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
|
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue