Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve camera transitions and related map callbacks #1838

Merged
merged 43 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
273a2c2
Enable setting camera bounds (iOS)
naftalibeder Apr 11, 2022
8f51b00
Implement camera easing, organize dict value extraction (iOS)
naftalibeder Apr 12, 2022
782b342
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 12, 2022
3188450
Add remaining camera animation mode types (iOS)
naftalibeder Apr 12, 2022
015ed22
Clarify comment
naftalibeder Apr 12, 2022
f856b46
Add camera animation example
naftalibeder Apr 12, 2022
cccab0a
Adjust import order
naftalibeder Apr 12, 2022
fdabbac
Refactor to enable animating padding and simplify camera creation (iOS)
naftalibeder Apr 13, 2022
ce4c042
Add rand animated padding, fix rand coordinates
naftalibeder Apr 13, 2022
db5832f
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 15, 2022
dc81d44
Add padding options, improve display
naftalibeder Apr 15, 2022
724be19
Adjust padding
naftalibeder Apr 15, 2022
a647b71
Store camera animator reference to allow stopping existing animation
naftalibeder Apr 15, 2022
4670f4d
Move padding out of camera to prevent wonky movement
naftalibeder Apr 15, 2022
9a7ad42
Add missing text
naftalibeder Apr 15, 2022
984774e
Pair camera and padding easing, refactor and clarify easing modes
naftalibeder Apr 18, 2022
e925728
Make position and padding update together, start with instant transition
naftalibeder Apr 18, 2022
00c4107
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 18, 2022
3e857a4
Default to nil values for camera, use nil anchor instead of .zero
naftalibeder Apr 18, 2022
9f09cda
Set shorter duration
naftalibeder Apr 18, 2022
e6592a7
Simplify CameraUpdateItem interface, handle padding anim fix inside m…
naftalibeder Apr 18, 2022
6f0b594
Use low-level animator for padding only in fly(to:)
naftalibeder Apr 18, 2022
5836bd6
Add option to change only padding
naftalibeder Apr 18, 2022
058f440
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 19, 2022
b8193b7
Re-enable 'moveTo' animation mode for backward compatibility
naftalibeder Apr 19, 2022
c18bab9
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 20, 2022
206fd45
Improve returned map state object, reorganize classes and add extensi…
naftalibeder Apr 20, 2022
369d3c4
Point to new map state type
naftalibeder Apr 20, 2022
3f8b890
Declare v10-only map state type
naftalibeder Apr 20, 2022
7c95092
Use updated map state shape to display center and bounds
naftalibeder Apr 20, 2022
57d234b
Rename
naftalibeder Apr 20, 2022
af78115
Edit syntax
naftalibeder Apr 20, 2022
b03da22
Edit title
naftalibeder Apr 20, 2022
5eb3676
Fix callback types
naftalibeder Apr 20, 2022
38fc84a
Ensure all camera props are passed on any change
naftalibeder Apr 22, 2022
e00bb88
Allow setting bounds or center, add padding options
naftalibeder Apr 22, 2022
5d69cf7
Add turf/bbox
naftalibeder Apr 22, 2022
4392295
Refactor move method for clarity and to move bounds around more
naftalibeder Apr 22, 2022
33ee694
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 22, 2022
ecd04e1
Implement min and max zoom level handling, organize RN-derived props
naftalibeder Apr 22, 2022
acf6039
Add zoom level constraints
naftalibeder Apr 22, 2022
2167f09
Merge branch 'main' of github.com:rnmapbox/maps into feat/map
naftalibeder Apr 22, 2022
55c4af0
Fix camera tests
naftalibeder Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| ---- | :--: | :-----: | :------: | :----------: |
| allowUpdates | `bool` | `true` | `false` | If false, the camera will not send any props to the native module. Intended to be used to prevent unnecessary tile fetching and improve performance when the map is not visible. Defaults to true. |
| animationDuration | `number` | `2000` | `false` | The duration a camera update takes (in ms) |
| animationMode | `enum` | `'easeTo'` | `false` | The animationstyle when the camara updates. One of: `flyTo`, `easeTo`, `linearTo`, `moveTo` |
| animationMode | `enum` | `'easeTo'` | `false` | The animation style when the camara updates. One of:<br/>`flyTo`: A complex flight animation, affecting both position and zoom.<br/>`easeTo`: A standard damped curve.<br/>`linearTo`: An even linear transition.<br/>`none`: An instantaneous change (v10 only).<br/>`moveTo`: An instantaneous change (<v10). |
| defaultSettings | `shape` | `none` | `false` | Default view settings applied on camera |
| &nbsp;&nbsp;centerCoordinate | `array` | `none` | `false` | Center coordinate on map [lng, lat] |
| &nbsp;&nbsp;padding | `shape` | `none` | `false` | Padding around edges of map in points |
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
"required": false,
"type": "enum",
"default": "'easeTo'",
"description": "The animationstyle when the camara updates. One of: `flyTo`, `easeTo`, `linearTo`, `moveTo`"
"description": "The animation style when the camara updates. One of:\n`flyTo`: A complex flight animation, affecting both position and zoom.\n`easeTo`: A standard damped curve.\n`linearTo`: An even linear transition.\n`none`: An instantaneous change (v10 only).\n`moveTo`: An instantaneous change (<v10)."
},
{
"name": "defaultSettings",
Expand Down
89 changes: 75 additions & 14 deletions example/src/examples/V10/CameraAnimation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState} from 'react';
import {Button, SafeAreaView, StyleSheet} from 'react-native';
import React, {useMemo, useState} from 'react';
import {Button, SafeAreaView, Text, View} from 'react-native';
import {
MapView,
Camera,
Expand All @@ -21,30 +21,68 @@ const styles = {
circleRadius: 6,
circleColor: colors.primary.blue,
},
sheet: {
paddingTop: 10,
paddingHorizontal: 10,
},
section: {
paddingVertical: 10,
},
buttonRow: {
flex: 0,
flexDirection: 'row',
justifyContent: 'space-between',
justifyContent: 'space-around',
},
};

