@mappedin/react-native-sdk 5.0.0-beta.9 → 5.0.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.
Files changed (4) hide show
  1. package/README.md +6 -574
  2. package/dist/index.d.ts +3525 -3372
  3. package/dist/index.js +199 -198
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  ## Resources
4
4
  - [Mappedin Developer Portal](https://developer.mappedin.com)
5
- - [React Native SDK V4 guides](https://developer.mappedin.com/guides/react-native/)
6
- - [Release notes](https://developer.mappedin.com/blog/2021-11-26-react-native-sdk-v4-release-notes/)
7
- - [Migration guide to V4](https://developer.mappedin.com/blog/2021-11-04-react-native-sdk-v4-migration-guide/)
8
- - [API Reference](https://developer.mappedin.com/docs/react-native/latest)
5
+ - [React Native SDK V5 guides](https://developer.mappedin.com/react-native-sdk/v5/)
6
+ - [Release notes](https://developer.mappedin.com/react-native-sdk/v5/release-notes)
7
+ - [Migration guide to V5](https://developer.mappedin.com/react-native-sdk/v5/migration-guide)
8
+ - [API Reference](https://developer.mappedin.com/react-native-sdk-api/v5/latest)
9
9
  - [Trial Keys](https://developer.mappedin.com/guides/api-keys)
10
10
 
11
11
  ## Installation
@@ -38,14 +38,13 @@ const MiMapView = (props: TMapViewProps) => React.ReactElement;
38
38
  | ----------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | -------- |
39
39
  | options | Options to initialize MapView with | <a href="modules.html#tmimapviewoptions">`TMiMapViewOptions`<a> | Yes |
40
40
  | ref | Exposes Imperative API <a href="classes/mapviewstore.html">`MapViewStore`</a> | React.MutableRefObject<<a href="classes/mapviewstore.html">`MapViewStore`</a>\> | No |
41
- | onPolygonClicked | Gets called when clicking interactive polygon | ({ polygon: <a href="classes/mappedinpolygon.html">`MappedinPolygon`</a> }) => void | No |
42
41
  | onDataLoaded | Fired when <a href="classes/mappedin.html">`Mappedin`</a> data is loaded | ({ venueData: <a href="classes/mappedin.html">`Mappedin`</a> }) => void | No |
43
42
  | onFirstMapLoaded | Fires when map can first be interacted with | () => void | No |
44
43
  | onBlueDotStateChanged | Fires when BlueDot state changes | ({ stateChange: <a href="modules.html#tbluedotstatechange">`TBlueDotStateChange`</a> }) => void | No |
45
44
  | onBlueDotPositionUpdated | Fires when BlueDot position changes | ({ update: <a href="modules.html#tbluedotpositionupdate">`TBlueDotPositionUpdate`</a> }) => void | No |
46
45
  | onCameraChanged | Fires when Camera position, tilt, zoom or rotation changes | ({ change: <a href="modules.html#TCameraChange">`TCameraChange`</a> }) => void | No |
47
46
  | onStateChanged | Fires when SDK State changes | ({ state: <a href="enums/state.html">`STATE`</a> }) => void | No |
48
-
47
+ | onClick | Fires when clicking within the mapView | (prop: <a href="modules.html#TMapClickEvent">TMapClickEvent</a> ) => void
49
48
  ### Imperative API
50
49
 
51
50
  <a href="classes/mapviewstore.html">Documented in Detail here: MapViewStore</a>
@@ -90,311 +89,7 @@ const App = () => {
90
89
  };
91
90
  ```
92
91
 
93
- ### Fetching venue data outside of the MiMapView component
94
-
95
- It is possible to fetch venue data (locations, maps, etc), outside of the MiMapView component. This can be helpful for cases where a map isn't always needed or there is a need to fetch the data first, and render the map later.
96
-
97
- ```tsx
98
-
99
- import { getVenue, MiMapView } from '@mappedin/react-native-sdk';
100
-
101
- const options = {
102
- clientId: '****',
103
- clientSecret: '***',
104
- venue: 'venue-slug',
105
- perspective: 'Website',
106
- };
107
-
108
- const App = () => {
109
- const [venueData, setVenueData] = React.useState<Mappedin>({});
110
-
111
- useEffect(() => {
112
- async function init() {
113
- const venueData = await getVenue(options);
114
- console.log(venueData.locations);
115
- setVenueData(venueData);
116
- }
117
- }, []);
118
-
119
- return (
120
- {venueData != null &&
121
- <MiMapView
122
- style={{ flex: 1 }}
123
- options={options}
124
- // pass venueData in
125
- venueData={venueData}
126
- />
127
- }
128
- );
129
- };
130
- ```
131
-
132
- ### Listen to polygon clicks
133
-
134
- ```tsx
135
- import { MiMapView } from '@mappedin/react-native-sdk';
136
- import type { MappedinLocation, Mappedin } from '@mappedin/react-native-sdk';
137
-
138
- const App = () => {
139
- const [venueData, setVenueData] = React.useState<Mappedin>({});
140
- const [
141
- selectedLocation,
142
- setSelectedLocation,
143
- ] = React.useState<MappedinLocation>({});
144
-
145
- return (
146
- <MiMapView
147
- style={{ flex: 1 }}
148
- options={options}
149
- onDataLoaded={({ venueData: Mappedin }) => {
150
- setVenueData(venueData);
151
- }}
152
- onPolygonClicked={({ polygon }) => {
153
- setSelectedLocation(polygon.locations[0]);
154
- }}
155
- />
156
- );
157
- };
158
- ```
159
-
160
- ### Rotate the map
161
-
162
- ```tsx
163
- import { MiMapView } from '@mappedin/react-native-sdk';
164
- import type { MapViewStore } from '@mappedin/react-native-sdk';
165
-
166
- // Imperative API
167
- const mapView = React.useRef<MapViewStore>();
168
-
169
- const App = () => {
170
- return (
171
- <MiMapView
172
- style={{ flex: 1 }}
173
- ref={mapView}
174
- options={options}
175
- onFirstMapLoaded={() => {
176
- mapView.current!.Camera.set({ rotation: 90 });
177
- }}
178
- />
179
- );
180
- };
181
- ```
182
-
183
- ### Focus on the polygon and highlight it
184
-
185
- ```tsx
186
- import { MiMapView } from '@mappedin/react-native-sdk';
187
- import type {
188
- MappedinPolygon,
189
- MapViewStore,
190
- Mappedin,
191
- } from '@mappedin/react-native-sdk';
192
-
193
- const App = () => {
194
- const [venueData, setVenueData] = React.useState<Mappedin>({});
195
- const [
196
- selectedLocation,
197
- setSelectedLocation,
198
- ] = React.useState<MappedinLocation>({});
199
-
200
- // Imperative API
201
- const mapView = React.useRef<MapViewStore>();
202
-
203
- return (
204
- <MiMapView
205
- style={{ flex: 1 }}
206
- ref={mapView}
207
- options={options}
208
- onDataLoaded={({ venueData: Mappedin }) => {
209
- setVenueData(venueData);
210
- }}
211
- onPolygonClicked={async ({ polygon: MappedinPolygon }) => {
212
- setSelectedLocation(polygon.locations[0]);
213
- mapView.current.clearAllPolygonColors();
214
- mapView.current.setPolygonColor(polygon, 'red');
215
- // lets wait for the focusOn to complete
216
- await mapView.current.Camera.focusOn({
217
- polygons: [polygon]
218
- });
219
- console.log('success!');
220
- }}
221
- />
222
- );
223
- };
224
- ```
225
-
226
- ### Enable Blue Dot and listen to update events
227
-
228
- ```tsx
229
- import { MiMapView } from '@mappedin/react-native-sdk';
230
- import type {
231
- TBlueDotUpdate,
232
- MapViewStore,
233
- MappedinMap,
234
- MappedinNode,
235
- } from '@mappedin/react-native-sdk';
236
-
237
- // Imperative API
238
- const mapView = React.useRef<MapViewStore>();
239
-
240
- const App = () => {
241
- return (
242
- <MiMapView
243
- style={{ flex: 1 }}
244
- ref={mapView}
245
- options={options}
246
- onFirstMapLoaded={() => {
247
- mapView.current.BlueDot.enable();
248
- }}
249
- onBlueDotStateChanged={({
250
- stateChange,
251
- }: {
252
- stateChange: TBlueDotStateChange;
253
- }) => {
254
- // This event can be used to get real time updates as to what the nearest node is
255
- const {
256
- map,
257
- nearestNode,
258
- }: {
259
- map: MappedinMap;
260
- nearestNode: MappedinNode;
261
- } = stateChange;
262
- }}
263
- />
264
- );
265
- };
266
- ```
267
-
268
- ### Set SDK into "FOLLOW" mode
269
-
270
- Setting the SDK into follow mode will lock the camera to follow the BlueDot at the center of the screen. Interacting with the map will put the SDK back into EXPLORE mode and emit onStateChanged event.
271
-
272
- ```tsx
273
- import { MiMapView } from '@mappedin/react-native-sdk';
274
- import type {
275
- TBlueDotUpdate,
276
- MapViewStore,
277
- MappedinLocation,
278
- MappedinNode,
279
- } from '@mappedin/react-native-sdk';
280
- import { STATE } from '@mappedin/react-native-sdk';
281
-
282
- // Imperative API
283
- const mapView = React.useRef<MapViewStore>();
284
- const nearestNode = React.useRef<MappedinNode>();
285
- const [
286
- selectedLocation,
287
- setSelectedLocation,
288
- ] = React.useState<MappedinLocation>({});
289
-
290
- const App = () => {
291
- return (
292
- <>
293
- <MiMapView
294
- style={{ flex: 1 }}
295
- ref={mapView}
296
- options={options}
297
- onStateChanged={({ state }) => {
298
- console.log('Current State is', state);
299
- }}
300
- onDataLoaded={() => {
301
- mapView.current.setState(STATE.FOLLOW);
302
- mapView.current.BlueDot.enable();
303
- }}
304
- onBlueStateChanged={({ stateChange }) => {
305
- nearestNode.current = stateChange.nearestNode;
306
- }}
307
- onPolygonClicked={({ polygon: MappedinPolygon }) => {
308
- setSelectedLocation(polygon.locations[0]);
309
- }}
310
- />
311
- </>
312
- );
313
- };
314
- ```
315
-
316
- ### Get Directions
317
-
318
- This API can be used to get a directions object from any MappedinLocation | MappedinNode | MappedinPolygon to any MappedinLocation | MappedinNode | MappedinPolygon. This can be used to show Text directions, as well as draw paths.
319
-
320
- Example:
321
-
322
- ```tsx
323
- ...
324
- <Button
325
- title="Get Directions"
326
- onPress={async () => {
327
- try {
328
- const directions = selectedLocation.directionsTo(destinationLocation);
329
- console.log(directions);
330
- } catch (e) {
331
- console.error(e);
332
- }
333
- }}
334
- ></Button>
335
- ...
336
-
337
- ```
338
-
339
- ## Get directions from one location to another and show path and connections on map
340
-
341
- ```tsx
342
- import { MiMapView } from '@mappedin/react-native-sdk';
343
- import type {
344
- MappedinLocation,
345
- MapViewStore,
346
- MappedinPolygon,
347
- } from '@mappedin/react-native-sdk';
348
-
349
- const App = () => {
350
- const mapView = React.useRef<MapViewStore>(null);
351
- const [destination, setDestination] = React.useState<MappedinLocation>(null);
352
- const [departure, setDeparture] = React.useState<MappedinLocation>(null);
353
-
354
- return (
355
- <>
356
- <MiMapView
357
- style={{flex: 1}}
358
- ref={mapView}
359
- options={options}
360
- onPolygonClicked={({polygon: MappedinPolygon}) => {
361
- // first, let's set departure
362
- if (departure == null) {
363
- setDeparture(polygon.locations[0]);
364
- } else {
365
- // then, destination
366
- setDestination(polygon.locations[0]);
367
- }
368
- }}
369
- />
370
- <Button
371
- title="Get Directions"
372
- onPress={async () => {
373
- try {
374
- // get Directions
375
- const directions = departure.directionsTo(destination);
376
- // draw path on map
377
- await mapView.current?.Journey.draw(directions);
378
- // focus on the path
379
- mapView.current?.Camera.focusOn({
380
- nodes: directions.path
381
- });
382
- } catch (e) {
383
- console.error(e);
384
- }
385
- }}></Button>
386
- <Button
387
- title="Reset"
388
- onPress={() => {
389
- mapView.current?.removeAllPaths();
390
- setDeparture(undefined);
391
- setDestination(undefined);
392
- }}></Button>
393
- </>
394
- );
395
- };
396
- ```
397
-
92
+ > See more detailed samples and guides on the [Mappedin Developer Portal](https://developer.mappedin.com)
398
93
  ## Preparing SVGs for use as assets in markers/tooltips/etc
399
94
 
400
95
  SVG is a popular format for image assets, which means there are a lot of proprietary, broken, or unnecessary tags when getting SVGs online.
@@ -418,122 +113,6 @@ Once the SVGs are prepared, they need to be wrapped in a `div` element which wil
418
113
  `
419
114
  ```
420
115
 
421
- ## Adding a Coordinate by lat/lon
422
-
423
- ```tsx
424
- import { MiMapView } from '@mappedin/react-native-sdk';
425
- import type {
426
- MapViewStore,
427
- } from '@mappedin/react-native-sdk';
428
-
429
- // Imperative API
430
- const mapView = React.useRef<MapViewStore>();
431
-
432
- const App = () => {
433
- return (
434
- <>
435
- <MiMapView
436
- style={{ flex: 1 }}
437
- ref={mapView}
438
- options={options}
439
- onFirstMapLoaded={() => {
440
- // create a coordinate
441
- const coordinate = mapView.current.venueData.maps[1].createCoordinate(43.52117572969203, -80.53869317220372);
442
-
443
- const coordinate2 = mapView.current.venueData.maps[1].createCoordinate(44.52117572969203, -79.53869317220372);
444
- // find distance between coordinates:
445
- console.log(coordinate.absoluteDistanceTo(coordinate2));
446
-
447
- // coordinates can also be used to place markers:
448
- mapView.current.createMarker(coordinate, ...)
449
- }}
450
- />
451
- )
452
- }
453
- ```
454
-
455
- ## Customizing appearance of labels
456
-
457
- Labels are added on map load by default, but this can be overriden by setting <a href="modules.html#tshowvenueoptions">labelAllLocationsOnInit</a> to false and taking control of labeling. We provide <a href="modules.html#labelthemes">2 themes</a>, and <a href="modules.html#tlabelappearance">full control</a> over further customization.
458
-
459
- ```tsx
460
- import { MiMapView, labelThemes } from '@mappedin/react-native-sdk';
461
- import type {
462
- MapViewStore,
463
- } from '@mappedin/react-native-sdk';
464
-
465
- // Imperative API
466
- const mapView = React.useRef<MapViewStore>();
467
-
468
- const App = () => {
469
- return (
470
- <>
471
- <MiMapView
472
- style={{ flex: 1 }}
473
- ref={mapView}
474
- options={{ ...options, labelAllLocationsOnInit: false }}
475
- onFirstMapLoaded={() => {
476
- // use one of the themes
477
- mapView.current.labelAllLocations({ appearance: labelThemes.lightOnDark })
478
- // OR, customize a set of properties
479
- mapView.current.labelAllLocations({ appearance: { text: { size: 12 }} })
480
- // OR, do both
481
- mapView.current.labelAllLocations({ appearance:
482
- {
483
- ...labelThemes.lightOnDark,
484
- margin: 20,
485
- text: {
486
- ...labelThemes.lightOnDark.text,
487
- size: 20
488
- }
489
- }
490
- })
491
- }}
492
- />
493
- )
494
- }
495
- ```
496
-
497
- ## Adding/Removing markers
498
-
499
- ```tsx
500
- import { MiMapView } from '@mappedin/react-native-sdk';
501
- import type {
502
- MapViewStore,
503
- } from '@mappedin/react-native-sdk';
504
-
505
- // Imperative API
506
- const mapView = React.useRef<MapViewStore>();
507
- const markerId = React.useRef(null);
508
-
509
- const App = () => {
510
- return (
511
- <>
512
- <MiMapView
513
- style={{ flex: 1 }}
514
- ref={mapView}
515
- options={options}
516
- onDataLoaded={() => {
517
- mapView.current.BlueDot.enable();
518
- }}
519
- onPolygonClicked={({ polygon }) => {
520
- if (markerId != null) {
521
- mapView.current.removeMarker(markerId);
522
- }
523
- // Let's add a marker anchored to the top of the first entrance to polygon
524
- markerId.current = mapView.current.createMarker(polygon.entrances[0], `
525
- <div style="width: 32px; height: 32px;">
526
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 293.334 293.334"><g fill="#010002"><path d="M146.667 0C94.903 0 52.946 41.957 52.946 93.721c0 22.322 7.849 42.789 20.891 58.878 4.204 5.178 11.237 13.331 14.903 18.906 21.109 32.069 48.19 78.643 56.082 116.864 1.354 6.527 2.986 6.641 4.743.212 5.629-20.609 20.228-65.639 50.377-112.757 3.595-5.619 10.884-13.483 15.409-18.379a94.561 94.561 0 0016.154-24.084c5.651-12.086 8.882-25.466 8.882-39.629C240.387 41.962 198.43 0 146.667 0zm0 144.358c-28.892 0-52.313-23.421-52.313-52.313 0-28.887 23.421-52.307 52.313-52.307s52.313 23.421 52.313 52.307c0 28.893-23.421 52.313-52.313 52.313z"/><circle cx="146.667" cy="90.196" r="21.756"/></g></svg>
527
- </div>
528
- `,
529
- {
530
- anchor: MARKER_ANCHOR.TOP,
531
- })
532
- }}
533
- />
534
- )
535
- }
536
- ```
537
116
 
538
117
  ## Get nearest node to point on screen
539
118
 
@@ -562,63 +141,6 @@ const App = () => {
562
141
  };
563
142
  ```
564
143
 
565
- ## Get Directions from BlueDot and show path and connections on map
566
-
567
- ```tsx
568
- import { MiMapView } from '@mappedin/react-native-sdk';
569
- import type {
570
- TBlueDotUpdate,
571
- MapViewStore,
572
- MappedinLocation,
573
- MappedinNode,
574
- } from '@mappedin/react-native-sdk';
575
-
576
- // Imperative API
577
- const mapView = React.useRef<MapViewStore>();
578
- const nearestNode = React.useRef<MappedinNode>();
579
- const [
580
- selectedLocation,
581
- setSelectedLocation,
582
- ] = React.useState<MappedinLocation>({});
583
-
584
- const App = () => {
585
- return (
586
- <>
587
- <MiMapView
588
- style={{ flex: 1 }}
589
- ref={mapView}
590
- options={options}
591
- onDataLoaded={() => {
592
- mapView.current.BlueDot.enable();
593
- }}
594
- onBlueDotStateChanged={({ stateChange }) => {
595
- nearestNode.current = stateChange.nearestNode;
596
- }}
597
- onPolygonClicked={({ polygon: MappedinPolygon }) => {
598
- setSelectedLocation(polygon.locations[0]);
599
- }}
600
- />
601
- <Button
602
- title="Get Directions"
603
- onPress={async () => {
604
- try {
605
- // get Directions
606
- const directions = nearestNode.current.directionsTo(selectedLocation);
607
- // draw path and connections on map
608
- await controller.current?.Journey.draw(directions);
609
- // focus on the path
610
- controller.current?.Camera.focusOn({
611
- nodes: directions.path
612
- });
613
- } catch (e) {
614
- console.error(e);
615
- }
616
- }}
617
- ></Button>
618
- </>
619
- );
620
- };
621
- ```
622
144
 
623
145
  ## Search and Suggestions
624
146
 
@@ -673,96 +195,6 @@ const App = () => {
673
195
  };
674
196
  ```
675
197
 
676
- ## Use `react-native-location` to power BlueDot
677
-
678
- ```tsx
679
- import RNLocation from 'react-native-location';
680
-
681
- const App = () => {
682
- ...
683
-
684
- RNLocation.requestPermission({
685
- ios: 'whenInUse',
686
- android: {
687
- detail: 'coarse',
688
- },
689
- }).then((granted) => {
690
- if (granted) {
691
- // Enable blue dot
692
- mapView.current.BlueDot.enable();
693
- RNLocation.subscribeToLocationUpdates((locations) => {
694
- const {
695
- accuracy,
696
- floor,
697
- latitude,
698
- longitude,
699
- timestamp,
700
- } = locations[0];
701
-
702
- const location = {
703
- timestamp,
704
- coords: {
705
- latitude,
706
- longitude,
707
- accuracy,
708
- floorLevel: floor,
709
- },
710
- };
711
- // pass locations in
712
- mapView.current.overrideLocation(location);
713
- });
714
- }
715
- });
716
-
717
- ...
718
- };
719
- ```
720
-
721
- ## MiniMap
722
-
723
- Component Signature:
724
-
725
- ```typescript
726
- const MiMiniMap = (props: TMiniMapProps) => React.ReactElement;
727
- ```
728
-
729
- ### Props:
730
-
731
- <a href="modules.html#tmiminimapprops">Documented in Detail here</a>
732
-
733
- | Prop | Description | Signature | Required |
734
- | --------------------- | ---------------------------------------------- | ------------------------------------------------------------------------ | -------- |
735
- | options | Options to initialize MapView with | <a href="modules.html#tmimapviewoptions">`TMiMapViewOptions`<a> | Yes |
736
- | location | Options to initialize MapView with | <a href="mclasses/mappedinlocation.html">`MappedinLocation \| string`<a> | Yes |
737
- | onLoad | Gets called when minimap is rendered | () => void | No |
738
- | polygonHighlightColor | Color to use when highlighting polygon | `string` | No |
739
- | focusOptions | Override focus Options when generating minimap | <a href="modules.html#tfocusoptions">`TFocusOptions`</a> | No |
740
-
741
- Example:
742
-
743
- ```tsx
744
- const App = () => {
745
- return (
746
- <MiMiniMap
747
- style={{ width: 500, height: 200 }}
748
- options={options: TGetVenueOptions}
749
- /**
750
- * Called when miniMap is rendered
751
- */
752
- onLoad={() => {}}
753
- /**
754
- * What color to use when highlighting polygon
755
- */
756
- polygonHighlightColor={string}
757
- /**
758
- * Finer control over focus
759
- */
760
- focusOptions={options: TFocusOptions}
761
- location={selectedLocation: MappedinLocation | MappedinLocation["id"]}
762
- />
763
- );
764
- };
765
- ```
766
198
 
767
199
  ### [experimental] Fetching an offline Venue bundle
768
200