diff --git a/src/ui/control/attribution_control.js b/src/ui/control/attribution_control.js index dfceca415db..d68443371e1 100644 --- a/src/ui/control/attribution_control.js +++ b/src/ui/control/attribution_control.js @@ -81,7 +81,7 @@ class AttributionControl { } return acc; }, `?`); - this._editLink.href = `https://www.mapbox.com/feedback/${paramString}${this._map.hash ? this._map.hash.getHashString() : ''}`; + this._editLink.href = `https://www.mapbox.com/feedback/${paramString}${this._map.hash ? this._map.hash.getHashString(true) : ''}`; } } diff --git a/src/ui/hash.js b/src/ui/hash.js index 9ed7bc77f0f..77af7663e35 100644 --- a/src/ui/hash.js +++ b/src/ui/hash.js @@ -42,16 +42,22 @@ class Hash { return this; } - getHashString() { + getHashString(mapFeedback) { const center = this._map.getCenter(), - zoom = this._map.getZoom(), + zoom = Math.round(this._map.getZoom() * 100) / 100, + precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)), + lng = Math.round(center.lng * Math.pow(10, precision))/ Math.pow(10, precision), + lat = Math.round(center.lat * Math.pow(10, precision)) / Math.pow(10, precision), bearing = this._map.getBearing(), - pitch = this._map.getPitch(), - precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); - - let hash = `#${Math.round(zoom * 100) / 100 - }/${Math.round(center.lat * Math.pow(10, precision)) / Math.pow(10, precision) - }/${Math.round(center.lng * Math.pow(10, precision)) / Math.pow(10, precision)}`; + pitch = this._map.getPitch(); + let hash = ''; + if (mapFeedback) { + // new map feedback site has some constraints that don't allow + // us to use the same hash format as we do for the Map hash option. + hash += `#/${lng}/${lat}/${zoom}`; + } else { + hash += `#${zoom}/${lat}/${lng}`; + } if (bearing || pitch) hash += (`/${Math.round(bearing * 10) / 10}`); if (pitch) hash += (`/${Math.round(pitch)}`); @@ -73,7 +79,7 @@ class Hash { } _updateHash() { - const hash = this.getHashString(this._map); + const hash = this.getHashString(); window.history.replaceState('', '', hash); } diff --git a/test/unit/ui/control/attribution.test.js b/test/unit/ui/control/attribution.test.js index a4e42cf219f..4dcb8940339 100644 --- a/test/unit/ui/control/attribution.test.js +++ b/test/unit/ui/control/attribution.test.js @@ -113,9 +113,9 @@ test('AttributionControl has the correct edit map link', (t) => { map.addSource('1', {type: 'vector', attribution: 'Improve this map'}); map.on('data', (e) => { if (e.dataType === 'source' && e.sourceDataType === 'metadata') { - t.equal(attribution._editLink.href, 'https://www.mapbox.com/feedback/?owner=mapbox&id=streets-v10&access_token=pk.123#0/0/0', 'edit link contains map location data'); + t.equal(attribution._editLink.href, 'https://www.mapbox.com/feedback/?owner=mapbox&id=streets-v10&access_token=pk.123#/0/0/0', 'edit link contains map location data'); map.setZoom(2); - t.equal(attribution._editLink.href, 'https://www.mapbox.com/feedback/?owner=mapbox&id=streets-v10&access_token=pk.123#2/0/0', 'edit link updates on mapmove'); + t.equal(attribution._editLink.href, 'https://www.mapbox.com/feedback/?owner=mapbox&id=streets-v10&access_token=pk.123#/0/0/2', 'edit link updates on mapmove'); t.end(); } });