Skip to content

Commit 9b3e344

Browse files
authored
Merge branch 'main' into feat/android-hybrid-composition
2 parents 1e339df + 164a856 commit 9b3e344

16 files changed

+333
-31
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ jobs:
196196
# name: maplibre-flutter-demo.app
197197
# path: example/build/ios/iphonesimulator
198198
build-web:
199-
name: "Build web"
199+
name: "Build Web"
200200
runs-on: ubuntu-latest
201201
defaults:
202202
run:
@@ -215,3 +215,23 @@ jobs:
215215
run: dart pub get
216216
- name: Build web
217217
run: flutter build web
218+
build-web-wasm:
219+
name: "Build Web WASM"
220+
runs-on: ubuntu-latest
221+
defaults:
222+
run:
223+
working-directory: example
224+
strategy:
225+
fail-fast: false
226+
matrix:
227+
sdk: [ '3.24.3', '' ]
228+
steps:
229+
- uses: actions/checkout@v4
230+
- uses: subosito/flutter-action@v2
231+
with:
232+
flutter-version: ${{ matrix.sdk }}
233+
cache: true
234+
- name: "Get Flutter dependencies"
235+
run: dart pub get
236+
- name: Build web
237+
run: flutter build web --wasm

.github/workflows/flutter-beta.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
# name: maplibre-flutter-demo.app
5656
# path: example/build/ios/iphonesimulator
5757
build-web:
58-
name: "Build web"
58+
name: "Build Web"
5959
runs-on: ubuntu-latest
6060
defaults:
6161
run:
@@ -67,4 +67,18 @@ jobs:
6767
channel: ${{ env.FLUTTER_CHANNEL }}
6868
cache: true
6969
- name: Build web
70-
run: flutter build web
70+
run: flutter build web
71+
build-web-wasm:
72+
name: "Build Web WASM"
73+
runs-on: ubuntu-latest
74+
defaults:
75+
run:
76+
working-directory: example
77+
steps:
78+
- uses: actions/checkout@v4
79+
- uses: subosito/flutter-action@v2
80+
with:
81+
channel: ${{ env.FLUTTER_CHANNEL }}
82+
cache: true
83+
- name: Build web
84+
run: flutter build web --wasm

_headers

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
Cross-Origin-Embedder-Policy: credentialless
3+
Cross-Origin-Opener-Policy: same-origin

