Skip to content

Commit

Permalink
fix update edit link, add query parameters for map feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed May 5, 2017
1 parent 44641e9 commit 23e96c9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
10 changes: 7 additions & 3 deletions dist/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ a.mapboxgl-ctrl-logo {
color: inherit;
text-decoration: underline;
}
.mapboxgl-ctrl-attrib .mapboxgl-improve-map {
/* stylelint-disable */
.mapboxgl-ctrl-attrib .mapbox-improve-map {
font-weight: bold;
margin-left: 2px;
}

/*stylelint-enable*/
.mapboxgl-ctrl-scale {
background-color: rgba(255,255,255,0.75);
font-size: 10px;
Expand Down Expand Up @@ -318,8 +319,11 @@ a.mapboxgl-ctrl-logo {
border: 2px dotted #202020;
opacity: 0.5;
}

@media print {
.mapboxgl-improve-map {
/* stylelint-disable */
.mapbox-improve-map {
display:none;
}
/* stylelint-enable */
}
14 changes: 10 additions & 4 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ class AttributionControl {
}

_updateEditLink() {
if (!this._editLink) this._editLink = this._container.querySelector('.mapboxgl-improve-map');
if (!this._editLink) this._editLink = this._container.querySelector('.mapbox-improve-map');
if (this._editLink) {
const center = this._map.getCenter();
this._editLink.href = `https://www.mapbox.com/map-feedback/#/${
center.lng}/${center.lat}/${Math.round(this._map.getZoom() + 1)}`;
Math.round(center.lng * 1000) / 1000}/${Math.round(center.lat * 1000) / 1000}/${Math.round(this._map.getZoom())}`;
if (this.styleOwner && this.styleId) {
this._editLink.href += `?owner=${this.styleOwner}&id=${this.styleId}`;
}
}
}

Expand All @@ -85,14 +88,18 @@ class AttributionControl {
if (!this._map.style) return;
let attributions = [];

if (this._map.style.stylesheet) {
const stylesheet = this._map.style.stylesheet;
this.styleOwner = stylesheet.owner;
this.styleId = stylesheet.id;
}
const sourceCaches = this._map.style.sourceCaches;
for (const id in sourceCaches) {
const source = sourceCaches[id].getSource();
if (source.attribution && attributions.indexOf(source.attribution) < 0) {
attributions.push(source.attribution);
}
}

// remove any entries that are substrings of another entry.
// first sort by length so that substrings come first
attributions.sort((a, b) => a.length - b.length);
Expand All @@ -109,7 +116,6 @@ class AttributionControl {

_updateCompact() {
const compact = this._map.getCanvasContainer().offsetWidth <= 640;

this._container.classList[compact ? 'add' : 'remove']('mapboxgl-compact');
}

Expand Down
10 changes: 6 additions & 4 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function createMap() {
style: {
version: 8,
sources: {},
layers: []
layers: [],
owner: 'mapbox',
id: 'streets-v10'
}
});
}
Expand Down Expand Up @@ -105,12 +107,12 @@ test('AttributionControl has the correct edit map link', (t) => {
map.addControl(attribution);

map.on('load', () => {
map.addSource('1', {type: 'vector', attribution: '<a class="mapboxgl-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a>'});
map.addSource('1', {type: 'vector', attribution: '<a class="mapbox-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a>'});
map.on('data', (e) => {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/1', 'edit link contains map location data');
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/0?owner=mapbox&id=streets-v10', 'edit link contains map location data');
map.setZoom(2);
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/3', 'edit link updates on mapmove');
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/2?owner=mapbox&id=streets-v10', 'edit link updates on mapmove');
t.end();
}
});
Expand Down

0 comments on commit 23e96c9

Please sign in to comment.