const zeroPadding = {
paddingTop: 0,
paddingBottom: 0,
paddingLeft: 0,
paddingRight: 0,
};

const randPadding = () => {
const randNum = () => {
const items = [0, 150, 300];
return items[Math.floor(Math.random() * items.length)];
};

return {
paddingTop: randNum(),
paddingBottom: randNum(),
paddingLeft: randNum(),
paddingRight: randNum(),
};
};

const CameraAnimation = props => {
const initialCoordinates = {
latitude: 40.759211,
longitude: -73.984638,
};

const [animationMode, setAnimationMode] = useState('flyTo');
const [animationMode, setAnimationMode] = useState('moveTo');
const [coordinates, setCoordinates] = useState(initialCoordinates);
const [padding, setPadding] = useState(zeroPadding);

const onPress = _animationMode => {
setAnimationMode(_animationMode);
const coordinatesDisplay = useMemo(() => {
const lon = coordinates.longitude.toFixed(4);
const lat = coordinates.latitude.toFixed(4);
return `Lon ${lon} | Lat ${lat}`;
}, [coordinates]);

const paddingDisplay = useMemo(() => {
return `L ${padding.paddingLeft} | R ${padding.paddingRight} | T ${padding.paddingTop} | B ${padding.paddingBottom}`;
}, [padding]);

const offset = Math.random() * 0.2;
const changePosition = _animationMode => {
setAnimationMode(_animationMode);
setCoordinates({
latitude: initialCoordinates.latitude + offset,
longitude: initialCoordinates.longitude + offset,
latitude: initialCoordinates.latitude + Math.random() * 0.2,
longitude: initialCoordinates.longitude + Math.random() * 0.2,
});
setPadding(randPadding());
};

const position = [coordinates.longitude, coordinates.latitude];
Expand All @@ -64,18 +102,41 @@ const CameraAnimation = props => {
centerCoordinate={position}
animationMode={animationMode}
zoomLevel={12}
padding={padding}
animationDuration={800}
/>

<ShapeSource id="source" shape={shape}>
<CircleLayer id="layer" style={styles.circle} />
</ShapeSource>
</MapView>

<SafeAreaView style={styles.buttonRow}>
<Button title="Flight" onPress={() => onPress('flyTo')} />
<Button title="Move" onPress={() => onPress('moveTo')} />
<Button title="Ease" onPress={() => onPress('easeTo')} />
<Button title="Linear" onPress={() => onPress('linearTo')} />
<SafeAreaView>
<View style={styles.sheet}>
<View style={styles.section}>
<View style={styles.buttonRow}>
<Button title="Flight" onPress={() => changePosition('flyTo')} />
<Button title="Ease" onPress={() => changePosition('easeTo')} />
<Button
title="Linear"
onPress={() => changePosition('linearTo')}
/>
<Button
title="Instant"
onPress={() => changePosition('moveTo')}
/>
<Button
title="Padding"
onPress={() => {
setAnimationMode('easeTo');
setPadding(randPadding());
}}
/>
</View>
<Text>Position ({coordinatesDisplay})</Text>
<Text>Padding ({paddingDisplay})</Text>
</View>
</View>
</SafeAreaView>
</Page>
);
Expand Down
5 changes: 3 additions & 2 deletions ios/RCTMGL-v10/MGLModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class MGLModule : NSObject {
"CameraModes":
[
"Flight": "flight",
"None": "none",
"Linear": "linear",
"Ease": "ease",
"Linear": "linear",
"None": "none",
"Move": "move", // Allows backward compatibility with <v10.
],
"EventTypes":
[
Expand Down
Loading