@rnmapbox/maps 10.1.22 → 10.1.24

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.
@@ -13,11 +13,6 @@ def isNewArchitectureEnabled() {
13
13
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
14
14
  }
15
15
 
16
-
17
- def getKotlinVersion() {
18
- return rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.6.21'
19
- }
20
-
21
16
  def getCoroutinesVersion(kotlinVersion) {
22
17
  return kotlinVersion >= '1.9' ? '1.8.0' : '1.6.4'
23
18
  }
@@ -30,17 +25,15 @@ if (rootProject.ext.has('expoRNMapboxMapsVersion')) {
30
25
  rootProject.ext.set('RNMapboxMapsVersion', rootProject.ext.get('expoRNMapboxMapsVersion'))
31
26
  }
32
27
 
33
- project.ext.set("kotlinVersion", getKotlinVersion())
34
-
35
28
  buildscript {
36
29
  repositories {
37
30
  google()
38
31
  mavenCentral()
39
32
  }
40
33
 
41
- def kotlinVersion = this.kotlinVersion
34
+ project.ext.set("kotlinVersion", rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.7.21')
42
35
  dependencies {
43
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
36
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.kotlinVersion}"
44
37
  }
45
38
  }
46
39
 
@@ -153,8 +146,8 @@ dependencies {
153
146
  // React Native
154
147
  implementation "com.facebook.react:react-native:+"
155
148
 
156
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${safeExtGet('kotlinxCoroutinesCoreVersion', getCoroutinesVersion(getKotlinVersion()))}"
157
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', getCoroutinesVersion(getKotlinVersion()))}"
149
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${safeExtGet('kotlinxCoroutinesCoreVersion', getCoroutinesVersion(project.kotlinVersion))}"
150
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${safeExtGet('kotlinxCoroutinesAndroidVersion', getCoroutinesVersion(project.kotlinVersion))}"
158
151
 
159
152
  // Mapbox SDK
160
153
  customizableDependencies('RNMapboxMapsLibs') {
@@ -4,35 +4,126 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.Camera = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = require("react");
8
8
  var _MapContext = _interopRequireDefault(require("../MapContext"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- class Camera extends _react.default.Component {
10
+ function isArray(value) {
11
+ return value.length !== undefined;
12
+ }
13
+ function buildMapboxGlPadding(padding) {
14
+ if (padding === undefined) {
15
+ // undefined
16
+ return undefined;
17
+ } else if (!isArray(padding)) {
18
+ // padding
19
+ return padding;
20
+ } else {
21
+ // Array
22
+ if (padding.length === 0) {
23
+ // []
24
+ return undefined;
25
+ } else if (padding.length < 2) {
26
+ // [padding]
27
+ return padding[0];
28
+ } else if (padding.length < 4) {
29
+ // [vertical, horizontal]
30
+ return {
31
+ left: padding[0],
32
+ right: padding[0],
33
+ top: padding[1],
34
+ bottom: padding[1]
35
+ };
36
+ } else {
37
+ // [top, right, bottom, left]
38
+ return {
39
+ top: padding[0],
40
+ right: padding[1],
41
+ bottom: padding[2],
42
+ left: padding[3]
43
+ };
44
+ }
45
+ }
46
+ }
47
+ class Camera extends _react.Component {
11
48
  static contextType = _MapContext.default;
12
49
  static UserTrackingModes = [];
13
50
  componentDidMount() {
14
51
  const {
15
52
  map
16
53
  } = this.context;
54
+ if (!map) {
55
+ return;
56
+ }
57
+
58
+ // minZoomLevel
59
+ if (this.props.minZoomLevel !== undefined) {
60
+ map.setMinZoom(this.props.minZoomLevel);
61
+ }
62
+
63
+ // maxZoomLevel
64
+ if (this.props.maxZoomLevel !== undefined) {
65
+ map.setMaxZoom(this.props.maxZoomLevel);
66
+ }
67
+
68
+ // zoomLevel
69
+ if (this.props.zoomLevel !== undefined) {
70
+ map.setZoom(this.props.zoomLevel);
71
+ }
72
+
73
+ // centerCoordinate
74
+ if (this.props.centerCoordinate !== undefined) {
75
+ map.flyTo({
76
+ center: this.props.centerCoordinate.slice(0, 2),
77
+ duration: 0
78
+ });
79
+ }
80
+ }
81
+ fitBounds(northEastCoordinates, southWestCoordinates, padding = 0, animationDuration = 0) {
17
82
  const {
18
- centerCoordinate
19
- } = this.props;
20
- if (map && centerCoordinate) {
83
+ map
84
+ } = this.context;
85
+ if (map) {
86
+ map.fitBounds([northEastCoordinates.slice(0, 2), southWestCoordinates.slice(0, 2)], {
87
+ padding: buildMapboxGlPadding(padding),
88
+ duration: animationDuration
89
+ });
90
+ }
91
+ }
92
+ flyTo(centerCoordinate, animationDuration = 2000) {
93
+ const {
94
+ map
95
+ } = this.context;
96
+ if (map) {
21
97
  map.flyTo({
22
- center: centerCoordinate
98
+ center: centerCoordinate.slice(0, 2),
99
+ duration: animationDuration
23
100
  });
24
101
  }
25
102
  }
26
- fitBounds(northEastCoordinates, southWestCoordinates, padding = 0, animationDuration = 0.0) {
103
+ moveTo(centerCoordinate, animationDuration = 0) {
27
104
  const {
28
105
  map
29
106
  } = this.context;
30
107
  if (map) {
31
- map.fitBounds([northEastCoordinates, southWestCoordinates]);
108
+ map.easeTo({
109
+ center: centerCoordinate.slice(0, 2),
110
+ duration: animationDuration
111
+ });
112
+ }
113
+ }
114
+ zoomTo(zoomLevel, animationDuration = 2000) {
115
+ const {
116
+ map
117
+ } = this.context;
118
+ if (map) {
119
+ map.flyTo({
120
+ zoom: zoomLevel,
121
+ duration: animationDuration
122
+ });
32
123
  }
33
124
  }
34
125
  render() {
35
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
126
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
36
127
  }
37
128
  }
38
129
  exports.Camera = Camera;
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_MapContext","obj","__esModule","default","Camera","React","Component","contextType","MapContext","UserTrackingModes","componentDidMount","map","context","centerCoordinate","props","flyTo","center","fitBounds","northEastCoordinates","southWestCoordinates","padding","animationDuration","render","createElement","Fragment","exports","_default"],"sourceRoot":"../../../../src","sources":["web/components/Camera.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEvC,MAAMG,MAAM,SAASC,cAAK,CAACC,SAAS,CAEjC;EAGD,OAAOC,WAAW,GAAGC,mBAAU;EAC/B,OAAOC,iBAAiB,GAAG,EAAE;EAE7BC,iBAAiBA,CAAA,EAAG;IAClB,MAAM;MAAEC;IAAI,CAAC,GAAG,IAAI,CAACC,OAAO;IAC5B,MAAM;MAAEC;IAAiB,CAAC,GAAG,IAAI,CAACC,KAAK;IACvC,IAAIH,GAAG,IAAIE,gBAAgB,EAAE;MAC3BF,GAAG,CAACI,KAAK,CAAC;QAAEC,MAAM,EAAEH;MAAiB,CAAC,CAAC;IACzC;EACF;EAEAI,SAASA,CACPC,oBAAsC,EACtCC,oBAAsC,EACtCC,OAAO,GAAG,CAAC,EACXC,iBAAiB,GAAG,GAAG,EACvB;IACA,MAAM;MAAEV;IAAI,CAAC,GAAG,IAAI,CAACC,OAAO;IAC5B,IAAID,GAAG,EAAE;MACPA,GAAG,CAACM,SAAS,CAAC,CAACC,oBAAoB,EAAEC,oBAAoB,CAAC,CAAC;IAC7D;EACF;EAEAG,MAAMA,CAAA,EAAG;IACP,oBAAOzB,MAAA,CAAAM,OAAA,CAAAoB,aAAA,CAAA1B,MAAA,CAAAM,OAAA,CAAAqB,QAAA,MAAI,CAAC;EACd;AACF;AAACC,OAAA,CAAArB,MAAA,GAAAA,MAAA;AAAA,IAAAsB,QAAA,GAAAD,OAAA,CAAAtB,OAAA,GAGcC,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["_react","require","_MapContext","_interopRequireDefault","obj","__esModule","default","isArray","value","length","undefined","buildMapboxGlPadding","padding","left","right","top","bottom","Camera","Component","contextType","MapContext","UserTrackingModes","componentDidMount","map","context","props","minZoomLevel","setMinZoom","maxZoomLevel","setMaxZoom","zoomLevel","setZoom","centerCoordinate","flyTo","center","slice","duration","fitBounds","northEastCoordinates","southWestCoordinates","animationDuration","moveTo","easeTo","zoomTo","zoom","render","React","createElement","Fragment","exports","_default"],"sourceRoot":"../../../../src","sources":["web/components/Camera.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAuC,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEvC,SAASG,OAAOA,CAAIC,KAAuB,EAAyB;EAClE,OAAQA,KAAK,CAAkBC,MAAM,KAAKC,SAAS;AACrD;AAEA,SAASC,oBAAoBA,CAC3BC,OAA2B,EACmB;EAC9C,IAAIA,OAAO,KAAKF,SAAS,EAAE;IACzB;IACA,OAAOA,SAAS;EAClB,CAAC,MAAM,IAAI,CAACH,OAAO,CAACK,OAAO,CAAC,EAAE;IAC5B;IACA,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL;IACA,IAAIA,OAAO,CAACH,MAAM,KAAK,CAAC,EAAE;MACxB;MACA,OAAOC,SAAS;IAClB,CAAC,MAAM,IAAIE,OAAO,CAACH,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,OAAOG,OAAO,CAAC,CAAC,CAAC;IACnB,CAAC,MAAM,IAAIA,OAAO,CAACH,MAAM,GAAG,CAAC,EAAE;MAC7B;MACA,OAAO;QACLI,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OAAO;IAC5B,IAAID,GAAG,EAAE;MACPA,GAAG,CAACU,KAAK,CAAC;QACRW,IAAI,EAAEd,SAAS;QACfM,QAAQ,EAAEI;MACZ,CAAC,CAAC;IACJ;EACF;EAEAK,MAAMA,CAAA,EAAG;IACP,oBAAOC,KAAA,CAAAC,aAAA,CAAAD,KAAA,CAAAE,QAAA,MAAI,CAAC;EACd;AACF;AAACC,OAAA,CAAAhC,MAAA,GAAAA,MAAA;AAAA,IAAAiC,QAAA,GAAAD,OAAA,CAAA3C,OAAA,GAGcW,MAAM","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _mapboxGl = require("mapbox-gl");
8
+ var _react = require("react");
9
+ var _reactDom = require("react-dom");
10
+ var _MapContext = _interopRequireDefault(require("../MapContext"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function MarkerView(props, ref) {
13
+ const {
14
+ map
15
+ } = (0, _react.useContext)(_MapContext.default);
16
+
17
+ // Create marker instance
18
+ const marker = (0, _react.useMemo)(() => {
19
+ const _marker = new _mapboxGl.Marker({
20
+ element: /*#__PURE__*/(0, _react.isValidElement)(props.children) ? document.createElement('div') : undefined
21
+ });
22
+
23
+ // Set marker coordinates
24
+ _marker.setLngLat(props.coordinate);
25
+
26
+ // Fix marker position
27
+ const {
28
+ style
29
+ } = _marker.getElement();
30
+ style.position = 'absolute';
31
+ style.top = '0';
32
+ style.left = '0';
33
+ return _marker;
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+
37
+ // Add marker to map
38
+ (0, _react.useEffect)(() => {
39
+ if (map === undefined) {
40
+ return;
41
+ }
42
+ marker.addTo(map);
43
+ return () => {
44
+ marker.remove();
45
+ };
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [map]);
48
+
49
+ // Expose marker instance
50
+ // eslint-disable-next-line react-hooks/exhaustive-deps
51
+ (0, _react.useImperativeHandle)(ref, () => marker, []);
52
+
53
+ // Update marker coordinates
54
+ const markerCoordinate = marker.getLngLat();
55
+ if (markerCoordinate.lng !== props.coordinate[0] || markerCoordinate.lat !== props.coordinate[1]) {
56
+ marker.setLngLat([props.coordinate[0], props.coordinate[1]]);
57
+ }
58
+
59
+ // Inject children into marker element
60
+ return /*#__PURE__*/(0, _reactDom.createPortal)(props.children, marker.getElement());
61
+ }
62
+ var _default = exports.default = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(MarkerView));
63
+ //# sourceMappingURL=MarkerView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_mapboxGl","require","_react","_reactDom","_MapContext","_interopRequireDefault","obj","__esModule","default","MarkerView","props","ref","map","useContext","MapContext","marker","useMemo","_marker","Marker","element","isValidElement","children","document","createElement","undefined","setLngLat","coordinate","style","getElement","position","top","left","useEffect","addTo","remove","useImperativeHandle","markerCoordinate","getLngLat","lng","lat","createPortal","_default","exports","memo","forwardRef"],"sourceRoot":"../../../../src","sources":["web/components/MarkerView.tsx"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAWA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,WAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAuC,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAOvC,SAASG,UAAUA,CAACC,KAAsB,EAAEC,GAAgB,EAAE;EAC5D,MAAM;IAAEC;EAAI,CAAC,GAAG,IAAAC,iBAAU,EAACC,mBAAU,CAAC;;EAEtC;EACA,MAAMC,MAAc,GAAG,IAAAC,cAAO,EAAC,MAAM;IACnC,MAAMC,OAAO,GAAG,IAAIC,gBAAM,CAAC;MACzBC,OAAO,EAAE,iBAAAC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C,IAAAa,QAAA,GAAAC,OAAA,CAAAlC,OAAA,gBAEc,IAAAmC,WAAI,gBAAC,IAAAC,iBAAU,EAACnC,UAAU,CAAC,CAAC","ignoreList":[]}
@@ -21,16 +21,24 @@ Object.defineProperty(exports, "MapView", {
21
21
  return _MapView.default;
22
22
  }
23
23
  });
24
+ Object.defineProperty(exports, "MarkerView", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _MarkerView.default;
28
+ }
29
+ });
24
30
  exports.default = void 0;
25
31
  var _MapboxModule = _interopRequireDefault(require("./MapboxModule"));
26
32
  var _Camera = _interopRequireDefault(require("./components/Camera"));
27
33
  var _MapView = _interopRequireDefault(require("./components/MapView"));
34
+ var _MarkerView = _interopRequireDefault(require("./components/MarkerView"));
28
35
  var _Logger = _interopRequireDefault(require("./utils/Logger"));
29
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
37
  const ExportedComponents = {
31
38
  Camera: _Camera.default,
32
39
  MapView: _MapView.default,
33
- Logger: _Logger.default
40
+ Logger: _Logger.default,
41
+ MarkerView: _MarkerView.default
34
42
  };
35
43
  const Mapbox = {
36
44
  ..._MapboxModule.default,
@@ -1 +1 @@
1
- {"version":3,"names":["_MapboxModule","_interopRequireDefault","require","_Camera","_MapView","_Logger","obj","__esModule","default","ExportedComponents","Camera","MapView","Logger","Mapbox","MapboxModule","_default","exports"],"sourceRoot":"../../../src","sources":["web/index.js"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAoC,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,kBAAkB,GAAG;EACzBC,MAAM,EAANA,eAAM;EACNC,OAAO,EAAPA,gBAAO;EACPC,MAAM,EAANA;AACF,CAAC;AAED,MAAMC,MAAM,GAAG;EACb,GAAGC,qBAAY;EACf,GAAGL;AACL,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,CAAAR,OAAA,GAGaK,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["_MapboxModule","_interopRequireDefault","require","_Camera","_MapView","_MarkerView","_Logger","obj","__esModule","default","ExportedComponents","Camera","MapView","Logger","MarkerView","Mapbox","MapboxModule","_default","exports"],"sourceRoot":"../../../src","sources":["web/index.js"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AAAoC,SAAAD,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEpC,MAAMG,kBAAkB,GAAG;EACzBC,MAAM,EAANA,eAAM;EACNC,OAAO,EAAPA,gBAAO;EACPC,MAAM,EAANA,eAAM;EACNC,UAAU,EAAVA;AACF,CAAC;AAED,MAAMC,MAAM,GAAG;EACb,GAAGC,qBAAY;EACf,GAAGN;AACL,CAAC;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAT,OAAA,GAGaM,MAAM","ignoreList":[]}
@@ -1,27 +1,118 @@
1
- import React from 'react';
1
+ import { Component } from 'react';
2
2
  import MapContext from '../MapContext';
3
- class Camera extends React.Component {
3
+ function isArray(value) {
4
+ return value.length !== undefined;
5
+ }
6
+ function buildMapboxGlPadding(padding) {
7
+ if (padding === undefined) {
8
+ // undefined
9
+ return undefined;
10
+ } else if (!isArray(padding)) {
11
+ // padding
12
+ return padding;
13
+ } else {
14
+ // Array
15
+ if (padding.length === 0) {
16
+ // []
17
+ return undefined;
18
+ } else if (padding.length < 2) {
19
+ // [padding]
20
+ return padding[0];
21
+ } else if (padding.length < 4) {
22
+ // [vertical, horizontal]
23
+ return {
24
+ left: padding[0],
25
+ right: padding[0],
26
+ top: padding[1],
27
+ bottom: padding[1]
28
+ };
29
+ } else {
30
+ // [top, right, bottom, left]
31
+ return {
32
+ top: padding[0],
33
+ right: padding[1],
34
+ bottom: padding[2],
35
+ left: padding[3]
36
+ };
37
+ }
38
+ }
39
+ }
40
+ class Camera extends Component {
4
41
  static contextType = MapContext;
5
42
  static UserTrackingModes = [];
6
43
  componentDidMount() {
7
44
  const {
8
45
  map
9
46
  } = this.context;
47
+ if (!map) {
48
+ return;
49
+ }
50
+
51
+ // minZoomLevel
52
+ if (this.props.minZoomLevel !== undefined) {
53
+ map.setMinZoom(this.props.minZoomLevel);
54
+ }
55
+
56
+ // maxZoomLevel
57
+ if (this.props.maxZoomLevel !== undefined) {
58
+ map.setMaxZoom(this.props.maxZoomLevel);
59
+ }
60
+
61
+ // zoomLevel
62
+ if (this.props.zoomLevel !== undefined) {
63
+ map.setZoom(this.props.zoomLevel);
64
+ }
65
+
66
+ // centerCoordinate
67
+ if (this.props.centerCoordinate !== undefined) {
68
+ map.flyTo({
69
+ center: this.props.centerCoordinate.slice(0, 2),
70
+ duration: 0
71
+ });
72
+ }
73
+ }
74
+ fitBounds(northEastCoordinates, southWestCoordinates, padding = 0, animationDuration = 0) {
10
75
  const {
11
- centerCoordinate
12
- } = this.props;
13
- if (map && centerCoordinate) {
76
+ map
77
+ } = this.context;
78
+ if (map) {
79
+ map.fitBounds([northEastCoordinates.slice(0, 2), southWestCoordinates.slice(0, 2)], {
80
+ padding: buildMapboxGlPadding(padding),
81
+ duration: animationDuration
82
+ });
83
+ }
84
+ }
85
+ flyTo(centerCoordinate, animationDuration = 2000) {
86
+ const {
87
+ map
88
+ } = this.context;
89
+ if (map) {
14
90
  map.flyTo({
15
- center: centerCoordinate
91
+ center: centerCoordinate.slice(0, 2),
92
+ duration: animationDuration
16
93
  });
17
94
  }
18
95
  }
19
- fitBounds(northEastCoordinates, southWestCoordinates, padding = 0, animationDuration = 0.0) {
96
+ moveTo(centerCoordinate, animationDuration = 0) {
20
97
  const {
21
98
  map
22
99
  } = this.context;
23
100
  if (map) {
24
- map.fitBounds([northEastCoordinates, southWestCoordinates]);
101
+ map.easeTo({
102
+ center: centerCoordinate.slice(0, 2),
103
+ duration: animationDuration
104
+ });
105
+ }
106
+ }
107
+ zoomTo(zoomLevel, animationDuration = 2000) {
108
+ const {
109
+ map
110
+ } = this.context;
111
+ if (map) {
112
+ map.flyTo({
113
+ zoom: zoomLevel,
114
+ duration: animationDuration
115
+ });
25
116
  }
26
117
  }
27
118
  render() {
@@ -1 +1 @@
1
- {"version":3,"names":["React","MapContext","Camera","Component","contextType","UserTrackingModes","componentDidMount","map","context","centerCoordinate","props","flyTo","center","fitBounds","northEastCoordinates","southWestCoordinates","padding","animationDuration","render","createElement","Fragment"],"sourceRoot":"../../../../src","sources":["web/components/Camera.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,OAAOC,UAAU,MAAM,eAAe;AAEtC,MAAMC,MAAM,SAASF,KAAK,CAACG,SAAS,CAEjC;EAGD,OAAOC,WAAW,GAAGH,UAAU;EAC/B,OAAOI,iBAAiB,GAAG,EAAE;EAE7BC,iBAAiBA,CAAA,EAAG;IAClB,MAAM;MAAEC;IAAI,CAAC,GAAG,IAAI,CAACC,OAAO;IAC5B,MAAM;MAAEC;IAAiB,CAAC,GAAG,IAAI,CAACC,KAAK;IACvC,IAAIH,GAAG,IAAIE,gBAAgB,EAAE;MAC3BF,GAAG,CAACI,KAAK,CAAC;QAAEC,MAAM,EAAEH;MAAiB,CAAC,CAAC;IACzC;EACF;EAEAI,SAASA,CACPC,oBAAsC,EACtCC,oBAAsC,EACtCC,OAAO,GAAG,CAAC,EACXC,iBAAiB,GAAG,GAAG,EACvB;IACA,MAAM;MAAEV;IAAI,CAAC,GAAG,IAAI,CAACC,OAAO;IAC5B,IAAID,GAAG,EAAE;MACPA,GAAG,CAACM,SAAS,CAAC,CAACC,oBAAoB,EAAEC,oBAAoB,CAAC,CAAC;IAC7D;EACF;EAEAG,MAAMA,CAAA,EAAG;IACP,oBAAOlB,KAAA,CAAAmB,aAAA,CAAAnB,KAAA,CAAAoB,QAAA,MAAI,CAAC;EACd;AACF;AAEA,SAASlB,MAAM;AACf,eAAeA,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["Component","MapContext","isArray","value","length","undefined","buildMapboxGlPadding","padding","left","right","top","bottom","Camera","contextType","UserTrackingModes","componentDidMount","map","context","props","minZoomLevel","setMinZoom","maxZoomLevel","setMaxZoom","zoomLevel","setZoom","centerCoordinate","flyTo","center","slice","duration","fitBounds","northEastCoordinates","southWestCoordinates","animationDuration","moveTo","easeTo","zoomTo","zoom","render","React","createElement","Fragment"],"sourceRoot":"../../../../src","sources":["web/components/Camera.tsx"],"mappings":"AAAA,SAASA,SAAS,QAAqB,OAAO;AAI9C,OAAOC,UAAU,MAAM,eAAe;AAEtC,SAASC,OAAOA,CAAIC,KAAuB,EAAyB;EAClE,OAAQA,KAAK,CAAkBC,MAAM,KAAKC,SAAS;AACrD;AAEA,SAASC,oBAAoBA,CAC3BC,OAA2B,EACmB;EAC9C,IAAIA,OAAO,KAAKF,SAAS,EAAE;IACzB;IACA,OAAOA,SAAS;EAClB,CAAC,MAAM,IAAI,CAACH,OAAO,CAACK,OAAO,CAAC,EAAE;IAC5B;IACA,OAAOA,OAAO;EAChB,CAAC,MAAM;IACL;IACA,IAAIA,OAAO,CAACH,MAAM,KAAK,CAAC,EAAE;MACxB;MACA,OAAOC,SAAS;IAClB,CAAC,MAAM,IAAIE,OAAO,CAACH,MAAM,GAAG,CAAC,EAAE;MAC7B;M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EACF;EAEAG,MAAMA,CAACb,SAAiB,EAAEU,iBAAiB,GAAG,IAAI,EAAE;IAClD,MAAM;MAAEjB;IAAI,CAAC,GAAG,IAAI,CAACC,OAAO;IAC5B,IAAID,GAAG,EAAE;MACPA,GAAG,CAACU,KAAK,CAAC;QACRW,IAAI,EAAEd,SAAS;QACfM,QAAQ,EAAEI;MACZ,CAAC,CAAC;IACJ;EACF;EAEAK,MAAMA,CAAA,EAAG;IACP,oBAAOC,KAAA,CAAAC,aAAA,CAAAD,KAAA,CAAAE,QAAA,MAAI,CAAC;EACd;AACF;AAEA,SAAS7B,MAAM;AACf,eAAeA,MAAM","ignoreList":[]}
@@ -0,0 +1,56 @@
1
+ import { Marker } from 'mapbox-gl';
2
+ import { forwardRef, isValidElement, memo, useContext, useEffect, useImperativeHandle, useMemo } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import MapContext from '../MapContext';
5
+ function MarkerView(props, ref) {
6
+ const {
7
+ map
8
+ } = useContext(MapContext);
9
+
10
+ // Create marker instance
11
+ const marker = useMemo(() => {
12
+ const _marker = new Marker({
13
+ element: /*#__PURE__*/isValidElement(props.children) ? document.createElement('div') : undefined
14
+ });
15
+
16
+ // Set marker coordinates
17
+ _marker.setLngLat(props.coordinate);
18
+
19
+ // Fix marker position
20
+ const {
21
+ style
22
+ } = _marker.getElement();
23
+ style.position = 'absolute';
24
+ style.top = '0';
25
+ style.left = '0';
26
+ return _marker;
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, []);
29
+
30
+ // Add marker to map
31
+ useEffect(() => {
32
+ if (map === undefined) {
33
+ return;
34
+ }
35
+ marker.addTo(map);
36
+ return () => {
37
+ marker.remove();
38
+ };
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [map]);
41
+
42
+ // Expose marker instance
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ useImperativeHandle(ref, () => marker, []);
45
+
46
+ // Update marker coordinates
47
+ const markerCoordinate = marker.getLngLat();
48
+ if (markerCoordinate.lng !== props.coordinate[0] || markerCoordinate.lat !== props.coordinate[1]) {
49
+ marker.setLngLat([props.coordinate[0], props.coordinate[1]]);
50
+ }
51
+
52
+ // Inject children into marker element
53
+ return /*#__PURE__*/createPortal(props.children, marker.getElement());
54
+ }
55
+ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(MarkerView));
56
+ //# sourceMappingURL=MarkerView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Marker","forwardRef","isValidElement","memo","useContext","useEffect","useImperativeHandle","useMemo","createPortal","MapContext","MarkerView","props","ref","map","marker","_marker","element","children","document","createElement","undefined","setLngLat","coordinate","style","getElement","position","top","left","addTo","remove","markerCoordinate","getLngLat","lng","lat"],"sourceRoot":"../../../../src","sources":["web/components/MarkerView.tsx"],"mappings":"AAAA,SAASA,MAAM,QAAQ,WAAW;AAClC,SACEC,UAAU,EACVC,cAAc,EACdC,IAAI,EAGJC,UAAU,EACVC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,QACF,OAAO;AACd,SAASC,YAAY,QAAQ,WAAW;AAExC,OAAOC,UAAU,MAAM,eAAe;AAOtC,SAASC,UAAUA,CAACC,KAAsB,EAAEC,GAAgB,EAAE;EAC5D,MAAM;IAAEC;EAAI,CAAC,GAAGT,UAAU,CAACK,UAAU,CAAC;;EAEtC;EACA,MAAMK,MAAc,GAAGP,OAAO,CAAC,MAAM;IACnC,MAAMQ,OAAO,GAAG,IAAIf,MAAM,CAAC;MACzBgB,OAAO,EAAE,aAAAd,cAAc,CAACS,KAAK,CAACM,QAAQ,CAAC,GACnCC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC,GAC7BC;IACN,CAAC,CAAC;;IAEF;IACAL,OAAO,CAACM,SAAS,CAACV,KAAK,CAACW,UAAU,CAAC;;IAEnC;IACA,MAAM;MAAEC;IAAM,CAAC,GAAGR,OAAO,CAACS,UAAU,CAAC,CAAC;IACtCD,KAAK,CAACE,QAAQ,GAAG,UAAU;IAC3BF,KAAK,CAACG,GAAG,GAAG,GAAG;IACfH,KAAK,CAACI,IAAI,GAAG,GAAG;IAEhB,OAAOZ,OAAO;IACd;EACF,CAAC,EAAE,EAAE,CAAC;;EAEN;EACAV,SAAS,CAAC,MAAM;IACd,IAAIQ,GAAG,KAAKO,SAAS,EAAE;MACrB;IACF;IAEAN,MAAM,CAACc,KAAK,CAACf,GAAG,CAAC;IAEjB,OAAO,MAAM;MACXC,MAAM,CAACe,MAAM,CAAC,CAAC;IACjB,CAAC;IACD;EACF,CAAC,EAAE,CAAChB,GAAG,CAAC,CAAC;;EAET;EACA;EACAP,mBAAmB,CAACM,GAAG,EAAE,MAAME,MAAM,EAAE,EAAE,CAAC;;EAE1C;EACA,MAAMgB,gBAAgB,GAAGhB,MAAM,CAACiB,SAAS,CAAC,CAAC;EAC3C,IACED,gBAAgB,CAACE,GAAG,KAAKrB,KAAK,CAACW,UAAU,CAAC,CAAC,CAAC,IAC5CQ,gBAAgB,CAACG,GAAG,KAAKtB,KAAK,CAACW,UAAU,CAAC,CAAC,CAAC,EAC5C;IACAR,MAAM,CAACO,SAAS,CAAC,CAACV,KAAK,CAACW,UAAU,CAAC,CAAC,CAAC,EAAEX,KAAK,CAACW,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;EAC9D;;EAEA;EACA,oBAAOd,YAAY,CAACG,KAAK,CAACM,QAAQ,EAAEH,MAAM,CAACU,UAAU,CAAC,CAAC,CAAC;AAC1D;AAEA,4BAAerB,IAAI,eAACF,UAAU,CAACS,UAAU,CAAC,CAAC","ignoreList":[]}
@@ -1,16 +1,18 @@
1
1
  import MapboxModule from './MapboxModule';
2
2
  import Camera from './components/Camera';
3
3
  import MapView from './components/MapView';
4
+ import MarkerView from './components/MarkerView';
4
5
  import Logger from './utils/Logger';
5
6
  const ExportedComponents = {
6
7
  Camera,
7
8
  MapView,
8
- Logger
9
+ Logger,
10
+ MarkerView
9
11
  };
10
12
  const Mapbox = {
11
13
  ...MapboxModule,
12
14
  ...ExportedComponents
13
15
  };
14
- export { Camera, MapView, Logger };
16
+ export { Camera, MapView, Logger, MarkerView };
15
17
  export default Mapbox;
16
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["MapboxModule","Camera","MapView","Logger","ExportedComponents","Mapbox"],"sourceRoot":"../../../src","sources":["web/index.js"],"mappings":"AAAA,OAAOA,YAAY,MAAM,gBAAgB;AACzC,OAAOC,MAAM,MAAM,qBAAqB;AACxC,OAAOC,OAAO,MAAM,sBAAsB;AAC1C,OAAOC,MAAM,MAAM,gBAAgB;AAEnC,MAAMC,kBAAkB,GAAG;EACzBH,MAAM;EACNC,OAAO;EACPC;AACF,CAAC;AAED,MAAME,MAAM,GAAG;EACb,GAAGL,YAAY;EACf,GAAGI;AACL,CAAC;AAED,SAASH,MAAM,EAAEC,OAAO,EAAEC,MAAM;AAChC,eAAeE,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["MapboxModule","Camera","MapView","MarkerView","Logger","ExportedComponents","Mapbox"],"sourceRoot":"../../../src","sources":["web/index.js"],"mappings":"AAAA,OAAOA,YAAY,MAAM,gBAAgB;AACzC,OAAOC,MAAM,MAAM,qBAAqB;AACxC,OAAOC,OAAO,MAAM,sBAAsB;AAC1C,OAAOC,UAAU,MAAM,yBAAyB;AAChD,OAAOC,MAAM,MAAM,gBAAgB;AAEnC,MAAMC,kBAAkB,GAAG;EACzBJ,MAAM;EACNC,OAAO;EACPE,MAAM;EACND;AACF,CAAC;AAED,MAAMG,MAAM,GAAG;EACb,GAAGN,YAAY;EACf,GAAGK;AACL,CAAC;AAED,SAASJ,MAAM,EAAEC,OAAO,EAAEE,MAAM,EAAED,UAAU;AAC5C,eAAeG,MAAM","ignoreList":[]}
@@ -1,17 +1,20 @@
1
1
  /// <reference types="mapbox-gl" />
2
- import React from 'react';
2
+ import { Component, ContextType } from 'react';
3
+ import { CameraProps, CameraRef } from '../../components/Camera';
4
+ import { Position } from '../../types/Position';
3
5
  import MapContext from '../MapContext';
4
- declare class Camera extends React.Component<{
5
- centerCoordinate: [number, number] | null;
6
- }> {
7
- context: React.ContextType<typeof MapContext>;
8
- static contextType: React.Context<{
6
+ declare class Camera extends Component<Pick<CameraProps, 'centerCoordinate' | 'zoomLevel' | 'minZoomLevel' | 'maxZoomLevel'>> implements Omit<CameraRef, 'setCamera'> {
7
+ context: ContextType<typeof MapContext>;
8
+ static contextType: import("react").Context<{
9
9
  map?: import("mapbox-gl").Map | undefined;
10
10
  }>;
11
11
  static UserTrackingModes: never[];
12
12
  componentDidMount(): void;
13
- fitBounds(northEastCoordinates: [number, number], southWestCoordinates: [number, number], padding?: number, animationDuration?: number): void;
14
- render(): React.JSX.Element;
13
+ fitBounds(northEastCoordinates: Position, southWestCoordinates: Position, padding?: number | number[], animationDuration?: number): void;
14
+ flyTo(centerCoordinate: Position, animationDuration?: number): void;
15
+ moveTo(centerCoordinate: Position, animationDuration?: number): void;
16
+ zoomTo(zoomLevel: number, animationDuration?: number): void;
17
+ render(): import("react").JSX.Element;
15
18
  }
16
19
  export { Camera };
17
20
  export default Camera;
@@ -1 +1 @@
1
- {"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../../../src/web/components/Camera.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,UAAU,MAAM,eAAe,CAAC;AAEvC,cAAM,MAAO,SAAQ,KAAK,CAAC,SAAS,CAAC;IACnC,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC3C,CAAC;IACA,OAAO,EAAG,KAAK,CAAC,WAAW,CAAC,OAAO,UAAU,CAAC,CAAC;IAE/C,MAAM,CAAC,WAAW;;OAAc;IAChC,MAAM,CAAC,iBAAiB,UAAM;IAE9B,iBAAiB;IAQjB,SAAS,CACP,oBAAoB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACtC,oBAAoB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACtC,OAAO,SAAI,EACX,iBAAiB,SAAM;IAQzB,MAAM;CAGP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../../../src/web/components/Camera.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,UAAU,MAAM,eAAe,CAAC;AA2CvC,cAAM,MACJ,SAAQ,SAAS,CACf,IAAI,CACF,WAAW,EACX,kBAAkB,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CACnE,CAEH,YAAW,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;IAEvC,OAAO,EAAG,WAAW,CAAC,OAAO,UAAU,CAAC,CAAC;IAEzC,MAAM,CAAC,WAAW;;OAAc;IAChC,MAAM,CAAC,iBAAiB,UAAM;IAE9B,iBAAiB;IA8BjB,SAAS,CACP,oBAAoB,EAAE,QAAQ,EAC9B,oBAAoB,EAAE,QAAQ,EAC9B,OAAO,GAAE,MAAM,GAAG,MAAM,EAAM,EAC9B,iBAAiB,SAAI;IAiBvB,KAAK,CAAC,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,SAAO;IAU1D,MAAM,CAAC,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,SAAI;IAUxD,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAiB,SAAO;IAUlD,MAAM;CAGP;AAED,OAAO,EAAE,MAAM,EAAE,CAAC;AAClB,eAAe,MAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { Marker } from 'mapbox-gl';
2
+ import { ReactElement } from 'react';
3
+ type MarkerViewProps = {
4
+ coordinate: [number, number];
5
+ children?: ReactElement;
6
+ };
7
+ declare const _default: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<MarkerViewProps & import("react").RefAttributes<Marker>>>;
8
+ export default _default;
9
+ //# sourceMappingURL=MarkerView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarkerView.d.ts","sourceRoot":"","sources":["../../../../../src/web/components/MarkerView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAIL,YAAY,EAMb,MAAM,OAAO,CAAC;AAKf,KAAK,eAAe,GAAG;IACrB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,CAAC;;AAyDF,wBAA4C"}
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.1.22",
4
+ "version": "10.1.24",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -59,7 +59,8 @@
59
59
  "expo": ">=47.0.0",
60
60
  "mapbox-gl": "^2.9.0",
61
61
  "react": ">=16.6.1",
62
- "react-native": ">=0.59.9"
62
+ "react-native": ">=0.59.9",
63
+ "react-dom": ">= 17.0.0"
63
64
  },
64
65
  "peerDependenciesMeta": {
65
66
  "expo": {
@@ -67,6 +68,9 @@
67
68
  },
68
69
  "mapbox-gl": {
69
70
  "optional": true
71
+ },
72
+ "react-dom": {
73
+ "optional": true
70
74
  }
71
75
  },
72
76
  "dependencies": {
@@ -193,7 +193,7 @@ def $RNMapboxMaps.pre_install(installer)
193
193
  end
194
194
 
195
195
  ## RNMapboxMapsDownloadToken
196
- # expo does not supports `.netrc`, so we need to patch curl commend used by cocoapods to pass the credentials
196
+ # expo does not support `.netrc`, so we need to patch curl command used by cocoapods to pass the credentials
197
197
 
198
198
  if $RNMapboxMapsDownloadToken
199
199
  module AddCredentialsToCurlWhenDownloadingMapbox
@@ -1,32 +1,142 @@
1
- import React from 'react';
1
+ import { Component, ContextType } from 'react';
2
2
 
3
+ import { CameraProps, CameraRef } from '../../components/Camera';
4
+ import { Position } from '../../types/Position';
3
5
  import MapContext from '../MapContext';
4
6
 
5
- class Camera extends React.Component<{
6
- centerCoordinate: [number, number] | null;
7
- }> {
8
- context!: React.ContextType<typeof MapContext>;
7
+ function isArray<T>(value: T | ArrayLike<T>): value is ArrayLike<T> {
8
+ return (value as ArrayLike<T>).length !== undefined;
9
+ }
10
+
11
+ function buildMapboxGlPadding(
12
+ padding?: number | number[],
13
+ ): number | mapboxgl.PaddingOptions | undefined {
14
+ if (padding === undefined) {
15
+ // undefined
16
+ return undefined;
17
+ } else if (!isArray(padding)) {
18
+ // padding
19
+ return padding;
20
+ } else {
21
+ // Array
22
+ if (padding.length === 0) {
23
+ // []
24
+ return undefined;
25
+ } else if (padding.length < 2) {
26
+ // [padding]
27
+ return padding[0];
28
+ } else if (padding.length < 4) {
29
+ // [vertical, horizontal]
30
+ return {
31
+ left: padding[0],
32
+ right: padding[0],
33
+ top: padding[1],
34
+ bottom: padding[1],
35
+ };
36
+ } else {
37
+ // [top, right, bottom, left]
38
+ return {
39
+ top: padding[0],
40
+ right: padding[1],
41
+ bottom: padding[2],
42
+ left: padding[3],
43
+ };
44
+ }
45
+ }
46
+ }
47
+
48
+ class Camera
49
+ extends Component<
50
+ Pick<
51
+ CameraProps,
52
+ 'centerCoordinate' | 'zoomLevel' | 'minZoomLevel' | 'maxZoomLevel'
53
+ >
54
+ >
55
+ implements Omit<CameraRef, 'setCamera'>
56
+ {
57
+ context!: ContextType<typeof MapContext>;
9
58
 
10
59
  static contextType = MapContext;
11
60
  static UserTrackingModes = [];
12
61
 
13
62
  componentDidMount() {
14
63
  const { map } = this.context;
15
- const { centerCoordinate } = this.props;
16
- if (map && centerCoordinate) {
17
- map.flyTo({ center: centerCoordinate });
64
+ if (!map) {
65
+ return;
66
+ }
67
+
68
+ // minZoomLevel
69
+ if (this.props.minZoomLevel !== undefined) {
70
+ map.setMinZoom(this.props.minZoomLevel);
71
+ }
72
+
73
+ // maxZoomLevel
74
+ if (this.props.maxZoomLevel !== undefined) {
75
+ map.setMaxZoom(this.props.maxZoomLevel);
76
+ }
77
+
78
+ // zoomLevel
79
+ if (this.props.zoomLevel !== undefined) {
80
+ map.setZoom(this.props.zoomLevel);
81
+ }
82
+
83
+ // centerCoordinate
84
+ if (this.props.centerCoordinate !== undefined) {
85
+ map.flyTo({
86
+ center: this.props.centerCoordinate.slice(0, 2) as [number, number],
87
+ duration: 0,
88
+ });
18
89
  }
19
90
  }
20
91
 
21
92
  fitBounds(
22
- northEastCoordinates: [number, number],
23
- southWestCoordinates: [number, number],
24
- padding = 0,
25
- animationDuration = 0.0,
93
+ northEastCoordinates: Position,
94
+ southWestCoordinates: Position,
95
+ padding: number | number[] = 0,
96
+ animationDuration = 0,
26
97
  ) {
27
98
  const { map } = this.context;
28
99
  if (map) {
29
- map.fitBounds([northEastCoordinates, southWestCoordinates]);
100
+ map.fitBounds(
101
+ [
102
+ northEastCoordinates.slice(0, 2) as [number, number],
103
+ southWestCoordinates.slice(0, 2) as [number, number],
104
+ ],
105
+ {
106
+ padding: buildMapboxGlPadding(padding),
107
+ duration: animationDuration,
108
+ },
109
+ );
110
+ }
111
+ }
112
+
113
+ flyTo(centerCoordinate: Position, animationDuration = 2000) {
114
+ const { map } = this.context;
115
+ if (map) {
116
+ map.flyTo({
117
+ center: centerCoordinate.slice(0, 2) as [number, number],
118
+ duration: animationDuration,
119
+ });
120
+ }
121
+ }
122
+
123
+ moveTo(centerCoordinate: Position, animationDuration = 0) {
124
+ const { map } = this.context;
125
+ if (map) {
126
+ map.easeTo({
127
+ center: centerCoordinate.slice(0, 2) as [number, number],
128
+ duration: animationDuration,
129
+ });
130
+ }
131
+ }
132
+
133
+ zoomTo(zoomLevel: number, animationDuration = 2000) {
134
+ const { map } = this.context;
135
+ if (map) {
136
+ map.flyTo({
137
+ zoom: zoomLevel,
138
+ duration: animationDuration,
139
+ });
30
140
  }
31
141
  }
32
142
 
@@ -0,0 +1,77 @@
1
+ import { Marker } from 'mapbox-gl';
2
+ import {
3
+ forwardRef,
4
+ isValidElement,
5
+ memo,
6
+ ReactElement,
7
+ Ref,
8
+ useContext,
9
+ useEffect,
10
+ useImperativeHandle,
11
+ useMemo,
12
+ } from 'react';
13
+ import { createPortal } from 'react-dom';
14
+
15
+ import MapContext from '../MapContext';
16
+
17
+ type MarkerViewProps = {
18
+ coordinate: [number, number];
19
+ children?: ReactElement;
20
+ };
21
+
22
+ function MarkerView(props: MarkerViewProps, ref: Ref<Marker>) {
23
+ const { map } = useContext(MapContext);
24
+
25
+ // Create marker instance
26
+ const marker: Marker = useMemo(() => {
27
+ const _marker = new Marker({
28
+ element: isValidElement(props.children)
29
+ ? document.createElement('div')
30
+ : undefined,
31
+ });
32
+
33
+ // Set marker coordinates
34
+ _marker.setLngLat(props.coordinate);
35
+
36
+ // Fix marker position
37
+ const { style } = _marker.getElement();
38
+ style.position = 'absolute';
39
+ style.top = '0';
40
+ style.left = '0';
41
+
42
+ return _marker;
43
+ // eslint-disable-next-line react-hooks/exhaustive-deps
44
+ }, []);
45
+
46
+ // Add marker to map
47
+ useEffect(() => {
48
+ if (map === undefined) {
49
+ return;
50
+ }
51
+
52
+ marker.addTo(map);
53
+
54
+ return () => {
55
+ marker.remove();
56
+ };
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, [map]);
59
+
60
+ // Expose marker instance
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ useImperativeHandle(ref, () => marker, []);
63
+
64
+ // Update marker coordinates
65
+ const markerCoordinate = marker.getLngLat();
66
+ if (
67
+ markerCoordinate.lng !== props.coordinate[0] ||
68
+ markerCoordinate.lat !== props.coordinate[1]
69
+ ) {
70
+ marker.setLngLat([props.coordinate[0], props.coordinate[1]]);
71
+ }
72
+
73
+ // Inject children into marker element
74
+ return createPortal(props.children, marker.getElement());
75
+ }
76
+
77
+ export default memo(forwardRef(MarkerView));
package/src/web/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import MapboxModule from './MapboxModule';
2
2
  import Camera from './components/Camera';
3
3
  import MapView from './components/MapView';
4
+ import MarkerView from './components/MarkerView';
4
5
  import Logger from './utils/Logger';
5
6
 
6
7
  const ExportedComponents = {
7
8
  Camera,
8
9
  MapView,
9
10
  Logger,
11
+ MarkerView,
10
12
  };
11
13
 
12
14
  const Mapbox = {
@@ -14,5 +16,5 @@ const Mapbox = {
14
16
  ...ExportedComponents,
15
17
  };
16
18
 
17
- export { Camera, MapView, Logger };
19
+ export { Camera, MapView, Logger, MarkerView };
18
20
  export default Mapbox;