@rnmapbox/maps 10.0.0-beta.75 → 10.0.0-beta.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImagesManager.kt +5 -5
- package/ios/RCTMGL-v10/RCMTGLImage.swift +2 -1
- package/ios/RCTMGL-v10/RCTMGLImages.swift +57 -17
- package/ios/RCTMGL-v10/RCTMGLMapView.swift +11 -1
- package/ios/RCTMGL-v10/RCTMGLUtils.swift +14 -5
- package/javascript/MGLModule.ts +54 -0
- package/javascript/Mapbox.ts +97 -0
- package/javascript/classes/index.d.ts +20 -1
- package/javascript/components/Annotation.tsx +141 -0
- package/javascript/components/Callout.d.ts +35 -0
- package/javascript/components/ImageSource.tsx +1 -1
- package/javascript/components/Images.tsx +58 -6
- package/javascript/components/MapView.tsx +1 -1
- package/javascript/components/MarkerView.tsx +3 -2
- package/javascript/components/PointAnnotation.tsx +4 -3
- package/javascript/components/ShapeSource.tsx +1 -1
- package/javascript/components/{Style.js → Style.tsx} +117 -35
- package/javascript/components/Terrain.tsx +8 -7
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +105 -94
- package/javascript/components/VectorSource.tsx +1 -1
- package/javascript/index.ts +4 -0
- package/javascript/modules/offline/offlineManager.ts +5 -1
- package/javascript/modules/snapshot/snapshotManager.ts +1 -0
- package/javascript/types/Position.ts +1 -0
- package/javascript/utils/Logger.ts +1 -1
- package/javascript/utils/geoUtils.ts +0 -35
- package/lib/commonjs/MGLModule.js +37 -0
- package/lib/commonjs/MGLModule.js.map +1 -0
- package/lib/commonjs/Mapbox.js +372 -0
- package/lib/commonjs/Mapbox.js.map +1 -0
- package/lib/commonjs/classes/index.d.js +2 -0
- package/lib/commonjs/classes/index.d.js.map +1 -1
- package/lib/commonjs/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/commonjs/components/Annotation.js.map +1 -0
- package/lib/commonjs/components/Callout.d.js +9 -0
- package/lib/commonjs/components/Callout.d.js.map +1 -0
- package/lib/commonjs/components/Images.js +17 -1
- package/lib/commonjs/components/Images.js.map +1 -1
- package/lib/commonjs/components/MapView.js.map +1 -1
- package/lib/commonjs/components/MarkerView.js.map +1 -1
- package/lib/commonjs/components/PointAnnotation.js.map +1 -1
- package/lib/commonjs/components/Style.js +11 -15
- package/lib/commonjs/components/Style.js.map +1 -1
- package/lib/commonjs/components/Terrain.js.map +1 -1
- package/lib/commonjs/components/UserLocation.js +26 -77
- package/lib/commonjs/components/UserLocation.js.map +1 -1
- package/lib/commonjs/index.js +16 -339
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/modules/offline/offlineManager.js +6 -0
- package/lib/commonjs/modules/offline/offlineManager.js.map +1 -1
- package/lib/commonjs/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/commonjs/types/Position.js +2 -0
- package/lib/commonjs/types/Position.js.map +1 -0
- package/lib/commonjs/utils/animated/Animated.js.map +1 -1
- package/lib/commonjs/utils/geoUtils.js +1 -19
- package/lib/commonjs/utils/geoUtils.js.map +1 -1
- package/lib/module/MGLModule.js +19 -0
- package/lib/module/MGLModule.js.map +1 -0
- package/lib/module/Mapbox.js +59 -0
- package/lib/module/Mapbox.js.map +1 -0
- package/lib/module/classes/index.d.js +2 -0
- package/lib/module/classes/index.d.js.map +1 -1
- package/lib/module/components/{annotations/Annotation.js → Annotation.js} +26 -27
- package/lib/module/components/Annotation.js.map +1 -0
- package/lib/module/components/Callout.d.js +2 -0
- package/lib/module/components/Callout.d.js.map +1 -0
- package/lib/module/components/Images.js +17 -1
- package/lib/module/components/Images.js.map +1 -1
- package/lib/module/components/MapView.js.map +1 -1
- package/lib/module/components/MarkerView.js.map +1 -1
- package/lib/module/components/PointAnnotation.js.map +1 -1
- package/lib/module/components/Style.js +11 -15
- package/lib/module/components/Style.js.map +1 -1
- package/lib/module/components/Terrain.js.map +1 -1
- package/lib/module/components/UserLocation.js +25 -76
- package/lib/module/components/UserLocation.js.map +1 -1
- package/lib/module/index.js +3 -108
- package/lib/module/index.js.map +1 -1
- package/lib/module/modules/offline/offlineManager.js +1 -0
- package/lib/module/modules/offline/offlineManager.js.map +1 -1
- package/lib/module/modules/snapshot/snapshotManager.js.map +1 -1
- package/lib/module/types/Position.js +2 -0
- package/lib/module/types/Position.js.map +1 -0
- package/lib/module/utils/animated/Animated.js.map +1 -1
- package/lib/module/utils/geoUtils.js +0 -16
- package/lib/module/utils/geoUtils.js.map +1 -1
- package/lib/typescript/MGLModule.d.ts +22 -0
- package/lib/typescript/MGLModule.d.ts.map +1 -0
- package/lib/typescript/Mapbox.d.ts +54 -0
- package/lib/typescript/Mapbox.d.ts.map +1 -0
- package/lib/typescript/components/Annotation.d.ts +34 -0
- package/lib/typescript/components/Annotation.d.ts.map +1 -0
- package/lib/typescript/components/ImageSource.d.ts +1 -1
- package/lib/typescript/components/ImageSource.d.ts.map +1 -1
- package/lib/typescript/components/Images.d.ts +24 -2
- package/lib/typescript/components/Images.d.ts.map +1 -1
- package/lib/typescript/components/MapView.d.ts +2 -5
- package/lib/typescript/components/MapView.d.ts.map +1 -1
- package/lib/typescript/components/MarkerView.d.ts +3 -2
- package/lib/typescript/components/MarkerView.d.ts.map +1 -1
- package/lib/typescript/components/PointAnnotation.d.ts +9 -3
- package/lib/typescript/components/PointAnnotation.d.ts.map +1 -1
- package/lib/typescript/components/ShapeSource.d.ts +1 -1
- package/lib/typescript/components/ShapeSource.d.ts.map +1 -1
- package/lib/typescript/components/Style.d.ts +74 -0
- package/lib/typescript/components/Style.d.ts.map +1 -0
- package/lib/typescript/components/Terrain.d.ts +2 -2
- package/lib/typescript/components/Terrain.d.ts.map +1 -1
- package/lib/typescript/components/UserLocation.d.ts +102 -0
- package/lib/typescript/components/UserLocation.d.ts.map +1 -0
- package/lib/typescript/components/VectorSource.d.ts +1 -1
- package/lib/typescript/components/VectorSource.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +4 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/modules/offline/offlineManager.d.ts +2 -1
- package/lib/typescript/modules/offline/offlineManager.d.ts.map +1 -1
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts +1 -0
- package/lib/typescript/modules/snapshot/snapshotManager.d.ts.map +1 -1
- package/lib/typescript/types/Position.d.ts +2 -0
- package/lib/typescript/types/Position.d.ts.map +1 -0
- package/lib/typescript/utils/Logger.d.ts +1 -1
- package/lib/typescript/utils/Logger.d.ts.map +1 -1
- package/lib/typescript/utils/animated/Animated.d.ts +23 -0
- package/lib/typescript/utils/animated/Animated.d.ts.map +1 -0
- package/lib/typescript/utils/geoUtils.d.ts +0 -8
- package/lib/typescript/utils/geoUtils.d.ts.map +1 -1
- package/package.json +3 -5
- package/index.d.ts +0 -516
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -162
- package/lib/commonjs/components/annotations/Annotation.js.map +0 -1
- package/lib/module/components/annotations/Annotation.js.map +0 -1
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import React, { ReactNode, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
requireNativeComponent,
|
|
4
|
+
Image as RNImage,
|
|
5
|
+
ImageURISource,
|
|
6
|
+
} from 'react-native';
|
|
3
7
|
import { ImageSourcePropType, ImageResolvedAssetSource } from 'react-native';
|
|
4
8
|
|
|
5
9
|
import { ShapeSource } from './ShapeSource';
|
|
@@ -12,7 +16,7 @@ export type RNMBEvent<PayloadType = { [key: string]: string }> = {
|
|
|
12
16
|
type: string;
|
|
13
17
|
};
|
|
14
18
|
|
|
15
|
-
function _isUrlOrPath(value:
|
|
19
|
+
function _isUrlOrPath(value: ImageEntry): value is string {
|
|
16
20
|
return (
|
|
17
21
|
(typeof value === 'string' || value instanceof String) &&
|
|
18
22
|
(value.startsWith('file://') ||
|
|
@@ -24,6 +28,16 @@ function _isUrlOrPath(value: string | ImageSourcePropType): value is string {
|
|
|
24
28
|
);
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
function isImageSourcePropType(
|
|
32
|
+
value: ImageEntry,
|
|
33
|
+
): value is ImageSourcePropType {
|
|
34
|
+
if (typeof value === 'number' || value instanceof Number) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
const valueAsSource = value as ImageURISource;
|
|
38
|
+
return !!valueAsSource.uri && typeof valueAsSource.uri === 'string';
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
type TypedReactNode<T> = ReactElement<T> | Array<TypedReactNode<T>> | never;
|
|
28
42
|
|
|
29
43
|
type NativeImage =
|
|
@@ -33,8 +47,33 @@ type NativeImage =
|
|
|
33
47
|
sdf?: boolean;
|
|
34
48
|
stretchX?: [number, number][];
|
|
35
49
|
stretchY?: [number, number][];
|
|
50
|
+
content?: [number, number, number, number];
|
|
51
|
+
scale?: number;
|
|
36
52
|
};
|
|
37
53
|
|
|
54
|
+
export type ImageEntryData = {
|
|
55
|
+
url?: string;
|
|
56
|
+
image?: ImageSourcePropType;
|
|
57
|
+
resolvedImage?: ImageResolvedAssetSource;
|
|
58
|
+
sdf?: boolean;
|
|
59
|
+
stretchX?: [number, number][];
|
|
60
|
+
stretchY?: [number, number][];
|
|
61
|
+
content?: [number, number, number, number];
|
|
62
|
+
scale?: number;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
type ResolvedImageEntryData = {
|
|
66
|
+
url?: string;
|
|
67
|
+
resolvedImage?: ImageResolvedAssetSource;
|
|
68
|
+
sdf?: boolean;
|
|
69
|
+
stretchX?: [number, number][];
|
|
70
|
+
stretchY?: [number, number][];
|
|
71
|
+
content?: [number, number, number, number];
|
|
72
|
+
scale?: number;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type ImageEntry = string | ImageSourcePropType | ImageEntryData;
|
|
76
|
+
|
|
38
77
|
const isChildAnImage = (
|
|
39
78
|
child: ReactNode,
|
|
40
79
|
): child is React.ReactElement<typeof Image> => {
|
|
@@ -47,7 +86,7 @@ interface Props {
|
|
|
47
86
|
* Keys are names - see iconImage expressions, values can be either urls-s objects
|
|
48
87
|
* with format {uri: 'http://...'}` or `require('image.png')` or `import 'image.png'`
|
|
49
88
|
*/
|
|
50
|
-
images?: { [key: string]:
|
|
89
|
+
images?: { [key: string]: ImageEntry };
|
|
51
90
|
|
|
52
91
|
/**
|
|
53
92
|
* If you have an asset under Image.xcassets on iOS and the drawables directory on android
|
|
@@ -77,7 +116,9 @@ class Images extends React.PureComponent<Props> {
|
|
|
77
116
|
return {};
|
|
78
117
|
}
|
|
79
118
|
|
|
80
|
-
const images: {
|
|
119
|
+
const images: {
|
|
120
|
+
[key: string]: string | ImageResolvedAssetSource | ResolvedImageEntryData;
|
|
121
|
+
} = {};
|
|
81
122
|
let nativeImages: NativeImage[] = [];
|
|
82
123
|
|
|
83
124
|
if (this.props.images) {
|
|
@@ -93,11 +134,20 @@ class Images extends React.PureComponent<Props> {
|
|
|
93
134
|
);
|
|
94
135
|
} else if (_isUrlOrPath(value)) {
|
|
95
136
|
images[imageName] = value;
|
|
96
|
-
} else {
|
|
137
|
+
} else if (isImageSourcePropType(value)) {
|
|
97
138
|
const res = RNImage.resolveAssetSource(value);
|
|
98
139
|
if (res && res.uri) {
|
|
99
140
|
images[imageName] = res;
|
|
100
141
|
}
|
|
142
|
+
} else {
|
|
143
|
+
let imageEntry = value as ImageEntryData;
|
|
144
|
+
if (imageEntry.image) {
|
|
145
|
+
imageEntry = {
|
|
146
|
+
...imageEntry,
|
|
147
|
+
resolvedImage: RNImage.resolveAssetSource(imageEntry.image),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
images[imageName] = imageEntry;
|
|
101
151
|
}
|
|
102
152
|
}
|
|
103
153
|
}
|
|
@@ -147,7 +197,9 @@ class Images extends React.PureComponent<Props> {
|
|
|
147
197
|
type NativeProps = {
|
|
148
198
|
hasOnImageMissing: boolean;
|
|
149
199
|
onImageMissing?: (event: React.SyntheticEvent<Element, RNMBEvent>) => void;
|
|
150
|
-
images?: {
|
|
200
|
+
images?: {
|
|
201
|
+
[key: string]: string | ImageResolvedAssetSource | ResolvedImageEntryData;
|
|
202
|
+
};
|
|
151
203
|
nativeImages?: NativeImage[];
|
|
152
204
|
};
|
|
153
205
|
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
import { getFilter } from '../utils/filterUtils';
|
|
22
22
|
import Logger from '../utils/Logger';
|
|
23
23
|
import { FilterExpression } from '../utils/MapboxStyles';
|
|
24
|
+
import { type Position } from '../types/Position';
|
|
24
25
|
|
|
25
26
|
import NativeBridgeComponent from './NativeBridgeComponent';
|
|
26
27
|
|
|
@@ -46,7 +47,6 @@ export type Point = {
|
|
|
46
47
|
y: number;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
export type Position = [number, number];
|
|
50
50
|
type BBox = [number, number, number, number];
|
|
51
51
|
|
|
52
52
|
export type RegionPayload = {
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
|
|
10
10
|
import { toJSONString } from '../utils';
|
|
11
11
|
import { makePoint } from '../utils/geoUtils';
|
|
12
|
+
import { type Position } from '../types/Position';
|
|
12
13
|
|
|
13
14
|
import PointAnnotation from './PointAnnotation';
|
|
14
15
|
|
|
@@ -20,7 +21,7 @@ type Props = ViewProps & {
|
|
|
20
21
|
/**
|
|
21
22
|
* The center point (specified as a map coordinate) of the marker.
|
|
22
23
|
*/
|
|
23
|
-
coordinate:
|
|
24
|
+
coordinate: Position;
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Any coordinate between (0, 0) and (1, 1), where (0, 0) is the top-left corner of
|
|
@@ -78,7 +79,7 @@ class MarkerView extends React.PureComponent<Props> {
|
|
|
78
79
|
return this.__idForPointAnnotation;
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
_getCoordinate(coordinate:
|
|
82
|
+
_getCoordinate(coordinate: Position): string | undefined {
|
|
82
83
|
if (!coordinate) {
|
|
83
84
|
return undefined;
|
|
84
85
|
}
|
|
@@ -10,6 +10,7 @@ import { type Feature } from 'geojson';
|
|
|
10
10
|
import { toJSONString, isFunction } from '../utils';
|
|
11
11
|
import { makePoint } from '../utils/geoUtils';
|
|
12
12
|
import { type BaseProps } from '../types/BaseProps';
|
|
13
|
+
import { Position } from '../types/Position';
|
|
13
14
|
|
|
14
15
|
import NativeBridgeComponent, { type RNMBEvent } from './NativeBridgeComponent';
|
|
15
16
|
|
|
@@ -24,7 +25,7 @@ const styles = StyleSheet.create({
|
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
type FeaturePayload = {
|
|
27
|
-
feature: Feature
|
|
28
|
+
feature: Feature<GeoJSON.Point, { id: string }>;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
type Props = BaseProps & {
|
|
@@ -56,7 +57,7 @@ type Props = BaseProps & {
|
|
|
56
57
|
/**
|
|
57
58
|
* The center point (specified as a map coordinate) of the annotation.
|
|
58
59
|
*/
|
|
59
|
-
coordinate:
|
|
60
|
+
coordinate: Position;
|
|
60
61
|
|
|
61
62
|
/**
|
|
62
63
|
* Specifies the anchor being set on a particular point of the annotation.
|
|
@@ -104,7 +105,7 @@ type Props = BaseProps & {
|
|
|
104
105
|
/**
|
|
105
106
|
* Expects one child, and an optional callout can be added as well
|
|
106
107
|
*/
|
|
107
|
-
children: React.ReactElement;
|
|
108
|
+
children: React.ReactElement | [React.ReactElement, React.ReactElement];
|
|
108
109
|
|
|
109
110
|
style?: ViewProps['style'];
|
|
110
111
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useMemo, useState, useEffect } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import { FilterExpression } from '../utils/MapboxStyles';
|
|
3
4
|
|
|
4
5
|
import CircleLayer from './CircleLayer';
|
|
5
6
|
import RasterLayer from './RasterLayer';
|
|
@@ -14,7 +15,7 @@ import RasterSource from './RasterSource';
|
|
|
14
15
|
import ImageSource from './ImageSource';
|
|
15
16
|
import { ShapeSource } from './ShapeSource';
|
|
16
17
|
|
|
17
|
-
function toCamelCase(s) {
|
|
18
|
+
function toCamelCase(s: string): string {
|
|
18
19
|
return s.replace(/([-_][a-z])/gi, ($1) => {
|
|
19
20
|
return $1.toUpperCase().replace('-', '').replace('_', '');
|
|
20
21
|
});
|
|
@@ -22,11 +23,13 @@ function toCamelCase(s) {
|
|
|
22
23
|
|
|
23
24
|
// Patches the Mapbox Style Specification keys into the style props attributes:
|
|
24
25
|
// icon-allow-overlap -> iconAllowOverlap
|
|
25
|
-
function toCamelCaseKeys(oldObj) {
|
|
26
|
+
function toCamelCaseKeys(oldObj?: { [key: string]: unknown }): {
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
} {
|
|
26
29
|
if (!oldObj) {
|
|
27
30
|
return {};
|
|
28
31
|
}
|
|
29
|
-
const newObj = {};
|
|
32
|
+
const newObj: { [key: string]: unknown } = {};
|
|
30
33
|
Object.keys(oldObj).forEach((key) => {
|
|
31
34
|
const value = oldObj[key];
|
|
32
35
|
if (key.includes('-')) {
|
|
@@ -38,7 +41,7 @@ function toCamelCaseKeys(oldObj) {
|
|
|
38
41
|
return newObj;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
function getLayerComponentType(layer) {
|
|
44
|
+
function getLayerComponentType(layer: { type: string }) {
|
|
42
45
|
const { type } = layer;
|
|
43
46
|
|
|
44
47
|
switch (type) {
|
|
@@ -65,8 +68,10 @@ function getLayerComponentType(layer) {
|
|
|
65
68
|
return null;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
function asLayerComponent(layer) {
|
|
69
|
-
|
|
71
|
+
function asLayerComponent(layer: MapboxJSONLayer) {
|
|
72
|
+
type GenericProps = { key?: string; id: string };
|
|
73
|
+
const LayerComponent: typeof React.PureComponent<GenericProps> | null =
|
|
74
|
+
getLayerComponentType(layer) as typeof React.PureComponent<GenericProps>;
|
|
70
75
|
if (!LayerComponent) {
|
|
71
76
|
return null;
|
|
72
77
|
}
|
|
@@ -76,7 +81,14 @@ function asLayerComponent(layer) {
|
|
|
76
81
|
...toCamelCaseKeys(layer.layout),
|
|
77
82
|
};
|
|
78
83
|
|
|
79
|
-
const layerProps
|
|
84
|
+
const layerProps: {
|
|
85
|
+
sourceID?: string;
|
|
86
|
+
sourceLayerID?: string;
|
|
87
|
+
minZoomLevel?: number;
|
|
88
|
+
maxZoomLevel?: number;
|
|
89
|
+
filter?: FilterExpression;
|
|
90
|
+
style?: object;
|
|
91
|
+
} = {};
|
|
80
92
|
|
|
81
93
|
if (layer.source) {
|
|
82
94
|
layerProps.sourceID = layer.source;
|
|
@@ -100,8 +112,17 @@ function asLayerComponent(layer) {
|
|
|
100
112
|
return <LayerComponent key={layer.id} id={layer.id} {...layerProps} />;
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
type SourceProps = {
|
|
116
|
+
url?: string;
|
|
117
|
+
tileUrlTemplates?: string[];
|
|
118
|
+
minZoomLevel?: number;
|
|
119
|
+
maxZoomLevel?: number;
|
|
120
|
+
attribution?: string;
|
|
121
|
+
tms?: boolean;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
function getTileSourceProps(source: MapboxJSONSource): SourceProps {
|
|
125
|
+
const sourceProps: SourceProps = {};
|
|
105
126
|
if (source.url) {
|
|
106
127
|
sourceProps.url = source.url;
|
|
107
128
|
}
|
|
@@ -123,20 +144,22 @@ function getTileSourceProps(source) {
|
|
|
123
144
|
return sourceProps;
|
|
124
145
|
}
|
|
125
146
|
|
|
126
|
-
function getVectorSource(id, source) {
|
|
147
|
+
function getVectorSource(id: string, source: MapboxJSONSource) {
|
|
127
148
|
const sourceProps = { ...getTileSourceProps(source) };
|
|
128
149
|
return <VectorSource key={id} id={id} {...sourceProps} />;
|
|
129
150
|
}
|
|
130
151
|
|
|
131
|
-
function getRasterSource(id, source) {
|
|
132
|
-
const sourceProps
|
|
152
|
+
function getRasterSource(id: string, source: MapboxJSONSource) {
|
|
153
|
+
const sourceProps: { tileSize?: number } & SourceProps = {
|
|
154
|
+
...getTileSourceProps(source),
|
|
155
|
+
};
|
|
133
156
|
if (source.tileSize) {
|
|
134
157
|
sourceProps.tileSize = source.tileSize;
|
|
135
158
|
}
|
|
136
159
|
return <RasterSource key={id} id={id} {...sourceProps} />;
|
|
137
160
|
}
|
|
138
161
|
|
|
139
|
-
function getImageSource(id, source) {
|
|
162
|
+
function getImageSource(id: string, source: MapboxJSONSource) {
|
|
140
163
|
const sourceProps = {
|
|
141
164
|
url: source.url,
|
|
142
165
|
coordinates: source.coordinates,
|
|
@@ -144,12 +167,24 @@ function getImageSource(id, source) {
|
|
|
144
167
|
return <ImageSource key={id} id={id} {...sourceProps} />;
|
|
145
168
|
}
|
|
146
169
|
|
|
147
|
-
|
|
148
|
-
|
|
170
|
+
type ShapeShourceShape = typeof ShapeSource.prototype.props['shape'];
|
|
171
|
+
|
|
172
|
+
function getShapeSource(id: string, source: MapboxJSONSource) {
|
|
173
|
+
const sourceProps: {
|
|
174
|
+
url?: string;
|
|
175
|
+
shape?: ShapeShourceShape;
|
|
176
|
+
cluster?: boolean;
|
|
177
|
+
clusterRadius?: number;
|
|
178
|
+
clusterMaxZoomLevel?: number;
|
|
179
|
+
clusterProperties?: object;
|
|
180
|
+
buffer?: number;
|
|
181
|
+
tolerance?: number;
|
|
182
|
+
lineMetrics?: boolean;
|
|
183
|
+
} & SourceProps = {};
|
|
149
184
|
if (source.data && typeof source.data === 'string') {
|
|
150
185
|
sourceProps.url = source.data;
|
|
151
186
|
} else if (source.data && typeof source.data === 'object') {
|
|
152
|
-
sourceProps.shape = source.data;
|
|
187
|
+
sourceProps.shape = source.data as ShapeShourceShape;
|
|
153
188
|
}
|
|
154
189
|
if (source.cluster !== undefined) {
|
|
155
190
|
sourceProps.cluster = source.cluster;
|
|
@@ -178,7 +213,7 @@ function getShapeSource(id, source) {
|
|
|
178
213
|
return <ShapeSource key={id} id={id} {...sourceProps} />;
|
|
179
214
|
}
|
|
180
215
|
|
|
181
|
-
function asSourceComponent(id, source) {
|
|
216
|
+
function asSourceComponent(id: string, source: MapboxJSONSource) {
|
|
182
217
|
switch (source.type) {
|
|
183
218
|
case 'vector':
|
|
184
219
|
return getVectorSource(id, source);
|
|
@@ -195,26 +230,79 @@ function asSourceComponent(id, source) {
|
|
|
195
230
|
return null;
|
|
196
231
|
}
|
|
197
232
|
|
|
233
|
+
type MapboxJSONLayer = {
|
|
234
|
+
type: string;
|
|
235
|
+
id: string;
|
|
236
|
+
paint?: { [k: string]: unknown };
|
|
237
|
+
layout?: { [k: string]: unknown };
|
|
238
|
+
source?: string;
|
|
239
|
+
minzoom?: number;
|
|
240
|
+
maxzoom?: number;
|
|
241
|
+
filter?: FilterExpression;
|
|
242
|
+
style?: object;
|
|
243
|
+
['source-layer']: string;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
type MapboxJSONSource = {
|
|
247
|
+
type: string;
|
|
248
|
+
url?: string;
|
|
249
|
+
tiles?: string[];
|
|
250
|
+
minzoom?: number;
|
|
251
|
+
maxzoom?: number;
|
|
252
|
+
attribution?: string;
|
|
253
|
+
scheme?: string;
|
|
254
|
+
tileSize?: number;
|
|
255
|
+
coordinates?: [
|
|
256
|
+
[number, number],
|
|
257
|
+
[number, number],
|
|
258
|
+
[number, number],
|
|
259
|
+
[number, number],
|
|
260
|
+
];
|
|
261
|
+
data?: string | object;
|
|
262
|
+
|
|
263
|
+
buffer: number;
|
|
264
|
+
cluster?: boolean;
|
|
265
|
+
clusterRadius?: number;
|
|
266
|
+
clusterMaxZoom?: number;
|
|
267
|
+
clusterProperties?: object;
|
|
268
|
+
tolerance?: number;
|
|
269
|
+
lineMetrics?: boolean;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
type MapboxJSON = {
|
|
273
|
+
layers?: MapboxJSONLayer[];
|
|
274
|
+
sources?: { [key: string]: MapboxJSONSource };
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
type Props = {
|
|
278
|
+
/**
|
|
279
|
+
* A JSON object conforming to the schema described in the Mapbox Style Specification , or a URL to such JSON.
|
|
280
|
+
*/
|
|
281
|
+
json: MapboxJSON | URL;
|
|
282
|
+
};
|
|
283
|
+
|
|
198
284
|
/**
|
|
199
285
|
* Style is a component that automatically adds sources / layers to the map using Mapbox GL Style Spec.
|
|
200
286
|
* Only [`sources`](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources) & [`layers`](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/) are supported.
|
|
201
287
|
* Other fields such as `sprites`, `glyphs` etc. will be ignored. Not all layer / source attributes from the style spec are supported, in general the supported attributes will be mentioned under https://github.com/rnmapbox/maps/tree/main/docs.
|
|
202
288
|
*/
|
|
203
|
-
const Style = (props) => {
|
|
289
|
+
const Style = (props: Props) => {
|
|
204
290
|
const [fetchedJson, setFetchedJson] = useState({});
|
|
205
|
-
const json =
|
|
291
|
+
const json: MapboxJSON =
|
|
292
|
+
typeof props.json === 'object' ? props.json : fetchedJson;
|
|
206
293
|
|
|
207
294
|
// Fetch style when props.json is a URL
|
|
208
295
|
useEffect(() => {
|
|
209
296
|
const abortController = new AbortController();
|
|
210
|
-
const fetchStyleJson = async () => {
|
|
297
|
+
const fetchStyleJson = async (json: string) => {
|
|
211
298
|
try {
|
|
212
|
-
const response = await fetch(
|
|
299
|
+
const response = await fetch(json, {
|
|
213
300
|
signal: abortController.signal,
|
|
214
301
|
});
|
|
215
302
|
const responseJson = await response.json();
|
|
216
303
|
setFetchedJson(responseJson);
|
|
217
|
-
} catch (
|
|
304
|
+
} catch (error: unknown) {
|
|
305
|
+
const e = error as { name?: string };
|
|
218
306
|
if (e.name === 'AbortError') {
|
|
219
307
|
return;
|
|
220
308
|
}
|
|
@@ -222,7 +310,7 @@ const Style = (props) => {
|
|
|
222
310
|
}
|
|
223
311
|
};
|
|
224
312
|
if (typeof props.json === 'string') {
|
|
225
|
-
fetchStyleJson();
|
|
313
|
+
fetchStyleJson(props.json);
|
|
226
314
|
}
|
|
227
315
|
return function cleanup() {
|
|
228
316
|
abortController.abort();
|
|
@@ -238,14 +326,15 @@ const Style = (props) => {
|
|
|
238
326
|
}, [json.layers]);
|
|
239
327
|
|
|
240
328
|
// Extract source components from json
|
|
329
|
+
const { sources } = json;
|
|
241
330
|
const sourceComponents = useMemo(() => {
|
|
242
|
-
if (!
|
|
331
|
+
if (!sources || !Object.keys(sources)) {
|
|
243
332
|
return [];
|
|
244
333
|
}
|
|
245
|
-
return Object.keys(
|
|
246
|
-
.map((id) => asSourceComponent(id,
|
|
334
|
+
return Object.keys(sources)
|
|
335
|
+
.map((id) => asSourceComponent(id, sources[id]))
|
|
247
336
|
.filter((x) => !!x);
|
|
248
|
-
}, [
|
|
337
|
+
}, [sources]);
|
|
249
338
|
|
|
250
339
|
return (
|
|
251
340
|
<>
|
|
@@ -255,11 +344,4 @@ const Style = (props) => {
|
|
|
255
344
|
);
|
|
256
345
|
};
|
|
257
346
|
|
|
258
|
-
Style.propTypes = {
|
|
259
|
-
/**
|
|
260
|
-
* A JSON object conforming to the schema described in the Mapbox Style Specification , or a URL to such JSON.
|
|
261
|
-
*/
|
|
262
|
-
json: PropTypes.any,
|
|
263
|
-
};
|
|
264
|
-
|
|
265
347
|
export default Style;
|
|
@@ -11,7 +11,7 @@ type Props = BaseProps & {
|
|
|
11
11
|
/**
|
|
12
12
|
* Name of a source of raster_dem type to be used for terrain elevation.
|
|
13
13
|
*/
|
|
14
|
-
sourceID
|
|
14
|
+
sourceID?: string;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Deprecated, use exaggeration in style instead
|
|
@@ -21,7 +21,11 @@ type Props = BaseProps & {
|
|
|
21
21
|
/**
|
|
22
22
|
* Customizable style attributes
|
|
23
23
|
*/
|
|
24
|
-
style
|
|
24
|
+
style?: TerrainLayerStyleProps;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type NativeProps = Omit<Props, 'style'> & {
|
|
28
|
+
reactStyle?: { [key: string]: StyleValue };
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
export const Terrain = memo((props: Props) => {
|
|
@@ -46,8 +50,5 @@ export const Terrain = memo((props: Props) => {
|
|
|
46
50
|
return <RCTMGLTerrain {...baseProps} />;
|
|
47
51
|
});
|
|
48
52
|
|
|
49
|
-
const RCTMGLTerrain: HostComponent<
|
|
50
|
-
|
|
51
|
-
reactStyle?: { [key: string]: StyleValue };
|
|
52
|
-
style?: undefined;
|
|
53
|
-
}> = requireNativeComponent(NATIVE_MODULE_NAME);
|
|
53
|
+
const RCTMGLTerrain: HostComponent<NativeProps> =
|
|
54
|
+
requireNativeComponent(NATIVE_MODULE_NAME);
|