Skip to content

Commit

Permalink
add support for GeoJSON attribution (#6364)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewharvey authored Jun 5, 2018
1 parent 30995d8 commit 560ca15
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion debug/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
map.on('load', function() {
map.addSource('geojson', {
"type": "geojson",
"data": "/test/integration/data/linestring.geojson"
"data": "/test/integration/data/linestring.geojson",
"attribution": "GeoJSON Attribution"
});
map.addLayer({
"id": "route",
Expand Down
1 change: 1 addition & 0 deletions flow-typed/style-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ declare type GeojsonSourceSpecification = {|
"type": "geojson",
"data"?: mixed,
"maxzoom"?: number,
"attribution"?: string,
"buffer"?: number,
"tolerance"?: number,
"cluster"?: boolean,
Expand Down
2 changes: 2 additions & 0 deletions src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class GeoJSONSource extends Evented implements Source {
minzoom: number;
maxzoom: number;
tileSize: number;
attribution: string;

isTileClipped: boolean;
reparseOverscaled: boolean;
Expand Down Expand Up @@ -109,6 +110,7 @@ class GeoJSONSource extends Evented implements Source {

if (options.maxzoom !== undefined) this.maxzoom = options.maxzoom;
if (options.type) this.type = options.type;
if (options.attribution) this.attribution = options.attribution;

const scale = EXTENT / this.tileSize;

Expand Down
4 changes: 4 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@
"default": 18,
"doc": "Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels)."
},
"attribution": {
"type": "string",
"doc": "Contains an attribution to be displayed when the map is shown to a user."
},
"buffer": {
"type": "number",
"default": 128,
Expand Down
6 changes: 4 additions & 2 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ test('AttributionControl dedupes attributions that are substrings of others', (t
map.addSource('3', { type: 'vector', attribution: 'Another Source' });
map.addSource('4', { type: 'vector', attribution: 'Hello' });
map.addSource('5', { type: 'vector', attribution: 'Hello World' });
map.addSource('6', { type: 'geojson', data: { type: 'FeatureCollection', features: [] }, attribution: 'Hello World' });
map.addSource('7', { type: 'geojson', data: { type: 'FeatureCollection', features: [] }, attribution: 'GeoJSON Source' });

});

let times = 0;
map.on('data', (e) => {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
if (++times === 5) {
t.equal(attribution._container.innerHTML, 'Hello World | Another Source');
if (++times === 7) {
t.equal(attribution._container.innerHTML, 'Hello World | Another Source | GeoJSON Source');
t.end();
}
}
Expand Down

0 comments on commit 560ca15

Please sign in to comment.