Skip to content

Commit

Permalink
Dedupe attributions that are substrings of others
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Apr 15, 2016
1 parent 1a913cb commit 48d674f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/ui/control/attribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ Attribution.prototype = util.inherit(Control, {
}
}

// remove any entries that are duplicates or strict substrings of another entry.
attributions.sort();
attributions = attributions.filter(function (attrib, i) {
for (var j = i + 1; j < attributions.length; j++) {
if (attributions[j].indexOf(attrib) >= 0) { return false; }
}
return true;
});

this._container.innerHTML = attributions.join(' | ');
this._editLink = this._container.getElementsByClassName('mapbox-improve-map')[0];
this._updateEditLink();
Expand Down
23 changes: 23 additions & 0 deletions test/manual/attribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@

new mapboxgl.Attribution({position: 'top-left'})
.addTo(map);

map.on('style.load', function () {
map.addSource('foo', new mapboxgl.GeoJSONSource({
data: {
type: 'FeatureCollection', features: []
}
}));
map.style.sources.foo.attribution = '<a href="https://www.mapbox.com/about/maps/" target="_blank">&copy; Mapbox</a> <a href="http://www.openstreetmap.org/about/" target="_blank">&copy; OpenStreetMap</a> <a class="mapbox-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a> &copy; Someone else like DG'

map.addSource('bar', new mapboxgl.GeoJSONSource({
data: {
type: 'FeatureCollection', features: []
}
}));
map.style.sources.bar.attribution = 'Another Source';

map.addSource('baz', new mapboxgl.GeoJSONSource({
data: {
type: 'FeatureCollection', features: []
}
}));
map.style.sources.baz.attribution = 'Another Source';
});
</script>
</body>
</html>

0 comments on commit 48d674f

Please sign in to comment.