@rnmapbox/maps 10.0.0-beta.43 → 10.0.0-beta.44
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/android/install.md +49 -1
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/camera/CameraStop.java +4 -4
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java +3 -3
- package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +6 -6
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
- package/docs/ShapeSource.md +13 -9
- package/docs/docs.json +29 -59
- package/index.d.ts +6 -56
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +2 -2
- package/ios/install.md +3 -2
- package/javascript/components/AbstractLayer.tsx +3 -3
- package/javascript/components/AbstractSource.tsx +23 -0
- package/javascript/components/HeadingIndicator.tsx +1 -1
- package/javascript/components/Images.js +1 -1
- package/javascript/components/MapView.js +5 -2
- package/javascript/components/MarkerView.tsx +1 -0
- package/javascript/components/NativeBridgeComponent.tsx +20 -14
- package/javascript/components/PointAnnotation.tsx +2 -1
- package/javascript/components/RasterSource.js +1 -1
- package/javascript/components/ShapeSource.tsx +412 -0
- package/javascript/components/Style.js +2 -2
- package/javascript/components/SymbolLayer.tsx +1 -3
- package/javascript/components/VectorSource.js +6 -3
- package/javascript/components/annotations/Annotation.js +1 -1
- package/javascript/index.js +2 -2
- package/javascript/utils/animated/Animated.js +2 -2
- package/javascript/utils/deprecation.ts +7 -4
- package/javascript/utils/filterUtils.tsx +1 -1
- package/javascript/utils/index.d.ts +16 -3
- package/package.json +1 -1
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/ShapeSource.js +0 -373
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { runNativeCommand, isAndroid } from '../utils';
|
|
3
|
+
import { type NativeArg, runNativeCommand, isAndroid } from '../utils';
|
|
4
4
|
|
|
5
5
|
let callbackIncrement = 0;
|
|
6
6
|
|
|
@@ -9,18 +9,24 @@ export type RNMBEvent<PayloadType = { [key: string]: string }> = {
|
|
|
9
9
|
type: string;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const NativeBridgeComponent = <
|
|
13
|
-
|
|
12
|
+
const NativeBridgeComponent = <
|
|
13
|
+
Props extends object,
|
|
14
|
+
BaseComponent extends new (...ags: any[]) => React.Component<Props>,
|
|
15
|
+
>(
|
|
16
|
+
Base: BaseComponent,
|
|
17
|
+
nativeModuleName: string,
|
|
18
|
+
) =>
|
|
19
|
+
class extends Base {
|
|
14
20
|
_nativeModuleName: string;
|
|
15
21
|
_onAndroidCallback: (e: any) => void;
|
|
16
22
|
_callbackMap: Map<string, any>;
|
|
17
23
|
_preRefMapMethodQueue: Array<{
|
|
18
|
-
method: { name: string; args:
|
|
19
|
-
resolver: (value:
|
|
24
|
+
method: { name: string; args: NativeArg[] };
|
|
25
|
+
resolver: (value: NativeArg) => void;
|
|
20
26
|
}>;
|
|
21
27
|
|
|
22
|
-
constructor(
|
|
23
|
-
super(
|
|
28
|
+
constructor(...args: any[]) {
|
|
29
|
+
super(...args);
|
|
24
30
|
|
|
25
31
|
this._nativeModuleName = nativeModuleName;
|
|
26
32
|
this._onAndroidCallback = this._onAndroidCallbackO.bind(this);
|
|
@@ -28,9 +34,9 @@ const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
|
|
|
28
34
|
this._preRefMapMethodQueue = [];
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
_addAddAndroidCallback(
|
|
37
|
+
_addAddAndroidCallback<ReturnType>(
|
|
32
38
|
id: string,
|
|
33
|
-
resolve: (value:
|
|
39
|
+
resolve: (value: ReturnType) => void,
|
|
34
40
|
reject: (error: Error) => void,
|
|
35
41
|
) {
|
|
36
42
|
this._callbackMap.set(id, { resolve, reject });
|
|
@@ -74,16 +80,16 @@ const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
|
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
_runNativeCommand<RefType>(
|
|
83
|
+
_runNativeCommand<RefType, ReturnType = NativeArg>(
|
|
78
84
|
methodName: string,
|
|
79
85
|
nativeRef: RefType,
|
|
80
|
-
args:
|
|
81
|
-
) {
|
|
86
|
+
args: NativeArg[] = [],
|
|
87
|
+
): Promise<ReturnType> {
|
|
82
88
|
if (!nativeRef) {
|
|
83
|
-
return new Promise((resolve) => {
|
|
89
|
+
return new Promise<ReturnType>((resolve) => {
|
|
84
90
|
this._preRefMapMethodQueue.push({
|
|
85
91
|
method: { name: methodName, args },
|
|
86
|
-
resolver: resolve,
|
|
92
|
+
resolver: resolve as (args: NativeArg) => void,
|
|
87
93
|
});
|
|
88
94
|
});
|
|
89
95
|
}
|
|
@@ -120,6 +120,7 @@ type PointAnnotationProps = {
|
|
|
120
120
|
*/
|
|
121
121
|
class PointAnnotation extends NativeBridgeComponent(
|
|
122
122
|
React.PureComponent<PointAnnotationProps>,
|
|
123
|
+
NATIVE_MODULE_NAME,
|
|
123
124
|
) {
|
|
124
125
|
static defaultProps = {
|
|
125
126
|
anchor: { x: 0.5, y: 0.5 },
|
|
@@ -129,7 +130,7 @@ class PointAnnotation extends NativeBridgeComponent(
|
|
|
129
130
|
_nativeRef: NativePointAnnotationRef | null = null;
|
|
130
131
|
|
|
131
132
|
constructor(props: PointAnnotationProps) {
|
|
132
|
-
super(props
|
|
133
|
+
super(props);
|
|
133
134
|
this._onSelected = this._onSelected.bind(this);
|
|
134
135
|
this._onDeselected = this._onDeselected.bind(this);
|
|
135
136
|
this._onDragStart = this._onDragStart.bind(this);
|
|
@@ -107,7 +107,7 @@ class RasterSource extends AbstractSource {
|
|
|
107
107
|
attribution: this.props.attribution,
|
|
108
108
|
};
|
|
109
109
|
return (
|
|
110
|
-
<RCTMGLRasterSource ref=
|
|
110
|
+
<RCTMGLRasterSource ref={this.setNativeRef} {...props}>
|
|
111
111
|
{cloneReactChildrenWithProps(this.props.children, {
|
|
112
112
|
sourceID: this.props.id,
|
|
113
113
|
})}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
HostComponent,
|
|
4
|
+
NativeMethods,
|
|
5
|
+
NativeModules,
|
|
6
|
+
NativeSyntheticEvent,
|
|
7
|
+
requireNativeComponent,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
|
|
10
|
+
import { getFilter } from '../utils/filterUtils';
|
|
11
|
+
import {
|
|
12
|
+
toJSONString,
|
|
13
|
+
cloneReactChildrenWithProps,
|
|
14
|
+
isFunction,
|
|
15
|
+
isAndroid,
|
|
16
|
+
} from '../utils';
|
|
17
|
+
import { copyPropertiesAsDeprecated } from '../utils/deprecation';
|
|
18
|
+
|
|
19
|
+
import AbstractSource from './AbstractSource';
|
|
20
|
+
import NativeBridgeComponent from './NativeBridgeComponent';
|
|
21
|
+
|
|
22
|
+
const MapboxGL = NativeModules.MGLModule;
|
|
23
|
+
|
|
24
|
+
export const NATIVE_MODULE_NAME = 'RCTMGLShapeSource';
|
|
25
|
+
|
|
26
|
+
export type OnPressEvent = {
|
|
27
|
+
features: Array<GeoJSON.Feature>;
|
|
28
|
+
coordinates: {
|
|
29
|
+
latitude: number;
|
|
30
|
+
longitude: number;
|
|
31
|
+
};
|
|
32
|
+
point: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
type OnPressEventDeprecated = OnPressEvent & {
|
|
38
|
+
nativeEvent?: OnPressEvent;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type Props = {
|
|
42
|
+
/**
|
|
43
|
+
* A string that uniquely identifies the source.
|
|
44
|
+
*/
|
|
45
|
+
id: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.
|
|
49
|
+
*/
|
|
50
|
+
url?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a feature collection.
|
|
54
|
+
*/
|
|
55
|
+
shape?:
|
|
56
|
+
| GeoJSON.GeometryCollection
|
|
57
|
+
| GeoJSON.Feature
|
|
58
|
+
| GeoJSON.FeatureCollection
|
|
59
|
+
| GeoJSON.Geometry;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Enables clustering on the source for point shapes.
|
|
63
|
+
*/
|
|
64
|
+
cluster?: boolean;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Specifies the radius of each cluster if clustering is enabled.
|
|
68
|
+
* A value of 512 produces a radius equal to the width of a tile.
|
|
69
|
+
* The default value is 50.
|
|
70
|
+
*/
|
|
71
|
+
clusterRadius?: number;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Specifies the maximum zoom level at which to cluster points if clustering is enabled.
|
|
75
|
+
* Defaults to one zoom level less than the value of maxZoomLevel so that, at the maximum zoom level,
|
|
76
|
+
* the shapes are not clustered.
|
|
77
|
+
*/
|
|
78
|
+
clusterMaxZoomLevel?: number;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* [`mapbox-gl` (v8) implementation only]
|
|
82
|
+
* Specifies custom properties on the generated clusters if clustering
|
|
83
|
+
* is enabled, aggregating values from clustered points.
|
|
84
|
+
*
|
|
85
|
+
* Has the form `{ "property_name": [operator, map_expression]}`, where
|
|
86
|
+
* `operator` is a custom reduce expression that references a special `["accumulated"]` value -
|
|
87
|
+
* it accumulates the property value from clusters/points the cluster contains
|
|
88
|
+
* `map_expression` produces the value of a single point
|
|
89
|
+
*
|
|
90
|
+
* Example: `{ "resultingSum": [["+", ["accumulated"], ["get", "resultingSum"]], ["get", "scalerank"]] }`
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
clusterProperties?: object;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Specifies the maximum zoom level at which to create vector tiles.
|
|
97
|
+
* A greater value produces greater detail at high zoom levels.
|
|
98
|
+
* The default value is 18.
|
|
99
|
+
*/
|
|
100
|
+
maxZoomLevel?: number;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Specifies the size of the tile buffer on each side.
|
|
104
|
+
* A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself.
|
|
105
|
+
* Larger values produce fewer rendering artifacts near tile edges and slower performance.
|
|
106
|
+
* The default value is 128.
|
|
107
|
+
*/
|
|
108
|
+
buffer?: number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Specifies the Douglas-Peucker simplification tolerance.
|
|
112
|
+
* A greater value produces simpler geometries and improves performance.
|
|
113
|
+
* The default value is 0.375.
|
|
114
|
+
*/
|
|
115
|
+
tolerance?: number;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Whether to calculate line distance metrics.
|
|
119
|
+
* This is required for line layers that specify lineGradient values.
|
|
120
|
+
* The default value is false.
|
|
121
|
+
*/
|
|
122
|
+
lineMetrics?: boolean;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Source press listener, gets called when a user presses one of the children layers only
|
|
126
|
+
* if that layer has a higher z-index than another source layers
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} event
|
|
129
|
+
* @param {Object[]} event.features - the geojson features that have hit by the press (might be multiple)
|
|
130
|
+
* @param {Object} event.coordinates - the coordinates of the click
|
|
131
|
+
* @param {Object} event.point - the point of the click
|
|
132
|
+
* @return void
|
|
133
|
+
*/
|
|
134
|
+
onPress?: (event: OnPressEvent) => void;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Overrides the default touch hitbox(44x44 pixels) for the source layers
|
|
138
|
+
*/
|
|
139
|
+
hitbox?: {
|
|
140
|
+
/**
|
|
141
|
+
* `width` of hitbox
|
|
142
|
+
*/
|
|
143
|
+
width: number;
|
|
144
|
+
/**
|
|
145
|
+
* `height` of hitbox
|
|
146
|
+
*/
|
|
147
|
+
height: number;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
children: React.ReactElement | React.ReactElement[];
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* ShapeSource is a map content source that supplies vector shapes to be shown on the map.
|
|
155
|
+
* The shape may be an url or a GeoJSON object
|
|
156
|
+
*/
|
|
157
|
+
export class ShapeSource extends NativeBridgeComponent(
|
|
158
|
+
AbstractSource<Props, NativeProps>,
|
|
159
|
+
NATIVE_MODULE_NAME,
|
|
160
|
+
) {
|
|
161
|
+
static NATIVE_ASSETS_KEY = 'assets';
|
|
162
|
+
|
|
163
|
+
static defaultProps = {
|
|
164
|
+
id: MapboxGL.StyleSource.DefaultSourceID,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
constructor(props: Props) {
|
|
168
|
+
super(props);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_setNativeRef(
|
|
172
|
+
nativeRef: React.Component<NativeProps> & Readonly<NativeMethods>,
|
|
173
|
+
) {
|
|
174
|
+
this.setNativeRef(nativeRef);
|
|
175
|
+
super._runPendingNativeCommands(nativeRef);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Returns all features from the source that match the query parameters whether the feature is currently
|
|
180
|
+
* rendered on the map.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* shapeSource.features()
|
|
184
|
+
*
|
|
185
|
+
* @param {Array=} filter - an optional filter statement to filter the returned Features.
|
|
186
|
+
* @return {FeatureCollection}
|
|
187
|
+
*/
|
|
188
|
+
async features(filter: Array<string> = []) {
|
|
189
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
190
|
+
'features',
|
|
191
|
+
this._nativeRef,
|
|
192
|
+
getFilter(filter),
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if (isAndroid()) {
|
|
196
|
+
return JSON.parse(res.data);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return res.data;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Returns the zoom needed to expand the cluster.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
|
|
207
|
+
*
|
|
208
|
+
* @param {Feature} feature - The feature cluster to expand.
|
|
209
|
+
* @return {number}
|
|
210
|
+
*/
|
|
211
|
+
async getClusterExpansionZoom(
|
|
212
|
+
feature: string | GeoJSON.Feature,
|
|
213
|
+
): Promise<string> {
|
|
214
|
+
if (typeof feature === 'number') {
|
|
215
|
+
console.warn(
|
|
216
|
+
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
217
|
+
);
|
|
218
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
219
|
+
'getClusterExpansionZoomById',
|
|
220
|
+
this._nativeRef,
|
|
221
|
+
[feature],
|
|
222
|
+
);
|
|
223
|
+
return res.data;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
227
|
+
'getClusterExpansionZoom',
|
|
228
|
+
this._nativeRef,
|
|
229
|
+
[JSON.stringify(feature)],
|
|
230
|
+
);
|
|
231
|
+
return res.data;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Returns the FeatureCollection from the cluster.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
|
|
239
|
+
*
|
|
240
|
+
* @param {GeoJSON.Feature} feature - The feature cluster to expand.
|
|
241
|
+
* @param {number} limit - The number of points to return.
|
|
242
|
+
* @param {number} offset - The amount of points to skip (for pagination).
|
|
243
|
+
* @return {FeatureCollection}
|
|
244
|
+
*/
|
|
245
|
+
async getClusterLeaves(
|
|
246
|
+
feature: number | GeoJSON.Feature,
|
|
247
|
+
limit: number,
|
|
248
|
+
offset: number,
|
|
249
|
+
) {
|
|
250
|
+
if (typeof feature === 'number') {
|
|
251
|
+
console.warn(
|
|
252
|
+
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
253
|
+
);
|
|
254
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
255
|
+
'getClusterLeavesById',
|
|
256
|
+
this._nativeRef,
|
|
257
|
+
[feature, limit, offset],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
if (isAndroid()) {
|
|
261
|
+
return JSON.parse(res.data);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return res.data;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
268
|
+
'getClusterLeaves',
|
|
269
|
+
this._nativeRef,
|
|
270
|
+
[JSON.stringify(feature), limit, offset],
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
if (isAndroid()) {
|
|
274
|
+
return JSON.parse(res.data);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return res.data;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Returns the FeatureCollection from the cluster (on the next zoom level).
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* const collection = await shapeSource.getClusterChildren(clusterId);
|
|
285
|
+
*
|
|
286
|
+
* @param {GeoJSON.Feature} feature - The feature cluster to expand.
|
|
287
|
+
* @return {FeatureCollection}
|
|
288
|
+
*/
|
|
289
|
+
async getClusterChildren(feature: number | GeoJSON.Feature) {
|
|
290
|
+
if (typeof feature === 'number') {
|
|
291
|
+
console.warn(
|
|
292
|
+
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
293
|
+
);
|
|
294
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
295
|
+
'getClusterChildrenById',
|
|
296
|
+
this._nativeRef,
|
|
297
|
+
[feature],
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
if (isAndroid()) {
|
|
301
|
+
return JSON.parse(res.data);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return res.data;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const res: { data: string } = await this._runNativeCommand(
|
|
308
|
+
'getClusterChildren',
|
|
309
|
+
this._nativeRef,
|
|
310
|
+
[JSON.stringify(feature)],
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
if (isAndroid()) {
|
|
314
|
+
return JSON.parse(res.data);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return res.data;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
setNativeProps(props: NativeProps) {
|
|
321
|
+
const shallowProps = Object.assign({}, props);
|
|
322
|
+
|
|
323
|
+
// Adds support for Animated
|
|
324
|
+
if (shallowProps.shape && typeof shallowProps.shape !== 'string') {
|
|
325
|
+
shallowProps.shape = JSON.stringify(shallowProps.shape);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
super.setNativeProps(shallowProps);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
_getShape() {
|
|
332
|
+
if (!this.props.shape) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
return toJSONString(this.props.shape);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
onPress(
|
|
339
|
+
event: NativeSyntheticEvent<{
|
|
340
|
+
payload: OnPressEvent;
|
|
341
|
+
}>,
|
|
342
|
+
) {
|
|
343
|
+
const {
|
|
344
|
+
nativeEvent: {
|
|
345
|
+
payload: { features, coordinates, point },
|
|
346
|
+
},
|
|
347
|
+
} = event;
|
|
348
|
+
let newEvent: OnPressEventDeprecated = {
|
|
349
|
+
features,
|
|
350
|
+
coordinates,
|
|
351
|
+
point,
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
newEvent = copyPropertiesAsDeprecated(
|
|
355
|
+
event as unknown as Record<string, unknown>,
|
|
356
|
+
newEvent,
|
|
357
|
+
(key) => {
|
|
358
|
+
console.warn(
|
|
359
|
+
`event.${key} is deprecated on ShapeSource#onPress, please use event.features`,
|
|
360
|
+
);
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
nativeEvent: (origNativeEvent: unknown) => ({
|
|
364
|
+
...(origNativeEvent as OnPressEvent),
|
|
365
|
+
payload: features[0],
|
|
366
|
+
}),
|
|
367
|
+
},
|
|
368
|
+
);
|
|
369
|
+
this.props.onPress?.(newEvent);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
render() {
|
|
373
|
+
const props = {
|
|
374
|
+
id: this.props.id,
|
|
375
|
+
url: this.props.url,
|
|
376
|
+
shape: this._getShape(),
|
|
377
|
+
hitbox: this.props.hitbox,
|
|
378
|
+
hasPressListener: isFunction(this.props.onPress),
|
|
379
|
+
onMapboxShapeSourcePress: this.onPress.bind(this),
|
|
380
|
+
cluster: this.props.cluster ? 1 : 0,
|
|
381
|
+
clusterRadius: this.props.clusterRadius,
|
|
382
|
+
clusterMaxZoomLevel: this.props.clusterMaxZoomLevel,
|
|
383
|
+
clusterProperties: this.props.clusterProperties,
|
|
384
|
+
maxZoomLevel: this.props.maxZoomLevel,
|
|
385
|
+
buffer: this.props.buffer,
|
|
386
|
+
tolerance: this.props.tolerance,
|
|
387
|
+
lineMetrics: this.props.lineMetrics,
|
|
388
|
+
onPress: undefined,
|
|
389
|
+
ref: (
|
|
390
|
+
nativeRef: React.Component<NativeProps> & Readonly<NativeMethods>,
|
|
391
|
+
) => this._setNativeRef(nativeRef),
|
|
392
|
+
onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
return (
|
|
396
|
+
<RCTMGLShapeSource {...props}>
|
|
397
|
+
{cloneReactChildrenWithProps(this.props.children, {
|
|
398
|
+
sourceID: this.props.id,
|
|
399
|
+
})}
|
|
400
|
+
</RCTMGLShapeSource>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
type NativeProps = {
|
|
406
|
+
id: string;
|
|
407
|
+
shape?: string;
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
type NativeShapeSource = HostComponent<NativeProps>;
|
|
411
|
+
const RCTMGLShapeSource: NativeShapeSource =
|
|
412
|
+
requireNativeComponent(NATIVE_MODULE_NAME);
|
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
|
|
4
4
|
import CircleLayer from './CircleLayer';
|
|
5
5
|
import RasterLayer from './RasterLayer';
|
|
6
|
-
import SymbolLayer from './SymbolLayer';
|
|
6
|
+
import { SymbolLayer } from './SymbolLayer';
|
|
7
7
|
import LineLayer from './LineLayer';
|
|
8
8
|
import FillLayer from './FillLayer';
|
|
9
9
|
import FillExtrusionLayer from './FillExtrusionLayer';
|
|
@@ -12,7 +12,7 @@ import HeatmapLayer from './HeatmapLayer';
|
|
|
12
12
|
import VectorSource from './VectorSource';
|
|
13
13
|
import RasterSource from './RasterSource';
|
|
14
14
|
import ImageSource from './ImageSource';
|
|
15
|
-
import ShapeSource from './ShapeSource';
|
|
15
|
+
import { ShapeSource } from './ShapeSource';
|
|
16
16
|
|
|
17
17
|
function toCamelCase(s) {
|
|
18
18
|
return s.replace(/([-_][a-z])/gi, ($1) => {
|
|
@@ -74,7 +74,7 @@ const RCTMGLSymbolLayer =
|
|
|
74
74
|
/**
|
|
75
75
|
* SymbolLayer is a style layer that renders icon and text labels at points or along lines on the map.
|
|
76
76
|
*/
|
|
77
|
-
class SymbolLayer extends AbstractLayer<Props, NativeTypeProps> {
|
|
77
|
+
export class SymbolLayer extends AbstractLayer<Props, NativeTypeProps> {
|
|
78
78
|
static defaultProps = {
|
|
79
79
|
sourceID: MapboxGL.StyleSource.DefaultSourceID,
|
|
80
80
|
};
|
|
@@ -109,5 +109,3 @@ class SymbolLayer extends AbstractLayer<Props, NativeTypeProps> {
|
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
export default SymbolLayer;
|
|
@@ -22,7 +22,10 @@ export const NATIVE_MODULE_NAME = 'RCTMGLVectorSource';
|
|
|
22
22
|
* VectorSource is a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map.
|
|
23
23
|
* The location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification.
|
|
24
24
|
*/
|
|
25
|
-
class VectorSource extends NativeBridgeComponent(
|
|
25
|
+
class VectorSource extends NativeBridgeComponent(
|
|
26
|
+
AbstractSource,
|
|
27
|
+
NATIVE_MODULE_NAME,
|
|
28
|
+
) {
|
|
26
29
|
static propTypes = {
|
|
27
30
|
...viewPropTypes,
|
|
28
31
|
|
|
@@ -98,7 +101,7 @@ class VectorSource extends NativeBridgeComponent(AbstractSource) {
|
|
|
98
101
|
};
|
|
99
102
|
|
|
100
103
|
constructor(props) {
|
|
101
|
-
super(props
|
|
104
|
+
super(props);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
_setNativeRef(nativeRef) {
|
|
@@ -177,7 +180,7 @@ class VectorSource extends NativeBridgeComponent(AbstractSource) {
|
|
|
177
180
|
onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
|
|
178
181
|
};
|
|
179
182
|
return (
|
|
180
|
-
<RCTMGLVectorSource ref=
|
|
183
|
+
<RCTMGLVectorSource ref={this.setNativeRef} {...props}>
|
|
181
184
|
{cloneReactChildrenWithProps(this.props.children, {
|
|
182
185
|
sourceID: this.props.id,
|
|
183
186
|
})}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Easing } from 'react-native';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
|
|
5
|
-
import SymbolLayer from '../SymbolLayer';
|
|
5
|
+
import { SymbolLayer } from '../SymbolLayer';
|
|
6
6
|
import Animated from '../../utils/animated/Animated';
|
|
7
7
|
import { AnimatedPoint } from '../../classes';
|
|
8
8
|
|
package/javascript/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import Annotation from './components/annotations/Annotation';
|
|
|
9
9
|
import Callout from './components/Callout';
|
|
10
10
|
import UserLocation from './components/UserLocation';
|
|
11
11
|
import VectorSource from './components/VectorSource';
|
|
12
|
-
import ShapeSource from './components/ShapeSource';
|
|
12
|
+
import { ShapeSource } from './components/ShapeSource';
|
|
13
13
|
import RasterSource from './components/RasterSource';
|
|
14
14
|
import RasterDemSource from './components/RasterDemSource';
|
|
15
15
|
import ImageSource from './components/ImageSource';
|
|
@@ -20,7 +20,7 @@ import HeatmapLayer from './components/HeatmapLayer';
|
|
|
20
20
|
import LineLayer from './components/LineLayer';
|
|
21
21
|
import CircleLayer from './components/CircleLayer';
|
|
22
22
|
import SkyLayer from './components/SkyLayer';
|
|
23
|
-
import SymbolLayer from './components/SymbolLayer';
|
|
23
|
+
import { SymbolLayer } from './components/SymbolLayer';
|
|
24
24
|
import RasterLayer from './components/RasterLayer';
|
|
25
25
|
import BackgroundLayer from './components/BackgroundLayer';
|
|
26
26
|
import { Terrain } from './components/Terrain';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Animated as RNAnimated } from 'react-native';
|
|
2
2
|
|
|
3
|
-
import ShapeSource from '../../components/ShapeSource';
|
|
3
|
+
import { ShapeSource } from '../../components/ShapeSource';
|
|
4
4
|
import ImageSource from '../../components/ImageSource';
|
|
5
5
|
import FillLayer from '../../components/FillLayer';
|
|
6
6
|
import FillExtrusionLayer from '../../components/FillExtrusionLayer';
|
|
7
7
|
import LineLayer from '../../components/LineLayer';
|
|
8
8
|
import CircleLayer from '../../components/CircleLayer';
|
|
9
|
-
import SymbolLayer from '../../components/SymbolLayer';
|
|
9
|
+
import { SymbolLayer } from '../../components/SymbolLayer';
|
|
10
10
|
import RasterLayer from '../../components/RasterLayer';
|
|
11
11
|
import BackgroundLayer from '../../components/BackgroundLayer';
|
|
12
12
|
|
|
@@ -18,12 +18,15 @@ export function deprecatedClass<C extends new (...args: any[]) => object>(
|
|
|
18
18
|
* Copy properties from origObject to newObject, which not exists in newObject,
|
|
19
19
|
* calls onDeprecatedCalled callback in case a copied property is invoked.
|
|
20
20
|
*/
|
|
21
|
-
export function copyPropertiesAsDeprecated
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export function copyPropertiesAsDeprecated<
|
|
22
|
+
DeprecatedType extends Record<string, unknown>,
|
|
23
|
+
WithDeprecatedType extends Record<string, unknown>,
|
|
24
|
+
>(
|
|
25
|
+
origObject: DeprecatedType,
|
|
26
|
+
newObject: WithDeprecatedType,
|
|
24
27
|
onDeprecatedCalled: (key: string) => void,
|
|
25
28
|
accessors: { [key: string]: (value: unknown) => unknown } = {},
|
|
26
|
-
):
|
|
29
|
+
): WithDeprecatedType {
|
|
27
30
|
const result = newObject;
|
|
28
31
|
for (const [key, value] of Object.entries(origObject)) {
|
|
29
32
|
if (!newObject[key]) {
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export type NativeArg =
|
|
4
|
+
| string
|
|
5
|
+
| number
|
|
6
|
+
| { [k: string]: NativeArg }
|
|
7
|
+
| NativeArg[];
|
|
8
|
+
|
|
1
9
|
export function isAndroid(): boolean;
|
|
2
10
|
export function isBoolean(_: unknown): argument is boolean;
|
|
3
11
|
export function isNumber(_: unknown): argument is number;
|
|
@@ -6,9 +14,14 @@ export function isString(_: unknown): argument is string;
|
|
|
6
14
|
export function isFunction(argument: unknown): argument is Function;
|
|
7
15
|
|
|
8
16
|
export function toJSONString(_: unknown): string;
|
|
9
|
-
export function runNativeCommand<RefType>(
|
|
17
|
+
export function runNativeCommand<RefType, ReturnType = NativeArg>(
|
|
10
18
|
module: string,
|
|
11
19
|
name: string,
|
|
12
20
|
nativeRef: RefType,
|
|
13
|
-
args:
|
|
14
|
-
):
|
|
21
|
+
args: NativeArg[],
|
|
22
|
+
): Promise<ReturnType>;
|
|
23
|
+
|
|
24
|
+
export function cloneReactChildrenWithProps(
|
|
25
|
+
children: React.ReactElement | React.ReactElement[],
|
|
26
|
+
propsToAdd: { [key: string]: string } = {},
|
|
27
|
+
): React.ReactElement | React.ReactElement[];
|