diff --git a/mapbox_maps_flutter_interface/lib/mapbox_maps_flutter_interface.dart b/mapbox_maps_flutter_interface/lib/mapbox_maps_flutter_interface.dart index cfcbba884..00dda3617 100644 --- a/mapbox_maps_flutter_interface/lib/mapbox_maps_flutter_interface.dart +++ b/mapbox_maps_flutter_interface/lib/mapbox_maps_flutter_interface.dart @@ -1,6 +1,13 @@ -library; +library mapbox_maps_flutter_interface; -import 'package:flutter/cupertino.dart'; +export 'src/mapbox_maps_flutter_platform_interface.dart'; +export 'src/map_interface.dart'; +export 'src/callbacks.dart'; +export 'package:turf/helpers.dart'; -part 'src/mapbox_maps_flutter_platform_interface.dart'; -part 'src/callbacks.dart'; +import 'dart:convert'; + +import 'package:turf/turf.dart' as turf; + +part 'src/pigeons/platform_interface_data_types.dart'; +part 'src/turf_adapter.dart'; diff --git a/mapbox_maps_flutter_interface/lib/src/callbacks.dart b/mapbox_maps_flutter_interface/lib/src/callbacks.dart index 815e6a300..988d70abc 100644 --- a/mapbox_maps_flutter_interface/lib/src/callbacks.dart +++ b/mapbox_maps_flutter_interface/lib/src/callbacks.dart @@ -1,3 +1,3 @@ -part of 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; -typedef OnPlatformViewCreated = void Function(int id); +typedef OnMapCreated = void Function(MapboxMapInterface mapboxMap); diff --git a/mapbox_maps_flutter_interface/lib/src/map_interface.dart b/mapbox_maps_flutter_interface/lib/src/map_interface.dart new file mode 100644 index 000000000..92c5a6fd8 --- /dev/null +++ b/mapbox_maps_flutter_interface/lib/src/map_interface.dart @@ -0,0 +1,18 @@ +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; + +/// An abstract base class that defines the interface for interacting with a Mapbox map. +/// +/// This interface provides methods for setting the camera options and retrieving the current camera state. +abstract base class MapboxMapInterface { + /// Sets the camera options for the map. + /// + /// [cameraOptions] - The desired camera options to apply to the map. + /// + /// Returns a [Future] that completes when the camera options have been applied. + Future setCamera(CameraOptions cameraOptions); + + /// Retrieves the current state of the camera. + /// + /// Returns a [Future] that completes with the current [CameraState] of the map. + Future getCameraState(); +} diff --git a/mapbox_maps_flutter_interface/lib/src/mapbox_maps_flutter_platform_interface.dart b/mapbox_maps_flutter_interface/lib/src/mapbox_maps_flutter_platform_interface.dart index d5f49955c..e51703531 100644 --- a/mapbox_maps_flutter_interface/lib/src/mapbox_maps_flutter_platform_interface.dart +++ b/mapbox_maps_flutter_interface/lib/src/mapbox_maps_flutter_platform_interface.dart @@ -1,4 +1,6 @@ -part of 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; +import 'package:flutter/widgets.dart'; + +import '../mapbox_maps_flutter_interface.dart'; abstract base class MapboxMapsFlutterPlatform { static MapboxMapsFlutterPlatform? _instance; @@ -38,5 +40,8 @@ abstract base class MapboxMapsFlutterPlatform { /// /// This method is responsible for creating the widget that integrates /// with the underlying platform's view system to render the map. - Widget buildView(); + Widget buildView({ + CameraOptions? cameraOptions, + OnMapCreated? onMapCreated, + }); } diff --git a/mapbox_maps_flutter_interface/lib/src/pigeons/platform_interface_data_types.dart b/mapbox_maps_flutter_interface/lib/src/pigeons/platform_interface_data_types.dart new file mode 100644 index 000000000..4a5c8fa08 --- /dev/null +++ b/mapbox_maps_flutter_interface/lib/src/pigeons/platform_interface_data_types.dart @@ -0,0 +1,279 @@ +// Autogenerated from Pigeon (v25.2.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers + +part of mapbox_maps_flutter_interface; + +/// Describes the coordinate on the screen, measured from top to bottom and from left to right. +/// Note: the `map` uses screen coordinate units measured in `logical pixels`. +class ScreenCoordinate { + ScreenCoordinate({ + required this.x, + required this.y, + }); + + /// A value representing the x position of this coordinate. + double x; + + /// A value representing the y position of this coordinate. + double y; + + List _toList() { + return [ + x, + y, + ]; + } + + Object encode() { + return _toList(); + } + + static ScreenCoordinate decode(Object result) { + result as List; + return ScreenCoordinate( + x: result[0]! as double, + y: result[1]! as double, + ); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! ScreenCoordinate || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return x == other.x && y == other.y; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => Object.hashAll(_toList()); +} + +/// The distance on each side between rectangles, when one is contained into other. +/// +/// All fields' values are in `logical pixel` units. +class MbxEdgeInsets { + MbxEdgeInsets({ + required this.top, + required this.left, + required this.bottom, + required this.right, + }); + + /// Padding from the top. + double top; + + /// Padding from the left. + double left; + + /// Padding from the bottom. + double bottom; + + /// Padding from the right. + double right; + + List _toList() { + return [ + top, + left, + bottom, + right, + ]; + } + + Object encode() { + return _toList(); + } + + static MbxEdgeInsets decode(Object result) { + result as List; + return MbxEdgeInsets( + top: result[0]! as double, + left: result[1]! as double, + bottom: result[2]! as double, + right: result[3]! as double, + ); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! MbxEdgeInsets || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return top == other.top && + left == other.left && + bottom == other.bottom && + right == other.right; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => Object.hashAll(_toList()); +} + +/// Various options for describing the viewpoint of a camera. All fields are +/// optional. +/// +/// Anchor and center points are mutually exclusive, with preference for the +/// center point when both are set. +class CameraOptions { + CameraOptions({ + this.center, + this.padding, + this.anchor, + this.zoom, + this.bearing, + this.pitch, + }); + + /// Coordinate at the center of the camera. + Point? center; + + /// Padding around the interior of the view that affects the frame of + /// reference for `center`. + MbxEdgeInsets? padding; + + /// Point of reference for `zoom` and `angle`, assuming an origin at the + /// top-left corner of the view. + ScreenCoordinate? anchor; + + /// Zero-based zoom level. Constrained to the minimum and maximum zoom + /// levels. + double? zoom; + + /// Bearing, measured in degrees from true north. Wrapped to [0, 360). + double? bearing; + + /// Pitch toward the horizon measured in degrees. + double? pitch; + + List _toList() { + return [ + center, + padding, + anchor, + zoom, + bearing, + pitch, + ]; + } + + Object encode() { + return _toList(); + } + + static CameraOptions decode(Object result) { + result as List; + return CameraOptions( + center: result[0] as Point?, + padding: result[1] as MbxEdgeInsets?, + anchor: result[2] as ScreenCoordinate?, + zoom: result[3] as double?, + bearing: result[4] as double?, + pitch: result[5] as double?, + ); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! CameraOptions || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return center == other.center && + padding == other.padding && + anchor == other.anchor && + zoom == other.zoom && + bearing == other.bearing && + pitch == other.pitch; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => Object.hashAll(_toList()); +} + +/// Describes the viewpoint of a camera. +class CameraState { + CameraState({ + required this.center, + required this.padding, + required this.zoom, + required this.bearing, + required this.pitch, + }); + + /// Coordinate at the center of the camera. + Point center; + + /// Padding around the interior of the view that affects the frame of + /// reference for `center`. + MbxEdgeInsets padding; + + /// Zero-based zoom level. Constrained to the minimum and maximum zoom + /// levels. + double zoom; + + /// Bearing, measured in degrees from true north. Wrapped to [0, 360). + double bearing; + + /// Pitch toward the horizon measured in degrees. + double pitch; + + List _toList() { + return [ + center, + padding, + zoom, + bearing, + pitch, + ]; + } + + Object encode() { + return _toList(); + } + + static CameraState decode(Object result) { + result as List; + return CameraState( + center: result[0]! as Point, + padding: result[1]! as MbxEdgeInsets, + zoom: result[2]! as double, + bearing: result[3]! as double, + pitch: result[4]! as double, + ); + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + bool operator ==(Object other) { + if (other is! CameraState || other.runtimeType != runtimeType) { + return false; + } + if (identical(this, other)) { + return true; + } + return center == other.center && + padding == other.padding && + zoom == other.zoom && + bearing == other.bearing && + pitch == other.pitch; + } + + @override + // ignore: avoid_equals_and_hash_code_on_mutable_classes + int get hashCode => Object.hashAll(_toList()); +} diff --git a/mapbox_maps_flutter_mobile/lib/src/turf_adapters.dart b/mapbox_maps_flutter_interface/lib/src/turf_adapter.dart similarity index 97% rename from mapbox_maps_flutter_mobile/lib/src/turf_adapters.dart rename to mapbox_maps_flutter_interface/lib/src/turf_adapter.dart index be76d48ba..24e56f491 100644 --- a/mapbox_maps_flutter_mobile/lib/src/turf_adapters.dart +++ b/mapbox_maps_flutter_interface/lib/src/turf_adapter.dart @@ -1,4 +1,4 @@ -part of mapbox_maps_flutter; +part of 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; final class Point extends turf.Point { Point({super.bbox, required super.coordinates}); diff --git a/mapbox_maps_flutter_interface/pubspec.yaml b/mapbox_maps_flutter_interface/pubspec.yaml index ffbf8b029..74180c21e 100644 --- a/mapbox_maps_flutter_interface/pubspec.yaml +++ b/mapbox_maps_flutter_interface/pubspec.yaml @@ -12,6 +12,7 @@ resolution: workspace dependencies: flutter: sdk: flutter + turf: ^0.0.10 dev_dependencies: flutter_test: diff --git a/mapbox_maps_flutter_mobile/android/gradle/wrapper/gradle-wrapper.properties b/mapbox_maps_flutter_mobile/android/gradle/wrapper/gradle-wrapper.properties index 111c25e79..09523c0e5 100644 --- a/mapbox_maps_flutter_mobile/android/gradle/wrapper/gradle-wrapper.properties +++ b/mapbox_maps_flutter_mobile/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip diff --git a/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/MapInterfaces.kt b/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/MapInterfaces.kt index 1f762995b..8b1d1730e 100644 --- a/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/MapInterfaces.kt +++ b/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/MapInterfaces.kt @@ -692,186 +692,6 @@ data class TileCoverOptions( override fun hashCode(): Int = toList().hashCode() } -/** - * The distance on each side between rectangles, when one is contained into other. - * - * All fields' values are in `logical pixel` units. - * - * Generated class from Pigeon that represents data sent in messages. - */ -data class MbxEdgeInsets( - /** Padding from the top. */ - val top: Double, - /** Padding from the left. */ - val left: Double, - /** Padding from the bottom. */ - val bottom: Double, - /** Padding from the right. */ - val right: Double -) { - companion object { - fun fromList(pigeonVar_list: List): MbxEdgeInsets { - val top = pigeonVar_list[0] as Double - val left = pigeonVar_list[1] as Double - val bottom = pigeonVar_list[2] as Double - val right = pigeonVar_list[3] as Double - return MbxEdgeInsets(top, left, bottom, right) - } - } - fun toList(): List { - return listOf( - top, - left, - bottom, - right, - ) - } - override fun equals(other: Any?): Boolean { - if (other !is MbxEdgeInsets) { - return false - } - if (this === other) { - return true - } - return top == other.top && - left == other.left && - bottom == other.bottom && - right == other.right - } - - override fun hashCode(): Int = toList().hashCode() -} - -/** - * Various options for describing the viewpoint of a camera. All fields are - * optional. - * - * Anchor and center points are mutually exclusive, with preference for the - * center point when both are set. - * - * Generated class from Pigeon that represents data sent in messages. - */ -data class CameraOptions( - /** Coordinate at the center of the camera. */ - val center: Point? = null, - /** - * Padding around the interior of the view that affects the frame of - * reference for `center`. - */ - val padding: MbxEdgeInsets? = null, - /** - * Point of reference for `zoom` and `angle`, assuming an origin at the - * top-left corner of the view. - */ - val anchor: ScreenCoordinate? = null, - /** - * Zero-based zoom level. Constrained to the minimum and maximum zoom - * levels. - */ - val zoom: Double? = null, - /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ - val bearing: Double? = null, - /** Pitch toward the horizon measured in degrees. */ - val pitch: Double? = null -) { - companion object { - fun fromList(pigeonVar_list: List): CameraOptions { - val center = pigeonVar_list[0] as Point? - val padding = pigeonVar_list[1] as MbxEdgeInsets? - val anchor = pigeonVar_list[2] as ScreenCoordinate? - val zoom = pigeonVar_list[3] as Double? - val bearing = pigeonVar_list[4] as Double? - val pitch = pigeonVar_list[5] as Double? - return CameraOptions(center, padding, anchor, zoom, bearing, pitch) - } - } - fun toList(): List { - return listOf( - center, - padding, - anchor, - zoom, - bearing, - pitch, - ) - } - override fun equals(other: Any?): Boolean { - if (other !is CameraOptions) { - return false - } - if (this === other) { - return true - } - return center == other.center && - padding == other.padding && - anchor == other.anchor && - zoom == other.zoom && - bearing == other.bearing && - pitch == other.pitch - } - - override fun hashCode(): Int = toList().hashCode() -} - -/** - * Describes the viewpoint of a camera. - * - * Generated class from Pigeon that represents data sent in messages. - */ -data class CameraState( - /** Coordinate at the center of the camera. */ - val center: Point, - /** - * Padding around the interior of the view that affects the frame of - * reference for `center`. - */ - val padding: MbxEdgeInsets, - /** - * Zero-based zoom level. Constrained to the minimum and maximum zoom - * levels. - */ - val zoom: Double, - /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ - val bearing: Double, - /** Pitch toward the horizon measured in degrees. */ - val pitch: Double -) { - companion object { - fun fromList(pigeonVar_list: List): CameraState { - val center = pigeonVar_list[0] as Point - val padding = pigeonVar_list[1] as MbxEdgeInsets - val zoom = pigeonVar_list[2] as Double - val bearing = pigeonVar_list[3] as Double - val pitch = pigeonVar_list[4] as Double - return CameraState(center, padding, zoom, bearing, pitch) - } - } - fun toList(): List { - return listOf( - center, - padding, - zoom, - bearing, - pitch, - ) - } - override fun equals(other: Any?): Boolean { - if (other !is CameraState) { - return false - } - if (this === other) { - return true - } - return center == other.center && - padding == other.padding && - zoom == other.zoom && - bearing == other.bearing && - pitch == other.pitch - } - - override fun hashCode(): Int = toList().hashCode() -} - /** * Holds options to be used for setting `camera bounds`. * @@ -1255,45 +1075,6 @@ data class MapOptions( override fun hashCode(): Int = toList().hashCode() } -/** - * Describes the coordinate on the screen, measured from top to bottom and from left to right. - * Note: the `map` uses screen coordinate units measured in `logical pixels`. - * - * Generated class from Pigeon that represents data sent in messages. - */ -data class ScreenCoordinate( - /** A value representing the x position of this coordinate. */ - val x: Double, - /** A value representing the y position of this coordinate. */ - val y: Double -) { - companion object { - fun fromList(pigeonVar_list: List): ScreenCoordinate { - val x = pigeonVar_list[0] as Double - val y = pigeonVar_list[1] as Double - return ScreenCoordinate(x, y) - } - } - fun toList(): List { - return listOf( - x, - y, - ) - } - override fun equals(other: Any?): Boolean { - if (other !is ScreenCoordinate) { - return false - } - if (this === other) { - return true - } - return x == other.x && - y == other.y - } - - override fun hashCode(): Int = toList().hashCode() -} - /** * Describes the coordinate box on the screen, measured in `logical pixels` * from top to bottom and from left to right. diff --git a/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/PlatformInterfaceDataTypes.kt b/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/PlatformInterfaceDataTypes.kt new file mode 100644 index 000000000..0560ffa4d --- /dev/null +++ b/mapbox_maps_flutter_mobile/android/src/main/kotlin/com/mapbox/maps/mapbox_maps/pigeons/PlatformInterfaceDataTypes.kt @@ -0,0 +1,227 @@ +// Autogenerated from Pigeon (v25.2.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") + +package com.mapbox.maps.mapbox_maps.pigeons + +import com.mapbox.geojson.Point +import com.mapbox.maps.mapbox_maps.mapping.turf.* + +/** + * Describes the coordinate on the screen, measured from top to bottom and from left to right. + * Note: the `map` uses screen coordinate units measured in `logical pixels`. + * + * Generated class from Pigeon that represents data sent in messages. + */ +data class ScreenCoordinate( + /** A value representing the x position of this coordinate. */ + val x: Double, + /** A value representing the y position of this coordinate. */ + val y: Double +) { + companion object { + fun fromList(pigeonVar_list: List): ScreenCoordinate { + val x = pigeonVar_list[0] as Double + val y = pigeonVar_list[1] as Double + return ScreenCoordinate(x, y) + } + } + fun toList(): List { + return listOf( + x, + y, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is ScreenCoordinate) { + return false + } + if (this === other) { + return true + } + return x == other.x && + y == other.y + } + + override fun hashCode(): Int = toList().hashCode() +} + +/** + * The distance on each side between rectangles, when one is contained into other. + * + * All fields' values are in `logical pixel` units. + * + * Generated class from Pigeon that represents data sent in messages. + */ +data class MbxEdgeInsets( + /** Padding from the top. */ + val top: Double, + /** Padding from the left. */ + val left: Double, + /** Padding from the bottom. */ + val bottom: Double, + /** Padding from the right. */ + val right: Double +) { + companion object { + fun fromList(pigeonVar_list: List): MbxEdgeInsets { + val top = pigeonVar_list[0] as Double + val left = pigeonVar_list[1] as Double + val bottom = pigeonVar_list[2] as Double + val right = pigeonVar_list[3] as Double + return MbxEdgeInsets(top, left, bottom, right) + } + } + fun toList(): List { + return listOf( + top, + left, + bottom, + right, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is MbxEdgeInsets) { + return false + } + if (this === other) { + return true + } + return top == other.top && + left == other.left && + bottom == other.bottom && + right == other.right + } + + override fun hashCode(): Int = toList().hashCode() +} + +/** + * Various options for describing the viewpoint of a camera. All fields are + * optional. + * + * Anchor and center points are mutually exclusive, with preference for the + * center point when both are set. + * + * Generated class from Pigeon that represents data sent in messages. + */ +data class CameraOptions( + /** Coordinate at the center of the camera. */ + val center: Point? = null, + /** + * Padding around the interior of the view that affects the frame of + * reference for `center`. + */ + val padding: MbxEdgeInsets? = null, + /** + * Point of reference for `zoom` and `angle`, assuming an origin at the + * top-left corner of the view. + */ + val anchor: ScreenCoordinate? = null, + /** + * Zero-based zoom level. Constrained to the minimum and maximum zoom + * levels. + */ + val zoom: Double? = null, + /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ + val bearing: Double? = null, + /** Pitch toward the horizon measured in degrees. */ + val pitch: Double? = null +) { + companion object { + fun fromList(pigeonVar_list: List): CameraOptions { + val center = pigeonVar_list[0] as Point? + val padding = pigeonVar_list[1] as MbxEdgeInsets? + val anchor = pigeonVar_list[2] as ScreenCoordinate? + val zoom = pigeonVar_list[3] as Double? + val bearing = pigeonVar_list[4] as Double? + val pitch = pigeonVar_list[5] as Double? + return CameraOptions(center, padding, anchor, zoom, bearing, pitch) + } + } + fun toList(): List { + return listOf( + center, + padding, + anchor, + zoom, + bearing, + pitch, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is CameraOptions) { + return false + } + if (this === other) { + return true + } + return center == other.center && + padding == other.padding && + anchor == other.anchor && + zoom == other.zoom && + bearing == other.bearing && + pitch == other.pitch + } + + override fun hashCode(): Int = toList().hashCode() +} + +/** + * Describes the viewpoint of a camera. + * + * Generated class from Pigeon that represents data sent in messages. + */ +data class CameraState( + /** Coordinate at the center of the camera. */ + val center: Point, + /** + * Padding around the interior of the view that affects the frame of + * reference for `center`. + */ + val padding: MbxEdgeInsets, + /** + * Zero-based zoom level. Constrained to the minimum and maximum zoom + * levels. + */ + val zoom: Double, + /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ + val bearing: Double, + /** Pitch toward the horizon measured in degrees. */ + val pitch: Double +) { + companion object { + fun fromList(pigeonVar_list: List): CameraState { + val center = pigeonVar_list[0] as Point + val padding = pigeonVar_list[1] as MbxEdgeInsets + val zoom = pigeonVar_list[2] as Double + val bearing = pigeonVar_list[3] as Double + val pitch = pigeonVar_list[4] as Double + return CameraState(center, padding, zoom, bearing, pitch) + } + } + fun toList(): List { + return listOf( + center, + padding, + zoom, + bearing, + pitch, + ) + } + override fun equals(other: Any?): Boolean { + if (other !is CameraState) { + return false + } + if (this === other) { + return true + } + return center == other.center && + padding == other.padding && + zoom == other.zoom && + bearing == other.bearing && + pitch == other.pitch + } + + override fun hashCode(): Int = toList().hashCode() +} \ No newline at end of file diff --git a/mapbox_maps_flutter_mobile/example/android/app/src/profile/AndroidManifest.xml b/mapbox_maps_flutter_mobile/example/android/app/src/profile/AndroidManifest.xml index dfa0ba8d3..f880684a6 100644 --- a/mapbox_maps_flutter_mobile/example/android/app/src/profile/AndroidManifest.xml +++ b/mapbox_maps_flutter_mobile/example/android/app/src/profile/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/mapbox_maps_flutter_mobile/example/android/gradle.properties b/mapbox_maps_flutter_mobile/example/android/gradle.properties index 3852c19ca..9b7e91c07 100644 --- a/mapbox_maps_flutter_mobile/example/android/gradle.properties +++ b/mapbox_maps_flutter_mobile/example/android/gradle.properties @@ -2,3 +2,6 @@ org.gradle.jvmargs=-Xmx4096M android.useAndroidX=true android.enableJetifier=false useLocalDependencies=false +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false diff --git a/mapbox_maps_flutter_mobile/example/android/gradle/wrapper/gradle-wrapper.properties b/mapbox_maps_flutter_mobile/example/android/gradle/wrapper/gradle-wrapper.properties index f58dbd5d8..c38a728c4 100644 --- a/mapbox_maps_flutter_mobile/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/mapbox_maps_flutter_mobile/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Apr 30 20:27:36 EEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/mapbox_maps_flutter_mobile/example/android/settings.gradle b/mapbox_maps_flutter_mobile/example/android/settings.gradle index dcd3b479a..34d8421bb 100644 --- a/mapbox_maps_flutter_mobile/example/android/settings.gradle +++ b/mapbox_maps_flutter_mobile/example/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "7.3.1" apply false + id "com.android.application" version '8.7.0' apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false } diff --git a/mapbox_maps_flutter_mobile/example/integration_test/animation_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/animation_test.dart index f05f01fa2..260c54096 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/animation_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/animation_test.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/integration_test/camera_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/camera_test.dart index 355c08f34..43611f2e2 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/camera_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/camera_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/integration_test/gestures_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/gestures_test.dart index 8b9561862..9ff632048 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/gestures_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/gestures_test.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/integration_test/interactive_features_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/interactive_features_test.dart index 1b3c2da36..54bc0f5e3 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/interactive_features_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/interactive_features_test.dart @@ -3,6 +3,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/integration_test/map_interface_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/map_interface_test.dart index ec0c9c0ee..e9ef8d7c0 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/map_interface_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/map_interface_test.dart @@ -5,6 +5,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/integration_test/snapshotter/snapshotter_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/snapshotter/snapshotter_test.dart index 3e2fc33f4..8cfde171e 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/snapshotter/snapshotter_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/snapshotter/snapshotter_test.dart @@ -5,6 +5,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart' + show CameraOptions; import '../empty_map_widget.dart' as app; void main() { @@ -96,7 +98,7 @@ void main() { expect(bounds, isNotNull); final camera = await snapshotter.camera( - coordinates: [cameraOptions.center!], + coordinates: [Point(coordinates: cameraState.center.coordinates)], bearing: cameraOptions.bearing, pitch: cameraOptions.pitch, ); diff --git a/mapbox_maps_flutter_mobile/example/integration_test/viewport_test.dart b/mapbox_maps_flutter_mobile/example/integration_test/viewport_test.dart index 14ffc80a5..0153f1818 100644 --- a/mapbox_maps_flutter_mobile/example/integration_test/viewport_test.dart +++ b/mapbox_maps_flutter_mobile/example/integration_test/viewport_test.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'empty_map_widget.dart' as app; void main() { diff --git a/mapbox_maps_flutter_mobile/example/lib/animation_example.dart b/mapbox_maps_flutter_mobile/example/lib/animation_example.dart index a04e6ac0b..c8199bfba 100644 --- a/mapbox_maps_flutter_mobile/example/lib/animation_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/animation_example.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class AnimationExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/camera_example.dart b/mapbox_maps_flutter_mobile/example/lib/camera_example.dart index d978e0a25..1a47c3b86 100644 --- a/mapbox_maps_flutter_mobile/example/lib/camera_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/camera_example.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class CameraExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/circle_annotations_example.dart b/mapbox_maps_flutter_mobile/example/lib/circle_annotations_example.dart index 9a8b6eb2e..901ee3898 100644 --- a/mapbox_maps_flutter_mobile/example/lib/circle_annotations_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/circle_annotations_example.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart' hide Visibility; import 'package:mapbox_maps_example/utils.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class CircleAnnotationExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/cluster_example.dart b/mapbox_maps_flutter_mobile/example/lib/cluster_example.dart index 2335f39c8..e5118e947 100644 --- a/mapbox_maps_flutter_mobile/example/lib/cluster_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/cluster_example.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class StyleClustersExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/full_map_example.dart b/mapbox_maps_flutter_mobile/example/lib/full_map_example.dart index a09176fa6..e4c0d4e26 100644 --- a/mapbox_maps_flutter_mobile/example/lib/full_map_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/full_map_example.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class FullMapExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/model_layer_example.dart b/mapbox_maps_flutter_mobile/example/lib/model_layer_example.dart index 05b9162f1..bd9781b4c 100644 --- a/mapbox_maps_flutter_mobile/example/lib/model_layer_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/model_layer_example.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class ModelLayerExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/model_layer_interactions_example.dart b/mapbox_maps_flutter_mobile/example/lib/model_layer_interactions_example.dart index 6f9ad1443..31f6eedbb 100644 --- a/mapbox_maps_flutter_mobile/example/lib/model_layer_interactions_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/model_layer_interactions_example.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class ModelLayerInteractionsExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/lib/polyline_annotations_example.dart b/mapbox_maps_flutter_mobile/example/lib/polyline_annotations_example.dart index 3c7682fe7..96d053c74 100644 --- a/mapbox_maps_flutter_mobile/example/lib/polyline_annotations_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/polyline_annotations_example.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; -import 'package:mapbox_maps_example/utils.dart'; +import 'utils.dart'; import 'example.dart'; diff --git a/mapbox_maps_flutter_mobile/example/lib/spinning_globe_example.dart b/mapbox_maps_flutter_mobile/example/lib/spinning_globe_example.dart index 9f187c4eb..2f472be3c 100644 --- a/mapbox_maps_flutter_mobile/example/lib/spinning_globe_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/spinning_globe_example.dart @@ -2,8 +2,10 @@ import 'dart:async'; import 'dart:math'; import 'package:flutter/material.dart'; -import 'package:mapbox_maps_example/example.dart'; +import 'example.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart' + show CameraOptions, CameraState; class SpinningGlobeExample extends StatefulWidget implements Example { @override diff --git a/mapbox_maps_flutter_mobile/example/lib/standard_style_interactions_example.dart b/mapbox_maps_flutter_mobile/example/lib/standard_style_interactions_example.dart index b9aa7d884..28a1d9589 100644 --- a/mapbox_maps_flutter_mobile/example/lib/standard_style_interactions_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/standard_style_interactions_example.dart @@ -1,6 +1,7 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; + import 'example.dart'; class StandardStyleInteractionsExample extends StatefulWidget diff --git a/mapbox_maps_flutter_mobile/example/lib/traffic_route_line_example.dart b/mapbox_maps_flutter_mobile/example/lib/traffic_route_line_example.dart index 0e784f9b9..276e18816 100644 --- a/mapbox_maps_flutter_mobile/example/lib/traffic_route_line_example.dart +++ b/mapbox_maps_flutter_mobile/example/lib/traffic_route_line_example.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:mapbox_maps_example/example.dart'; +import 'example.dart'; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; class TrafficRouteLineExample extends StatefulWidget implements Example { diff --git a/mapbox_maps_flutter_mobile/example/pubspec.lock b/mapbox_maps_flutter_mobile/example/pubspec.lock index 19d810e5d..03e2d7470 100644 --- a/mapbox_maps_flutter_mobile/example/pubspec.lock +++ b/mapbox_maps_flutter_mobile/example/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: transitive description: name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.12.0" benchmark: dependency: transitive description: @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: fake_async - sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" url: "https://pub.dev" source: hosted - version: "1.3.3" + version: "1.3.2" ffi: dependency: transitive description: @@ -534,10 +534,10 @@ packages: dependency: transitive description: name: webdriver - sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade" + sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.0.4" xdg_directories: dependency: transitive description: diff --git a/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/MapInterfaces.swift b/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/MapInterfaces.swift index 1ffc51221..d192ba28b 100644 --- a/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/MapInterfaces.swift +++ b/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/MapInterfaces.swift @@ -482,146 +482,6 @@ struct TileCoverOptions { } } -/// The distance on each side between rectangles, when one is contained into other. -/// -/// All fields' values are in `logical pixel` units. -/// -/// Generated class from Pigeon that represents data sent in messages. -struct MbxEdgeInsets { - /// Padding from the top. - var top: Double - /// Padding from the left. - var left: Double - /// Padding from the bottom. - var bottom: Double - /// Padding from the right. - var right: Double - - - // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ pigeonVar_list: [Any?]) -> MbxEdgeInsets? { - let top = pigeonVar_list[0] as! Double - let left = pigeonVar_list[1] as! Double - let bottom = pigeonVar_list[2] as! Double - let right = pigeonVar_list[3] as! Double - - return MbxEdgeInsets( - top: top, - left: left, - bottom: bottom, - right: right - ) - } - func toList() -> [Any?] { - return [ - top, - left, - bottom, - right, - ] - } -} - -/// Various options for describing the viewpoint of a camera. All fields are -/// optional. -/// -/// Anchor and center points are mutually exclusive, with preference for the -/// center point when both are set. -/// -/// Generated class from Pigeon that represents data sent in messages. -struct CameraOptions { - /// Coordinate at the center of the camera. - var center: Point? = nil - /// Padding around the interior of the view that affects the frame of - /// reference for `center`. - var padding: MbxEdgeInsets? = nil - /// Point of reference for `zoom` and `angle`, assuming an origin at the - /// top-left corner of the view. - var anchor: ScreenCoordinate? = nil - /// Zero-based zoom level. Constrained to the minimum and maximum zoom - /// levels. - var zoom: Double? = nil - /// Bearing, measured in degrees from true north. Wrapped to [0, 360). - var bearing: Double? = nil - /// Pitch toward the horizon measured in degrees. - var pitch: Double? = nil - - - // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ pigeonVar_list: [Any?]) -> CameraOptions? { - let center: Point? = nilOrValue(pigeonVar_list[0]) - let padding: MbxEdgeInsets? = nilOrValue(pigeonVar_list[1]) - let anchor: ScreenCoordinate? = nilOrValue(pigeonVar_list[2]) - let zoom: Double? = nilOrValue(pigeonVar_list[3]) - let bearing: Double? = nilOrValue(pigeonVar_list[4]) - let pitch: Double? = nilOrValue(pigeonVar_list[5]) - - return CameraOptions( - center: center, - padding: padding, - anchor: anchor, - zoom: zoom, - bearing: bearing, - pitch: pitch - ) - } - func toList() -> [Any?] { - return [ - center, - padding, - anchor, - zoom, - bearing, - pitch, - ] - } -} - -/// Describes the viewpoint of a camera. -/// -/// Generated class from Pigeon that represents data sent in messages. -struct CameraState { - /// Coordinate at the center of the camera. - var center: Point - /// Padding around the interior of the view that affects the frame of - /// reference for `center`. - var padding: MbxEdgeInsets - /// Zero-based zoom level. Constrained to the minimum and maximum zoom - /// levels. - var zoom: Double - /// Bearing, measured in degrees from true north. Wrapped to [0, 360). - var bearing: Double - /// Pitch toward the horizon measured in degrees. - var pitch: Double - - - // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ pigeonVar_list: [Any?]) -> CameraState? { - let center = pigeonVar_list[0] as! Point - let padding = pigeonVar_list[1] as! MbxEdgeInsets - let zoom = pigeonVar_list[2] as! Double - let bearing = pigeonVar_list[3] as! Double - let pitch = pigeonVar_list[4] as! Double - - return CameraState( - center: center, - padding: padding, - zoom: zoom, - bearing: bearing, - pitch: pitch - ) - } - func toList() -> [Any?] { - return [ - center, - padding, - zoom, - bearing, - pitch, - ] - } -} - /// Holds options to be used for setting `camera bounds`. /// /// Generated class from Pigeon that represents data sent in messages. @@ -905,35 +765,6 @@ struct MapOptions { } } -/// Describes the coordinate on the screen, measured from top to bottom and from left to right. -/// Note: the `map` uses screen coordinate units measured in `logical pixels`. -/// -/// Generated class from Pigeon that represents data sent in messages. -struct ScreenCoordinate { - /// A value representing the x position of this coordinate. - var x: Double - /// A value representing the y position of this coordinate. - var y: Double - - - // swift-format-ignore: AlwaysUseLowerCamelCase - static func fromList(_ pigeonVar_list: [Any?]) -> ScreenCoordinate? { - let x = pigeonVar_list[0] as! Double - let y = pigeonVar_list[1] as! Double - - return ScreenCoordinate( - x: x, - y: y - ) - } - func toList() -> [Any?] { - return [ - x, - y, - ] - } -} - /// Describes the coordinate box on the screen, measured in `logical pixels` /// from top to bottom and from left to right. /// @@ -4965,14 +4796,14 @@ protocol StyleManager { /// @return The `transition options` of the current style in use. func getStyleTransition(completion: @escaping (Result) -> Void) /// Adds new import to current style, loaded from a JSON string. - /// + /// /// @param importId Identifier of import to update. /// @param json The JSON string to be loaded directly as the import. /// @param config A map containing the configuration options of the import. /// @param importPosition The import will be positioned according to the ImportPosition parameters. If not specified, then the import is moved to the top of the import stack. func addStyleImportFromJSON(importId: String, json: String, config: [String: Any]?, importPosition: ImportPosition?) throws /// Adds new import to current style, loaded from an URI. - /// + /// /// @param importId Identifier of import to update. /// @param uri URI of the import. /// @param config A map containing the configuration options of the import. @@ -4981,7 +4812,7 @@ protocol StyleManager { /// Updates an existing import in the style. /// The function replaces the content of the import, with the content loaded from the provided data value. /// The configuration values of the import are merged with the configuration provided in the update. - /// + /// /// @param importId Identifier of import to update. /// @param json The JSON string to be loaded directly as the import. /// @param config A map containing the configuration options of the import. @@ -4989,13 +4820,13 @@ protocol StyleManager { /// Updates an existing import in the style. /// The function replaces the content of the import, with the content loaded from the provided URI. /// The configuration values of the import are merged with the configuration provided in the update. - /// + /// /// @param importId Identifier of import to update. /// @param uri URI of the import. /// @param config A map containing the configuration options of the import. func updateStyleImportWithURI(importId: String, uri: String, config: [String: Any]?) throws /// Moves import to position before another import, specified with `beforeId`. Order of imported styles corresponds to order of their layers. - /// + /// /// @param importId Identifier of import to move. /// @param importPosition The import will be positioned according to the ImportPosition parameters. If not specified, then the import is moved to the top of the import stack. func moveStyleImport(importId: String, importPosition: ImportPosition?) throws @@ -5543,7 +5374,7 @@ class StyleManagerSetup { getStyleTransitionChannel.setMessageHandler(nil) } /// Adds new import to current style, loaded from a JSON string. - /// + /// /// @param importId Identifier of import to update. /// @param json The JSON string to be loaded directly as the import. /// @param config A map containing the configuration options of the import. @@ -5567,7 +5398,7 @@ class StyleManagerSetup { addStyleImportFromJSONChannel.setMessageHandler(nil) } /// Adds new import to current style, loaded from an URI. - /// + /// /// @param importId Identifier of import to update. /// @param uri URI of the import. /// @param config A map containing the configuration options of the import. @@ -5593,7 +5424,7 @@ class StyleManagerSetup { /// Updates an existing import in the style. /// The function replaces the content of the import, with the content loaded from the provided data value. /// The configuration values of the import are merged with the configuration provided in the update. - /// + /// /// @param importId Identifier of import to update. /// @param json The JSON string to be loaded directly as the import. /// @param config A map containing the configuration options of the import. @@ -5617,7 +5448,7 @@ class StyleManagerSetup { /// Updates an existing import in the style. /// The function replaces the content of the import, with the content loaded from the provided URI. /// The configuration values of the import are merged with the configuration provided in the update. - /// + /// /// @param importId Identifier of import to update. /// @param uri URI of the import. /// @param config A map containing the configuration options of the import. @@ -5639,7 +5470,7 @@ class StyleManagerSetup { updateStyleImportWithURIChannel.setMessageHandler(nil) } /// Moves import to position before another import, specified with `beforeId`. Order of imported styles corresponds to order of their layers. - /// + /// /// @param importId Identifier of import to move. /// @param importPosition The import will be positioned according to the ImportPosition parameters. If not specified, then the import is moved to the top of the import stack. let moveStyleImportChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.mapbox_maps_flutter.StyleManager.moveStyleImport\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) diff --git a/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/PlatformInterfaceDataTypes.swift b/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/PlatformInterfaceDataTypes.swift new file mode 100644 index 000000000..8524c6b93 --- /dev/null +++ b/mapbox_maps_flutter_mobile/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Generated/PlatformInterfaceDataTypes.swift @@ -0,0 +1,209 @@ +// Autogenerated from Pigeon (v25.2.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +import Foundation + +#if os(iOS) + import Flutter +#elseif os(macOS) + import FlutterMacOS +#else + #error("Unsupported platform.") +#endif +import struct Turf.Point + +/// Error class for passing custom error details to Dart side. +final class PlatformInterfaceDataTypesError: Error { + let code: String + let message: String? + let details: Sendable? + + init(code: String, message: String?, details: Sendable?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PlatformInterfaceDataTypesError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + +private func nilOrValue(_ value: Any?) -> T? { + if value is NSNull { return nil } + return value as! T? +} + +/// Describes the coordinate on the screen, measured from top to bottom and from left to right. +/// Note: the `map` uses screen coordinate units measured in `logical pixels`. +/// +/// Generated class from Pigeon that represents data sent in messages. +struct ScreenCoordinate { + /// A value representing the x position of this coordinate. + var x: Double + /// A value representing the y position of this coordinate. + var y: Double + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> ScreenCoordinate? { + let x = pigeonVar_list[0] as! Double + let y = pigeonVar_list[1] as! Double + + return ScreenCoordinate( + x: x, + y: y + ) + } + func toList() -> [Any?] { + return [ + x, + y, + ] + } +} + +/// The distance on each side between rectangles, when one is contained into other. +/// +/// All fields' values are in `logical pixel` units. +/// +/// Generated class from Pigeon that represents data sent in messages. +struct MbxEdgeInsets { + /// Padding from the top. + var top: Double + /// Padding from the left. + var left: Double + /// Padding from the bottom. + var bottom: Double + /// Padding from the right. + var right: Double + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> MbxEdgeInsets? { + let top = pigeonVar_list[0] as! Double + let left = pigeonVar_list[1] as! Double + let bottom = pigeonVar_list[2] as! Double + let right = pigeonVar_list[3] as! Double + + return MbxEdgeInsets( + top: top, + left: left, + bottom: bottom, + right: right + ) + } + func toList() -> [Any?] { + return [ + top, + left, + bottom, + right, + ] + } +} + +/// Various options for describing the viewpoint of a camera. All fields are +/// optional. +/// +/// Anchor and center points are mutually exclusive, with preference for the +/// center point when both are set. +/// +/// Generated class from Pigeon that represents data sent in messages. +struct CameraOptions { + /// Coordinate at the center of the camera. + var center: Point? = nil + /// Padding around the interior of the view that affects the frame of + /// reference for `center`. + var padding: MbxEdgeInsets? = nil + /// Point of reference for `zoom` and `angle`, assuming an origin at the + /// top-left corner of the view. + var anchor: ScreenCoordinate? = nil + /// Zero-based zoom level. Constrained to the minimum and maximum zoom + /// levels. + var zoom: Double? = nil + /// Bearing, measured in degrees from true north. Wrapped to [0, 360). + var bearing: Double? = nil + /// Pitch toward the horizon measured in degrees. + var pitch: Double? = nil + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CameraOptions? { + let center: Point? = nilOrValue(pigeonVar_list[0]) + let padding: MbxEdgeInsets? = nilOrValue(pigeonVar_list[1]) + let anchor: ScreenCoordinate? = nilOrValue(pigeonVar_list[2]) + let zoom: Double? = nilOrValue(pigeonVar_list[3]) + let bearing: Double? = nilOrValue(pigeonVar_list[4]) + let pitch: Double? = nilOrValue(pigeonVar_list[5]) + + return CameraOptions( + center: center, + padding: padding, + anchor: anchor, + zoom: zoom, + bearing: bearing, + pitch: pitch + ) + } + func toList() -> [Any?] { + return [ + center, + padding, + anchor, + zoom, + bearing, + pitch, + ] + } +} + +/// Describes the viewpoint of a camera. +/// +/// Generated class from Pigeon that represents data sent in messages. +struct CameraState { + /// Coordinate at the center of the camera. + var center: Point + /// Padding around the interior of the view that affects the frame of + /// reference for `center`. + var padding: MbxEdgeInsets + /// Zero-based zoom level. Constrained to the minimum and maximum zoom + /// levels. + var zoom: Double + /// Bearing, measured in degrees from true north. Wrapped to [0, 360). + var bearing: Double + /// Pitch toward the horizon measured in degrees. + var pitch: Double + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> CameraState? { + let center = pigeonVar_list[0] as! Point + let padding = pigeonVar_list[1] as! MbxEdgeInsets + let zoom = pigeonVar_list[2] as! Double + let bearing = pigeonVar_list[3] as! Double + let pitch = pigeonVar_list[4] as! Double + + return CameraState( + center: center, + padding: padding, + zoom: zoom, + bearing: bearing, + pitch: pitch + ) + } + func toList() -> [Any?] { + return [ + center, + padding, + zoom, + bearing, + pitch, + ] + } +} diff --git a/mapbox_maps_flutter_mobile/lib/mapbox_maps_flutter.dart b/mapbox_maps_flutter_mobile/lib/mapbox_maps_flutter.dart index a60585993..3aa21a463 100644 --- a/mapbox_maps_flutter_mobile/lib/mapbox_maps_flutter.dart +++ b/mapbox_maps_flutter_mobile/lib/mapbox_maps_flutter.dart @@ -11,9 +11,8 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; import 'package:meta/meta.dart'; -import 'package:turf/turf.dart' as turf; -export 'package:turf/helpers.dart'; +export 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; part 'src/annotation/circle_annotation_manager.dart'; part 'src/annotation/point_annotation_manager.dart'; @@ -66,7 +65,6 @@ part 'src/style/interactive_features/standard_poi.dart'; part 'src/location_settings.dart'; part 'src/snapshotter/snapshotter.dart'; part 'src/log_configuration.dart'; -part 'src/turf_adapters.dart'; part 'src/extensions.dart'; part 'src/map_events.dart'; part 'src/offline/offline_messenger.dart'; diff --git a/mapbox_maps_flutter_mobile/lib/src/mapbox_map.dart b/mapbox_maps_flutter_mobile/lib/src/mapbox_map.dart index 1ca57a7dd..cb6f2993d 100644 --- a/mapbox_maps_flutter_mobile/lib/src/mapbox_map.dart +++ b/mapbox_maps_flutter_mobile/lib/src/mapbox_map.dart @@ -136,7 +136,7 @@ extension on _MapWidgetDebugOptions { } /// Controller for a single MapboxMap instance running on the host platform. -class MapboxMap extends ChangeNotifier { +final class MapboxMap extends MapboxMapInterface with ChangeNotifier { MapboxMap._({ required _MapboxMapsPlatform mapboxMapsPlatform, this.onMapTapListener, @@ -344,10 +344,14 @@ class MapboxMap extends ChangeNotifier { /// The map will retain its current values for any details not passed via the camera options argument. /// It is not guaranteed that the provided `camera options` will be set, the map may apply constraints resulting in a /// different `camera state`. + @override Future setCamera(CameraOptions cameraOptions) => - _cameraManager.setCamera(cameraOptions); + _cameraManager.setCamera( + cameraOptions, + ); /// Returns the current `camera state`. + @override Future getCameraState() => _cameraManager.getCameraState(); /// Sets the `camera bounds options` of the map. The map will retain its current values for any diff --git a/mapbox_maps_flutter_mobile/lib/src/mapbox_maps_flutter_mobile.dart b/mapbox_maps_flutter_mobile/lib/src/mapbox_maps_flutter_mobile.dart index d25115ea3..59ef402a7 100644 --- a/mapbox_maps_flutter_mobile/lib/src/mapbox_maps_flutter_mobile.dart +++ b/mapbox_maps_flutter_mobile/lib/src/mapbox_maps_flutter_mobile.dart @@ -1,13 +1,17 @@ part of 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; base class MapboxMapsFlutterMobile extends MapboxMapsFlutterPlatform { - late final MapboxMap _mapboxMap; - @override - Widget buildView() { + Widget buildView({ + CameraOptions? cameraOptions, + OnMapCreated? onMapCreated, + }) { return MapWidget( + cameraOptions: cameraOptions, onMapCreated: (MapboxMap mapboxMap) { - _mapboxMap = mapboxMap; + if (onMapCreated != null) { + onMapCreated(mapboxMap); + } }, ); } diff --git a/mapbox_maps_flutter_mobile/lib/src/pigeons/map_interfaces.dart b/mapbox_maps_flutter_mobile/lib/src/pigeons/map_interfaces.dart index 8ae8b74c2..08c0919ce 100644 --- a/mapbox_maps_flutter_mobile/lib/src/pigeons/map_interfaces.dart +++ b/mapbox_maps_flutter_mobile/lib/src/pigeons/map_interfaces.dart @@ -561,230 +561,6 @@ class TileCoverOptions { int get hashCode => Object.hashAll(_toList()); } -/// The distance on each side between rectangles, when one is contained into other. -/// -/// All fields' values are in `logical pixel` units. -class MbxEdgeInsets { - MbxEdgeInsets({ - required this.top, - required this.left, - required this.bottom, - required this.right, - }); - - /// Padding from the top. - double top; - - /// Padding from the left. - double left; - - /// Padding from the bottom. - double bottom; - - /// Padding from the right. - double right; - - List _toList() { - return [ - top, - left, - bottom, - right, - ]; - } - - Object encode() { - return _toList(); - } - - static MbxEdgeInsets decode(Object result) { - result as List; - return MbxEdgeInsets( - top: result[0]! as double, - left: result[1]! as double, - bottom: result[2]! as double, - right: result[3]! as double, - ); - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - bool operator ==(Object other) { - if (other is! MbxEdgeInsets || other.runtimeType != runtimeType) { - return false; - } - if (identical(this, other)) { - return true; - } - return top == other.top && - left == other.left && - bottom == other.bottom && - right == other.right; - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()); -} - -/// Various options for describing the viewpoint of a camera. All fields are -/// optional. -/// -/// Anchor and center points are mutually exclusive, with preference for the -/// center point when both are set. -class CameraOptions { - CameraOptions({ - this.center, - this.padding, - this.anchor, - this.zoom, - this.bearing, - this.pitch, - }); - - /// Coordinate at the center of the camera. - Point? center; - - /// Padding around the interior of the view that affects the frame of - /// reference for `center`. - MbxEdgeInsets? padding; - - /// Point of reference for `zoom` and `angle`, assuming an origin at the - /// top-left corner of the view. - ScreenCoordinate? anchor; - - /// Zero-based zoom level. Constrained to the minimum and maximum zoom - /// levels. - double? zoom; - - /// Bearing, measured in degrees from true north. Wrapped to [0, 360). - double? bearing; - - /// Pitch toward the horizon measured in degrees. - double? pitch; - - List _toList() { - return [ - center, - padding, - anchor, - zoom, - bearing, - pitch, - ]; - } - - Object encode() { - return _toList(); - } - - static CameraOptions decode(Object result) { - result as List; - return CameraOptions( - center: result[0] as Point?, - padding: result[1] as MbxEdgeInsets?, - anchor: result[2] as ScreenCoordinate?, - zoom: result[3] as double?, - bearing: result[4] as double?, - pitch: result[5] as double?, - ); - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - bool operator ==(Object other) { - if (other is! CameraOptions || other.runtimeType != runtimeType) { - return false; - } - if (identical(this, other)) { - return true; - } - return center == other.center && - padding == other.padding && - anchor == other.anchor && - zoom == other.zoom && - bearing == other.bearing && - pitch == other.pitch; - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()); -} - -/// Describes the viewpoint of a camera. -class CameraState { - CameraState({ - required this.center, - required this.padding, - required this.zoom, - required this.bearing, - required this.pitch, - }); - - /// Coordinate at the center of the camera. - Point center; - - /// Padding around the interior of the view that affects the frame of - /// reference for `center`. - MbxEdgeInsets padding; - - /// Zero-based zoom level. Constrained to the minimum and maximum zoom - /// levels. - double zoom; - - /// Bearing, measured in degrees from true north. Wrapped to [0, 360). - double bearing; - - /// Pitch toward the horizon measured in degrees. - double pitch; - - List _toList() { - return [ - center, - padding, - zoom, - bearing, - pitch, - ]; - } - - Object encode() { - return _toList(); - } - - static CameraState decode(Object result) { - result as List; - return CameraState( - center: result[0]! as Point, - padding: result[1]! as MbxEdgeInsets, - zoom: result[2]! as double, - bearing: result[3]! as double, - pitch: result[4]! as double, - ); - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - bool operator ==(Object other) { - if (other is! CameraState || other.runtimeType != runtimeType) { - return false; - } - if (identical(this, other)) { - return true; - } - return center == other.center && - padding == other.padding && - zoom == other.zoom && - bearing == other.bearing && - pitch == other.pitch; - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()); -} - /// Holds options to be used for setting `camera bounds`. class CameraBoundsOptions { CameraBoundsOptions({ @@ -1266,56 +1042,6 @@ class MapOptions { int get hashCode => Object.hashAll(_toList()); } -/// Describes the coordinate on the screen, measured from top to bottom and from left to right. -/// Note: the `map` uses screen coordinate units measured in `logical pixels`. -class ScreenCoordinate { - ScreenCoordinate({ - required this.x, - required this.y, - }); - - /// A value representing the x position of this coordinate. - double x; - - /// A value representing the y position of this coordinate. - double y; - - List _toList() { - return [ - x, - y, - ]; - } - - Object encode() { - return _toList(); - } - - static ScreenCoordinate decode(Object result) { - result as List; - return ScreenCoordinate( - x: result[0]! as double, - y: result[1]! as double, - ); - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - bool operator ==(Object other) { - if (other is! ScreenCoordinate || other.runtimeType != runtimeType) { - return false; - } - if (identical(this, other)) { - return true; - } - return x == other.x && y == other.y; - } - - @override - // ignore: avoid_equals_and_hash_code_on_mutable_classes - int get hashCode => Object.hashAll(_toList()); -} - /// Describes the coordinate box on the screen, measured in `logical pixels` /// from top to bottom and from left to right. class ScreenBox { diff --git a/mapbox_maps_flutter_mobile/lib/src/viewport/states/overview_viewport_state.dart b/mapbox_maps_flutter_mobile/lib/src/viewport/states/overview_viewport_state.dart index a1cdc37ca..0c7789583 100644 --- a/mapbox_maps_flutter_mobile/lib/src/viewport/states/overview_viewport_state.dart +++ b/mapbox_maps_flutter_mobile/lib/src/viewport/states/overview_viewport_state.dart @@ -21,7 +21,7 @@ part of mapbox_maps_flutter; /// ``` final class OverviewViewportState extends ViewportState { /// The geometry to display in the overview. - final turf.GeometryObject geometry; + final GeometryObject geometry; /// Extra padding to add around the [geometry]. /// diff --git a/mapbox_maps_flutter_mobile/pubspec.yaml b/mapbox_maps_flutter_mobile/pubspec.yaml index fb45eebd6..2c04af077 100644 --- a/mapbox_maps_flutter_mobile/pubspec.yaml +++ b/mapbox_maps_flutter_mobile/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^2.0.5 - turf: ^0.0.8 typed_data: ^1.3.0 meta: ^1.9.1 mapbox_maps_flutter_interface: any diff --git a/mapbox_maps_flutter_mobile/test/events_test.dart b/mapbox_maps_flutter_mobile/test/events_test.dart index d6a3877e4..ee5a3c375 100644 --- a/mapbox_maps_flutter_mobile/test/events_test.dart +++ b/mapbox_maps_flutter_mobile/test/events_test.dart @@ -6,7 +6,9 @@ void main() { final json = { 'timestamp': 1, 'cameraState': { - 'center': {'coordinates': [0, 0]}, + 'center': { + 'coordinates': [0, 0] + }, 'padding': {'top': 0, 'left': 1, 'bottom': 2, 'right': 3}, 'zoom': 11, 'bearing': 0, @@ -15,7 +17,8 @@ void main() { }; var cameraChangedEventData = CameraChangedEventData.fromJson(json); expect(cameraChangedEventData.timestamp, 1); - expect(cameraChangedEventData.cameraState.center.coordinates, Position.of([0, 0])); + expect(cameraChangedEventData.cameraState.center.coordinates, + Position.of([0, 0])); expect(cameraChangedEventData.cameraState.padding.top, 0); expect(cameraChangedEventData.cameraState.padding.left, 1); expect(cameraChangedEventData.cameraState.padding.bottom, 2); diff --git a/mapbox_maps_flutter_v3/.pubignore b/mapbox_maps_flutter_v3/.pubignore new file mode 100644 index 000000000..34924180a --- /dev/null +++ b/mapbox_maps_flutter_v3/.pubignore @@ -0,0 +1,4 @@ +*.lock +**/android/gradlew +**/android/gradlew.bat +**/android/gradle/wrapper/gradle-wrapper.jar \ No newline at end of file diff --git a/mapbox_maps_flutter_v3/example/integration_test/app.dart b/mapbox_maps_flutter_v3/example/integration_test/app.dart new file mode 100644 index 000000000..3a8af8367 --- /dev/null +++ b/mapbox_maps_flutter_v3/example/integration_test/app.dart @@ -0,0 +1,40 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; + +const ACCESS_TOKEN = String.fromEnvironment('ACCESS_TOKEN'); + +Future main( + {double? width, + double? height, + CameraOptions? camera, + Alignment alignment = Alignment.topLeft}) { + final completer = Completer(); + + MapboxOptions.setAccessToken(ACCESS_TOKEN); + + runApp(MaterialApp( + home: Align( + alignment: alignment, + child: SizedBox( + width: width, + height: height, + child: MapWidget( + key: ValueKey("mapWidget"), + cameraOptions: camera, + onMapCreated: (MapboxMap mapboxMap) { + completer.complete(mapboxMap); + }, + ), + ), + ))); + + return completer.future; +} + +void runEmpty() { + MapboxOptions.setAccessToken(ACCESS_TOKEN); + + runApp(MaterialApp()); +} diff --git a/mapbox_maps_flutter_v3/example/integration_test/camera_test.dart b/mapbox_maps_flutter_v3/example/integration_test/camera_test.dart new file mode 100644 index 000000000..b271f25cc --- /dev/null +++ b/mapbox_maps_flutter_v3/example/integration_test/camera_test.dart @@ -0,0 +1,74 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; + +import 'app.dart' as app; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + final initialCamera = CameraOptions( + center: Point(coordinates: Position(0, 0)), + padding: MbxEdgeInsets(top: 10, left: 20, bottom: 30, right: 40), + zoom: 15, + pitch: 60, + bearing: 12, + ); + + group('camera get and set', () { + testWidgets('set camera when creating a map', (WidgetTester tester) async { + final mapFuture = app.main(camera: initialCamera); + await tester.pumpAndSettle(); + final mapboxMap = await mapFuture; + + // Verify that the camera options are set correctly + final camera = await mapboxMap.getCameraState(); + expect(camera.center.coordinates.lng, + closeTo(initialCamera.center!.coordinates.lng, 0.0001)); + expect(camera.center.coordinates.lat, + closeTo(initialCamera.center!.coordinates.lat, 0.0001)); + expect(camera.padding.top, closeTo(initialCamera.padding!.top, 0.0001)); + expect(camera.padding.left, closeTo(initialCamera.padding!.left, 0.0001)); + expect(camera.padding.bottom, + closeTo(initialCamera.padding!.bottom, 0.0001)); + expect( + camera.padding.right, closeTo(initialCamera.padding!.right, 0.0001)); + expect(camera.zoom, closeTo(initialCamera.zoom!, 0.0001)); + expect(camera.pitch, closeTo(initialCamera.pitch!, 0.0001)); + expect(camera.bearing, closeTo(initialCamera.bearing!, 0.0001)); + }); + + testWidgets('set camera after map created', (tester) async { + final mapFuture = app.main(); + await tester.pumpAndSettle(); + final mapboxMap = await mapFuture; + + // Set the camera options + final cameraOptions = CameraOptions( + center: Point(coordinates: Position(1, 1)), + padding: MbxEdgeInsets(top: 10, left: 20, bottom: 30, right: 40), + zoom: 15, + pitch: 60, + bearing: 12, + ); + + await mapboxMap.setCamera(cameraOptions); + await tester.pumpAndSettle(); + + final camera = await mapboxMap.getCameraState(); + expect(camera.center.coordinates.lng, + closeTo(cameraOptions.center!.coordinates.lng, 0.0001)); + expect(camera.center.coordinates.lat, + closeTo(cameraOptions.center!.coordinates.lat, 0.0001)); + expect( + camera.padding.top, closeTo(cameraOptions.padding?.top ?? 0, 0.0001)); + expect(camera.padding.left, closeTo(cameraOptions.padding!.left, 0.0001)); + expect(camera.padding.bottom, + closeTo(cameraOptions.padding!.bottom, 0.0001)); + expect( + camera.padding.right, closeTo(cameraOptions.padding!.right, 0.0001)); + expect(camera.zoom, closeTo(cameraOptions.zoom!, 0.0001)); + expect(camera.pitch, closeTo(cameraOptions.pitch!, 0.0001)); + expect(camera.bearing, closeTo(cameraOptions.bearing!, 0.0001)); + }); + }); +} diff --git a/mapbox_maps_flutter_v3/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/mapbox_maps_flutter_v3/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index f0bf926d2..a37adb51b 100644 --- a/mapbox_maps_flutter_v3/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/mapbox_maps_flutter_v3/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-common-ios.git", "state" : { - "revision" : "6efcdd6ca3ded3647f3ff897845c679d52dd625a", - "version" : "24.12.0-rc.1" + "revision" : "316a4f97bcf45aaae632327b69fac545cc38e42f", + "version" : "24.12.0" } }, { @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-core-maps-ios.git", "state" : { - "revision" : "bfb41b136ecd52b45e35fe25b1b4840309a3994d", - "version" : "11.12.0-rc.1" + "revision" : "853cfc3c431d42291e1c4a0d550fc8cf6ea90015", + "version" : "11.12.0" } }, { @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-maps-ios.git", "state" : { - "revision" : "5f46396a6816c6d89a4ca8df39c22db2f9f9e3d2", - "version" : "11.12.0-rc.1" + "revision" : "c141954157c3aaf09bc1bc3d233239666421b96e", + "version" : "11.12.0" } }, { diff --git a/mapbox_maps_flutter_v3/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved b/mapbox_maps_flutter_v3/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved index f0bf926d2..a37adb51b 100644 --- a/mapbox_maps_flutter_v3/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/mapbox_maps_flutter_v3/example/ios/Runner.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-common-ios.git", "state" : { - "revision" : "6efcdd6ca3ded3647f3ff897845c679d52dd625a", - "version" : "24.12.0-rc.1" + "revision" : "316a4f97bcf45aaae632327b69fac545cc38e42f", + "version" : "24.12.0" } }, { @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-core-maps-ios.git", "state" : { - "revision" : "bfb41b136ecd52b45e35fe25b1b4840309a3994d", - "version" : "11.12.0-rc.1" + "revision" : "853cfc3c431d42291e1c4a0d550fc8cf6ea90015", + "version" : "11.12.0" } }, { @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mapbox/mapbox-maps-ios.git", "state" : { - "revision" : "5f46396a6816c6d89a4ca8df39c22db2f9f9e3d2", - "version" : "11.12.0-rc.1" + "revision" : "c141954157c3aaf09bc1bc3d233239666421b96e", + "version" : "11.12.0" } }, { diff --git a/mapbox_maps_flutter_v3/example/lib/main.dart b/mapbox_maps_flutter_v3/example/lib/main.dart index ae7879e15..ba69b26da 100644 --- a/mapbox_maps_flutter_v3/example/lib/main.dart +++ b/mapbox_maps_flutter_v3/example/lib/main.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; +import 'utils.dart'; + void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); @@ -18,18 +20,36 @@ class _MyAppState extends State { "MAPBOX_ACCESS_TOKEN", ); + late final MapboxMap _mapboxMap; + @override void initState() { super.initState(); MapboxOptions.setAccessToken(ACCESS_TOKEN); } + _onMapCreated(MapboxMap mapboxMap) { + _mapboxMap = mapboxMap; + + Future.delayed(const Duration(seconds: 2), () { + _mapboxMap.setCamera( + CameraOptions( + center: City.saigon, + ), + ); + }); + } + @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Example app')), - body: Center(child: MapWidget()), + body: Center( + child: MapWidget( + cameraOptions: CameraOptions(center: City.helsinki, zoom: 6), + onMapCreated: _onMapCreated, + )), ), ); } diff --git a/mapbox_maps_flutter_v3/example/lib/utils.dart b/mapbox_maps_flutter_v3/example/lib/utils.dart new file mode 100644 index 000000000..4aabe8e70 --- /dev/null +++ b/mapbox_maps_flutter_v3/example/lib/utils.dart @@ -0,0 +1,7 @@ +import 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; + +extension City on Point { + static Point get helsinki => + Point(coordinates: Position.of([24.941, 60.173])); + static Point get saigon => Point(coordinates: Position.of([106.700, 10.776])); +} diff --git a/mapbox_maps_flutter_v3/example/pubspec.lock b/mapbox_maps_flutter_v3/example/pubspec.lock index 7855744a1..24048737d 100644 --- a/mapbox_maps_flutter_v3/example/pubspec.lock +++ b/mapbox_maps_flutter_v3/example/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: transitive description: name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.12.0" benchmark: dependency: transitive description: @@ -77,10 +77,10 @@ packages: dependency: transitive description: name: fake_async - sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" url: "https://pub.dev" source: hosted - version: "1.3.3" + version: "1.3.2" file: dependency: transitive description: @@ -404,10 +404,10 @@ packages: dependency: transitive description: name: webdriver - sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade" + sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.0.4" sdks: dart: ">=3.7.0-0 <4.0.0" flutter: ">=3.27.0" diff --git a/mapbox_maps_flutter_v3/example/test/widget_test.dart b/mapbox_maps_flutter_v3/example/test/widget_test.dart index c4bfe976d..5f3efff37 100644 --- a/mapbox_maps_flutter_v3/example/test/widget_test.dart +++ b/mapbox_maps_flutter_v3/example/test/widget_test.dart @@ -18,8 +18,8 @@ void main() { // Verify that platform version is retrieved. expect( find.byWidgetPredicate( - (Widget widget) => widget is Text && - widget.data!.startsWith('Running on:'), + (Widget widget) => + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/mapbox_maps_flutter_v3/lib/mapbox_maps_flutter_v3.dart b/mapbox_maps_flutter_v3/lib/mapbox_maps_flutter_v3.dart index f10cc7014..641ee72f2 100644 --- a/mapbox_maps_flutter_v3/lib/mapbox_maps_flutter_v3.dart +++ b/mapbox_maps_flutter_v3/lib/mapbox_maps_flutter_v3.dart @@ -1,9 +1,6 @@ library; -import 'dart:io'; +export 'src/map_widget.dart'; +export 'src/mapbox_options.dart'; -import 'package:flutter/material.dart'; -import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; - -part 'src/map_widget.dart'; -part 'src/mapbox_options.dart'; +export 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; diff --git a/mapbox_maps_flutter_v3/lib/src/map_widget.dart b/mapbox_maps_flutter_v3/lib/src/map_widget.dart index ec6181ee7..5cc7f2e2a 100644 --- a/mapbox_maps_flutter_v3/lib/src/map_widget.dart +++ b/mapbox_maps_flutter_v3/lib/src/map_widget.dart @@ -1,12 +1,56 @@ -part of 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; +import 'package:flutter/widgets.dart'; +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; +typedef MapboxMap = MapboxMapInterface; + +/// A widget that displays a Mapbox map using the Mapbox Maps Flutter SDK. +/// +/// You use this class to display map information and to manipulate the map contents from your application. +/// You can center the map on a given coordinate, specify the size of the area you want to display, +/// and style the features of the map to fit your application's use case. +/// +/// Use of MapWidget requires a Mapbox API access token. +/// Obtain an access token on the [Mapbox account page](https://www.mapbox.com/studio/account/tokens/). +/// +/// Warning: Please note that you are responsible for getting permission to use the map data, +/// and for ensuring your use adheres to the relevant terms of use. +/// +/// ### Example: +/// ```dart +/// MapWidget( +/// cameraOptions: CameraOptions( +/// center: Point(37.7749, -122.4194), +/// zoom: 12.0, +/// ), +/// onMapCreated: (mapboxMap) { +/// // Handle map creation logic here. +/// }, +/// ) +/// ``` class MapWidget extends StatelessWidget { final MapboxMapsFlutterPlatform _platform; - MapWidget({super.key}) : _platform = MapboxMapsFlutterPlatform.instance; + /// The initial Camera options when creating a MapWidget. + final CameraOptions? cameraOptions; + + /// Callback that is triggered when the map has been successfully created. + /// + /// This provides an opportunity to perform additional setup or configuration + /// once the map is ready. The [OnMapCreated] callback can be used to access + /// the [MapboxMap] instance and interact with it. + final OnMapCreated? onMapCreated; + + MapWidget({ + super.key, + this.cameraOptions, + this.onMapCreated, + }) : _platform = MapboxMapsFlutterPlatform.instance; @override Widget build(BuildContext context) { - return _platform.buildView(); + return _platform.buildView( + cameraOptions: cameraOptions, + onMapCreated: onMapCreated, + ); } } diff --git a/mapbox_maps_flutter_v3/lib/src/mapbox_options.dart b/mapbox_maps_flutter_v3/lib/src/mapbox_options.dart index bb65344bf..a179cfd34 100644 --- a/mapbox_maps_flutter_v3/lib/src/mapbox_options.dart +++ b/mapbox_maps_flutter_v3/lib/src/mapbox_options.dart @@ -1,4 +1,4 @@ -part of 'package:mapbox_maps_flutter_v3/mapbox_maps_flutter_v3.dart'; +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; /// A class that provides options and configurations for Mapbox services. /// diff --git a/mapbox_maps_flutter_web/example/pubspec.lock b/mapbox_maps_flutter_web/example/pubspec.lock index c62789efa..d7ec1b519 100644 --- a/mapbox_maps_flutter_web/example/pubspec.lock +++ b/mapbox_maps_flutter_web/example/pubspec.lock @@ -1,14 +1,30 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + args: + dependency: transitive + description: + name: args + sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04 + url: "https://pub.dev" + source: hosted + version: "2.7.0" async: dependency: transitive description: name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + sha256: d2872f9c19731c2e5f10444b14686eb7cc85c76274bd6c16e1816bff9a3bab63 url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.12.0" + benchmark: + dependency: transitive + description: + name: benchmark + sha256: cb3eeea01e3f054df76ee9775ca680f3afa5f19f39b2bb426ba78ba27654493b + url: "https://pub.dev" + source: hosted + version: "0.3.0" boolean_selector: dependency: transitive description: @@ -49,14 +65,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + dart_sort_queue: + dependency: transitive + description: + name: dart_sort_queue + sha256: f3353ba8b4850e072d3368757f62edb79af34a9703c3e3df9c59342721f5f5b1 + url: "https://pub.dev" + source: hosted + version: "0.0.2+3" fake_async: dependency: transitive description: name: fake_async - sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc" url: "https://pub.dev" source: hosted - version: "1.3.3" + version: "1.3.2" file: dependency: transitive description: @@ -98,11 +122,27 @@ packages: description: flutter source: sdk version: "0.0.0" + geotypes: + dependency: transitive + description: + name: geotypes + sha256: "5bedf57de92283133dd221e363812ef50eaaba414f0823b1974ef7d84b86991f" + url: "https://pub.dev" + source: hosted + version: "0.0.2" integration_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" leak_tracker: dependency: transitive description: @@ -205,6 +245,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.3" + rbush: + dependency: transitive + description: + name: rbush + sha256: "48b683421b4afb43a642f82c6aa31911e54f3069143d31c7d33cbe329df13403" + url: "https://pub.dev" + source: hosted + version: "1.1.1" sky_engine: dependency: transitive description: flutter @@ -242,6 +290,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.1" + sweepline_intersections: + dependency: transitive + description: + name: sweepline_intersections + sha256: a665c707200a4f07140a4029b41a7c4883beb3f04322cd8e08ebf650f69e1176 + url: "https://pub.dev" + source: hosted + version: "0.0.4" sync_http: dependency: transitive description: @@ -266,6 +322,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.4" + turf: + dependency: transitive + description: + name: turf + sha256: "75347c45a5c1de805db7cb182286f05a3770e01546626c4dc292709d15cbe436" + url: "https://pub.dev" + source: hosted + version: "0.0.10" + turf_equality: + dependency: transitive + description: + name: turf_equality + sha256: f0f44ffe389547941358e0d3d4a747db2bd56115b32ff1cede5e5bdf3126a3e2 + url: "https://pub.dev" + source: hosted + version: "0.1.0" + turf_pip: + dependency: transitive + description: + name: turf_pip + sha256: ba4fd414baffd5d7b30880658ad6db82461c49ec023f8ffd0c23d398ad8b14be + url: "https://pub.dev" + source: hosted + version: "0.0.2" vector_math: dependency: transitive description: @@ -294,10 +374,10 @@ packages: dependency: transitive description: name: webdriver - sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade" + sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.0.4" sdks: dart: ">=3.7.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/mapbox_maps_flutter_web/example/test/widget_test.dart b/mapbox_maps_flutter_web/example/test/widget_test.dart index bcec5bab4..df76b5acc 100644 --- a/mapbox_maps_flutter_web/example/test/widget_test.dart +++ b/mapbox_maps_flutter_web/example/test/widget_test.dart @@ -18,8 +18,8 @@ void main() { // Verify that platform version is retrieved. expect( find.byWidgetPredicate( - (Widget widget) => widget is Text && - widget.data!.startsWith('Running on:'), + (Widget widget) => + widget is Text && widget.data!.startsWith('Running on:'), ), findsOneWidget, ); diff --git a/mapbox_maps_flutter_web/lib/src/bindings.dart b/mapbox_maps_flutter_web/lib/src/bindings.dart index 44394d9a0..2370856ea 100644 --- a/mapbox_maps_flutter_web/lib/src/bindings.dart +++ b/mapbox_maps_flutter_web/lib/src/bindings.dart @@ -8,13 +8,66 @@ import 'package:web/web.dart'; @JS() external String accessToken; +@JS() +@anonymous +extension type LngLat._(JSObject _) implements JSObject { + external LngLat(num lng, num lat); + external num lat; + external num lng; +} + +@JS() +@anonymous +extension type CameraOptions._(JSObject _) implements JSObject { + external factory CameraOptions({ + LngLat? center, + PaddingOptions? padding, + double? zoom, + double? bearing, + double? pitch, + }); + external LngLat? center; + external PaddingOptions? padding; + external double? zoom; + external double? bearing; + external double? pitch; +} + +@JS() +@anonymous +extension type PaddingOptions._(JSObject _) implements JSObject { + external factory PaddingOptions({ + num top, + num left, + num bottom, + num right, + }); + external num top; + external num left; + external num bottom; + external num right; +} + @JS() @anonymous extension type MapOptions._(JSObject _) implements JSObject { - external factory MapOptions({required HTMLDivElement container}); + external factory MapOptions({ + required HTMLDivElement container, + LngLat? center, + PaddingOptions? padding, + double? zoom, + double? bearing, + double? pitch, + }); } extension type Map._(JSObject _) implements JSObject { external Map(MapOptions container); external void on(String event, JSFunction callback); + external void jumpTo(CameraOptions camera); + external LngLat getCenter(); + external PaddingOptions getPadding(); + external double getZoom(); + external double getBearing(); + external double getPitch(); } diff --git a/mapbox_maps_flutter_web/lib/src/conversion.dart b/mapbox_maps_flutter_web/lib/src/conversion.dart new file mode 100644 index 000000000..1846add2e --- /dev/null +++ b/mapbox_maps_flutter_web/lib/src/conversion.dart @@ -0,0 +1,36 @@ +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; +import 'package:mapbox_maps_flutter_web/src/bindings.dart'; + +extension PointToLngLat on Point { + LngLat toLngLat() { + return LngLat(coordinates.lng, coordinates.lat); + } +} + +extension LngLatToPoint on LngLat { + Point toPoint() { + return Point(coordinates: Position(lng, lat)); + } +} + +extension PaddingOptionsToMbxEdgeInsets on PaddingOptions { + MbxEdgeInsets toMbxEdgeInsets() { + return MbxEdgeInsets( + top: top.toDouble(), + left: left.toDouble(), + bottom: bottom.toDouble(), + right: right.toDouble(), + ); + } +} + +extension MbxEdgeInsetsToPaddingOptions on MbxEdgeInsets { + PaddingOptions toPaddingOptions() { + return PaddingOptions( + top: top, + left: left, + bottom: bottom, + right: right, + ); + } +} diff --git a/mapbox_maps_flutter_web/lib/src/mapbox_map.dart b/mapbox_maps_flutter_web/lib/src/mapbox_map.dart new file mode 100644 index 000000000..45cf2657e --- /dev/null +++ b/mapbox_maps_flutter_web/lib/src/mapbox_map.dart @@ -0,0 +1,45 @@ +import 'dart:js_interop'; + +import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; +import 'package:mapbox_maps_flutter_web/src/bindings.dart' as gl_js; +import 'package:mapbox_maps_flutter_web/src/conversion.dart'; + +final class MapboxMap extends MapboxMapInterface { + final gl_js.Map nativeMap; + + MapboxMap(this.nativeMap); + + @override + Future getCameraState() { + final camera = CameraState( + center: nativeMap.getCenter().toPoint(), + padding: nativeMap.getPadding().toMbxEdgeInsets(), + zoom: nativeMap.getZoom(), + bearing: nativeMap.getBearing(), + pitch: nativeMap.getPitch(), + ); + return Future.value(camera); + } + + @override + Future setCamera(CameraOptions cameraOptions) { + final options = gl_js.CameraOptions(); + if (cameraOptions.center != null) { + options.center = cameraOptions.center!.toLngLat(); + } + if (cameraOptions.padding != null) { + options.padding = cameraOptions.padding!.toPaddingOptions(); + } + if (cameraOptions.zoom != null) { + options.zoom = cameraOptions.zoom; + } + if (cameraOptions.bearing != null) { + options.bearing = cameraOptions.bearing; + } + if (cameraOptions.pitch != null) { + options.pitch = cameraOptions.pitch; + } + nativeMap.jumpTo(options); + return Future.value(); + } +} diff --git a/mapbox_maps_flutter_web/lib/src/mapbox_maps_flutter_web.dart b/mapbox_maps_flutter_web/lib/src/mapbox_maps_flutter_web.dart index 22deedc59..12b05b150 100644 --- a/mapbox_maps_flutter_web/lib/src/mapbox_maps_flutter_web.dart +++ b/mapbox_maps_flutter_web/lib/src/mapbox_maps_flutter_web.dart @@ -4,7 +4,9 @@ import 'dart:ui_web'; import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:mapbox_maps_flutter_interface/mapbox_maps_flutter_interface.dart'; -import 'package:mapbox_maps_flutter_web/src/bindings.dart'; +import 'package:mapbox_maps_flutter_web/src/bindings.dart' as gl_js; +import 'package:mapbox_maps_flutter_web/src/conversion.dart'; +import 'package:mapbox_maps_flutter_web/src/mapbox_map.dart'; import 'package:web/web.dart'; const mapboxGlCss = 'https://api.mapbox.com/mapbox-gl-js/v3.11.1/mapbox-gl.css'; @@ -18,48 +20,64 @@ base class MapboxMapsFlutterWeb extends MapboxMapsFlutterPlatform { late HTMLDivElement _mapElement; @override - Widget buildView() { + Widget buildView({ + CameraOptions? cameraOptions, + OnMapCreated? onMapCreated, + }) { final viewType = 'mapbox-maps-flutter-web/$hashCode'; // Attach the mapDiv to the DOM platformViewRegistry.registerViewFactory(viewType, (int id) { - _mapElement = - document.createElement("div") as HTMLDivElement - ..style.position = 'absolute' - ..style.top = '0' - ..style.bottom = '0' - ..style.height = '100%' - ..style.width = '100%'; + _mapElement = document.createElement("div") as HTMLDivElement + ..style.position = 'absolute' + ..style.top = '0' + ..style.bottom = '0' + ..style.height = '100%' + ..style.width = '100%'; - _initMap(); + _initMap( + cameraOptions: cameraOptions, + onMapCreated: onMapCreated, + ); return _mapElement; }); return HtmlElementView(viewType: viewType); } - _initMap() async { - final link = - document.createElement('link') as HTMLLinkElement - ..rel = 'stylesheet' - ..href = mapboxGlCss - ..type = 'text/css'; + _initMap({ + CameraOptions? cameraOptions, + OnMapCreated? onMapCreated, + }) async { + final link = document.createElement('link') as HTMLLinkElement + ..rel = 'stylesheet' + ..href = mapboxGlCss + ..type = 'text/css'; _mapElement.append(link); await link.onLoad.first; - final options = MapOptions(container: _mapElement); - final nativeMap = Map(options); + final options = gl_js.MapOptions( + container: _mapElement, + center: cameraOptions?.center?.toLngLat(), + padding: cameraOptions?.padding?.toPaddingOptions(), + zoom: cameraOptions?.zoom, + bearing: cameraOptions?.bearing, + pitch: cameraOptions?.pitch, + ); + final nativeMap = gl_js.Map(options); + + onMapCreated?.call(MapboxMap(nativeMap)); nativeMap.on('load', (() {}).toJS); } @override Future getAccessToken() { - return Future.value(accessToken); + return Future.value(gl_js.accessToken); } @override void setAccessToken(String token) { - accessToken = token; + gl_js.accessToken = token; } } diff --git a/scripts/check_test_suite.dart b/scripts/check_test_suite.dart index 316a4d559..c4ad7b23f 100644 --- a/scripts/check_test_suite.dart +++ b/scripts/check_test_suite.dart @@ -32,15 +32,18 @@ void main() { .where((testFile) => !includedTestFiles.contains(testFile)) .toList(); - missingTests.remove('all_test.dart'); // Exclude the aggregated test suite file itself + missingTests + .remove('all_test.dart'); // Exclude the aggregated test suite file itself if (missingTests.isNotEmpty) { - print('The following test files are missing from the aggregated test suite:'); + print( + 'The following test files are missing from the aggregated test suite:'); for (var missingTest in missingTests) { print(missingTest); } print(''); - print('Import the missing test files in the integration_test/all_test.dart.'); + print( + 'Import the missing test files in the integration_test/all_test.dart.'); print("Don't forget to invoke the main function of the test file as well."); exit(1); // Exit with error code 1 if there are missing tests } else {