Skip to content

Commit

Permalink
Review per @ryanhamley
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Corbin committed Sep 4, 2019
1 parent 533dd54 commit 276b677
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/ui/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Hash {
return part;
}).filter(a => a);
if (!found) {
parts.push(`${this._hashName || ''}=${hash}`);
parts.push(`${this._hashName}=${hash}`);
}
return `#${parts.join('&')}`;
}
Expand All @@ -100,6 +100,7 @@ class Hash {
_getCurrentHash() {
const hash = window.location.hash.replace('#', '');
if (this._hashName) {
// Split the parameter-styled hash into parts and find the value we need
const keyval = hash.split('&').map(
part => part.split('=')
).find(part => part[0] === this._hashName);
Expand All @@ -110,7 +111,7 @@ class Hash {

_onHashChange() {
const loc = this._getCurrentHash();
if (loc.length >= 3 && !loc.some(v => isNaN(+v))) {
if (loc.length >= 3 && !loc.some(v => isNaN(v))) {
this._map.jumpTo({
center: [+loc[2], +loc[1]],
zoom: +loc[0],
Expand Down
4 changes: 3 additions & 1 deletion src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ const defaultOptions = {
*
* @param {(boolean|string)} [options.hash=false] If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL.
* For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`.
* If a string is provided, it will be used as the name for a parameter-styled hash, e.g. `http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar`.
* An additional string may optionally be provided to indicate a parameter-styled hash,
* e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo
* is a custom parameter and bar is an arbitrary hash distinct from the map hash.
* @param {boolean} [options.interactive=true] If `false`, no mouse, touch, or keyboard listeners will be attached to the map, so it will not respond to interaction.
* @param {number} [options.bearingSnap=7] The threshold, measured in degrees, that determines when the map's
* bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/hash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test('hash', (t) => {
t.equal(map.getBearing(), 30);
t.equal(map.getPitch(), 60);

window.location.hash = '#4/wronlgy/formed/hash';
window.location.hash = '#4/wrongly/formed/hash';

t.false(hash._onHashChange());

Expand Down

0 comments on commit 276b677

Please sign in to comment.