@rnmapbox/maps 10.0.0-beta.42 → 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 +69 -2
- 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/components/mapview/RCTMGLMapView.kt +1 -0
- package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
- package/docs/HeadingIndicator.md +1 -1
- package/docs/ShapeSource.md +13 -9
- package/docs/SymbolLayer.md +4 -3
- package/docs/docs.json +41 -67
- package/index.d.ts +16 -128
- package/ios/RCTMGL-v10/RCTMGLCamera.swift +5 -21
- package/ios/install.md +3 -2
- package/javascript/components/AbstractLayer.tsx +72 -0
- package/javascript/components/AbstractSource.tsx +23 -0
- package/javascript/components/BackgroundLayer.js +1 -1
- package/javascript/components/CircleLayer.js +1 -1
- package/javascript/components/FillExtrusionLayer.js +1 -1
- package/javascript/components/FillLayer.js +1 -1
- package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +6 -7
- package/javascript/components/HeatmapLayer.js +1 -1
- package/javascript/components/Images.js +1 -1
- package/javascript/components/LineLayer.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/RasterLayer.js +1 -1
- package/javascript/components/RasterSource.js +1 -1
- package/javascript/components/ShapeSource.tsx +412 -0
- package/javascript/components/SkyLayer.js +1 -1
- package/javascript/components/Style.js +2 -2
- package/javascript/components/SymbolLayer.tsx +111 -0
- package/javascript/components/Terrain.tsx +0 -60
- package/javascript/components/UserLocation.js +1 -1
- package/javascript/components/VectorSource.js +6 -3
- package/javascript/components/annotations/Annotation.js +1 -1
- package/javascript/global.d.ts +4 -0
- package/javascript/index.js +2 -2
- package/javascript/utils/MapboxStyles.ts +157 -50
- package/javascript/utils/StyleValue.ts +8 -6
- package/javascript/utils/animated/Animated.js +2 -2
- package/javascript/utils/deprecation.ts +7 -4
- package/javascript/utils/{filterUtils.js → filterUtils.tsx} +1 -1
- package/javascript/utils/index.d.ts +16 -3
- package/package.json +1 -1
- package/scripts/autogenHelpers/DocJSONBuilder.js +2 -3
- package/scripts/autogenHelpers/globals.js +18 -7
- package/scripts/templates/MapboxStyles.ts.ejs +7 -2
- package/javascript/components/AbstractLayer.js +0 -46
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/ShapeSource.js +0 -373
- package/javascript/components/SymbolLayer.js +0 -120
|
@@ -28,7 +28,7 @@ export function transformStyle(
|
|
|
28
28
|
const styleProps = Object.keys(style) as Array<keyof typeof style>;
|
|
29
29
|
for (const styleProp of styleProps) {
|
|
30
30
|
const styleType = getStyleType(styleProp);
|
|
31
|
-
let rawStyle: RawValueType = style[styleProp];
|
|
31
|
+
let rawStyle: RawValueType | undefined = style[styleProp];
|
|
32
32
|
|
|
33
33
|
if (styleType === 'color' && typeof rawStyle === 'string') {
|
|
34
34
|
const color = processColor(rawStyle);
|
|
@@ -43,11 +43,13 @@ export function transformStyle(
|
|
|
43
43
|
(Image.resolveAssetSource(rawStyle) as unknown as RawValueType) || {};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (rawStyle !== undefined) {
|
|
47
|
+
const bridgeValue = new BridgeValue(rawStyle);
|
|
48
|
+
nativeStyle[styleProp] = {
|
|
49
|
+
styletype: styleType,
|
|
50
|
+
stylevalue: bridgeValue.toJSON(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
return nativeStyle;
|
|
@@ -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[];
|
package/package.json
CHANGED
|
@@ -22,7 +22,6 @@ const IGNORE_FILES = [
|
|
|
22
22
|
'AbstractLayer',
|
|
23
23
|
'AbstractSource',
|
|
24
24
|
'NativeBridgeComponent',
|
|
25
|
-
'NativeBridgeComponent.tsx',
|
|
26
25
|
];
|
|
27
26
|
const IGNORE_PATTERN = /\.web\./;
|
|
28
27
|
|
|
@@ -359,7 +358,7 @@ class DocJSONBuilder {
|
|
|
359
358
|
return reject(err);
|
|
360
359
|
}
|
|
361
360
|
|
|
362
|
-
let fileName = fileNameWithExt.replace(
|
|
361
|
+
let fileName = fileNameWithExt.replace(/\.(js|tsx|ts$)/, '');
|
|
363
362
|
if (
|
|
364
363
|
IGNORE_FILES.includes(fileName) ||
|
|
365
364
|
fileName.match(IGNORE_PATTERN)
|
|
@@ -370,7 +369,7 @@ class DocJSONBuilder {
|
|
|
370
369
|
|
|
371
370
|
let parsedComponents = docgen.parse(content, {
|
|
372
371
|
babelOptions: {
|
|
373
|
-
filename:
|
|
372
|
+
filename: fileNameWithExt,
|
|
374
373
|
},
|
|
375
374
|
});
|
|
376
375
|
let [parsed] = parsedComponents;
|
|
@@ -292,20 +292,31 @@ global.dtsInterfaceType = function (prop) {
|
|
|
292
292
|
propTypes.push('string[]');
|
|
293
293
|
break;
|
|
294
294
|
case 'enum':
|
|
295
|
-
propTypes.push(
|
|
295
|
+
propTypes.push(
|
|
296
|
+
`Enum<${pascelCase(prop.name)}Enum, ${pascelCase(
|
|
297
|
+
prop.name,
|
|
298
|
+
)}EnumValues>[]`,
|
|
299
|
+
);
|
|
296
300
|
break;
|
|
297
301
|
}
|
|
298
302
|
// propTypes.push('ConstantPropType');
|
|
299
303
|
} else if (prop.type === 'number') {
|
|
300
304
|
propTypes.push('number');
|
|
301
305
|
} else if (prop.type === 'enum') {
|
|
302
|
-
propTypes.push(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
propTypes.push(
|
|
307
|
+
`Enum<${pascelCase(prop.name)}Enum, ${pascelCase(prop.name)}EnumValues>`,
|
|
308
|
+
);
|
|
309
|
+
} else if (prop.type === 'boolean') {
|
|
310
|
+
propTypes.push('boolean');
|
|
311
|
+
} else if (prop.type === 'resolvedImage') {
|
|
312
|
+
propTypes.push('ResolvedImageType');
|
|
313
|
+
} else if (prop.type === 'formatted') {
|
|
314
|
+
propTypes.push('FormattedString');
|
|
315
|
+
} else if (prop.type === 'string') {
|
|
308
316
|
propTypes.push('string');
|
|
317
|
+
} else {
|
|
318
|
+
console.error('Unexpected type:', prop.type);
|
|
319
|
+
throw new Error(`Unexpected type: ${prop.type} for ${prop.name}`);
|
|
309
320
|
}
|
|
310
321
|
|
|
311
322
|
/*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const layers = locals.layers;
|
|
3
3
|
-%>
|
|
4
4
|
/* This file was generated from MapboxStyle.ts.ejs do not modify */
|
|
5
|
-
|
|
5
|
+
import { type ImageSourcePropType } from 'react-native';
|
|
6
6
|
|
|
7
7
|
export type Translation = { x: number; y: number } | [number, number];
|
|
8
8
|
|
|
@@ -11,6 +11,8 @@ export interface Transition {
|
|
|
11
11
|
delay: number;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export type FormattedString = string; /* TODO */
|
|
15
|
+
|
|
14
16
|
type ExpressionName =
|
|
15
17
|
// Types
|
|
16
18
|
| 'array' | 'boolean' | 'collator' | 'format' | 'image' | 'literal' | 'number' | 'number-format' | 'object' | 'string'
|
|
@@ -47,6 +49,8 @@ export type Expression = [ExpressionName, ...ExpressionField[]];
|
|
|
47
49
|
|
|
48
50
|
type ExpressionParameters = 'zoom' | 'feature' | 'feature-state' | 'sky-radial-progress' | 'line-progress' | 'heatmap-density';
|
|
49
51
|
|
|
52
|
+
type ResolvedImageType = ImageSourcePropType;
|
|
53
|
+
|
|
50
54
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
55
|
export type Value<T, AllowedParameters extends ExpressionParameters[] = []> =
|
|
52
56
|
| T
|
|
@@ -59,9 +63,10 @@ export type Value<T, AllowedParameters extends ExpressionParameters[] = []> =
|
|
|
59
63
|
<%- pascelCase(k) %> = '<%- k %>',
|
|
60
64
|
<%_ } _%>
|
|
61
65
|
}
|
|
66
|
+
type <%- pascelCase(enumInfo.name) %>EnumValues = <%- Object.keys(enumInfo.values).map(k => `'${k}'`).join(' | ') %>;
|
|
62
67
|
<%_ } _%>
|
|
63
68
|
|
|
64
|
-
type Enum<EnumType> = EnumType |
|
|
69
|
+
type Enum<EnumType, EnumValues> = EnumType | EnumValues;
|
|
65
70
|
|
|
66
71
|
<%_ for (let layer of layers) { _%>
|
|
67
72
|
export interface <%- pascelCase(layer.name) %>LayerStyleProps {
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/* eslint react/prop-types:0 */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { processColor } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { getFilter } from '../utils/filterUtils';
|
|
6
|
-
import { transformStyle } from '../utils/StyleValue';
|
|
7
|
-
|
|
8
|
-
class AbstractLayer extends React.PureComponent {
|
|
9
|
-
get baseProps() {
|
|
10
|
-
return {
|
|
11
|
-
...this.props,
|
|
12
|
-
id: this.props.id,
|
|
13
|
-
sourceID: this.props.sourceID,
|
|
14
|
-
reactStyle: this.getStyle(this.props.style),
|
|
15
|
-
minZoomLevel: this.props.minZoomLevel,
|
|
16
|
-
maxZoomLevel: this.props.maxZoomLevel,
|
|
17
|
-
aboveLayerID: this.props.aboveLayerID,
|
|
18
|
-
belowLayerID: this.props.belowLayerID,
|
|
19
|
-
layerIndex: this.props.layerIndex,
|
|
20
|
-
filter: getFilter(this.props.filter),
|
|
21
|
-
style: undefined,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getStyleTypeFormatter(styleType) {
|
|
26
|
-
if (styleType === 'color') {
|
|
27
|
-
return processColor;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getStyle(style) {
|
|
32
|
-
return transformStyle(style);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
setNativeProps(props) {
|
|
36
|
-
if (this.refs.nativeLayer) {
|
|
37
|
-
let propsToPass = props;
|
|
38
|
-
if (props.style) {
|
|
39
|
-
propsToPass = { ...props, reactStyle: this.getStyle(props.style) };
|
|
40
|
-
}
|
|
41
|
-
this.refs.nativeLayer.setNativeProps(propsToPass);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default AbstractLayer;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
class AbstractSource extends React.PureComponent {
|
|
4
|
-
setNativeProps(props) {
|
|
5
|
-
if (this._nativeRef) {
|
|
6
|
-
this._nativeRef.setNativeProps(props);
|
|
7
|
-
} else {
|
|
8
|
-
if (this.refs.nativeSource) {
|
|
9
|
-
this.refs.nativeSource.setNativeProps(props);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default AbstractSource;
|
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { NativeModules, requireNativeComponent } from 'react-native';
|
|
4
|
-
|
|
5
|
-
import { getFilter } from '../utils/filterUtils';
|
|
6
|
-
import {
|
|
7
|
-
toJSONString,
|
|
8
|
-
cloneReactChildrenWithProps,
|
|
9
|
-
viewPropTypes,
|
|
10
|
-
isFunction,
|
|
11
|
-
isAndroid,
|
|
12
|
-
} from '../utils';
|
|
13
|
-
import { copyPropertiesAsDeprecated } from '../utils/deprecation';
|
|
14
|
-
|
|
15
|
-
import AbstractSource from './AbstractSource';
|
|
16
|
-
import NativeBridgeComponent from './NativeBridgeComponent';
|
|
17
|
-
|
|
18
|
-
const MapboxGL = NativeModules.MGLModule;
|
|
19
|
-
|
|
20
|
-
export const NATIVE_MODULE_NAME = 'RCTMGLShapeSource';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* ShapeSource is a map content source that supplies vector shapes to be shown on the map.
|
|
24
|
-
* The shape may be an url or a GeoJSON object
|
|
25
|
-
*/
|
|
26
|
-
class ShapeSource extends NativeBridgeComponent(AbstractSource) {
|
|
27
|
-
static NATIVE_ASSETS_KEY = 'assets';
|
|
28
|
-
|
|
29
|
-
static propTypes = {
|
|
30
|
-
...viewPropTypes,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A string that uniquely identifies the source.
|
|
34
|
-
*/
|
|
35
|
-
id: PropTypes.string.isRequired,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.
|
|
39
|
-
*/
|
|
40
|
-
url: PropTypes.string,
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a feature collection.
|
|
44
|
-
*/
|
|
45
|
-
shape: PropTypes.object,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Enables clustering on the source for point shapes.
|
|
49
|
-
*/
|
|
50
|
-
cluster: PropTypes.bool,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Specifies the radius of each cluster if clustering is enabled.
|
|
54
|
-
* A value of 512 produces a radius equal to the width of a tile.
|
|
55
|
-
* The default value is 50.
|
|
56
|
-
*/
|
|
57
|
-
clusterRadius: PropTypes.number,
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Specifies the maximum zoom level at which to cluster points if clustering is enabled.
|
|
61
|
-
* Defaults to one zoom level less than the value of maxZoomLevel so that, at the maximum zoom level,
|
|
62
|
-
* the shapes are not clustered.
|
|
63
|
-
*/
|
|
64
|
-
clusterMaxZoomLevel: PropTypes.number,
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* [`mapbox-gl` (v8) implementation only]
|
|
68
|
-
* Specifies custom properties on the generated clusters if clustering
|
|
69
|
-
* is enabled, aggregating values from clustered points.
|
|
70
|
-
*
|
|
71
|
-
* Has the form `{ "property_name": [operator, map_expression]}`, where
|
|
72
|
-
* `operator` is a custom reduce expression that references a special `["accumulated"]` value -
|
|
73
|
-
* it accumulates the property value from clusters/points the cluster contains
|
|
74
|
-
* `map_expression` produces the value of a single point
|
|
75
|
-
*
|
|
76
|
-
* Example: `{ "resultingSum": [["+", ["accumulated"], ["get", "resultingSum"]], ["get", "scalerank"]] }`
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
clusterProperties: PropTypes.object,
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Specifies the maximum zoom level at which to create vector tiles.
|
|
83
|
-
* A greater value produces greater detail at high zoom levels.
|
|
84
|
-
* The default value is 18.
|
|
85
|
-
*/
|
|
86
|
-
maxZoomLevel: PropTypes.number,
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Specifies the size of the tile buffer on each side.
|
|
90
|
-
* A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself.
|
|
91
|
-
* Larger values produce fewer rendering artifacts near tile edges and slower performance.
|
|
92
|
-
* The default value is 128.
|
|
93
|
-
*/
|
|
94
|
-
buffer: PropTypes.number,
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Specifies the Douglas-Peucker simplification tolerance.
|
|
98
|
-
* A greater value produces simpler geometries and improves performance.
|
|
99
|
-
* The default value is 0.375.
|
|
100
|
-
*/
|
|
101
|
-
tolerance: PropTypes.number,
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Whether to calculate line distance metrics.
|
|
105
|
-
* This is required for line layers that specify lineGradient values.
|
|
106
|
-
* The default value is false.
|
|
107
|
-
*/
|
|
108
|
-
lineMetrics: PropTypes.bool,
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Source press listener, gets called when a user presses one of the children layers only
|
|
112
|
-
* if that layer has a higher z-index than another source layers
|
|
113
|
-
*
|
|
114
|
-
* @param {Object} event
|
|
115
|
-
* @param {Object[]} event.features - the geojson features that have hit by the press (might be multiple)
|
|
116
|
-
* @param {Object} event.coordinates - the coordinates of the click
|
|
117
|
-
* @param {Object} event.point - the point of the click
|
|
118
|
-
* @return void
|
|
119
|
-
*/
|
|
120
|
-
onPress: PropTypes.func,
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Overrides the default touch hitbox(44x44 pixels) for the source layers
|
|
124
|
-
*/
|
|
125
|
-
hitbox: PropTypes.shape({
|
|
126
|
-
/**
|
|
127
|
-
* `width` of hitbox
|
|
128
|
-
*/
|
|
129
|
-
width: PropTypes.number.isRequired,
|
|
130
|
-
/**
|
|
131
|
-
* `height` of hitbox
|
|
132
|
-
*/
|
|
133
|
-
height: PropTypes.number.isRequired,
|
|
134
|
-
}),
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
static defaultProps = {
|
|
138
|
-
id: MapboxGL.StyleSource.DefaultSourceID,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
constructor(props) {
|
|
142
|
-
super(props, NATIVE_MODULE_NAME);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
_setNativeRef(nativeRef) {
|
|
146
|
-
this._nativeRef = nativeRef;
|
|
147
|
-
super._runPendingNativeCommands(nativeRef);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Returns all features from the source that match the query parameters whether the feature is currently
|
|
152
|
-
* rendered on the map.
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* shapeSource.features()
|
|
156
|
-
*
|
|
157
|
-
* @param {Array=} filter - an optional filter statement to filter the returned Features.
|
|
158
|
-
* @return {FeatureCollection}
|
|
159
|
-
*/
|
|
160
|
-
async features(filter = []) {
|
|
161
|
-
const res = await this._runNativeCommand('features', this._nativeRef, [
|
|
162
|
-
getFilter(filter),
|
|
163
|
-
]);
|
|
164
|
-
|
|
165
|
-
if (isAndroid()) {
|
|
166
|
-
return JSON.parse(res.data);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return res.data;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Returns the zoom needed to expand the cluster.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
|
|
177
|
-
*
|
|
178
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
179
|
-
* @return {number}
|
|
180
|
-
*/
|
|
181
|
-
async getClusterExpansionZoom(feature) {
|
|
182
|
-
if (typeof feature === 'number') {
|
|
183
|
-
console.warn(
|
|
184
|
-
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
185
|
-
);
|
|
186
|
-
const res = await this._runNativeCommand(
|
|
187
|
-
'getClusterExpansionZoomById',
|
|
188
|
-
this._nativeRef,
|
|
189
|
-
[feature],
|
|
190
|
-
);
|
|
191
|
-
return res.data;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const res = await this._runNativeCommand(
|
|
195
|
-
'getClusterExpansionZoom',
|
|
196
|
-
this._nativeRef,
|
|
197
|
-
[JSON.stringify(feature)],
|
|
198
|
-
);
|
|
199
|
-
return res.data;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Returns the FeatureCollection from the cluster.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
|
|
207
|
-
*
|
|
208
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
209
|
-
* @param {number} limit - The number of points to return.
|
|
210
|
-
* @param {number} offset - The amount of points to skip (for pagination).
|
|
211
|
-
* @return {FeatureCollection}
|
|
212
|
-
*/
|
|
213
|
-
async getClusterLeaves(feature, limit, offset) {
|
|
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 = await this._runNativeCommand(
|
|
219
|
-
'getClusterLeavesById',
|
|
220
|
-
this._nativeRef,
|
|
221
|
-
[feature, limit, offset],
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
if (isAndroid()) {
|
|
225
|
-
return JSON.parse(res.data);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return res.data;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const res = await this._runNativeCommand(
|
|
232
|
-
'getClusterLeaves',
|
|
233
|
-
this._nativeRef,
|
|
234
|
-
[JSON.stringify(feature), limit, offset],
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
if (isAndroid()) {
|
|
238
|
-
return JSON.parse(res.data);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return res.data;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Returns the FeatureCollection from the cluster (on the next zoom level).
|
|
246
|
-
*
|
|
247
|
-
* @example
|
|
248
|
-
* const collection = await shapeSource.getClusterChildren(clusterId);
|
|
249
|
-
*
|
|
250
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
251
|
-
* @return {FeatureCollection}
|
|
252
|
-
*/
|
|
253
|
-
async getClusterChildren(feature) {
|
|
254
|
-
if (typeof feature === 'number') {
|
|
255
|
-
console.warn(
|
|
256
|
-
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
257
|
-
);
|
|
258
|
-
const res = await this._runNativeCommand(
|
|
259
|
-
'getClusterChildrenById',
|
|
260
|
-
this._nativeRef,
|
|
261
|
-
[feature],
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
if (isAndroid()) {
|
|
265
|
-
return JSON.parse(res.data);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return res.data;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const res = await this._runNativeCommand(
|
|
272
|
-
'getClusterChildren',
|
|
273
|
-
this._nativeRef,
|
|
274
|
-
[JSON.stringify(feature)],
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
if (isAndroid()) {
|
|
278
|
-
return JSON.parse(res.data);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return res.data;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
setNativeProps(props) {
|
|
285
|
-
const shallowProps = Object.assign({}, props);
|
|
286
|
-
|
|
287
|
-
// Adds support for Animated
|
|
288
|
-
if (shallowProps.shape && typeof shallowProps.shape !== 'string') {
|
|
289
|
-
shallowProps.shape = JSON.stringify(shallowProps.shape);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
super.setNativeProps(shallowProps);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
_getShape() {
|
|
296
|
-
if (!this.props.shape) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
return toJSONString(this.props.shape);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
onPress(event) {
|
|
303
|
-
const {
|
|
304
|
-
nativeEvent: {
|
|
305
|
-
payload: { features, coordinates, point },
|
|
306
|
-
},
|
|
307
|
-
} = event;
|
|
308
|
-
let newEvent = {
|
|
309
|
-
features,
|
|
310
|
-
coordinates,
|
|
311
|
-
point,
|
|
312
|
-
};
|
|
313
|
-
newEvent = copyPropertiesAsDeprecated(
|
|
314
|
-
event,
|
|
315
|
-
newEvent,
|
|
316
|
-
(key) => {
|
|
317
|
-
console.warn(
|
|
318
|
-
`event.${key} is deprecated on ShapeSource#onPress, please use event.features`,
|
|
319
|
-
);
|
|
320
|
-
},
|
|
321
|
-
{
|
|
322
|
-
nativeEvent: (origNativeEvent) => ({
|
|
323
|
-
...origNativeEvent,
|
|
324
|
-
payload: features[0],
|
|
325
|
-
}),
|
|
326
|
-
},
|
|
327
|
-
);
|
|
328
|
-
this.props.onPress(newEvent);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
render() {
|
|
332
|
-
const props = {
|
|
333
|
-
id: this.props.id,
|
|
334
|
-
url: this.props.url,
|
|
335
|
-
shape: this._getShape(),
|
|
336
|
-
hitbox: this.props.hitbox,
|
|
337
|
-
hasPressListener: isFunction(this.props.onPress),
|
|
338
|
-
onMapboxShapeSourcePress: this.onPress.bind(this),
|
|
339
|
-
cluster: this.props.cluster ? 1 : 0,
|
|
340
|
-
clusterRadius: this.props.clusterRadius,
|
|
341
|
-
clusterMaxZoomLevel: this.props.clusterMaxZoomLevel,
|
|
342
|
-
clusterProperties: this.props.clusterProperties,
|
|
343
|
-
maxZoomLevel: this.props.maxZoomLevel,
|
|
344
|
-
buffer: this.props.buffer,
|
|
345
|
-
tolerance: this.props.tolerance,
|
|
346
|
-
lineMetrics: this.props.lineMetrics,
|
|
347
|
-
onPress: undefined,
|
|
348
|
-
ref: (nativeRef) => this._setNativeRef(nativeRef),
|
|
349
|
-
onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
return (
|
|
353
|
-
<RCTMGLShapeSource {...props}>
|
|
354
|
-
{cloneReactChildrenWithProps(this.props.children, {
|
|
355
|
-
sourceID: this.props.id,
|
|
356
|
-
})}
|
|
357
|
-
</RCTMGLShapeSource>
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const RCTMGLShapeSource = requireNativeComponent(
|
|
363
|
-
NATIVE_MODULE_NAME,
|
|
364
|
-
ShapeSource,
|
|
365
|
-
{
|
|
366
|
-
nativeOnly: {
|
|
367
|
-
hasPressListener: true,
|
|
368
|
-
onMapboxShapeSourcePress: true,
|
|
369
|
-
},
|
|
370
|
-
},
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
export default ShapeSource;
|