Skip to content

Commit 5cfe032

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Fix CanvasSourceSpecification not available in Map#addSource
GitOrigin-RevId: a4f531911706d235f4291086e18c7c4c060cdb52
1 parent 3b5549e commit 5cfe032

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type {FeatureSelector} from './style/style';
5252
export type {StyleImageInterface} from './style/style_image';
5353
export type {CustomLayerInterface} from './style/style_layer/custom_style_layer';
5454
export type {CustomSourceInterface} from './source/custom_source';
55+
export type {CanvasSourceSpecification} from './source/canvas_source';
5556

5657
export type {Anchor} from './ui/anchor';
5758
export type {PopupOptions} from './ui/popup';

src/source/source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {Callback} from '../types/callback';
2222
import type {MapEvents} from '../ui/events';
2323
import type {SourceSpecification} from '../style-spec/types';
2424
import type {CustomSourceInterface} from '../source/custom_source';
25+
import type {CanvasSourceSpecification} from '../source/canvas_source';
2526

2627
export type {Source};
2728

@@ -150,7 +151,7 @@ export type SourceType = keyof typeof sourceTypes;
150151
*/
151152
export const create = function (
152153
id: string,
153-
specification: SourceSpecification | CustomSourceInterface<unknown>,
154+
specification: SourceSpecification | CanvasSourceSpecification | CustomSourceInterface<unknown>,
154155
dispatcher: Dispatcher,
155156
eventedParent: Evented,
156157
): Source {

src/style/style.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import type {SerializedExpression} from '../style-spec/expression/expression';
125125
import type {ActorMessages} from '../util/actor_messages';
126126
import type {StringifiedImageId} from '../style-spec/expression/types/image_id';
127127
import type {CustomSourceInterface} from '../source/custom_source';
128+
import type {CanvasSourceSpecification} from '../source/canvas_source';
128129
import type {StyleModelMap} from './style_mode';
129130
import type {TypedStyleLayer} from './style_layer/typed_style_layer';
130131
import type {LngLatLike} from '../geo/lng_lat';
@@ -2090,7 +2091,7 @@ class Style extends Evented<MapEvents> {
20902091
return this.modelManager.listModels(this.getActualScope());
20912092
}
20922093

2093-
addSource(id: string, source: (SourceSpecification | CustomSourceInterface<unknown>) & {collectResourceTiming?: boolean}, options: StyleSetterOptions = {}): void {
2094+
addSource(id: string, source: (SourceSpecification | CanvasSourceSpecification | CustomSourceInterface<unknown>) & {collectResourceTiming?: boolean}, options: StyleSetterOptions = {}): void {
20942095
this._checkLoaded();
20952096

20962097
if (this.getOwnSource(id) !== undefined) {

src/ui/map.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import type {Interaction} from './interactions';
103103
import type {SpriteFormat} from '../render/image_manager';
104104
import type {PitchRotateKey} from './handler_manager';
105105
import type {CustomSourceInterface} from '../source/custom_source';
106+
import type {CanvasSourceSpecification} from '../source/canvas_source';
106107
import type {RasterQueryParameters, RasterQueryResult} from '../source/raster_array_tile_source';
107108
import type {IndoorTileOptions} from '../style/indoor_data';
108109

@@ -2530,7 +2531,7 @@ export class Map extends Camera {
25302531
* @see Example: GeoJSON source: [Add live realtime data](https://docs.mapbox.com/mapbox-gl-js/example/live-geojson/)
25312532
* @see Example: Raster DEM source: [Add hillshading](https://docs.mapbox.com/mapbox-gl-js/example/hillshade/)
25322533
*/
2533-
addSource(id: string, source: SourceSpecification | CustomSourceInterface<unknown>): this {
2534+
addSource(id: string, source: SourceSpecification | CanvasSourceSpecification | CustomSourceInterface<unknown>): this {
25342535
if (!this._isValidId(id)) {
25352536
return this;
25362537
}

test/build/typings/mapbox-gl.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,18 @@ map.addSource('urban-areas', {
191191
'data': 'https://docs.mapbox.com/mapbox-gl-js/assets/ne_50m_urban_areas.geojson'
192192
});
193193

194+
map.addSource('canvas-source', {
195+
type: 'canvas',
196+
canvas: 'myCanvas',
197+
animate: true,
198+
coordinates: [
199+
[-76.54, 39.18],
200+
[-76.52, 39.18],
201+
[-76.52, 39.17],
202+
[-76.54, 39.17]
203+
]
204+
});
205+
194206
map.addSource('points', {
195207
'type': 'geojson',
196208
'data': {

0 commit comments

Comments
 (0)