Skip to content

Commit cb4cac9

Browse files
committed
[v8] Align type names with base map libraries (#2474)
1 parent 9136655 commit cb4cac9

File tree

24 files changed

+235
-347
lines changed

24 files changed

+235
-347
lines changed

docs/upgrade-guide.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Upgrade Guide
22

3+
## Upgrading to v8.0
4+
5+
- All imports from `react-map-gl` should be replaced with one of the following endpoints:
6+
+ If using with `mapbox-gl@>=3.5.0`: import from `react-map-gl/mapbox`
7+
+ If using with `mapbox-gl@<3.5.0`: import from `react-map-gl/mapbox-legacy`
8+
- Some TypeScript types have been renamed to align with the official types from the base map libraries:
9+
10+
| Old name | New name |
11+
|----------|----------|
12+
| `MapStyle` | `StyleSpecification` |
13+
| `Fog` | `FogSpecification` |
14+
| `Light` | `LightSpecification` |
15+
| `Terrain` | `TerrainSpecification` |
16+
| `Projection` | `ProjectionSpecification` |
17+
| `*Layer` | `*LayerSpecification` |
18+
| `*SourceRaw` | `*SourceSpecification` |
19+
20+
321
## Upgrading to v7.1
422

523
- `maplibre-gl` users no longer need to install `mapbox-gl` or a placeholder package as dependency. Change your imports to the new endpoint `react-map-gl/maplibre`. Components imported from here do not require setting the `mapLib` prop, and use the types defined by `maplibre-gl`.

examples/mapbox/filter/src/map-style.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type {FillLayer} from 'react-map-gl/mapbox';
1+
import type {FillLayerSpecification} from 'react-map-gl/mapbox';
22

3-
export const countiesLayer: FillLayer = {
3+
export const countiesLayer: FillLayerSpecification = {
44
id: 'counties',
55
source: '',
66
type: 'fill',
@@ -11,7 +11,7 @@ export const countiesLayer: FillLayer = {
1111
}
1212
};
1313
// Highlighted county polygons
14-
export const highlightLayer: FillLayer = {
14+
export const highlightLayer: FillLayerSpecification = {
1515
id: 'counties-highlighted',
1616
type: 'fill',
1717
source: 'counties',

examples/mapbox/terrain/src/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import Map, {Source, Layer} from 'react-map-gl/mapbox';
44

55
import ControlPanel from './control-panel';
66

7-
import type {SkyLayer} from 'react-map-gl/mapbox';
7+
import type {SkyLayerSpecification} from 'react-map-gl/mapbox';
88

99
const TOKEN = ''; // Set your mapbox token here
1010

11-
const skyLayer: SkyLayer = {
11+
const skyLayer: SkyLayerSpecification = {
1212
id: 'sky',
1313
type: 'sky',
1414
paint: {

examples/mapbox/zoom-to-bounds/src/map-style.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import type {GeoJSONSource, FillLayer, LineLayer} from 'react-map-gl/mapbox';
1+
import type {
2+
GeoJSONSourceSpecification,
3+
FillLayerSpecification,
4+
LineLayerSpecification
5+
} from 'react-map-gl/mapbox';
26

37
import MAP_STYLE from '../../../map-style-basic-v8.json';
48

5-
const sfNeighborhoods: GeoJSONSource = {
9+
const sfNeighborhoods: GeoJSONSourceSpecification = {
610
type: 'geojson',
711
data: 'https://raw.githubusercontent.com/uber/react-map-gl/master/examples/.data/feature-example-sf.json'
812
};
913

10-
const fillLayer: FillLayer = {
14+
const fillLayer: FillLayerSpecification = {
1115
id: 'sf-neighborhoods-fill',
1216
source: 'sf-neighborhoods',
1317
type: 'fill',
@@ -18,7 +22,7 @@ const fillLayer: FillLayer = {
1822
}
1923
};
2024

21-
const lineLayer: LineLayer = {
25+
const lineLayer: LineLayerSpecification = {
2226
id: 'sf-neighborhoods-outline',
2327
source: 'sf-neighborhoods',
2428
type: 'line',

examples/maplibre/filter/src/map-style.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type {FillLayer} from 'react-map-gl/maplibre';
1+
import type {FillLayerSpecification} from 'react-map-gl/maplibre';
22

3-
export const countiesLayer: FillLayer = {
3+
export const countiesLayer: FillLayerSpecification = {
44
id: 'counties',
55
source: '',
66
type: 'fill',
@@ -10,7 +10,7 @@ export const countiesLayer: FillLayer = {
1010
}
1111
};
1212
// Highlighted county polygons
13-
export const highlightLayer: FillLayer = {
13+
export const highlightLayer: FillLayerSpecification = {
1414
id: 'counties-highlighted',
1515
type: 'fill',
1616
source: 'counties',

examples/maplibre/zoom-to-bounds/src/map-style.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import type {GeoJSONSource, FillLayer, LineLayer} from 'react-map-gl/maplibre';
1+
import type {
2+
GeoJSONSourceSpecification,
3+
FillLayerSpecification,
4+
LineLayerSpecification
5+
} from 'react-map-gl/maplibre';
26

37
import MAP_STYLE from '../../../map-style-basic-v8.json';
48

5-
const sfNeighborhoods: GeoJSONSource = {
9+
const sfNeighborhoods: GeoJSONSourceSpecification = {
610
type: 'geojson',
711
data: 'https://raw.githubusercontent.com/visgl/react-map-gl/master/examples/.data/feature-example-sf.json'
812
};
913

10-
const fillLayer: FillLayer = {
14+
const fillLayer: FillLayerSpecification = {
1115
id: 'sf-neighborhoods-fill',
1216
source: 'sf-neighborhoods',
1317
type: 'fill',
@@ -18,7 +22,7 @@ const fillLayer: FillLayer = {
1822
}
1923
};
2024

21-
const lineLayer: LineLayer = {
25+
const lineLayer: LineLayerSpecification = {
2226
id: 'sf-neighborhoods-outline',
2327
source: 'sf-neighborhoods',
2428
type: 'line',

modules/main/src/mapbox-legacy/components/layer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import assert from '../utils/assert';
44
import {deepEqual} from '../utils/deep-equal';
55

66
import type {MapInstance, CustomLayerInterface} from '../types/lib';
7-
import type {AnyLayer} from '../types/style-spec';
7+
import type {LayerSpecification} from '../types/style-spec';
88

99
// Omiting property from a union type, see
1010
// https://github.com/microsoft/TypeScript/issues/39556#issuecomment-656925230
1111
type OptionalId<T> = T extends {id: string} ? Omit<T, 'id'> & {id?: string} : T;
1212
type OptionalSource<T> = T extends {source: string} ? Omit<T, 'source'> & {source?: string} : T;
1313

14-
export type LayerProps = (OptionalSource<OptionalId<AnyLayer>> | CustomLayerInterface) & {
14+
export type LayerProps = (OptionalSource<OptionalId<LayerSpecification>> | CustomLayerInterface) & {
1515
/** If set, the layer will be inserted before the specified layer */
1616
beforeId?: string;
1717
};

modules/main/src/mapbox-legacy/components/source.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import type {
99
ImageSourceImplemtation,
1010
AnySourceImplementation
1111
} from '../types/internal';
12-
import type {AnySource, ImageSource, VectorSource} from '../types/style-spec';
12+
import type {
13+
SourceSpecification,
14+
ImageSourceSpecification,
15+
VectorSourceSpecification
16+
} from '../types/style-spec';
1317
import type {MapInstance} from '../types/lib';
1418

15-
export type SourceProps = AnySource & {
19+
export type SourceProps = SourceSpecification & {
1620
id?: string;
1721
children?: any;
1822
};
@@ -61,11 +65,11 @@ function updateSource(source: AnySourceImplementation, props: SourceProps, prevP
6165
coordinates: props.coordinates
6266
});
6367
} else if ('setCoordinates' in source && changedKeyCount === 1 && changedKey === 'coordinates') {
64-
source.setCoordinates((props as unknown as ImageSource).coordinates);
68+
source.setCoordinates((props as unknown as ImageSourceSpecification).coordinates);
6569
} else if ('setUrl' in source && changedKey === 'url') {
66-
source.setUrl((props as VectorSource).url);
70+
source.setUrl((props as VectorSourceSpecification).url);
6771
} else if ('setTiles' in source && changedKey === 'tiles') {
68-
source.setTiles((props as VectorSource).tiles);
72+
source.setTiles((props as VectorSourceSpecification).tiles);
6973
} else {
7074
// eslint-disable-next-line
7175
console.warn(`Unable to update <Source> prop: ${changedKey}`);

modules/main/src/mapbox-legacy/mapbox/mapbox.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import type {
1616
LngLatBoundsLike,
1717
MapGeoJSONFeature
1818
} from '../types/common';
19-
import type {MapStyle, Light, Terrain, Fog, Projection} from '../types/style-spec';
19+
import type {
20+
StyleSpecification,
21+
LightSpecification,
22+
TerrainSpecification,
23+
FogSpecification,
24+
ProjectionSpecification
25+
} from '../types/style-spec';
2026
import type {MapInstance} from '../types/lib';
2127
import type {Transform, MapInstanceInternal} from '../types/internal';
2228
import type {
@@ -57,31 +63,31 @@ export type MapboxProps = Partial<ViewState> &
5763
// Styling
5864

5965
/** Mapbox style */
60-
mapStyle?: string | MapStyle | ImmutableLike<MapStyle>;
66+
mapStyle?: string | StyleSpecification | ImmutableLike<StyleSpecification>;
6167
/** Enable diffing when the map style changes
6268
* @default true
6369
*/
6470
styleDiffing?: boolean;
6571
/** The projection property of the style. Must conform to the Projection Style Specification.
6672
* @default 'mercator'
6773
*/
68-
projection?: Projection;
74+
projection?: ProjectionSpecification | ProjectionSpecification['name'];
6975
/** The fog property of the style. Must conform to the Fog Style Specification .
7076
* If `undefined` is provided, removes the fog from the map. */
71-
fog?: Fog;
77+
fog?: FogSpecification;
7278
/** Light properties of the map. */
73-
light?: Light;
79+
light?: LightSpecification;
7480
/** Terrain property of the style. Must conform to the Terrain Style Specification .
7581
* If `undefined` is provided, removes terrain from the map. */
76-
terrain?: Terrain;
82+
terrain?: TerrainSpecification;
7783

7884
/** Default layers to query on pointer events */
7985
interactiveLayerIds?: string[];
8086
/** CSS cursor */
8187
cursor?: string;
8288
};
8389

84-
const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as MapStyle;
90+
const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification;
8591

8692
const pointerEvents = {
8793
mousedown: 'onMouseDown',
Lines changed: 28 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,34 @@
11
/*
22
* Mapbox Style Specification types
33
*/
4-
// Layers
5-
import type {
6-
BackgroundLayer,
7-
SkyLayer,
8-
CircleLayer,
9-
FillLayer,
10-
FillExtrusionLayer,
11-
HeatmapLayer,
12-
HillshadeLayer,
13-
LineLayer,
14-
RasterLayer,
15-
SymbolLayer
16-
} from 'mapbox-gl';
17-
18-
export type AnyLayer =
19-
| BackgroundLayer
20-
| CircleLayer
21-
| FillExtrusionLayer
22-
| FillLayer
23-
| HeatmapLayer
24-
| HillshadeLayer
25-
| LineLayer
26-
| RasterLayer
27-
| SymbolLayer
28-
| SkyLayer;
29-
304
export type {
31-
BackgroundLayer,
32-
SkyLayer,
33-
CircleLayer,
34-
FillLayer,
35-
FillExtrusionLayer,
36-
HeatmapLayer,
37-
HillshadeLayer,
38-
LineLayer,
39-
RasterLayer,
40-
SymbolLayer
41-
};
42-
43-
// Sources
44-
import type {
45-
Projection as ProjectionSpecification,
46-
GeoJSONSourceRaw as GeoJSONSource,
47-
VideoSourceRaw as VideoSource,
48-
ImageSourceRaw as ImageSource,
49-
VectorSource,
50-
RasterSource,
51-
CanvasSourceRaw as CanvasSource,
52-
RasterDemSource
53-
} from 'mapbox-gl';
5+
// Layers
6+
AnyLayer as LayerSpecification,
7+
BackgroundLayer as BackgroundLayerSpecification,
8+
SkyLayer as SkyLayerSpecification,
9+
CircleLayer as CircleLayerSpecification,
10+
FillLayer as FillLayerSpecification,
11+
FillExtrusionLayer as FillExtrusionLayerSpecification,
12+
HeatmapLayer as HeatmapLayerSpecification,
13+
HillshadeLayer as HillshadeLayerSpecification,
14+
LineLayer as LineLayerSpecification,
15+
RasterLayer as RasterLayerSpecification,
16+
SymbolLayer as SymbolLayerSpecification,
5417

55-
export type AnySource =
56-
| GeoJSONSource
57-
| VideoSource
58-
| ImageSource
59-
| CanvasSource
60-
| VectorSource
61-
| RasterSource
62-
| RasterDemSource;
18+
// Sources
19+
AnySourceData as SourceSpecification,
20+
CanvasSourceRaw as CanvasSourceSpecification,
21+
GeoJSONSourceRaw as GeoJSONSourceSpecification,
22+
VideoSourceRaw as VideoSourceSpecification,
23+
ImageSourceRaw as ImageSourceSpecification,
24+
VectorSource as VectorSourceSpecification,
25+
RasterSource as RasterSourceSpecification,
26+
RasterDemSource as RasterDemSourceSpecification,
6327

64-
export type {
65-
GeoJSONSource,
66-
VideoSource,
67-
ImageSource,
68-
CanvasSource,
69-
VectorSource,
70-
RasterSource,
71-
RasterDemSource
72-
};
73-
74-
// Other
75-
export type {Style as MapStyle, Light, Fog, TerrainSpecification as Terrain} from 'mapbox-gl';
76-
77-
export type Projection = ProjectionSpecification | ProjectionSpecification['name'];
28+
// Style
29+
Style as StyleSpecification,
30+
Light as LightSpecification,
31+
Fog as FogSpecification,
32+
TerrainSpecification,
33+
Projection as ProjectionSpecification
34+
} from 'mapbox-gl';

0 commit comments

Comments
 (0)