Skip to content

Commit 233add3

Browse files
authored
#236 iOS Snapshotter as __block variable (#369)
* FIX-236 iOS snapshot manager by setting snapshotter to __block variable * FIX-236 Also deallocate from error block * Allow toggling of snapshot logo for Android * Allow disable logo for Android snapshot manager * Update tests * Update documentation and add info to CONTRIBUTING.md about documentation generator
1 parent 97816be commit 233add3

File tree

16 files changed

+152
-65
lines changed

16 files changed

+152
-65
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ commit the changes and push them to a fork for creating a pull request.
1717

1818
1. If you add a feature, make sure you add it to the documentation
1919
1. If you add an objective-c or java method, make sure you update the declaration file: `index.d.ts`.
20+
21+
22+
## Documentation
23+
24+
1. Documentation is auto-generated from code blocks and comments. To generate documentation:
25+
1. `npm install -g documentation` to install documentation generator
26+
1. `npm run generate` to generate updated documentation

__tests__/modules/snapshot/SnapshotOptions.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('SnapshotOptions', () => {
2525
height: 50.0,
2626
writeToDisk: false,
2727
centerCoordinate: JSON.stringify(makePoint(centerCoordinate)),
28+
withLogo: true,
2829
});
2930
});
3031

@@ -37,6 +38,7 @@ describe('SnapshotOptions', () => {
3738
width: 314,
3839
height: 600,
3940
writeToDisk: true,
41+
withLogo: true,
4042
styleURL: NativeModules.MGLModule.StyleURL.Dark,
4143
};
4244

@@ -56,6 +58,7 @@ describe('SnapshotOptions', () => {
5658
height: 600,
5759
styleURL: NativeModules.MGLModule.StyleURL.Light,
5860
writeToDisk: false,
61+
withLogo: true,
5962
};
6063

6164
const geoJSONBounds = JSON.stringify(

android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private MapSnapshotter.Options getOptions(ReadableMap jsOptions) {
105105
(int) jsOptions.getDouble("width"),
106106
(int) jsOptions.getDouble("height"));
107107

108+
options.withLogo(jsOptions.getBoolean("withLogo"));
108109
options.withStyle(jsOptions.getString("styleURL"));
109110
options.withPixelRatio(Float.valueOf(mContext.getResources().getDisplayMetrics().scaledDensity).intValue());
110111

docs/Annotation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
| animationEasingFunction | `func` | `Easing.linear` | `false` | FIX ME NO DESCRIPTION |
1111
| coordinates | `array` | `none` | `false` | FIX ME NO DESCRIPTION |
1212
| onPress | `func` | `none` | `false` | FIX ME NO DESCRIPTION |
13+
| children | `any` | `none` | `false` | FIX ME NO DESCRIPTION |
14+
| style | `any` | `none` | `false` | FIX ME NO DESCRIPTION |
1315
| icon | `union` | `none` | `false` | FIX ME NO DESCRIPTION |
1416

1517
### methods

docs/Camera.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
| followHeading | `number` | `none` | `false` | FIX ME NO DESCRIPTION |
3939
| triggerKey | `any` | `none` | `false` | FIX ME NO DESCRIPTION |
4040
| alignment | `array` | `none` | `false` | FIX ME NO DESCRIPTION |
41+
| onUserTrackingModeChange | `func` | `none` | `false` | FIX ME NO DESCRIPTION |
4142
| isUserInteraction | `FIX ME UNKNOWN TYPE` | `false` | `false` | FIX ME NO DESCRIPTION |
4243

4344
### methods

docs/MapView.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| contentInset | `union` | `none` | `false` | The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport. |
88
| style | `any` | `none` | `false` | Style for wrapping React Native View |
99
| styleURL | `string` | `MapboxGL.StyleURL.Street` | `false` | Style URL for map |
10+
| preferredFramesPerSecond | `number` | `none` | `false` | iOS: The preferred frame rate at which the map view is rendered.<br/>The default value for this property is MGLMapViewPreferredFramesPerSecondDefault,<br/>which will adaptively set the preferred frame rate based on the capability of<br/>the user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.<br/><br/>Android: The maximum frame rate at which the map view is rendered, but it can't excess the ability of device hardware.<br/>This property can be set to arbitrary integer values. |
1011
| localizeLabels | `bool` | `false` | `false` | Automatically change the language of the map labels to the system’s preferred language,<br/>this is not something that can be toggled on/off |
1112
| zoomEnabled | `bool` | `none` | `false` | Enable/Disable zoom on the map |
1213
| scrollEnabled | `bool` | `true` | `false` | Enable/Disable scroll on the map |
@@ -30,6 +31,7 @@
3031
| onWillStartRenderingMap | `func` | `none` | `false` | This event is triggered when the map will start rendering the map. |
3132
| onDidFinishRenderingMap | `func` | `none` | `false` | This event is triggered when the map finished rendering the map. |
3233
| onDidFinishRenderingMapFully | `func` | `none` | `false` | This event is triggered when the map fully finished rendering the map. |
34+
| onUserLocationUpdate | `func` | `none` | `false` | This event is triggered when the user location is updated. |
3335
| onDidFinishLoadingStyle | `func` | `none` | `false` | This event is triggered when a style has finished loading. |
3436
| regionWillChangeDebounceTime | `number` | `10` | `false` | The emitted frequency of regionwillchange events |
3537
| regionDidChangeDebounceTime | `number` | `500` | `false` | The emitted frequency of regiondidchange events |
@@ -119,14 +121,14 @@ this._map.queryRenderedFeaturesInRect([30, 40, 20, 10], ['==', 'type', 'Point'],
119121
```
120122

121123

122-
#### setCamera(config)
124+
#### setCamera()
123125

124126
Map camera will perform updates based on provided config. Deprecated use Camera#setCamera.
125127

126128
##### arguments
127129
| Name | Type | Required | Description |
128130
| ---- | :--: | :------: | :----------: |
129-
| `config` | `n/a` | `Yes` | undefined |
131+
130132

131133

132134
#### takeSnap(writeToDisk)

docs/PointAnnotation.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
_**deprecated and buggy, use [SymbolLayer](https://github.com/react-native-mapbox-gl/maps/blob/master/docs/SymbolLayer.md) instead**_
2-
31
## <MapboxGL.PointAnnotation />
42
### PointAnnotation represents a one-dimensional shape located at a single geographical coordinate. PointAnnotation is legacy, soon to be deprecated, and should use ShapeSource and SymbolLayer instead.
53

docs/VectorSource.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,22 @@
1111
| &nbsp;&nbsp;width | `number` | `none` | `true` | FIX ME NO DESCRIPTION |
1212
| &nbsp;&nbsp;height | `number` | `none` | `true` | FIX ME NO DESCRIPTION |
1313

14+
### methods
15+
#### features([layerIDs][, filter])
16+
17+
Returns all features that match the query parameters regardless of whether or not the feature is<br/>currently rendered on the map. The domain of the query includes all currently-loaded vector tiles<br/>and GeoJSON source tiles. This function does not check tiles outside of the visible viewport.
18+
19+
##### arguments
20+
| Name | Type | Required | Description |
21+
| ---- | :--: | :------: | :----------: |
22+
| `layerIDs` | `Array` | `No` | A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array. |
23+
| `filter` | `Array` | `No` | an optional filter statement to filter the returned Features. |
24+
25+
26+
27+
```javascript
28+
vectorSource.features(['id1', 'id2'])
29+
```
30+
31+
1432

docs/docs.json

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,13 @@
684684
"default": "none",
685685
"description": "FIX ME NO DESCRIPTION"
686686
},
687+
{
688+
"name": "onUserTrackingModeChange",
689+
"required": false,
690+
"type": "func",
691+
"default": "none",
692+
"description": "FIX ME NO DESCRIPTION"
693+
},
687694
{
688695
"name": "isUserInteraction",
689696
"required": false,
@@ -2488,11 +2495,7 @@
24882495
"name": "setCamera",
24892496
"docblock": "Map camera will perform updates based on provided config. Deprecated use Camera#setCamera.",
24902497
"modifiers": [],
2491-
"params": [
2492-
{
2493-
"name": "config"
2494-
}
2495-
],
2498+
"params": [],
24962499
"returns": null,
24972500
"description": "Map camera will perform updates based on provided config. Deprecated use Camera#setCamera.",
24982501
"examples": []
@@ -2574,27 +2577,6 @@
25742577
}
25752578
],
25762579
"props": [
2577-
{
2578-
"name": "showUserLocation",
2579-
"required": false,
2580-
"type": "bool",
2581-
"default": "none",
2582-
"description": "Shows the users location on the map"
2583-
},
2584-
{
2585-
"name": "userTrackingMode",
2586-
"required": false,
2587-
"type": "number",
2588-
"default": "none",
2589-
"description": "The mode used to track the user location on the map"
2590-
},
2591-
{
2592-
"name": "userLocationVerticalAlignment",
2593-
"required": false,
2594-
"type": "number",
2595-
"default": "none",
2596-
"description": "The vertical alignment of the user location within in map. This is only enabled while tracking the users location."
2597-
},
25982580
{
25992581
"name": "contentInset",
26002582
"required": false,
@@ -2616,6 +2598,13 @@
26162598
"default": "MapboxGL.StyleURL.Street",
26172599
"description": "Style URL for map"
26182600
},
2601+
{
2602+
"name": "preferredFramesPerSecond",
2603+
"required": false,
2604+
"type": "number",
2605+
"default": "none",
2606+
"description": "iOS: The preferred frame rate at which the map view is rendered.\nThe default value for this property is MGLMapViewPreferredFramesPerSecondDefault,\nwhich will adaptively set the preferred frame rate based on the capability of\nthe user’s device to maintain a smooth experience. This property can be set to arbitrary integer values.\n\nAndroid: The maximum frame rate at which the map view is rendered, but it can't excess the ability of device hardware.\nThis property can be set to arbitrary integer values."
2607+
},
26192608
{
26202609
"name": "localizeLabels",
26212610
"required": false,
@@ -2807,6 +2796,13 @@
28072796
"default": "none",
28082797
"description": "This event is triggered when the map fully finished rendering the map."
28092798
},
2799+
{
2800+
"name": "onUserLocationUpdate",
2801+
"required": false,
2802+
"type": "func",
2803+
"default": "none",
2804+
"description": "This event is triggered when the user location is updated."
2805+
},
28102806
{
28112807
"name": "onDidFinishLoadingStyle",
28122808
"required": false,
@@ -4705,7 +4701,9 @@
47054701
{
47064702
"name": "setLocationManager",
47074703
"docblock": null,
4708-
"modifiers": [],
4704+
"modifiers": [
4705+
"async"
4706+
],
47094707
"params": [
47104708
{
47114709
"name": "{running}",
@@ -4780,7 +4778,43 @@
47804778
"VectorSource": {
47814779
"description": "VectorSource is a map content source that supplies tiled vector data in Mapbox Vector Tile format to be shown on the map.\nThe location of and metadata about the tiles are defined either by an option dictionary or by an external file that conforms to the TileJSON specification.",
47824780
"displayName": "VectorSource",
4783-
"methods": [],
4781+
"methods": [
4782+
{
4783+
"name": "features",
4784+
"docblock": "Returns all features that match the query parameters regardless of whether or not the feature is\ncurrently rendered on the map. The domain of the query includes all currently-loaded vector tiles\nand GeoJSON source tiles. This function does not check tiles outside of the visible viewport.\n\n@example\nvectorSource.features(['id1', 'id2'])\n\n@param {Array=} layerIDs - A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.\n@param {Array=} filter - an optional filter statement to filter the returned Features.\n@return {FeatureCollection}",
4785+
"modifiers": [
4786+
"async"
4787+
],
4788+
"params": [
4789+
{
4790+
"name": "layerIDs",
4791+
"description": "A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.",
4792+
"type": {
4793+
"name": "Array"
4794+
},
4795+
"optional": true
4796+
},
4797+
{
4798+
"name": "filter",
4799+
"description": "an optional filter statement to filter the returned Features.",
4800+
"type": {
4801+
"name": "Array"
4802+
},
4803+
"optional": true
4804+
}
4805+
],
4806+
"returns": {
4807+
"description": null,
4808+
"type": {
4809+
"name": "FeatureCollection"
4810+
}
4811+
},
4812+
"description": "Returns all features that match the query parameters regardless of whether or not the feature is\ncurrently rendered on the map. The domain of the query includes all currently-loaded vector tiles\nand GeoJSON source tiles. This function does not check tiles outside of the visible viewport.",
4813+
"examples": [
4814+
"\nvectorSource.features(['id1', 'id2'])\n\n"
4815+
]
4816+
}
4817+
],
47844818
"props": [
47854819
{
47864820
"name": "id",
@@ -4903,6 +4937,20 @@
49034937
"default": "none",
49044938
"description": "FIX ME NO DESCRIPTION"
49054939
},
4940+
{
4941+
"name": "children",
4942+
"required": false,
4943+
"type": "any",
4944+
"default": "none",
4945+
"description": "FIX ME NO DESCRIPTION"
4946+
},
4947+
{
4948+
"name": "style",
4949+
"required": false,
4950+
"type": "any",
4951+
"default": "none",
4952+
"description": "FIX ME NO DESCRIPTION"
4953+
},
49064954
{
49074955
"name": "icon",
49084956
"required": false,
@@ -5148,7 +5196,7 @@
51485196
}
51495197
],
51505198
"examples": [
5151-
"// creates a temp file png of base map\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n centerCoordinate: [-74.126410, 40.797968],\n width: width,\n height: height,\n zoomLevel: 12,\n pitch: 30,\n heading: 20,\n styleURL: MapboxGL.StyleURL.Dark,\n writeToDisk: true, // creates a temp file\n});\n\n// creates base64 png of base map\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n centerCoordinate: [-74.126410, 40.797968],\n width: width,\n height: height,\n zoomLevel: 12,\n pitch: 30,\n heading: 20,\n styleURL: MapboxGL.StyleURL.Dark,\n});\n\n// creates snapshot with bounds\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n bounds: [[-74.126410, 40.797968], [-74.143727, 40.772177]],\n width: width,\n height: height,\n styleURL: MapboxGL.StyleURL.Dark,\n});"
5199+
"// creates a temp file png of base map\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n centerCoordinate: [-74.126410, 40.797968],\n width: width,\n height: height,\n zoomLevel: 12,\n pitch: 30,\n heading: 20,\n styleURL: MapboxGL.StyleURL.Dark,\n writeToDisk: true, // Create a temporary file\n});\n\n// creates base64 png of base map without logo\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n centerCoordinate: [-74.126410, 40.797968],\n width: width,\n height: height,\n zoomLevel: 12,\n pitch: 30,\n heading: 20,\n styleURL: MapboxGL.StyleURL.Dark,\n withLogo: false, // Disable Mapbox logo (Android only)\n});\n\n// creates snapshot with bounds\nconst uri = await MapboxGL.snapshotManager.takeSnap({\n bounds: [[-74.126410, 40.797968], [-74.143727, 40.772177]],\n width: width,\n height: height,\n styleURL: MapboxGL.StyleURL.Dark,\n});"
51525200
],
51535201
"returns": {
51545202
"description": "",

docs/snapshotManager.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const uri = await MapboxGL.snapshotManager.takeSnap({
2424
pitch: 30,
2525
heading: 20,
2626
styleURL: MapboxGL.StyleURL.Dark,
27-
writeToDisk: true, // creates a temp file
27+
writeToDisk: true, // Create a temporary file
2828
});
2929

30-
// creates base64 png of base map
30+
// creates base64 png of base map without logo
3131
const uri = await MapboxGL.snapshotManager.takeSnap({
3232
centerCoordinate: [-74.126410, 40.797968],
3333
width: width,
@@ -36,6 +36,7 @@ const uri = await MapboxGL.snapshotManager.takeSnap({
3636
pitch: 30,
3737
heading: 20,
3838
styleURL: MapboxGL.StyleURL.Dark,
39+
withLogo: false, // Disable Mapbox logo (Android only)
3940
});
4041

4142
// creates snapshot with bounds

0 commit comments

Comments
 (0)