diff --git a/debug/debug.html b/debug/debug.html index b6bbce6a6e5..d291fe59d09 100644 --- a/debug/debug.html +++ b/debug/debug.html @@ -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", diff --git a/flow-typed/style-spec.js b/flow-typed/style-spec.js index df6e3260355..ce38e309978 100644 --- a/flow-typed/style-spec.js +++ b/flow-typed/style-spec.js @@ -110,6 +110,7 @@ declare type GeojsonSourceSpecification = {| "type": "geojson", "data"?: mixed, "maxzoom"?: number, + "attribution"?: string, "buffer"?: number, "tolerance"?: number, "cluster"?: boolean, diff --git a/src/source/geojson_source.js b/src/source/geojson_source.js index c1f06bf4a10..0d9a9291743 100644 --- a/src/source/geojson_source.js +++ b/src/source/geojson_source.js @@ -65,6 +65,7 @@ class GeoJSONSource extends Evented implements Source { minzoom: number; maxzoom: number; tileSize: number; + attribution: string; isTileClipped: boolean; reparseOverscaled: boolean; @@ -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; diff --git a/src/style-spec/reference/v8.json b/src/style-spec/reference/v8.json index 13595ee793f..c404deed477 100644 --- a/src/style-spec/reference/v8.json +++ b/src/style-spec/reference/v8.json @@ -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, diff --git a/test/unit/ui/control/attribution.test.js b/test/unit/ui/control/attribution.test.js index a7e5c31393b..a29df15b327 100644 --- a/test/unit/ui/control/attribution.test.js +++ b/test/unit/ui/control/attribution.test.js @@ -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(); } }