Skip to content

Commit ca1b0b1

Browse files
committed
feat: add TypeScript types for Standard Style configuration
1 parent 432d534 commit ca1b0b1

3 files changed

Lines changed: 73 additions & 5 deletions

File tree

example/src/examples/V11/StyleImportConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useState } from 'react';
33
import { MapView, Camera, StyleImport } from '@rnmapbox/maps';
44

55
const StyleImportConfig = () => {
6-
const [lightPreset, setLightPreset] = useState('night');
6+
const [lightPreset, setLightPreset] = useState<'day' | 'night'>('night');
77
const nextLightPreset = lightPreset === 'night' ? 'day' : 'night';
88
return (
99
<>

src/Mapbox.native.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export { default as PointAnnotation } from './components/PointAnnotation';
2121
export { default as Annotation } from './components/Annotation';
2222
export { default as Callout } from './components/Callout';
2323
export { default as StyleImport } from './components/StyleImport';
24+
export type { StandardStyleConfig } from './components/StyleImport';
2425
export {
2526
default as UserLocation,
2627
UserLocationRenderMode,

src/components/StyleImport.tsx

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,67 @@ import { memo } from 'react';
22

33
import NativeStyleImport from '../specs/RNMBXStyleImportNativeComponent';
44

5+
/**
6+
* Configuration options for the Mapbox Standard style.
7+
*
8+
* These options are available when using `StyleImport` with `id="basemap"` and
9+
* a Standard style URL (e.g., `mapbox://styles/mapbox/standard`).
10+
*/
11+
export type StandardStyleConfig = {
12+
/** Light preset: controls time-of-day lighting */
13+
lightPreset?: 'dawn' | 'day' | 'dusk' | 'night';
14+
/** Color theme */
15+
theme?: 'default' | 'faded' | 'monochrome';
16+
/** Font family for labels (e.g., 'Montserrat') */
17+
font?: string;
18+
/** Show generic 3D objects */
19+
show3dObjects?: boolean;
20+
/** Show extruded 3D buildings */
21+
show3dBuildings?: boolean;
22+
/** Show 3D building facades (v11.16+) */
23+
show3dFacades?: boolean;
24+
/** Show 3D landmarks (v11.16+) */
25+
show3dLandmarks?: boolean;
26+
/** Show 3D trees (v11.17+) */
27+
show3dTrees?: boolean;
28+
/** Show point of interest labels */
29+
showPointOfInterestLabels?: boolean;
30+
/** Show transit labels */
31+
showTransitLabels?: boolean;
32+
/** Show place labels */
33+
showPlaceLabels?: boolean;
34+
/** Show road labels */
35+
showRoadLabels?: boolean;
36+
/** Show pedestrian roads */
37+
showPedestrianRoads?: boolean;
38+
/** Color override for buildings (v11.18+) */
39+
colorBuildings?: string;
40+
/** Color override for commercial areas (v11.18+) */
41+
colorCommercial?: string;
42+
/** Color override for education areas (v11.18+) */
43+
colorEducation?: string;
44+
/** Color override for industrial areas (v11.18+) */
45+
colorIndustrial?: string;
46+
/** Color override for land (v11.18+) */
47+
colorLand?: string;
48+
/** Color override for medical areas (v11.18+) */
49+
colorMedical?: string;
50+
/** Color override for roads (v11.18+) */
51+
colorRoads?: string;
52+
/** Color override for motorways (v11.18+) */
53+
colorMotorways?: string;
54+
/** Color override for water (v11.18+) */
55+
colorWater?: string;
56+
/** Color override for greenspaces (v11.18+) */
57+
colorGreenspaces?: string;
58+
/** Color override for boundaries (v11.18+) */
59+
colorBoundaries?: string;
60+
};
61+
62+
type StyleImportConfig = StandardStyleConfig & {
63+
[key: string]: string | boolean | undefined;
64+
};
65+
566
type Props = {
667
/**
768
* id of the style import (eg. basemap)
@@ -16,11 +77,12 @@ type Props = {
1677
/**
1778
* config is a dictionary of configuration options for the style import.
1879
*
80+
* When using the Mapbox Standard style with `id="basemap"`, use {@link StandardStyleConfig}
81+
* keys for autocomplete. Arbitrary keys are also accepted for forward compatibility.
82+
*
1983
* See https://github.com/mapbox/mapbox-maps-ios/blob/main/Sources/MapboxMaps/Documentation.docc/Migrate%20to%20v11.md#21-the-mapbox-standard-style
2084
*/
21-
config: {
22-
[key: string]: string;
23-
};
85+
config: StyleImportConfig;
2486
};
2587

2688
/**
@@ -29,5 +91,10 @@ type Props = {
2991
* See https://github.com/mapbox/mapbox-maps-ios/blob/main/Sources/MapboxMaps/Documentation.docc/Migrate%20to%20v11.md#21-the-mapbox-standard-style
3092
*/
3193
export default memo((props: Props) => {
32-
return <NativeStyleImport {...props} />;
94+
return (
95+
<NativeStyleImport
96+
{...props}
97+
config={props.config as unknown as { [key: string]: string }}
98+
/>
99+
);
33100
});

0 commit comments

Comments
 (0)