@rnmapbox/maps 10.0.0-beta.31 → 10.0.0-beta.32

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.
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { Map } from 'mapbox-gl';
3
+
4
+ const MapContext = React.createContext<{ map?: Map }>({});
5
+
6
+ export default MapContext;
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+
3
+ import MapContext from '../MapContext';
4
+
5
+ class Camera extends React.Component<{
6
+ centerCoordinate: [number, number] | null;
7
+ }> {
8
+ context!: React.ContextType<typeof MapContext>;
9
+
10
+ static contextType = MapContext;
11
+ static UserTrackingModes = [];
12
+
13
+ componentDidMount() {
14
+ const { map } = this.context;
15
+ const { centerCoordinate } = this.props;
16
+ if (map && centerCoordinate) {
17
+ map.flyTo({ center: centerCoordinate });
18
+ }
19
+ }
20
+
21
+ fitBounds(
22
+ northEastCoordinates: [number, number],
23
+ southWestCoordinates: [number, number],
24
+ padding = 0,
25
+ animationDuration = 0.0,
26
+ ) {
27
+ const { map } = this.context;
28
+ if (map) {
29
+ map.fitBounds([northEastCoordinates, southWestCoordinates]);
30
+ }
31
+ }
32
+
33
+ render() {
34
+ return <></>;
35
+ }
36
+ }
37
+
38
+ export { Camera };
39
+ export default Camera;
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import mapboxgl from 'mapbox-gl';
3
+
4
+ import MapContext from '../MapContext';
5
+
6
+ /**
7
+ * MapView backed by Mapbox GL KS
8
+ */
9
+ class MapView extends React.Component<
10
+ { styleURL: string; children: JSX.Element },
11
+ { map?: object | null }
12
+ > {
13
+ state = { map: null };
14
+ mapContainer: HTMLElement | null = null;
15
+ map: object | null = null;
16
+
17
+ componentDidMount() {
18
+ const { styleURL } = this.props;
19
+ if (!this.mapContainer) {
20
+ console.error('MapView - mapContainer should is null');
21
+ return;
22
+ }
23
+ const map = new mapboxgl.Map({
24
+ container: this.mapContainer,
25
+ style: styleURL || 'mapbox://styles/mapbox/streets-v11',
26
+ });
27
+ this.map = map;
28
+ this.setState({ map });
29
+ }
30
+
31
+ render() {
32
+ const { children } = this.props;
33
+ const { map } = this.state;
34
+ return (
35
+ <div
36
+ style={{ width: '100%', height: '100%' }}
37
+ ref={(el) => (this.mapContainer = el)}
38
+ >
39
+ {map && (
40
+ <div style={{ position: 'absolute' }}>
41
+ <MapContext.Provider value={{ map }}>
42
+ {children}
43
+ </MapContext.Provider>
44
+ </div>
45
+ )}
46
+ </div>
47
+ );
48
+ }
49
+ }
50
+
51
+ export default MapView;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rnmapbox/maps",
3
3
  "description": "A Mapbox react native module for creating custom maps",
4
- "version": "10.0.0-beta.31",
4
+ "version": "10.0.0-beta.32",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -65,6 +65,7 @@
65
65
  "@react-native-community/eslint-config": "^3.0.1",
66
66
  "@sinonjs/fake-timers": "^8.0.1",
67
67
  "@testing-library/react-native": "^8.0.0",
68
+ "@types/mapbox-gl": "^2.7.5",
68
69
  "@types/react-native": ">=0.59.9",
69
70
  "@typescript-eslint/eslint-plugin": "^5.20.0",
70
71
  "@typescript-eslint/parser": "^5.20.0",
@@ -89,7 +90,8 @@
89
90
  "react-docgen": "6.0.0-alpha.3",
90
91
  "react-native": "0.67.0",
91
92
  "react-test-renderer": "17.0.2",
92
- "typescript": "^4.4.3"
93
+ "typescript": "^4.4.3",
94
+ "mapbox-gl": "^ 2.9.0"
93
95
  },
94
96
  "jest": {
95
97
  "preset": "react-native",
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
-
3
- const MapContext = React.createContext({});
4
-
5
- export default MapContext;