@maplibre/maplibre-react-native 9.0.1 → 10.0.0-alpha.1
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/.eslintrc.js +10 -2
- package/.husky/pre-commit +5 -0
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/.yarn/sdks/eslint/bin/eslint.js +20 -0
- package/.yarn/sdks/eslint/lib/api.js +20 -0
- package/.yarn/sdks/eslint/package.json +6 -0
- package/.yarn/sdks/integrations.yml +5 -0
- package/.yarn/sdks/prettier/index.js +20 -0
- package/.yarn/sdks/prettier/package.json +6 -0
- package/.yarn/sdks/typescript/bin/tsc +20 -0
- package/.yarn/sdks/typescript/bin/tsserver +20 -0
- package/.yarn/sdks/typescript/lib/tsc.js +20 -0
- package/.yarn/sdks/typescript/lib/tsserver.js +225 -0
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +225 -0
- package/.yarn/sdks/typescript/lib/typescript.js +20 -0
- package/.yarn/sdks/typescript/package.json +6 -0
- package/CHANGELOG.md +15 -1
- package/android/build.gradle +2 -2
- package/android/rctmgl/build.gradle +2 -4
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSource.java +14 -0
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSourceManager.java +26 -0
- package/android/rctmgl/src/main/java/com/mapbox/rctmgl/utils/ClusterPropertyEntry.java +13 -0
- package/docs/Annotation.md +8 -9
- package/docs/BackgroundLayer.md +2 -10
- package/docs/Callout.md +5 -5
- package/docs/Camera.md +18 -47
- package/docs/CircleLayer.md +2 -10
- package/docs/FillExtrusionLayer.md +2 -10
- package/docs/FillLayer.md +2 -10
- package/docs/HeatmapLayer.md +2 -10
- package/docs/ImageSource.md +3 -2
- package/docs/Images.md +5 -3
- package/docs/Light.md +1 -1
- package/docs/LineLayer.md +2 -10
- package/docs/MapView.md +53 -37
- package/docs/MarkerView.md +4 -2
- package/docs/NativeUserLocation.md +2 -2
- package/docs/PointAnnotation.md +5 -8
- package/docs/RasterLayer.md +2 -10
- package/docs/RasterSource.md +3 -2
- package/docs/ShapeSource.md +12 -6
- package/docs/Style.md +1 -1
- package/docs/SymbolLayer.md +3 -10
- package/docs/UserLocation.md +8 -10
- package/docs/VectorSource.md +6 -5
- package/docs/coordinates.md +6 -0
- package/docs/docs.json +561 -1308
- package/docs/location.md +6 -0
- package/docs/snapshotManager.md +3 -3
- package/ios/RCTMGL/RCTMGLShapeSource.h +1 -0
- package/ios/RCTMGL/RCTMGLShapeSource.m +14 -0
- package/ios/RCTMGL/RCTMGLShapeSourceManager.m +1 -0
- package/ios/RCTMGL.xcodeproj/project.pbxproj +1 -0
- package/javascript/@types/assets.d.ts +4 -0
- package/javascript/MGLModule.ts +37 -0
- package/javascript/Maplibre.ts +65 -0
- package/javascript/components/AbstractLayer.tsx +107 -0
- package/javascript/components/AbstractSource.tsx +27 -0
- package/javascript/components/BackgroundLayer.tsx +43 -0
- package/javascript/components/{Callout.js → Callout.tsx} +67 -65
- package/javascript/components/{Camera.js → Camera.tsx} +266 -251
- package/javascript/components/CircleLayer.tsx +46 -0
- package/javascript/components/FillExtrusionLayer.tsx +47 -0
- package/javascript/components/FillLayer.tsx +41 -0
- package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +8 -8
- package/javascript/components/HeatmapLayer.tsx +44 -0
- package/javascript/components/ImageSource.tsx +78 -0
- package/javascript/components/Images.tsx +134 -0
- package/javascript/components/Light.tsx +67 -0
- package/javascript/components/LineLayer.tsx +42 -0
- package/javascript/components/{MapView.js → MapView.tsx} +365 -354
- package/javascript/components/MarkerView.tsx +104 -0
- package/javascript/components/{NativeBridgeComponent.js → NativeBridgeComponent.tsx} +44 -13
- package/javascript/components/NativeUserLocation.tsx +33 -0
- package/javascript/components/PointAnnotation.tsx +221 -0
- package/javascript/components/RasterLayer.tsx +41 -0
- package/javascript/components/RasterSource.tsx +117 -0
- package/javascript/components/ShapeSource.tsx +383 -0
- package/javascript/components/{Style.js → Style.tsx} +132 -38
- package/javascript/components/SymbolLayer.tsx +72 -0
- package/javascript/components/{UserLocation.js → UserLocation.tsx} +111 -110
- package/javascript/components/VectorSource.tsx +207 -0
- package/javascript/components/annotations/Annotation.tsx +134 -0
- package/javascript/index.ts +4 -0
- package/javascript/modules/location/{locationManager.js → locationManager.ts} +71 -10
- package/javascript/modules/offline/{OfflineCreatePackOptions.js → OfflineCreatePackOptions.ts} +20 -4
- package/javascript/modules/offline/{OfflinePack.js → OfflinePack.ts} +23 -7
- package/javascript/modules/offline/{offlineManager.js → offlineManager.ts} +81 -24
- package/javascript/modules/snapshot/{SnapshotOptions.js → SnapshotOptions.ts} +43 -6
- package/javascript/modules/snapshot/{snapshotManager.js → snapshotManager.ts} +5 -5
- package/javascript/requestAndroidLocationPermissions.ts +29 -0
- package/javascript/types/BaseProps.ts +5 -0
- package/javascript/types/OnPressEvent.ts +13 -0
- package/javascript/types/index.ts +7 -0
- package/javascript/utils/BridgeValue.ts +90 -0
- package/javascript/utils/{Logger.js → Logger.ts} +37 -18
- package/javascript/utils/MaplibreStyles.d.ts +1486 -0
- package/javascript/utils/StyleValue.ts +49 -0
- package/javascript/utils/animated/AbstractAnimatedCoordinates.ts +134 -0
- package/javascript/utils/animated/AnimatedCoordinatesArray.ts +112 -0
- package/javascript/utils/animated/{AnimatedExtractCoordinateFromArray.js → AnimatedExtractCoordinateFromArray.ts} +5 -5
- package/javascript/utils/animated/{AnimatedPoint.js → AnimatedPoint.ts} +20 -12
- package/javascript/utils/animated/{AnimatedRouteCoordinatesArray.js → AnimatedRouteCoordinatesArray.ts} +39 -14
- package/javascript/utils/animated/{AnimatedShape.js → AnimatedShape.ts} +31 -10
- package/javascript/utils/{deprecation.js → deprecation.ts} +9 -6
- package/javascript/utils/filterUtils.ts +9 -0
- package/javascript/utils/geoUtils.ts +79 -0
- package/javascript/utils/{index.js → index.ts} +44 -24
- package/javascript/utils/styleMap.ts +264 -0
- package/package.json +43 -34
- package/plugin/build/withMapLibre.js +3 -2
- package/scripts/autogenHelpers/globals.js +1 -1
- package/scripts/autogenerate.js +14 -6
- package/scripts/templates/MaplibreStyles.ts.ejs +99 -0
- package/scripts/templates/index.d.ts.ejs +71 -42
- package/scripts/templates/{styleMap.js.ejs → styleMap.ts.ejs} +3 -33
- package/setup-jest.js +3 -10
- package/tsconfig.json +20 -61
- package/index.d.ts +0 -954
- package/javascript/components/AbstractLayer.js +0 -75
- package/javascript/components/AbstractSource.js +0 -15
- package/javascript/components/BackgroundLayer.js +0 -97
- package/javascript/components/CircleLayer.js +0 -101
- package/javascript/components/FillExtrusionLayer.js +0 -98
- package/javascript/components/FillLayer.js +0 -94
- package/javascript/components/HeatmapLayer.js +0 -99
- package/javascript/components/ImageSource.js +0 -82
- package/javascript/components/Images.js +0 -119
- package/javascript/components/Light.js +0 -47
- package/javascript/components/LineLayer.js +0 -94
- package/javascript/components/MarkerView.js +0 -87
- package/javascript/components/NativeUserLocation.js +0 -41
- package/javascript/components/PointAnnotation.js +0 -216
- package/javascript/components/RasterLayer.js +0 -95
- package/javascript/components/RasterSource.js +0 -124
- package/javascript/components/ShapeSource.js +0 -357
- package/javascript/components/SymbolLayer.js +0 -120
- package/javascript/components/VectorSource.js +0 -200
- package/javascript/components/annotations/Annotation.js +0 -122
- package/javascript/index.js +0 -149
- package/javascript/utils/BridgeValue.js +0 -81
- package/javascript/utils/animated/AnimatedCoordinatesArray.js +0 -191
- package/javascript/utils/filterUtils.js +0 -7
- package/javascript/utils/geoUtils.js +0 -73
- package/javascript/utils/styleMap.js +0 -1932
- /package/javascript/utils/animated/{Animated.js → Animated.ts} +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {cloneReactChildrenWithProps, viewPropTypes} from '../utils';
|
|
2
|
-
|
|
3
|
-
import AbstractSource from './AbstractSource';
|
|
4
|
-
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import {NativeModules, requireNativeComponent} from 'react-native';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
|
|
9
|
-
const MapLibreGL = NativeModules.MGLModule;
|
|
10
|
-
|
|
11
|
-
export const NATIVE_MODULE_NAME = 'RCTMGLRasterSource';
|
|
12
|
-
|
|
13
|
-
const isTileTemplateUrl = url =>
|
|
14
|
-
url &&
|
|
15
|
-
(url.includes('{z}') || url.includes('{bbox-') || url.includes('{quadkey}'));
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* RasterSource is a map content source that supplies raster image tiles to be shown on the map.
|
|
19
|
-
* The location of and metadata about the tiles are defined either by an option dictionary
|
|
20
|
-
* or by an external file that conforms to the TileJSON specification.
|
|
21
|
-
*/
|
|
22
|
-
class RasterSource extends AbstractSource {
|
|
23
|
-
static propTypes = {
|
|
24
|
-
...viewPropTypes,
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A string that uniquely identifies the source.
|
|
28
|
-
*/
|
|
29
|
-
id: PropTypes.string.isRequired,
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A URL to a TileJSON configuration file describing the source’s contents and other metadata.
|
|
33
|
-
*/
|
|
34
|
-
url: PropTypes.string,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* An array of tile URL templates. If multiple endpoints are specified, clients may use any combination of endpoints.
|
|
38
|
-
* Example: https://example.com/raster-tiles/{z}/{x}/{y}.png
|
|
39
|
-
*/
|
|
40
|
-
tileUrlTemplates: PropTypes.arrayOf(PropTypes.string),
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* An unsigned integer that specifies the minimum zoom level at which to display tiles from the source.
|
|
44
|
-
* The value should be between 0 and 22, inclusive, and less than
|
|
45
|
-
* maxZoomLevel, if specified. The default value for this option is 0.
|
|
46
|
-
*/
|
|
47
|
-
minZoomLevel: PropTypes.number,
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* An unsigned integer that specifies the maximum zoom level at which to display tiles from the source.
|
|
51
|
-
* The value should be between 0 and 22, inclusive, and less than
|
|
52
|
-
* minZoomLevel, if specified. The default value for this option is 22.
|
|
53
|
-
*/
|
|
54
|
-
maxZoomLevel: PropTypes.number,
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Size of the map tiles.
|
|
58
|
-
* Mapbox urls default to 256, all others default to 512.
|
|
59
|
-
*/
|
|
60
|
-
tileSize: PropTypes.number,
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Influences the y direction of the tile coordinates. (tms inverts y axis)
|
|
64
|
-
*/
|
|
65
|
-
tms: PropTypes.bool,
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* An HTML or literal text string defining the buttons to be displayed in an action sheet when the
|
|
69
|
-
* source is part of a map view’s style and the map view’s attribution button is pressed.
|
|
70
|
-
*/
|
|
71
|
-
attribution: PropTypes.string,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
static defaultProps = {
|
|
75
|
-
id: MapLibreGL.StyleSource.DefaultSourceID,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
constructor(props) {
|
|
79
|
-
super(props);
|
|
80
|
-
if (isTileTemplateUrl(props.url)) {
|
|
81
|
-
console.warn(
|
|
82
|
-
`RasterSource 'url' property contains a Tile URL Template, but is intended for a StyleJSON URL. Please migrate your VectorSource to use: \`tileUrlTemplates=["${props.url}"]\` instead.`,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
render() {
|
|
88
|
-
let {url} = this.props;
|
|
89
|
-
let {tileUrlTemplates} = this.props;
|
|
90
|
-
|
|
91
|
-
// Swapping url for tileUrlTemplates to provide backward compatiblity
|
|
92
|
-
// when RasterSource supported only tile url as url prop
|
|
93
|
-
if (isTileTemplateUrl(url)) {
|
|
94
|
-
tileUrlTemplates = [url];
|
|
95
|
-
url = undefined;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const props = {
|
|
99
|
-
...this.props,
|
|
100
|
-
id: this.props.id,
|
|
101
|
-
url,
|
|
102
|
-
tileUrlTemplates,
|
|
103
|
-
minZoomLevel: this.props.minZoomLevel,
|
|
104
|
-
maxZoomLevel: this.props.maxZoomLevel,
|
|
105
|
-
tileSize: this.props.tileSize,
|
|
106
|
-
tms: this.props.tms,
|
|
107
|
-
attribution: this.props.attribution,
|
|
108
|
-
};
|
|
109
|
-
return (
|
|
110
|
-
<RCTMGLRasterSource ref="nativeSource" {...props}>
|
|
111
|
-
{cloneReactChildrenWithProps(this.props.children, {
|
|
112
|
-
sourceID: this.props.id,
|
|
113
|
-
})}
|
|
114
|
-
</RCTMGLRasterSource>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const RCTMGLRasterSource = requireNativeComponent(
|
|
120
|
-
NATIVE_MODULE_NAME,
|
|
121
|
-
RasterSource,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
export default RasterSource;
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import {getFilter} from '../utils/filterUtils';
|
|
2
|
-
import {
|
|
3
|
-
toJSONString,
|
|
4
|
-
cloneReactChildrenWithProps,
|
|
5
|
-
viewPropTypes,
|
|
6
|
-
isFunction,
|
|
7
|
-
isAndroid,
|
|
8
|
-
} from '../utils';
|
|
9
|
-
import {copyPropertiesAsDeprecated} from '../utils/deprecation';
|
|
10
|
-
|
|
11
|
-
import AbstractSource from './AbstractSource';
|
|
12
|
-
import NativeBridgeComponent from './NativeBridgeComponent';
|
|
13
|
-
|
|
14
|
-
import PropTypes from 'prop-types';
|
|
15
|
-
import React from 'react';
|
|
16
|
-
import {NativeModules, requireNativeComponent} from 'react-native';
|
|
17
|
-
|
|
18
|
-
const MapLibreGL = 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 a 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 colllection.
|
|
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
|
-
* Specifies the maximum zoom level at which to create vector tiles.
|
|
68
|
-
* A greater value produces greater detail at high zoom levels.
|
|
69
|
-
* The default value is 18.
|
|
70
|
-
*/
|
|
71
|
-
maxZoomLevel: PropTypes.number,
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Specifies the size of the tile buffer on each side.
|
|
75
|
-
* A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself.
|
|
76
|
-
* Larger values produce fewer rendering artifacts near tile edges and slower performance.
|
|
77
|
-
* The default value is 128.
|
|
78
|
-
*/
|
|
79
|
-
buffer: PropTypes.number,
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Specifies the Douglas-Peucker simplification tolerance.
|
|
83
|
-
* A greater value produces simpler geometries and improves performance.
|
|
84
|
-
* The default value is 0.375.
|
|
85
|
-
*/
|
|
86
|
-
tolerance: PropTypes.number,
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Whether to calculate line distance metrics.
|
|
90
|
-
* This is required for line layers that specify lineGradient values.
|
|
91
|
-
* The default value is false.
|
|
92
|
-
*/
|
|
93
|
-
lineMetrics: PropTypes.bool,
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Source press listener, gets called when a user presses one of the children layers only
|
|
97
|
-
* if that layer has a higher z-index than another source layers
|
|
98
|
-
*
|
|
99
|
-
* @param {Object} event
|
|
100
|
-
* @param {Object[]} event.features - the geojson features that have hit by the press (might be multiple)
|
|
101
|
-
* @param {Object} event.coordinates - the coordinates of the click
|
|
102
|
-
* @param {Object} event.point - the point of the click
|
|
103
|
-
* @return void
|
|
104
|
-
*/
|
|
105
|
-
onPress: PropTypes.func,
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Overrides the default touch hitbox(44x44 pixels) for the source layers
|
|
109
|
-
*/
|
|
110
|
-
hitbox: PropTypes.shape({
|
|
111
|
-
/**
|
|
112
|
-
* `width` of hitbox
|
|
113
|
-
*/
|
|
114
|
-
width: PropTypes.number.isRequired,
|
|
115
|
-
/**
|
|
116
|
-
* `height` of hitbox
|
|
117
|
-
*/
|
|
118
|
-
height: PropTypes.number.isRequired,
|
|
119
|
-
}),
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
static defaultProps = {
|
|
123
|
-
id: MapLibreGL.StyleSource.DefaultSourceID,
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
constructor(props) {
|
|
127
|
-
super(props, NATIVE_MODULE_NAME);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
_setNativeRef(nativeRef) {
|
|
131
|
-
this._nativeRef = nativeRef;
|
|
132
|
-
super._runPendingNativeCommands(nativeRef);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Returns all features from the source that match the query parameters regardless of whether or not the feature is
|
|
137
|
-
* currently rendered on the map.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* shapeSource.features()
|
|
141
|
-
*
|
|
142
|
-
* @param {Array=} filter - an optional filter statement to filter the returned Features.
|
|
143
|
-
* @return {FeatureCollection}
|
|
144
|
-
*/
|
|
145
|
-
async features(filter = []) {
|
|
146
|
-
const res = await this._runNativeCommand('features', this._nativeRef, [
|
|
147
|
-
getFilter(filter),
|
|
148
|
-
]);
|
|
149
|
-
|
|
150
|
-
if (isAndroid()) {
|
|
151
|
-
return JSON.parse(res.data);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return res.data;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Returns the zoom needed to expand the cluster.
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
|
|
162
|
-
*
|
|
163
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
164
|
-
* @return {number}
|
|
165
|
-
*/
|
|
166
|
-
async getClusterExpansionZoom(feature) {
|
|
167
|
-
if (typeof feature === 'number') {
|
|
168
|
-
console.warn(
|
|
169
|
-
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
170
|
-
);
|
|
171
|
-
const res = await this._runNativeCommand(
|
|
172
|
-
'getClusterExpansionZoomById',
|
|
173
|
-
this._nativeRef,
|
|
174
|
-
[feature],
|
|
175
|
-
);
|
|
176
|
-
return res.data;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const res = await this._runNativeCommand(
|
|
180
|
-
'getClusterExpansionZoom',
|
|
181
|
-
this._nativeRef,
|
|
182
|
-
[JSON.stringify(feature)],
|
|
183
|
-
);
|
|
184
|
-
return res.data;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Returns the FeatureCollection from the cluster.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
|
|
192
|
-
*
|
|
193
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
194
|
-
* @param {number} limit - The number of points to return.
|
|
195
|
-
* @param {number} offset - The amount of points to skip (for pagination).
|
|
196
|
-
* @return {FeatureCollection}
|
|
197
|
-
*/
|
|
198
|
-
async getClusterLeaves(feature, limit, offset) {
|
|
199
|
-
if (typeof feature === 'number') {
|
|
200
|
-
console.warn(
|
|
201
|
-
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
202
|
-
);
|
|
203
|
-
const res = await this._runNativeCommand(
|
|
204
|
-
'getClusterLeavesById',
|
|
205
|
-
this._nativeRef,
|
|
206
|
-
[feature, limit, offset],
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
if (isAndroid()) {
|
|
210
|
-
return JSON.parse(res.data);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return res.data;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const res = await this._runNativeCommand(
|
|
217
|
-
'getClusterLeaves',
|
|
218
|
-
this._nativeRef,
|
|
219
|
-
[JSON.stringify(feature), limit, offset],
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
if (isAndroid()) {
|
|
223
|
-
return JSON.parse(res.data);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return res.data;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Returns the FeatureCollection from the cluster (on the next zoom level).
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* const collection = await shapeSource.getClusterChildren(clusterId);
|
|
234
|
-
*
|
|
235
|
-
* @param {Feature} feature - The feature cluster to expand.
|
|
236
|
-
* @return {FeatureCollection}
|
|
237
|
-
*/
|
|
238
|
-
async getClusterChildren(feature) {
|
|
239
|
-
if (typeof feature === 'number') {
|
|
240
|
-
console.warn(
|
|
241
|
-
'Using cluster_id is deprecated and will be removed from the future releases. Please use cluster as an argument instead.',
|
|
242
|
-
);
|
|
243
|
-
const res = await this._runNativeCommand(
|
|
244
|
-
'getClusterChildrenById',
|
|
245
|
-
this._nativeRef,
|
|
246
|
-
[feature],
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
if (isAndroid()) {
|
|
250
|
-
return JSON.parse(res.data);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return res.data;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const res = await this._runNativeCommand(
|
|
257
|
-
'getClusterChildren',
|
|
258
|
-
this._nativeRef,
|
|
259
|
-
[JSON.stringify(feature)],
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
if (isAndroid()) {
|
|
263
|
-
return JSON.parse(res.data);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
return res.data;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
setNativeProps(props) {
|
|
270
|
-
const shallowProps = Object.assign({}, props);
|
|
271
|
-
|
|
272
|
-
// Adds support for Animated
|
|
273
|
-
if (shallowProps.shape && typeof shallowProps !== 'string') {
|
|
274
|
-
shallowProps.shape = JSON.stringify(shallowProps.shape);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
super.setNativeProps(shallowProps);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
_getShape() {
|
|
281
|
-
if (!this.props.shape) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
return toJSONString(this.props.shape);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
onPress(event) {
|
|
288
|
-
const {
|
|
289
|
-
nativeEvent: {
|
|
290
|
-
payload: {features, coordinates, point},
|
|
291
|
-
},
|
|
292
|
-
} = event;
|
|
293
|
-
let newEvent = {
|
|
294
|
-
features,
|
|
295
|
-
coordinates,
|
|
296
|
-
point,
|
|
297
|
-
};
|
|
298
|
-
newEvent = copyPropertiesAsDeprecated(
|
|
299
|
-
event,
|
|
300
|
-
newEvent,
|
|
301
|
-
key => {
|
|
302
|
-
console.warn(
|
|
303
|
-
`event.${key} is deprecated on ShapeSource#onPress, please use event.features`,
|
|
304
|
-
);
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
nativeEvent: origNativeEvent => ({
|
|
308
|
-
...origNativeEvent,
|
|
309
|
-
payload: features[0],
|
|
310
|
-
}),
|
|
311
|
-
},
|
|
312
|
-
);
|
|
313
|
-
this.props.onPress(newEvent);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
render() {
|
|
317
|
-
const props = {
|
|
318
|
-
id: this.props.id,
|
|
319
|
-
url: this.props.url,
|
|
320
|
-
shape: this._getShape(),
|
|
321
|
-
hitbox: this.props.hitbox,
|
|
322
|
-
hasPressListener: isFunction(this.props.onPress),
|
|
323
|
-
onMapboxShapeSourcePress: this.onPress.bind(this),
|
|
324
|
-
cluster: this.props.cluster ? 1 : 0,
|
|
325
|
-
clusterRadius: this.props.clusterRadius,
|
|
326
|
-
clusterMaxZoomLevel: this.props.clusterMaxZoomLevel,
|
|
327
|
-
maxZoomLevel: this.props.maxZoomLevel,
|
|
328
|
-
buffer: this.props.buffer,
|
|
329
|
-
tolerance: this.props.tolerance,
|
|
330
|
-
lineMetrics: this.props.lineMetrics,
|
|
331
|
-
onPress: undefined,
|
|
332
|
-
ref: nativeRef => this._setNativeRef(nativeRef),
|
|
333
|
-
onAndroidCallback: isAndroid() ? this._onAndroidCallback : undefined,
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
return (
|
|
337
|
-
<RCTMGLShapeSource {...props}>
|
|
338
|
-
{cloneReactChildrenWithProps(this.props.children, {
|
|
339
|
-
sourceID: this.props.id,
|
|
340
|
-
})}
|
|
341
|
-
</RCTMGLShapeSource>
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const RCTMGLShapeSource = requireNativeComponent(
|
|
347
|
-
NATIVE_MODULE_NAME,
|
|
348
|
-
ShapeSource,
|
|
349
|
-
{
|
|
350
|
-
nativeOnly: {
|
|
351
|
-
hasPressListener: true,
|
|
352
|
-
onMapboxShapeSourcePress: true,
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
export default ShapeSource;
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import {viewPropTypes} from '../utils';
|
|
2
|
-
import {SymbolLayerStyleProp} from '../utils/styleMap';
|
|
3
|
-
|
|
4
|
-
import AbstractLayer from './AbstractLayer';
|
|
5
|
-
|
|
6
|
-
import PropTypes from 'prop-types';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import {View, NativeModules, requireNativeComponent} from 'react-native';
|
|
9
|
-
|
|
10
|
-
const MapLibreGL = NativeModules.MGLModule;
|
|
11
|
-
|
|
12
|
-
export const NATIVE_MODULE_NAME = 'RCTMGLSymbolLayer';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* SymbolLayer is a style layer that renders icon and text labels at points or along lines on the map.
|
|
16
|
-
*/
|
|
17
|
-
class SymbolLayer extends AbstractLayer {
|
|
18
|
-
static propTypes = {
|
|
19
|
-
...viewPropTypes,
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A string that uniquely identifies the source in the style to which it is added.
|
|
23
|
-
*/
|
|
24
|
-
id: PropTypes.string.isRequired,
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The source from which to obtain the data to style.
|
|
28
|
-
* If the source has not yet been added to the current style, the behavior is undefined.
|
|
29
|
-
* Inferred from parent source only if the layer is a direct child to it.
|
|
30
|
-
*/
|
|
31
|
-
sourceID: PropTypes.string,
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Identifier of the layer within the source identified by the sourceID property from which the receiver obtains the data to style.
|
|
35
|
-
*/
|
|
36
|
-
sourceLayerID: PropTypes.string,
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Inserts a layer above aboveLayerID.
|
|
40
|
-
*/
|
|
41
|
-
aboveLayerID: PropTypes.string,
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Inserts a layer below belowLayerID
|
|
45
|
-
*/
|
|
46
|
-
belowLayerID: PropTypes.string,
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Inserts a layer at a specified index
|
|
50
|
-
*/
|
|
51
|
-
layerIndex: PropTypes.number,
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Filter only the features in the source layer that satisfy a condition that you define
|
|
55
|
-
*/
|
|
56
|
-
filter: PropTypes.array,
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* The minimum zoom level at which the layer gets parsed and appears.
|
|
60
|
-
*/
|
|
61
|
-
minZoomLevel: PropTypes.number,
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* The maximum zoom level at which the layer gets parsed and appears.
|
|
65
|
-
*/
|
|
66
|
-
maxZoomLevel: PropTypes.number,
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Customizable style attributes
|
|
70
|
-
*/
|
|
71
|
-
style: PropTypes.oneOfType([
|
|
72
|
-
SymbolLayerStyleProp,
|
|
73
|
-
PropTypes.arrayOf(SymbolLayerStyleProp),
|
|
74
|
-
]),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
static defaultProps = {
|
|
78
|
-
sourceID: MapLibreGL.StyleSource.DefaultSourceID,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
_shouldSnapshot() {
|
|
82
|
-
let isSnapshot = false;
|
|
83
|
-
|
|
84
|
-
if (React.Children.count(this.props.children) <= 0) {
|
|
85
|
-
return isSnapshot;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
React.Children.forEach(this.props.children, child => {
|
|
89
|
-
if (child.type === View) {
|
|
90
|
-
isSnapshot = true;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return isSnapshot;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
render() {
|
|
98
|
-
const props = {
|
|
99
|
-
...this.baseProps,
|
|
100
|
-
snapshot: this._shouldSnapshot(),
|
|
101
|
-
sourceLayerID: this.props.sourceLayerID,
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<RCTMGLSymbolLayer ref="nativeLayer" {...props}>
|
|
106
|
-
{this.props.children}
|
|
107
|
-
</RCTMGLSymbolLayer>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const RCTMGLSymbolLayer = requireNativeComponent(
|
|
113
|
-
NATIVE_MODULE_NAME,
|
|
114
|
-
SymbolLayer,
|
|
115
|
-
{
|
|
116
|
-
nativeOnly: {reactStyle: true, snapshot: true},
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
export default SymbolLayer;
|