react-native-maps 0.31.0 → 1.0.0-beta.2

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.
Files changed (70) hide show
  1. package/README.md +1 -5
  2. package/android/src/main/AndroidManifest.xml +0 -3
  3. package/android/src/main/java/com/airbnb/android/react/maps/AirMapLocalTile.java +11 -4
  4. package/android/src/main/java/com/airbnb/android/react/maps/AirMapLocalTileManager.java +5 -1
  5. package/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java +2 -41
  6. package/android/src/main/java/com/airbnb/android/react/maps/AirMapTileProvider.java +5 -5
  7. package/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +0 -32
  8. package/ios/AirGoogleMaps/AIRGoogleMap.m +37 -31
  9. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +0 -95
  10. package/ios/AirMaps/AIRMap.h +0 -1
  11. package/ios/AirMaps/AIRMap.m +0 -12
  12. package/ios/AirMaps/AIRMapManager.m +2 -132
  13. package/lib/AnimatedRegion.d.ts +19 -0
  14. package/lib/AnimatedRegion.js +134 -0
  15. package/lib/Geojson.d.ts +166 -0
  16. package/lib/Geojson.js +165 -0
  17. package/lib/MapCallout.d.ts +40 -0
  18. package/lib/MapCallout.js +51 -0
  19. package/lib/MapCalloutSubview.d.ts +34 -0
  20. package/lib/MapCalloutSubview.js +48 -0
  21. package/lib/MapCircle.d.ts +117 -0
  22. package/lib/MapCircle.js +53 -0
  23. package/lib/MapHeatmap.d.ts +77 -0
  24. package/lib/MapHeatmap.js +59 -0
  25. package/lib/MapLocalTile.d.ts +35 -0
  26. package/lib/MapLocalTile.js +44 -0
  27. package/lib/MapMarker.d.ts +289 -0
  28. package/lib/MapMarker.js +113 -0
  29. package/lib/MapOverlay.d.ts +86 -0
  30. package/lib/MapOverlay.js +63 -0
  31. package/lib/MapPolygon.d.ts +156 -0
  32. package/lib/MapPolygon.js +74 -0
  33. package/lib/MapPolyline.d.ts +156 -0
  34. package/lib/MapPolyline.js +53 -0
  35. package/lib/MapUrlTile.d.ts +134 -0
  36. package/lib/MapUrlTile.js +44 -0
  37. package/lib/MapView.d.ts +825 -0
  38. package/lib/MapView.js +418 -0
  39. package/{src/MapView.web.js → lib/MapView.web.d.ts} +0 -0
  40. package/lib/MapView.web.js +9 -0
  41. package/lib/MapWMSTile.d.ts +116 -0
  42. package/lib/MapWMSTile.js +44 -0
  43. package/lib/ProviderConstants.d.ts +2 -0
  44. package/lib/ProviderConstants.js +5 -0
  45. package/lib/decorateMapComponent.d.ts +35 -0
  46. package/lib/decorateMapComponent.js +80 -0
  47. package/{src/index.js → lib/index.d.ts} +5 -16
  48. package/lib/index.js +66 -0
  49. package/lib/sharedTypes.d.ts +82 -0
  50. package/lib/sharedTypes.js +2 -0
  51. package/package.json +19 -28
  52. package/react-native-google-maps.podspec +1 -1
  53. package/react-native-maps.podspec +1 -1
  54. package/index.d.ts +0 -637
  55. package/src/AnimatedRegion.js +0 -164
  56. package/src/Geojson.js +0 -334
  57. package/src/MapCallout.js +0 -51
  58. package/src/MapCalloutSubview.js +0 -44
  59. package/src/MapCircle.js +0 -150
  60. package/src/MapHeatmap.js +0 -99
  61. package/src/MapLocalTile.js +0 -52
  62. package/src/MapMarker.js +0 -377
  63. package/src/MapOverlay.js +0 -86
  64. package/src/MapPolygon.js +0 -202
  65. package/src/MapPolyline.js +0 -168
  66. package/src/MapUrlTile.js +0 -131
  67. package/src/MapView.js +0 -1160
  68. package/src/MapWMSTile.js +0 -122
  69. package/src/ProviderConstants.js +0 -2
  70. package/src/decorateMapComponent.js +0 -112
