Skip to content

Commit

Permalink
feat: rename tilt to pinch (josxha#45)
Browse files Browse the repository at this point in the history
- [X] rename all tilt references to pinch
- [X] update CHANGELOG.md
- [X] update comments for tilt / pinch

Closes a task of josxha#22

---------

Co-authored-by: Joscha <[email protected]>
  • Loading branch information
gabbopalma and josxha authored Sep 24, 2024
1 parent de370a8 commit 6fcc076
Show file tree
Hide file tree
Showing 27 changed files with 389 additions and 268 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
- Bump MapLibre Native on Android to version 11.5.0.
- Add and remove sources to the active map style programmatically.
- Add and remove layers to the active map style programmatically.
- Add `minZoom`, `maxZoom`, `minTilt`, `maxTilt` and `maxBounds` parameter.
- Add `duration` parameter to `flyTo()`.
- Add `minZoom`, `maxZoom`, `minPitch`, `maxPitch` and `maxBounds` parameter.
- Add duration parameters to `flyTo()`.
- `flyTo()` returns after the animation completes or throws an exception if it
has been cancelled.
- Deprecate `tilt` parameters in favor of `pitch`.
- Deprecate `onClick`, `onDoubleClick`, `onSecondaryClick` and `onLongClick` in
favor of the event system.

### Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ functionality.
<img src="https://raw.githubusercontent.com/josxha/flutter-maplibre/d8e2c7daf15221f716a2ebbd63e57a317cb089ab/docs/static/img/showcase-map.jpg" alt="Custom styled map" />
</td>
<td style="text-align: center;">
<strong>Tilt or rotate the map</strong>
<strong>Pitch or rotate the map</strong>
<img src="https://raw.githubusercontent.com/josxha/flutter-maplibre/d8e2c7daf15221f716a2ebbd63e57a317cb089ab/docs/static/img/showcase-tilt.jpg" alt="Tilted and rotated map" />
</td>
<td style="text-align: center;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MapLibreMapController(
val cameraBuilder = CameraPosition.Builder()
.zoom(mapOptions.zoom)
.bearing(mapOptions.bearing)
.tilt(mapOptions.tilt)
.tilt(mapOptions.pitch)
if (mapOptions.center != null)
cameraBuilder.target(
LatLng(
Expand All @@ -95,8 +95,8 @@ class MapLibreMapController(
.compassEnabled(true)
.minZoomPreference(mapOptions.minZoom)
.maxZoomPreference(mapOptions.maxZoom)
.minPitchPreference(mapOptions.minTilt)
.maxPitchPreference(mapOptions.maxTilt)
.minPitchPreference(mapOptions.minPitch)
.maxPitchPreference(mapOptions.maxPitch)
.camera(cameraBuilder.build())

MapLibre.getInstance(context) // needs to be called before MapView gets created
Expand Down Expand Up @@ -563,10 +563,10 @@ class MapLibreMapController(
mapLibreMap.setMinZoomPreference(options.minZoom)
if (mapOptions.maxZoom != options.maxZoom)
mapLibreMap.setMaxZoomPreference(options.maxZoom)
if (mapOptions.minTilt != options.minTilt)
mapLibreMap.setMinPitchPreference(options.minTilt)
if (mapOptions.maxTilt != options.maxTilt)
mapLibreMap.setMaxPitchPreference(options.maxTilt)
if (mapOptions.minPitch != options.minPitch)
mapLibreMap.setMinPitchPreference(options.minPitch)
if (mapOptions.maxPitch != options.maxPitch)
mapLibreMap.setMaxPitchPreference(options.maxPitch)

// map bounds
val oldBounds = mapOptions.maxBounds
Expand Down
32 changes: 16 additions & 16 deletions android/src/main/kotlin/com/github/josxha/maplibre/Pigeon.g.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ data class MapOptions (
val style: String,
/** The initial zoom level of the map. */
val zoom: Double,
/** The initial tilt of the map. */
val tilt: Double,
/** The initial pitch / tilt of the map. */
val pitch: Double,
/** The initial bearing of the map. */
val bearing: Double,
/** The initial center coordinates of the map. */
Expand All @@ -118,9 +118,9 @@ data class MapOptions (
/** The maximum zoom level of the map. */
val maxZoom: Double,
/** The minimum pitch / tilt of the map. */
val minTilt: Double,
val minPitch: Double,
/** The maximum pitch / tilt of the map. */
val maxTilt: Double,
val maxPitch: Double,
/** If the native map should listen to click events. */
val listensOnClick: Boolean,
/** If the native map should listen to long click events. */
Expand All @@ -133,32 +133,32 @@ data class MapOptions (
fun fromList(pigeonVar_list: List<Any?>): MapOptions {
val style = pigeonVar_list[0] as String
val zoom = pigeonVar_list[1] as Double
val tilt = pigeonVar_list[2] as Double
val pitch = pigeonVar_list[2] as Double
val bearing = pigeonVar_list[3] as Double
val center = pigeonVar_list[4] as LngLat?
val maxBounds = pigeonVar_list[5] as LngLatBounds?
val minZoom = pigeonVar_list[6] as Double
val maxZoom = pigeonVar_list[7] as Double
val minTilt = pigeonVar_list[8] as Double
val maxTilt = pigeonVar_list[9] as Double
val minPitch = pigeonVar_list[8] as Double
val maxPitch = pigeonVar_list[9] as Double
val listensOnClick = pigeonVar_list[10] as Boolean
val listensOnLongClick = pigeonVar_list[11] as Boolean
val gestures = pigeonVar_list[12] as MapGestures
return MapOptions(style, zoom, tilt, bearing, center, maxBounds, minZoom, maxZoom, minTilt, maxTilt, listensOnClick, listensOnLongClick, gestures)
return MapOptions(style, zoom, pitch, bearing, center, maxBounds, minZoom, maxZoom, minPitch, maxPitch, listensOnClick, listensOnLongClick, gestures)
}
}
fun toList(): List<Any?> {
return listOf(
style,
zoom,
tilt,
pitch,
bearing,
center,
maxBounds,
minZoom,
maxZoom,
minTilt,
maxTilt,
minPitch,
maxPitch,
listensOnClick,
listensOnLongClick,
gestures,
Expand Down Expand Up @@ -263,24 +263,24 @@ data class ScreenLocation (
data class MapCamera (
val center: LngLat,
val zoom: Double,
val tilt: Double,
val pitch: Double,
val bearing: Double
)
{
companion object {
fun fromList(pigeonVar_list: List<Any?>): MapCamera {
val center = pigeonVar_list[0] as LngLat
val zoom = pigeonVar_list[1] as Double
val tilt = pigeonVar_list[2] as Double
val pitch = pigeonVar_list[2] as Double
val bearing = pigeonVar_list[3] as Double
return MapCamera(center, zoom, tilt, bearing)
return MapCamera(center, zoom, pitch, bearing)
}
}
fun toList(): List<Any?> {
return listOf(
center,
zoom,
tilt,
pitch,
bearing,
)
}
Expand Down Expand Up @@ -419,7 +419,7 @@ interface MapLibreHostApi {
fun flyTo(center: LngLat?, zoom: Double?, bearing: Double?, pitch: Double?, durationMs: Long, callback: (Result<Unit>) -> Unit)
/**
* Get the current camera position with the map center, zoom level, camera
* tilt and map rotation.
* pitch and map rotation.
*/
fun getCamera(callback: (Result<MapCamera>) -> Unit)
/** Get the visible region of the current map camera. */
Expand Down
24 changes: 17 additions & 7 deletions example/integration_test/smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ void main() {
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
await ctrl.jumpTo(center: Position(1, 1), bearing: 1, zoom: 1, tilt: 1);
await ctrl.jumpTo(
center: Position(1, 1),
bearing: 1,
zoom: 1,
pitch: 1,
);
await tester.pumpAndSettle();
final camera = await ctrl.getCamera();
expect(camera.center.lng, closeTo(1, 0.00001));
expect(camera.center.lat, closeTo(1, 0.00001));
expect(camera.zoom, closeTo(1, 0.00001));
expect(camera.bearing, closeTo(1, 0.00001));
expect(camera.tilt, closeTo(1, 0.00001));
expect(camera.pitch, closeTo(1, 0.00001));
},
);
testWidgets(
Expand All @@ -43,14 +48,19 @@ void main() {
final app = App(onMapCreated: (controller) => ctrl = controller);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
await ctrl.jumpTo(center: Position(1, 2), bearing: 1, zoom: 1, tilt: 1);
await ctrl.jumpTo(
center: Position(1, 2),
bearing: 1,
zoom: 1,
pitch: 1,
);
await tester.pumpAndSettle();
final camera = await ctrl.getCamera();
expect(camera.center.lng, closeTo(1, 0.00001));
expect(camera.center.lat, closeTo(2, 0.00001));
expect(camera.zoom, closeTo(1, 0.00001));
expect(camera.bearing, closeTo(1, 0.00001));
expect(camera.tilt, closeTo(1, 0.00001));
expect(camera.pitch, closeTo(1, 0.00001));
},
);
testWidgets(
Expand All @@ -64,7 +74,7 @@ void main() {
center: Position(2, 1),
bearing: 2,
zoom: 2,
tilt: 2,
pitch: 2,
webSpeed: 100,
nativeDuration: Duration.zero,
);
Expand All @@ -74,7 +84,7 @@ void main() {
expect(camera.center.lat, closeTo(1, 0.00001));
expect(camera.zoom, closeTo(2, 0.00001));
expect(camera.bearing, closeTo(2, 0.00001));
expect(camera.tilt, closeTo(2, 0.00001));
expect(camera.pitch, closeTo(2, 0.00001));
},
);
/*testWidgets(
Expand All @@ -88,7 +98,7 @@ void main() {
center: Position(2, 2),
bearing: 2,
zoom: 2,
tilt: 2,
pitch: 2,
webSpeed: 0.1,
nativeDuration: const Duration(days: 1),
);
Expand Down
44 changes: 44 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
6 changes: 3 additions & 3 deletions example/lib/controller_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _ControllerPageState extends State<ControllerPage> {
await _controller.jumpTo(
center: Position(172.4714, -42.4862),
zoom: 4,
tilt: 0,
pitch: 0,
bearing: 0,
);
debugPrint('jumpTo end');
Expand All @@ -48,7 +48,7 @@ class _ControllerPageState extends State<ControllerPage> {
center: Position(-18.6874, 64.9445),
zoom: 5,
bearing: -50,
tilt: 60,
pitch: 60,
);
debugPrint('flyTo end');
} catch (error) {
Expand All @@ -75,7 +75,7 @@ center.lng: ${camera.center.lng}
center.lat: ${camera.center.lat}
zoom: ${camera.zoom}
bearing: ${camera.bearing}
tilt: ${camera.tilt}'''),
pitch: ${camera.pitch}'''),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/events_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _EventsPageState extends State<EventsPage> {
MapEventMoveCamera() => _print(
'move camera: center ${_formatPosition(event.camera.center)}, '
'zoom ${event.camera.zoom.toStringAsFixed(2)}, '
'tilt ${event.camera.tilt.toStringAsFixed(2)}, '
'pitch ${event.camera.pitch.toStringAsFixed(2)}, '
'bearing ${event.camera.bearing.toStringAsFixed(2)}',
),
MapEventStartMoveCamera() =>
Expand Down
6 changes: 3 additions & 3 deletions example/lib/kiosk_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _KioskPageState extends State<KioskPage> {
center: location.center,
zoom: location.zoom,
bearing: location.bearing,
tilt: location.tilt,
pitch: location.pitch,
);
index++;
if (index >= _locations.length) index = 0;
Expand All @@ -65,10 +65,10 @@ class _KioskPageState extends State<KioskPage> {
}

class _Location {
const _Location(this.center, this.zoom, this.bearing, this.tilt);
const _Location(this.center, this.zoom, this.bearing, this.pitch);

final Position center;
final double zoom;
final double bearing;
final double tilt;
final double pitch;
}
2 changes: 1 addition & 1 deletion example/lib/layers_fill_extrusion_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _LayersFillExtrusionPageState extends State<LayersFillExtrusionPage> {
options: MapOptions(
center: Position(-87.61694, 41.86625),
zoom: 15.99,
tilt: 40,
pitch: 40,
bearing: 20,
style: StyledMapPage.styleUrl,
),
Expand Down
18 changes: 9 additions & 9 deletions example/lib/parameters_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ParametersPage extends StatefulWidget {
class _ParametersPageState extends State<ParametersPage> {
double _minZoom = 0;
double _maxZoom = 22;
double _minTilt = 0;
double _maxTilt = 60;
double _minPitch = 0;
double _maxPitch = 60;
LngLatBounds _lngLatBounds = const LngLatBounds(
longitudeWest: -180,
longitudeEast: 179,
Expand Down Expand Up @@ -44,13 +44,13 @@ class _ParametersPageState extends State<ParametersPage> {
}),
),
_SliderWidget(
label: 'Tilt',
start: _minTilt,
end: _maxTilt,
label: 'Pitch',
start: _minPitch,
end: _maxPitch,
max: 85,
onChanged: (range) => setState(() {
_minTilt = range.start;
_maxTilt = range.end;
_minPitch = range.start;
_maxPitch = range.end;
}),
),
_SliderWidget(
Expand Down Expand Up @@ -89,8 +89,8 @@ class _ParametersPageState extends State<ParametersPage> {
zoom: 3,
minZoom: _minZoom,
maxZoom: _maxZoom,
minTilt: _minTilt,
maxTilt: _maxTilt,
minPitch: _minPitch,
maxPitch: _maxPitch,
maxBounds: _lngLatBounds,
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/two_maps_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class _ButtonsWidget extends StatelessWidget {
center: Position(-18.6874, 64.9445),
zoom: 5,
bearing: -50,
tilt: 60,
pitch: 60,
);
},
child: const Text('Animate to Iceland'),
Expand Down
Loading

0 comments on commit 6fcc076

Please sign in to comment.