Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix update edit link, add query parameters for map feedback #4685

Merged
merged 10 commits into from
May 31, 2017
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 */
}
13 changes: 11 additions & 2 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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I'm understanding this right, the change from .mapboxgl-improve-map to .mapbox-improve-map is in order to match against the CSS class used in our the TileJSON provided by Mapbox's vector tile sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct @anandthakker - I will ticket out changing that css class at the API level separately

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())}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we dropping the +1 from this._map.getZoom() + 1? Was it incorrect in the first place?

Copy link
Contributor Author

@mollymerp mollymerp May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anandthakker GL and raster zoom levels are off by one 😊. the old map-feedback link used Mapbox.js and therefore we had to add a zoom level to the hash for the link to open at the right spot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still necessary to round the zoom level?

if (this.styleOwner && this.styleId) {
this._editLink.href += `?owner=${this.styleOwner}&id=${this.styleId}`;
}
}
}

Expand All @@ -85,6 +88,12 @@ 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();
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just omit these params if owner or id isn't set rather than passing defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these aren't defaults – I set them up at L17-18 😛

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg I'm reading through the test 😭 😭 😭 😭

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');
Copy link
Member

@tristen tristen May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that needs to change! hash should follow params. Structure should look like this:

https://www.mapbox.com/feedback/?owner=mapbox&id=streets-v10#/0/0/2

t.end();
}
});
Expand Down