package/src/MapView.js DELETED
@@ -1,1160 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import React from 'react';
3
- import {
4
- Platform,
5
- Animated as RNAnimated,
6
- requireNativeComponent,
7
- NativeModules,
8
- findNodeHandle,
9
- } from 'react-native';
10
- import {
11
- EdgeInsetsPropType,
12
- PointPropType,
13
- ColorPropType,
14
- ViewPropTypes,
15
- } from 'deprecated-react-native-prop-types';
16
- import MapMarker from './MapMarker';
17
- import MapPolyline from './MapPolyline';
18
- import MapPolygon from './MapPolygon';
19
- import MapCircle from './MapCircle';
20
- import MapCallout from './MapCallout';
21
- import MapCalloutSubview from './MapCalloutSubview';
22
- import MapOverlay from './MapOverlay';
23
- import MapUrlTile from './MapUrlTile';
24
- import MapWMSTile from './MapWMSTile';
25
- import MapLocalTile from './MapLocalTile';
26
- import MapHeatMap from './MapHeatmap';
27
- import AnimatedRegion from './AnimatedRegion';
28
- import Geojson from './Geojson';
29
- import {
30
- contextTypes as childContextTypes,
31
- getAirMapName,
32
- googleMapIsInstalled,
33
- createNotSupportedComponent,
34
- } from './decorateMapComponent';
35
- import * as ProviderConstants from './ProviderConstants';
36
-
37
- export const MAP_TYPES = {
38
- STANDARD: 'standard',
39
- SATELLITE: 'satellite',
40
- HYBRID: 'hybrid',
41
- TERRAIN: 'terrain',
42
- NONE: 'none',
43
- MUTEDSTANDARD: 'mutedStandard',
44
- };
45
-
46
- const GOOGLE_MAPS_ONLY_TYPES = [MAP_TYPES.TERRAIN, MAP_TYPES.NONE];
47
-
48
- const viewConfig = {
49
- uiViewClassName: 'AIR<provider>Map',
50
- validAttributes: {
51
- region: true,
52
- },
53
- };
54
-
55
- /**
56
- * Defines the map camera.
57
- */
58
- const CameraShape = PropTypes.shape({
59
- center: PropTypes.shape({
60
- latitude: PropTypes.number.isRequired,
61
- longitude: PropTypes.number.isRequired,
62
- }),
63
- pitch: PropTypes.number.isRequired,
64
- heading: PropTypes.number.isRequired,
65
- altitude: PropTypes.number.isRequired,
66
- zoom: PropTypes.number.isRequired,
67
- });
68
-
69
- const propTypes = {
70
- ...ViewPropTypes,
71
- /**
72
- * When provider is "google", we will use GoogleMaps.
73
- * Any value other than "google" will default to using
74
- * MapKit in iOS or GoogleMaps in android as the map provider.
75
- */
76
- provider: PropTypes.oneOf(['google']),
77
-
78
- /**
79
- * Used to style and layout the `MapView`. See `StyleSheet.js` and
80
- * `ViewStylePropTypes.js` for more info.
81
- */
82
- style: ViewPropTypes.style,
83
-
84
- /**
85
- * A json object that describes the style of the map. This is transformed to a string
86
- * and saved in mayStyleString to be sent to android and ios
87
- * https://developers.google.com/maps/documentation/ios-sdk/styling#use_a_string_resource
88
- * https://developers.google.com/maps/documentation/android-api/styling
89
- */
90
- customMapStyle: PropTypes.array,
91
-
92
- /**
93
- * A json string that describes the style of the map
94
- * https://developers.google.com/maps/documentation/ios-sdk/styling#use_a_string_resource
95
- * https://developers.google.com/maps/documentation/android-api/styling
96
- */
97
- customMapStyleString: PropTypes.string,
98
-
99
- /**
100
- * If `true` the app will ask for the user's location.
101
- * Default value is `false`.
102
- *
103
- * **NOTE**: You need to add NSLocationWhenInUseUsageDescription key in
104
- * Info.plist to enable geolocation, otherwise it is going
105
- * to *fail silently*! You will also need to add an explanation for why
106
- * you need the users location against `NSLocationWhenInUseUsageDescription` in Info.plist.
107
- * Otherwise Apple may reject your app submission.
108
- */
109
- showsUserLocation: PropTypes.bool,
110
-
111
- /**
112
- * The title of the annotation for current user location. This only works if
113
- * `showsUserLocation` is true.
114
- * There is a default value `My Location` set by MapView.
115
- *
116
- * @platform ios
117
- */
118
- userLocationAnnotationTitle: PropTypes.string,
119
-
120
- /**
121
- * The user interface style for the map view
122
- * There is a default value is the device settings.
123
- *
124
- * @platform ios
125
- */
126
- userInterfaceStyle: PropTypes.oneOf(['light', 'dark']),
127
-
128
- /**
129
- * If `false` hide the button to move map to the current user's location.
130
- * Default value is `true`.
131
- *
132
- * @platform android
133
- */
134
- showsMyLocationButton: PropTypes.bool,
135
-
136
- /**
137
- * If `true` the map will focus on the user's location. This only works if
138
- * `showsUserLocation` is true and the user has shared their location.
139
- * Default value is `false`.
140
- *
141
- * @platform ios
142
- */
143
- followsUserLocation: PropTypes.bool,
144
- /**
145
- * If `true` clicking user location will show the default callout for userLocation annotation
146
- * Default value is `false`.
147
- *
148
- * @platform ios
149
- */
150
- userLocationCalloutEnabled: PropTypes.bool,
151
-
152
- /**
153
- * If `false` points of interest won't be displayed on the map.
154
- * Default value is `true`.
155
- *
156
- */
157
- showsPointsOfInterest: PropTypes.bool,
158
-
159
- /**
160
- * If `false` compass won't be displayed on the map.
161
- * Default value is `true`.
162
- *
163
- * @platform ios
164
- */
165
- showsCompass: PropTypes.bool,
166
-
167
- /**
168
- * If `false` the user won't be able to pinch/zoom the map.
169
- * Default value is `true`.
170
- *
171
- */
172
- zoomEnabled: PropTypes.bool,
173
-
174
- /**
175
- * If `false` the user won't be able to double tap to zoom the map.
176
- * However it will greatly decrease delay of tap gesture recognition.
177
- * Default value is `true`.
178
- *
179
- */
180
- zoomTapEnabled: PropTypes.bool,
181
-
182
- /**
183
- *If `false` the user won't be able to zoom the map
184
- * Default value is `true`.
185
- *
186
- *@platform android
187
- */
188
- zoomControlEnabled: PropTypes.bool,
189
-
190
- /**
191
- * If `false` the user won't be able to pinch/rotate the map.
192
- * Default value is `true`.
193
- *
194
- */
195
- rotateEnabled: PropTypes.bool,
196
-
197
- /**
198
- * If `false` the map will stay centered while rotating or zooming.
199
- * Default value is `true`.
200
- *
201
- */
202
- scrollDuringRotateOrZoomEnabled: PropTypes.bool,
203
-
204
- /**
205
- * If `true` the map will be cached to an Image for performance
206
- * Default value is `false`.
207
- *
208
- */
209
- cacheEnabled: PropTypes.bool,
210
-
211
- /**
212
- * If `true` the map will be showing a loading indicator
213
- * Default value is `false`.
214
- *
215
- */
216
- loadingEnabled: PropTypes.bool,
217
-
218
- /**
219
- * Loading background color while generating map cache image or loading the map
220
- * Default color is light gray.
221
- *
222
- */
223
- loadingBackgroundColor: ColorPropType,
224
-
225
- /**
226
- * Loading indicator color while generating map cache image or loading the map
227
- * Default color is gray color for iOS, theme color for Android.
228
- *
229
- */
230
- loadingIndicatorColor: ColorPropType,
231
-
232
- /**
233
- * If `false` the user won't be able to change the map region being displayed.
234
- * Default value is `true`.
235
- *
236
- */
237
- scrollEnabled: PropTypes.bool,
238
-
239
- /**
240
- * If `false` the user won't be able to adjust the camera’s pitch angle.
241
- * Default value is `true`.
242
- *
243
- */
244
- pitchEnabled: PropTypes.bool,
245
-
246
- /**
247
- * If `false` will hide 'Navigate' and 'Open in Maps' buttons on marker press
248
- * Default value is `true`.
249
- *
250
- * @platform android
251
- */
252
- toolbarEnabled: PropTypes.bool,
253
-
254
- /**
255
- * A Boolean indicating whether on marker press the map will move to the pressed marker
256
- * Default value is `true`
257
- *
258
- * @platform android
259
- */
260
- moveOnMarkerPress: PropTypes.bool,
261
-
262
- /**
263
- * A Boolean indicating whether the map shows scale information.
264
- * Default value is `false`
265
- *
266
- * @platform ios
267
- */
268
- showsScale: PropTypes.bool,
269
-
270
- /**
271
- * A Boolean indicating whether the map displays extruded building information.
272
- * Default value is `true`.
273
- */
274
- showsBuildings: PropTypes.bool,
275
-
276
- /**
277
- * A Boolean value indicating whether the map displays traffic information.
278
- * Default value is `false`.
279
- */
280
- showsTraffic: PropTypes.bool,
281
-
282
- /**
283
- * A Boolean indicating whether indoor maps should be enabled.
284
- * Default value is `false`
285
- *
286
- * @platform android
287
- */
288
- showsIndoors: PropTypes.bool,
289
-
290
- /**
291
- * A Boolean indicating whether indoor level picker should be enabled.
292
- * Default value is `false`
293
- *
294
- * @platform android
295
- */
296
- showsIndoorLevelPicker: PropTypes.bool,
297
-
298
- /**
299
- * The map type to be displayed.
300
- *
301
- * - standard: standard road map (default)
302
- * - satellite: satellite view
303
- * - hybrid: satellite view with roads and points of interest overlayed
304
- * - terrain: topographic view
305
- * - none: no base map
306
- */
307
- mapType: PropTypes.oneOf(Object.values(MAP_TYPES)),
308
-
309
- /**
310
- * The region to be displayed by the map.
311
- *
312
- * The region is defined by the center coordinates and the span of
313
- * coordinates to display.
314
- */
315
- region: PropTypes.shape({
316
- /**
317
- * Coordinates for the center of the map.
318
- */
319
- latitude: PropTypes.number.isRequired,
320
- longitude: PropTypes.number.isRequired,
321
-
322
- /**
323
- * Difference between the minimun and the maximum latitude/longitude
324
- * to be displayed.
325
- */
326
- latitudeDelta: PropTypes.number.isRequired,
327
- longitudeDelta: PropTypes.number.isRequired,
328
- }),
329
-
330
- /**
331
- * The initial region to be displayed by the map. Use this prop instead of `region`
332
- * only if you don't want to control the viewport of the map besides the initial region.
333
- *
334
- * Changing this prop after the component has mounted will not result in a region change.
335
- *
336
- * This is similar to the `initialValue` prop of a text input.
337
- */
338
- initialRegion: PropTypes.shape({
339
- /**
340
- * Coordinates for the center of the map.
341
- */
342
- latitude: PropTypes.number.isRequired,
343
- longitude: PropTypes.number.isRequired,
344
-
345
- /**
346
- * Difference between the minimun and the maximum latitude/longitude
347
- * to be displayed.
348
- */
349
- latitudeDelta: PropTypes.number.isRequired,
350
- longitudeDelta: PropTypes.number.isRequired,
351
- }),
352
-
353
- /**
354
- * The camera view the map should use.
355
- *
356
- * Use the camera system, instead of the region system, if you need control over
357
- * the pitch or heading.
358
- */
359
- camera: CameraShape,
360
-
361
- /**
362
- * The initial camera view the map should use. Use this prop instead of `camera`
363
- * only if you don't want to control the camera of the map besides the initial view.
364
- *
365
- * Use the camera system, instead of the region system, if you need control over
366
- * the pitch or heading.
367
- *
368
- * Changing this prop after the component has mounted will not result in a camera change.
369
- *
370
- * This is similar to the `initialValue` prop of a text input.
371
- */
372
- initialCamera: CameraShape,
373
-
374
- /**
375
- * A Boolean indicating whether to use liteMode for android
376
- * Default value is `false`
377
- *
378
- * @platform android
379
- */
380
- liteMode: PropTypes.bool,
381
-
382
- /**
383
- * (Google Maps only)
384
- *
385
- * Padding that is used by the Google Map View to position
386
- * the camera, legal labels and buttons
387
- *
388
- */
389
- mapPadding: EdgeInsetsPropType,
390
-
391
- /**
392
- * (Google Maps only, iOS)
393
- *
394
- * Whether the safe area padding is added to the Google Map View padding.
395
- * This affects where markers, compass, Google logo etc. are placed on the view.
396
- *
397
- */
398
- paddingAdjustmentBehavior: PropTypes.oneOf(['always', 'automatic', 'never']),
399
-
400
- /**
401
- * Maximum size of area that can be displayed.
402
- *
403
- * @platform ios
404
- */
405
- maxDelta: PropTypes.number,
406
-
407
- /**
408
- * Minimum size of area that can be displayed.
409
- *
410
- * @platform ios
411
- */
412
- minDelta: PropTypes.number,
413
-
414
- /**
415
- * Insets for the map's legal label, originally at bottom left of the map.
416
- * See `EdgeInsetsPropType.js` for more information.
417
- */
418
- legalLabelInsets: EdgeInsetsPropType,
419
-
420
- /**
421
- * Callback that is called once the map is fully loaded.
422
- */
423
- onMapReady: PropTypes.func,
424
-
425
- /**
426
- * Callback that is called once all tiles have been loaded
427
- * (or failed permanently) and labels have been rendered.
428
- */
429
- onMapLoaded: PropTypes.func,
430
-
431
- /**
432
- * Callback that is called once the kml is fully loaded.
433
- */
434
- onKmlReady: PropTypes.func,
435
-
436
- /**
437
- * Callback that is called continuously when the user is dragging the map.
438
- */
439
- onRegionChange: PropTypes.func,
440
-
441
- /**
442
- * Callback that is called once, when the user is done moving the map.
443
- */
444
- onRegionChangeComplete: PropTypes.func,
445
-
446
- /**
447
- * Callback that is called when user taps on the map.
448
- */
449
- onPress: PropTypes.func,
450
-
451
- /**
452
- * Callback that is called when user double taps on the map.
453
- */
454
- onDoublePress: PropTypes.func,
455
-
456
- /**
457
- * Callback that is called when user makes a "long press" somewhere on the map.
458
- */
459
- onLongPress: PropTypes.func,
460
-
461
- /**
462
- * Callback that is called when the underlying map figures our users current location.
463
- */
464
- onUserLocationChange: PropTypes.func,
465
-
466
- /**
467
- * Callback that is called when user makes a "drag" somewhere on the map
468
- */
469
- onPanDrag: PropTypes.func,
470
-
471
- /**
472
- * Callback that is called when user click on a POI
473
- */
474
- onPoiClick: PropTypes.func,
475
-
476
- /**
477
- * Callback that is called when a marker on the map is tapped by the user.
478
- */
479
- onMarkerPress: PropTypes.func,
480
-
481
- /**
482
- * Callback that is called when a marker on the map becomes selected. This will be called when
483
- * the callout for that marker is about to be shown.
484
- *
485
- * @platform ios
486
- */
487
- onMarkerSelect: PropTypes.func,
488
-
489
- /**
490
- * Callback that is called when a marker on the map becomes deselected. This will be called when
491
- * the callout for that marker is about to be hidden.
492
- *
493
- * @platform ios
494
- */
495
- onMarkerDeselect: PropTypes.func,
496
-
497
- /**
498
- * Callback that is called when a callout is tapped by the user.
499
- */
500
- onCalloutPress: PropTypes.func,
501
-
502
- /**
503
- * Callback that is called when the user initiates a drag on a marker (if it is draggable)
504
- */
505
- onMarkerDragStart: PropTypes.func,
506
-
507
- /**
508
- * Callback called continuously as a marker is dragged
509
- */
510
- onMarkerDrag: PropTypes.func,
511
-
512
- /**
513
- * Callback that is called when a drag on a marker finishes. This is usually the point you
514
- * will want to setState on the marker's coordinate again
515
- */
516
- onMarkerDragEnd: PropTypes.func,
517
-
518
- /**
519
- * Minimum zoom value for the map, must be between 0 and 20
520
- */
521
- minZoomLevel: PropTypes.number,
522
-
523
- /**
524
- * Maximum zoom value for the map, must be between 0 and 20
525
- */
526
- maxZoomLevel: PropTypes.number,
527
-
528
- /**
529
- * Url KML Source
530
- */
531
- kmlSrc: PropTypes.string,
532
-
533
- /**
534
- * Offset Point x y for compass location.
535
- *
536
- * @platform ios
537
- */
538
- compassOffset: PointPropType,
539
-
540
- /**
541
- * Callback that is called when a level is activated on a indoor building.
542
- */
543
- onIndoorLevelActivated: PropTypes.func,
544
-
545
- /**
546
- * Callback that is called when a Building is focused.
547
- */
548
- onIndoorBuildingFocused: PropTypes.func,
549
-
550
- /**
551
- * Sets the tint color of the map. (Changes the color of the position indicator) Defaults to system blue.
552
- *
553
- * @platform ios
554
- */
555
- tintColor: ColorPropType,
556
- };
557
-
558
- class MapView extends React.Component {
559
- constructor(props) {
560
- super(props);
561
-
562
- this.state = {
563
- isReady: Platform.OS === 'ios',
564
- };
565
-
566
- this._onMapReady = this._onMapReady.bind(this);
567
- this._onMarkerPress = this._onMarkerPress.bind(this);
568
- this._onChange = this._onChange.bind(this);
569
- this._onLayout = this._onLayout.bind(this);
570
- }
571
-
572
- setNativeProps(props) {
573
- this.map.setNativeProps(props);
574
- }
575
-
576
- getChildContext() {
577
- return { provider: this.props.provider };
578
- }
579
-
580
- getSnapshotBeforeUpdate(prevProps) {
581
- if (
582
- this.state.isReady &&
583
- this.props.customMapStyle !== prevProps.customMapStyle
584
- ) {
585
- this._updateStyle(this.props);
586
- }
587
- return this.props.region || null;
588
- }
589
-
590
- componentDidUpdate(prevProps, prevState, region) {
591
- const a = this.__lastRegion;
592
- const b = region;
593
- if (!a || !b) {
594
- return;
595
- }
596
- if (
597
- a.latitude !== b.latitude ||
598
- a.longitude !== b.longitude ||
599
- a.latitudeDelta !== b.latitudeDelta ||
600
- a.longitudeDelta !== b.longitudeDelta
601
- ) {
602
- this.map.setNativeProps({ region: b });
603
- }
604
- }
605
-
606
- componentDidMount() {
607
- const { isReady } = this.state;
608
- if (isReady) {
609
- this._updateStyle(this.props);
610
- }
611
- }
612
-
613
- _updateStyle(props) {
614
- const { customMapStyle } = props;
615
- this.map.setNativeProps({
616
- customMapStyleString: JSON.stringify(customMapStyle),
617
- });
618
- }
619
-
620
- _onMapReady() {
621
- const { region, initialRegion, onMapReady } = this.props;
622
- if (region) {
623
- this.map.setNativeProps({ region });
624
- } else if (initialRegion) {
625
- this.map.setNativeProps({ initialRegion });
626
- }
627
- this._updateStyle(this.props);
628
- this.setState({ isReady: true }, () => {
629
- if (onMapReady) {
630
- onMapReady();
631
- }
632
- });
633
- }
634
-
635
- _onLayout(e) {
636
- const { layout } = e.nativeEvent;
637
- if (!layout.width || !layout.height) {
638
- return;
639
- }
640
- if (this.state.isReady && !this.__layoutCalled) {
641
- const { region, initialRegion } = this.props;
642
- if (region) {
643
- this.__layoutCalled = true;
644
- this.map.setNativeProps({ region });
645
- } else if (initialRegion) {
646
- this.__layoutCalled = true;
647
- this.map.setNativeProps({ initialRegion });
648
- }
649
- }
650
- if (this.props.onLayout) {
651
- this.props.onLayout(e);
652
- }
653
- }
654
-
655
- _onMarkerPress(event) {
656
- if (this.props.onMarkerPress) {
657
- this.props.onMarkerPress(event.nativeEvent);
658
- }
659
- }
660
-
661
- _onChange({ nativeEvent }) {
662
- this.__lastRegion = nativeEvent.region;
663
- const isGesture = nativeEvent.isGesture;
664
- const details = { isGesture };
665
-
666
- if (nativeEvent.continuous) {
667
- if (this.props.onRegionChange) {
668
- this.props.onRegionChange(nativeEvent.region, details);
669
- }
670
- } else if (this.props.onRegionChangeComplete) {
671
- this.props.onRegionChangeComplete(nativeEvent.region, details);
672
- }
673
- }
674
-
675
- getCamera() {
676
- if (Platform.OS === 'android') {
677
- return NativeModules.AirMapModule.getCamera(this._getHandle());
678
- } else if (Platform.OS === 'ios') {
679
- return this._runCommand('getCamera', []);
680
- }
681
- return Promise.reject('getCamera not supported on this platform');
682
- }
683
-
684
- setCamera(camera) {
685
- this._runCommand('setCamera', [camera]);
686
- }
687
-
688
- animateCamera(camera, opts) {
689
- this._runCommand('animateCamera', [camera, opts ? opts.duration : 500]);
690
- }
691
-
692
- animateToNavigation(location, bearing, angle, duration) {
693
- console.warn(
694
- 'animateToNavigation() is deprecated, use animateCamera() instead'
695
- );
696
- this._runCommand('animateToNavigation', [
697
- location,
698
- bearing,
699
- angle,
700
- duration || 500,
701
- ]);
702
- }
703
-
704
- animateToRegion(region, duration) {
705
- this._runCommand('animateToRegion', [region, duration || 500]);
706
- }
707
-
708
- animateToCoordinate(latLng, duration) {
709
- console.warn(
710
- 'animateToCoordinate() is deprecated, use animateCamera() instead'
711
- );
712
- this._runCommand('animateToCoordinate', [latLng, duration || 500]);
713
- }
714
-
715
- animateToBearing(bearing, duration) {
716
- console.warn(
717
- 'animateToBearing() is deprecated, use animateCamera() instead'
718
- );
719
- this._runCommand('animateToBearing', [bearing, duration || 500]);
720
- }
721
-
722
- animateToViewingAngle(angle, duration) {
723
- console.warn(
724
- 'animateToViewingAngle() is deprecated, use animateCamera() instead'
725
- );
726
- this._runCommand('animateToViewingAngle', [angle, duration || 500]);
727
- }
728
-
729
- fitToElements(options = {}) {
730
- const {
731
- edgePadding = { top: 0, right: 0, bottom: 0, left: 0 },
732
- animated = true,
733
- } = options;
734
-
735
- this._runCommand('fitToElements', [edgePadding, animated]);
736
- }
737
-
738
- fitToSuppliedMarkers(markers, options = {}) {
739
- const {
740
- edgePadding = { top: 0, right: 0, bottom: 0, left: 0 },
741
- animated = true,
742
- } = options;
743
-
744
- this._runCommand('fitToSuppliedMarkers', [markers, edgePadding, animated]);
745
- }
746
-
747
- fitToCoordinates(coordinates = [], options = {}) {
748
- const {
749
- edgePadding = { top: 0, right: 0, bottom: 0, left: 0 },
750
- animated = true,
751
- } = options;
752
-
753
- this._runCommand('fitToCoordinates', [coordinates, edgePadding, animated]);
754
- }
755
-
756
- /**
757
- * Get visible boudaries
758
- *
759
- * @return Promise Promise with the bounding box ({ northEast: <LatLng>, southWest: <LatLng> })
760
- */
761
- async getMapBoundaries() {
762
- if (Platform.OS === 'android') {
763
- return await NativeModules.AirMapModule.getMapBoundaries(
764
- this._getHandle()
765
- );
766
- } else if (Platform.OS === 'ios') {
767
- return await this._runCommand('getMapBoundaries', []);
768
- }
769
- return Promise.reject('getMapBoundaries not supported on this platform');
770
- }
771
-
772
- setMapBoundaries(northEast, southWest) {
773
- this._runCommand('setMapBoundaries', [northEast, southWest]);
774
- }
775
-
776
- setIndoorActiveLevelIndex(activeLevelIndex) {
777
- this._runCommand('setIndoorActiveLevelIndex', [activeLevelIndex]);
778
- }
779
-
780
- /**
781
- * Takes a snapshot of the map and saves it to a picture
782
- * file or returns the image as a base64 encoded string.
783
- *
784
- * @param config Configuration options
785
- * @param [config.width] Width of the rendered map-view (when omitted actual view width is used).
786
- * @param [config.height] Height of the rendered map-view (when omitted actual height is used).
787
- * @param [config.region] Region to render (Only supported on iOS).
788
- * @param [config.format] Encoding format ('png', 'jpg') (default: 'png').
789
- * @param [config.quality] Compression quality (only used for jpg) (default: 1.0).
790
- * @param [config.result] Result format ('file', 'base64') (default: 'file').
791
- *
792
- * @return Promise Promise with either the file-uri or base64 encoded string
793
- */
794
- takeSnapshot(args) {
795
- // For the time being we support the legacy API on iOS.
796
- // This will be removed in a future release and only the
797
- // new Promise style API shall be supported.
798
- if (Platform.OS === 'ios' && arguments.length === 4) {
799
- console.warn(
800
- 'Old takeSnapshot API has been deprecated; will be removed in the near future'
801
- );
802
- const width = arguments[0];
803
- const height = arguments[1];
804
- const region = arguments[2];
805
- const callback = arguments[3];
806
- this._runCommand('takeSnapshot', [
807
- width || 0,
808
- height || 0,
809
- region || {},
810
- 'png',
811
- 1,
812
- 'legacy',
813
- callback,
814
- ]);
815
- return undefined;
816
- }
817
-
818
- // Sanitize inputs
819
- const config = {
820
- width: args.width || 0,
821
- height: args.height || 0,
822
- region: args.region || {},
823
- format: args.format || 'png',
824
- quality: args.quality || 1.0,
825
- result: args.result || 'file',
826
- };
827
- if (config.format !== 'png' && config.format !== 'jpg') {
828
- throw new Error('Invalid format specified');
829
- }
830
- if (config.result !== 'file' && config.result !== 'base64') {
831
- throw new Error('Invalid result specified');
832
- }
833
-
834
- // Call native function
835
- if (Platform.OS === 'android') {
836
- return NativeModules.AirMapModule.takeSnapshot(this._getHandle(), config);
837
- } else if (Platform.OS === 'ios') {
838
- return new Promise((resolve, reject) => {
839
- this._runCommand('takeSnapshot', [
840
- config.width,
841
- config.height,
842
- config.region,
843
- config.format,
844
- config.quality,
845
- config.result,
846
- (err, snapshot) => {
847
- if (err) {
848
- reject(err);
849
- } else {
850
- resolve(snapshot);
851
- }
852
- },
853
- ]);
854
- });
855
- }
856
- return Promise.reject('takeSnapshot not supported on this platform');
857
- }
858
-
859
- /**
860
- * Convert a coordinate to address by using default Geocoder
861
- *
862
- * @param coordinate Coordinate
863
- * @param [coordinate.latitude] Latitude
864
- * @param [coordinate.longitude] Longitude
865
- *
866
- * @return Promise with return type Address
867
- */
868
- addressForCoordinate(coordinate) {
869
- if (Platform.OS === 'android') {
870
- return NativeModules.AirMapModule.getAddressFromCoordinates(
871
- this._getHandle(),
872
- coordinate
873
- );
874
- } else if (Platform.OS === 'ios') {
875
- return this._runCommand('getAddressFromCoordinates', [coordinate]);
876
- }
877
- return Promise.reject('getAddress not supported on this platform');
878
- }
879
-
880
- /**
881
- * Convert a map coordinate to user-space point
882
- *
883
- * @param coordinate Coordinate
884
- * @param [coordinate.latitude] Latitude
885
- * @param [coordinate.longitude] Longitude
886
- *
887
- * @return Promise Promise with the point ({ x: Number, y: Number })
888
- */
889
- pointForCoordinate(coordinate) {
890
- if (Platform.OS === 'android') {
891
- return NativeModules.AirMapModule.pointForCoordinate(
892
- this._getHandle(),
893
- coordinate
894
- );
895
- } else if (Platform.OS === 'ios') {
896
- return this._runCommand('pointForCoordinate', [coordinate]);
897
- }
898
- return Promise.reject('pointForCoordinate not supported on this platform');
899
- }
900
-
901
- /**
902
- * Convert a user-space point to a map coordinate
903
- *
904
- * @param point Point
905
- * @param [point.x] X
906
- * @param [point.x] Y
907
- *
908
- * @return Promise Promise with the coordinate ({ latitude: Number, longitude: Number })
909
- */
910
- coordinateForPoint(point) {
911
- if (Platform.OS === 'android') {
912
- return NativeModules.AirMapModule.coordinateForPoint(
913
- this._getHandle(),
914
- point
915
- );
916
- } else if (Platform.OS === 'ios') {
917
- return this._runCommand('coordinateForPoint', [point]);
918
- }
919
- return Promise.reject('coordinateForPoint not supported on this platform');
920
- }
921
-
922
- /**
923
- * Get markers' centers and frames in user-space coordinates
924
- *
925
- * @param onlyVisible boolean true to include only visible markers, false to include all
926
- *
927
- * @return Promise Promise with { <identifier>: { point: Point, frame: Frame } }
928
- */
929
- getMarkersFrames(onlyVisible = false) {
930
- if (Platform.OS === 'ios') {
931
- return this._runCommand('getMarkersFrames', [onlyVisible]);
932
- }
933
- return Promise.reject('getMarkersFrames not supported on this platform');
934
- }
935
-
936
- /**
937
- * Get bounding box from region
938
- *
939
- * @param region Region
940
- *
941
- * @return Object Object bounding box ({ northEast: <LatLng>, southWest: <LatLng> })
942
- */
943
- boundingBoxForRegion(region) {
944
- return {
945
- northEast: {
946
- latitude: region.latitude + region.latitudeDelta / 2,
947
- longitude: region.longitude + region.longitudeDelta / 2,
948
- },
949
- southWest: {
950
- latitude: region.latitude - region.latitudeDelta / 2,
951
- longitude: region.longitude - region.longitudeDelta / 2,
952
- },
953
- };
954
- }
955
-
956
- _uiManagerCommand(name) {
957
- const UIManager = NativeModules.UIManager;
958
- const componentName = getAirMapName(this.props.provider);
959
-
960
- if (!UIManager.getViewManagerConfig) {
961
- // RN < 0.58
962
- return UIManager[componentName].Commands[name];
963
- }
964
-
965
- // RN >= 0.58
966
- return UIManager.getViewManagerConfig(componentName).Commands[name];
967
- }
968
-
969
- _mapManagerCommand(name) {
970
- const managerName = getAirMapName(this.props.provider);
971
-
972
- if (managerName === 'UI') {
973
- const UIManager = NativeModules.UIManager;
974
- if (!UIManager.getViewManagerConfig) {
975
- // RN < 0.58
976
- return UIManager[name];
977
- }
978
-
979
- // RN >= 0.58
980
- return UIManager.getViewManagerConfig(name);
981
- }
982
-
983
- return NativeModules[`${getAirMapName(this.props.provider)}Manager`][name];
984
- }
985
-
986
- _getHandle() {
987
- return findNodeHandle(this.map);
988
- }
989
-
990
- _runCommand(name, args) {
991
- switch (Platform.OS) {
992
- case 'android':
993
- return NativeModules.UIManager.dispatchViewManagerCommand(
994
- this._getHandle(),
995
- this._uiManagerCommand(name),
996
- args
997
- );
998
-
999
- case 'ios':
1000
- return this._mapManagerCommand(name)(this._getHandle(), ...args);
1001
-
1002
- default:
1003
- return Promise.reject(`Invalid platform was passed: ${Platform.OS}`);
1004
- }
1005
- }
1006
-
1007
- render() {
1008
- let props;
1009
-
1010
- if (this.state.isReady) {
1011
- props = {
1012
- region: null,
1013
- initialRegion: null,
1014
- onMarkerPress: this._onMarkerPress,
1015
- onChange: this._onChange,
1016
- onMapReady: this._onMapReady,
1017
- onLayout: this._onLayout,
1018
- ...this.props,
1019
- };
1020
- if (
1021
- Platform.OS === 'ios' &&
1022
- props.provider === ProviderConstants.PROVIDER_DEFAULT &&
1023
- GOOGLE_MAPS_ONLY_TYPES.includes(props.mapType)
1024
- ) {
1025
- props.mapType = MAP_TYPES.standard;
1026
- }
1027
- if (props.onPanDrag) {
1028
- props.handlePanDrag = !!props.onPanDrag;
1029
- }
1030
- } else {
1031
- props = {
1032
- style: this.props.style,
1033
- region: null,
1034
- initialRegion: this.props.initialRegion || null,
1035
- onMarkerPress: this._onMarkerPress,
1036
- onChange: this._onChange,
1037
- onMapReady: this._onMapReady,
1038
- onLayout: this._onLayout,
1039
- };
1040
- }
1041
-
1042
- if (Platform.OS === 'android' && this.props.liteMode) {
1043
- return (
1044
- <AIRMapLite
1045
- ref={(ref) => {
1046
- this.map = ref;
1047
- }}
1048
- {...props}
1049
- />
1050
- );
1051
- }
1052
-
1053
- const AIRMap = getAirMapComponent(this.props.provider);
1054
-
1055
- return (
1056
- <AIRMap
1057
- ref={(ref) => {
1058
- this.map = ref;
1059
- }}
1060
- {...props}
1061
- />
1062
- );
1063
- }
1064
- }
1065
-
1066
- MapView.propTypes = propTypes;
1067
- MapView.viewConfig = viewConfig;
1068
- MapView.childContextTypes = childContextTypes;
1069
-
1070
- MapView.MAP_TYPES = MAP_TYPES;
1071
-
1072
- const nativeComponent = (Component) =>
1073
- requireNativeComponent(Component, MapView, {
1074
- nativeOnly: {
1075
- onChange: true,
1076
- onMapReady: true,
1077
- onKmlReady: true,
1078
- handlePanDrag: true,
1079
- },
1080
- });
1081
- const airMaps = {
1082
- default: nativeComponent('AIRMap'),
1083
- };
1084
- if (Platform.OS === 'android') {
1085
- airMaps.google = airMaps.default;
1086
- } else {
1087
- airMaps.google = googleMapIsInstalled
1088
- ? nativeComponent('AIRGoogleMap')
1089
- : createNotSupportedComponent(
1090
- 'react-native-maps: AirGoogleMaps dir must be added to your xCode project to support GoogleMaps on iOS.'
1091
- );
1092
- }
1093
- const getAirMapComponent = (provider) => airMaps[provider || 'default'];
1094
-
1095
- let AIRMapLite;
1096
- if (!NativeModules.UIManager.getViewManagerConfig) {
1097
- // RN < 0.58
1098
- AIRMapLite =
1099
- NativeModules.UIManager.AIRMapLite &&
1100
- requireNativeComponent('AIRMapLite', MapView, {
1101
- nativeOnly: {
1102
- onChange: true,
1103
- onMapReady: true,
1104
- handlePanDrag: true,
1105
- },
1106
- });
1107
- } else {
1108
- // RN >= 0.58
1109
- AIRMapLite =
1110
- NativeModules.UIManager.getViewManagerConfig('AIRMapLite') &&
1111
- requireNativeComponent('AIRMapLite', MapView, {
1112
- nativeOnly: {
1113
- onChange: true,
1114
- onMapReady: true,
1115
- handlePanDrag: true,
1116
- },
1117
- });
1118
- }
1119
-
1120
- export const Animated = RNAnimated.createAnimatedComponent(MapView);
1121
-
1122
- export const enableLatestRenderer = () => {
1123
- if (Platform.OS !== 'android') {
1124
- return;
1125
- }
1126
- return NativeModules.AirMapModule.enableLatestRenderer();
1127
- };
1128
-
1129
- export const ProviderPropType = PropTypes.oneOf(
1130
- Object.values(ProviderConstants)
1131
- );
1132
-
1133
- /**
1134
- * TODO:
1135
- * All of these properties on MapView are unecessary since they can be imported
1136
- * individually with the es6 exports in index.js. Removing them is a breaking change,
1137
- * but potentially allows for better dead code elimination since references are not
1138
- * kept to components which are never used.
1139
- */
1140
-
1141
- MapView.Marker = MapMarker;
1142
- MapView.Polyline = MapPolyline;
1143
- MapView.Polygon = MapPolygon;
1144
- MapView.Circle = MapCircle;
1145
- MapView.UrlTile = MapUrlTile;
1146
- MapView.MapWMSTile = MapWMSTile;
1147
- MapView.LocalTile = MapLocalTile;
1148
- MapView.Heatmap = MapHeatMap;
1149
- MapView.Overlay = MapOverlay;
1150
- MapView.Callout = MapCallout;
1151
- MapView.CalloutSubview = MapCalloutSubview;
1152
- Object.assign(MapView, ProviderConstants);
1153
- MapView.ProviderPropType = ProviderPropType;
1154
-
1155
- MapView.Animated = Animated;
1156
- MapView.AnimatedRegion = AnimatedRegion;
1157
-
1158
- MapView.Geojson = Geojson;
1159
-
1160
- export default MapView;