example/lib/controller_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ pitch: ${camera.pitch}'''),
147147
),
148148
),
149149
OutlinedButton(
150-
onPressed: () async {
151-
final region = await _controller.getVisibleRegion();
150+
onPressed: () {
151+
final region = _controller.getVisibleRegion();
152152
if (context.mounted) {
153153
ScaffoldMessenger.of(context)
154154
..hideCurrentSnackBar()

example/lib/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import 'package:maplibre_example/two_maps_page.dart';
2626
import 'package:maplibre_example/user_interface_page.dart';
2727
import 'package:maplibre_example/user_location_page.dart';
2828
import 'package:maplibre_example/web_controls_page.dart';
29+
import 'package:maplibre_example/widget_layer_page.dart';
2930

3031
void main() {
3132
runApp(const MyApp());
@@ -53,6 +54,7 @@ class MyApp extends StatelessWidget {
5354
StyledMapPage.location: (context) => const StyledMapPage(),
5455
UserLocationPage.location: (context) => const UserLocationPage(),
5556
UserInterfacePage.location: (context) => const UserInterfacePage(),
57+
WidgetLayerPage.location: (context) => const WidgetLayerPage(),
5658
OfflinePage.location: (context) => const OfflinePage(),
5759
PermissionsPage.location: (context) => const PermissionsPage(),
5860
LayersSymbolPage.location: (context) => const LayersSymbolPage(),

example/lib/menu_page.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import 'package:maplibre_example/two_maps_page.dart';
2525
import 'package:maplibre_example/user_interface_page.dart';
2626
import 'package:maplibre_example/user_location_page.dart';
2727
import 'package:maplibre_example/web_controls_page.dart';
28+
import 'package:maplibre_example/widget_layer_page.dart';
2829

2930
class MenuPage extends StatelessWidget {
3031
const MenuPage({super.key});
@@ -118,6 +119,11 @@ class MenuPage extends StatelessWidget {
118119
iconData: Icons.control_point_duplicate_outlined,
119120
location: AnnotationsMixedPage.location,
120121
),
122+
ItemCard(
123+
label: 'Widgets',
124+
iconData: Icons.location_on,
125+
location: WidgetLayerPage.location,
126+
),
121127
ItemCard(
122128
label: 'Circles',
123129
iconData: Icons.circle,

example/lib/widget_layer_page.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:maplibre/maplibre.dart';
3+
4+
@immutable
5+
class WidgetLayerPage extends StatefulWidget {
6+
const WidgetLayerPage({super.key});
7+
8+
static const location = '/widget-layer';
9+
10+
@override
11+
State<WidgetLayerPage> createState() => _WidgetLayerPageState();
12+
}
13+
14+
class _WidgetLayerPageState extends State<WidgetLayerPage> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
appBar: AppBar(title: const Text('Widget Layer')),
19+
body: MapLibreMap(
20+
options: MapOptions(
21+
initZoom: 3,
22+
initCenter: Position(0, 0),
23+
attribution: false,
24+
nativeCompass: false,
25+
nativeLogo: false,
26+
),
27+
children: [
28+
WidgetLayer(
29+
markers: [
30+
// A 3D marker
31+
Marker(
32+
size: const Size.square(50),
33+
point: Position(-10, 0),
34+
child:
35+
const Icon(Icons.location_on, color: Colors.red, size: 50),
36+
alignment: Alignment.bottomCenter,
37+
),
38+
Marker(
39+
size: const Size.square(50),
40+
point: Position(-5, 0),
41+
child:
42+
const Icon(Icons.location_on, color: Colors.red, size: 50),
43+
alignment: Alignment.bottomCenter,
44+
rotate: true,
45+
),
46+
Marker(
47+
size: const Size.square(50),
48+
point: Position(0, 0),
49+
child:
50+
const Icon(Icons.location_on, color: Colors.red, size: 50),
51+
alignment: Alignment.bottomCenter,
52+
flat: true,
53+
),
54+
Marker(
55+
size: const Size.square(50),
56+
point: Position(5, 0),
57+
child:
58+
const Icon(Icons.location_on, color: Colors.red, size: 50),
59+
alignment: Alignment.bottomCenter,
60+
flat: true,
61+
rotate: true,
62+
),
63+
],
64+
),
65+
// display the UI widgets above the widget markers.
66+
const SourceAttribution(),
67+
],
68+
),
69+
);
70+
}
71+
}

lib/maplibre.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export 'src/ui/map_zoom_buttons.dart';
2121
export 'src/ui/source_attribution.dart';
2222
export 'src/utils.dart';
2323
export 'src/web_controls.dart';
24+
export 'src/widget_layer.dart';

lib/src/map_controller.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ abstract interface class MapController {
1919
(throw StateError('Unable to find an instance of MapController'));
2020

2121
/// Convert a latitude/longitude coordinate to a screen location.
22+
// TODO: can be made sync when flutter raster and ui thread are merged
2223
Future<Offset> toScreenLocation(Position lngLat);
2324

2425
/// Get the latitude/longitude coordinate for a screen location.
26+
// TODO: can be made sync when flutter raster and ui thread are merged
2527
Future<Position> toLngLat(Offset screenLocation);
2628

29+
/// Convert a latitude/longitude coordinate to a screen location.
30+
// TODO: can be made sync when flutter raster and ui thread are merged
31+
Future<List<Offset>> toScreenLocations(List<Position> lngLats);
32+
33+
/// Get the latitude/longitude coordinate for a screen location.
34+
// TODO: can be made sync when flutter raster and ui thread are merged
35+
Future<List<Position>> toLngLats(List<Offset> screenLocations);
36+
2737
/// Instantly move the map camera to a new location.
2838
Future<void> moveCamera({
2939
Position? center,
@@ -90,12 +100,14 @@ abstract interface class MapController {
90100
/// The distance between pixels decreases as the latitude approaches the
91101
/// poles. This relationship parallels the relationship between longitudinal
92102
/// coordinates at different latitudes.
103+
// TODO: can be made sync when flutter raster and ui thread are merged
93104
Future<double> getMetersPerPixelAtLatitude(double latitude);
94105

95106
/// Get a list of all attributions from the map style.
96107
Future<List<String>> getAttributions();
97108

98109
/// The smallest bounding box that includes the visible region.
110+
// TODO: can be made sync when flutter raster and ui thread are merged
99111
Future<LngLatBounds> getVisibleRegion();
100112

101113
/// Add an image to the map.

lib/src/native/extensions.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ extension LngLatExt on pigeon.LngLat {
2424
/// Extension methods for the [jni.LatLng] class. Not exported publicly.
2525
extension JniLatLngExt on jni.LatLng {
2626
/// Convert an internal [jni.LatLng] to a [Position].
27-
Position toPosition() => Position(getLongitude(), getLatitude());
27+
Position toPosition({bool releaseOriginal = false}) {
28+
final position = Position(getLongitude(), getLatitude());
29+
if (releaseOriginal) release();
30+
return position;
31+
}
2832
}
2933

3034
/// Extension methods for the [jni.PointF] class. Not exported publicly.
3135
extension PointExt on jni.PointF {
3236
/// Convert an [jni.PointF] to a [Offset].
33-
Offset toOffset() => Offset(x, y);
37+
Offset toOffset({bool releaseOriginal = false}) {
38+
final offset = Offset(x, y);
39+
if (releaseOriginal) release();
40+
return offset;
41+
}
3442
}
3543

3644
/// Extension methods for the [Offset] class. Not exported publicly.

0 commit comments

Comments
 (0)