Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

upgrade-ios-version #277

Merged
merged 11 commits into from
Aug 15, 2023
3 changes: 1 addition & 2 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ source 'https://cdn.cocoapods.org/'
source 'https://github.com/m0nac0/flutter-maplibre-podspecs.git'

# Uncomment this line to define a global platform for your project
platform :ios, '11.0'
platform :ios, '12.0'
stefanschaller marked this conversation as resolved.
Show resolved Hide resolved

pod 'MapLibre'
pod 'MapLibreAnnotationExtension'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
22 changes: 10 additions & 12 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ PODS:
- Flutter (1.0.0)
- location (0.0.1):
- Flutter
- MapLibre (5.12.2)
- MapboxMobileEvents (0.10.11)
- MapLibre (5.14.0-pre1):
- MapboxMobileEvents (= 0.10.11)
- maplibre_gl (0.0.1):
- Flutter
- MapLibre (~> 5.12.2)
- MapLibreAnnotationExtension (~> 0.0.1-beta.2)
- MapLibreAnnotationExtension (0.0.1-beta.2):
- MapLibre (~> 5.12.0)
- MapLibre (= 5.14.0-pre1)
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -21,13 +20,12 @@ DEPENDENCIES:
- location (from `.symlinks/plugins/location/ios`)
- MapLibre
- maplibre_gl (from `.symlinks/plugins/maplibre_gl/ios`)
- MapLibreAnnotationExtension
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)

SPEC REPOS:
https://github.com/m0nac0/flutter-maplibre-podspecs.git:
trunk:
- MapboxMobileEvents
- MapLibre
- MapLibreAnnotationExtension

EXTERNAL SOURCES:
device_info_plus:
Expand All @@ -45,11 +43,11 @@ SPEC CHECKSUMS:
device_info_plus: 7545d84d8d1b896cb16a4ff98c19f07ec4b298ea
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
location: 3a2eed4dd2fab25e7b7baf2a9efefe82b512d740
MapLibre: 5aa820115d91293a4d09e681e7470f88bd34b672
maplibre_gl: 2a0ce99f40b3a133b0e8b40b5ef37e0562165399
MapLibreAnnotationExtension: bc7f1041206218d7d24ba0908e3145cd54b86664
MapboxMobileEvents: 1176afebbeca86806614a3dc409840bc02a3dd89
stefanschaller marked this conversation as resolved.
Show resolved Hide resolved
MapLibre: 6cc3261b33747cb91ce83055ec13dc5da2473270
maplibre_gl: 7ea8a4355da59ba13294760193f1dcc31b9101e8
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9

PODFILE CHECKSUM: a908f6081c2697d922d17bcdb852cad068049f2e
PODFILE CHECKSUM: 00bbce151cce7e3542226c3dbb2422a2cb667d7a

COCOAPODS: 1.12.1
7 changes: 5 additions & 2 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/MapLibreAnnotationExtension-framework/MapLibreAnnotationExtension.framework",
"${BUILT_PRODUCTS_DIR}/MapboxMobileEvents-framework/MapboxMobileEvents.framework",
"${BUILT_PRODUCTS_DIR}/device_info_plus/device_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/location/location.framework",
"${BUILT_PRODUCTS_DIR}/maplibre_gl/maplibre_gl.framework",
Expand All @@ -258,7 +258,7 @@
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapLibreAnnotationExtension.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/location.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/maplibre_gl.framework",
Expand Down Expand Up @@ -382,6 +382,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -513,6 +514,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -540,6 +542,7 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
20 changes: 10 additions & 10 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,6 +24,14 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MGLMapboxMetricsEnabledSettingShownInApp</key>
<true/>
<key>NSLocationAlwaysUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,15 +53,5 @@
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>MGLMapboxMetricsEnabledSettingShownInApp</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Shows your location on the map and helps improve the map</string>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
9 changes: 9 additions & 0 deletions example/lib/animate_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ class AnimateCameraState extends State<AnimateCamera> {
},
child: const Text('zoomBy with focus'),
),
TextButton(
onPressed: () {
mapController.animateCamera(
CameraUpdate.newLatLngZoom(const LatLng(48, 11), 5),
duration: const Duration(milliseconds: 300),
);
},
child: const Text('latlngZoom'),
),
TextButton(
onPressed: () {
mapController.animateCamera(
Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:device_info_plus/device_info_plus.dart';
import 'package:maplibre_gl_example/get_map_informations.dart';
import 'package:maplibre_gl_example/given_bounds.dart';
import 'package:maplibre_gl_example/no_location_permission_page.dart';
import 'package:maplibre_gl_example/trip_calculation_example.dart';

import 'animate_camera.dart';
import 'annotation_order_maps.dart';
Expand All @@ -35,6 +36,7 @@ import 'sources.dart';
import 'package:maplibre_gl/mapbox_gl.dart';

final List<ExamplePage> _allPages = <ExamplePage>[
const TripCalculationPage(),
const MapUiPage(),
const FullMapPage(),
const AnimateCameraPage(),
Expand Down
215 changes: 215 additions & 0 deletions example/lib/trip_calculation_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import 'dart:async';
import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:maplibre_gl/mapbox_gl.dart';
import 'package:maplibre_gl_example/page.dart';

class TripCalculationPage extends ExamplePage {
const TripCalculationPage({super.key})
: super(const Icon(Icons.trip_origin), 'Trip calculation example');
stefanschaller marked this conversation as resolved.
Show resolved Hide resolved

@override
Widget build(BuildContext context) {
return const TripCalculationExampleBody();
}
}

class TripCalculationExampleBody extends StatefulWidget {
const TripCalculationExampleBody({super.key});

@override
State<TripCalculationExampleBody> createState() =>
_TripCalculationExampleBodyState();
}

class _TripCalculationExampleBodyState
extends State<TripCalculationExampleBody> {
final _controllerCompleter = Completer<MaplibreMapController>();
LatLng? origin;
Symbol? originSymbol;

LatLng? destination;
Symbol? destinationSymbol;
Line? _route;

final _boundingBox = BoundingBoxConstraint();

@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
MaplibreMap(
trackCameraPosition: true,
tiltGesturesEnabled: false,
myLocationEnabled: false,
compassEnabled: false,
cameraTargetBounds: _boundingBox.bounds,
minMaxZoomPreference: _boundingBox.zoomPreference,
initialCameraPosition: const CameraPosition(
target: LatLng(50.834060793873505, 4.340443996254663),
zoom: 12,
),
onMapCreated: (controller) =>
_controllerCompleter.complete(controller),
onMapClick: _onMapClick,
),
SafeArea(
child: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (origin != null && destination != null) ...[
ElevatedButton.icon(
onPressed: _calculateRoute,
icon: const Icon(Icons.play_arrow),
label: const Text("Calculate Route"),
),
ElevatedButton.icon(
onPressed: _reset,
icon: const Icon(Icons.delete),
label: const Text("Reset"),
),
],
if (origin == null && destination == null) ...[
const Card(
child: Padding(
padding: EdgeInsets.all(8),
child: Text("Tap on the screen to select a point"),
),
),
],
],
),
),
),
],
),
);
}

bool _didAddImage = false;

Future<void> _onMapClick(Point<double> point, LatLng coordinate) async {
final controller = await _controllerCompleter.future;
if (!mounted) return;

const markerImageName = "custom-marker";

if (!_didAddImage) {
final bytes = await rootBundle.load("assets/symbols/custom-marker.png");
await controller.addImage(markerImageName, bytes.buffer.asUint8List());
}

final symbolOptions = SymbolOptions(
geometry: coordinate,
iconSize: 1.4,
iconImage: markerImageName,
);

if (origin == null) {
originSymbol = await controller.addSymbol(symbolOptions);
setState(() => origin = coordinate);
} else {
if (destinationSymbol != null) {
await controller.removeSymbol(destinationSymbol!);
}
destinationSymbol = await controller.addSymbol(symbolOptions);
setState(() => destination = coordinate);
}

var zoom = controller.cameraPosition?.zoom ?? 0;

const targetZoom = 16.5;
final zoomDiff = (zoom - targetZoom).abs();
if (zoomDiff <= 2) {
await controller.animateCamera(CameraUpdate.newLatLng(coordinate));
} else {
await controller
.animateCamera(CameraUpdate.newLatLngZoom(coordinate, targetZoom));
}
}

Future<void> _reset() async {
final controller = await _controllerCompleter.future;
if (!mounted) return;
await controller.removeSymbols(
[originSymbol, destinationSymbol].whereNotNull().toList());
if (_route != null) {
await controller.removeLine(_route!);
}

setState(() {
origin = null;
destination = null;
});
}

Future<void> _calculateRoute() async {
if (_route != null) return;

final controller = await _controllerCompleter.future;
if (!mounted) return;

final points = [origin!, destination!];
final route = await controller.addLine(LineOptions(geometry: points));
controller.animateCamera(
CameraUpdate.newLatLngBounds(
points.convertToBounds(),
top: 24 + MediaQuery.of(context).padding.top + kToolbarHeight,
left: 64,
right: 64,
bottom: 300,
),
duration: const Duration(seconds: 2),
);
if (!mounted) return;

setState(() => _route = route);
}
}

extension on List<LatLng> {
// https://stackoverflow.com/a/66545600/9277334
LatLngBounds convertToBounds() {
final route = this;

assert(route.isNotEmpty);
final firstLatLng = route.first;
var s = firstLatLng.latitude,
n = firstLatLng.latitude,
w = firstLatLng.longitude,
e = firstLatLng.longitude;
for (var i = 1; i < route.length; i++) {
final latlng = this[i];
s = min(s, latlng.latitude);
n = max(n, latlng.latitude);
w = min(w, latlng.longitude);
e = max(e, latlng.longitude);
}
return LatLngBounds(southwest: LatLng(s, w), northeast: LatLng(n, e));
}
}

class BoundingBoxConstraint {
// From: https://gist.github.com/graydon/11198540
final _mobileMapBounds = CameraTargetBounds(
LatLngBounds(
northeast: const LatLng(51.4750237087, 6.15665815596),
southwest: const LatLng(49.5294835476, 2.51357303225),
),
);

/// If this is not added, the user could zoom out way too much, that almost everything
/// of the world is visible, but we don't have the whole world rendered.
final zoomPreference = const MinMaxZoomPreference(5.85, 25);

CameraTargetBounds get bounds {
return _mobileMapBounds;
}
}
1 change: 0 additions & 1 deletion ios/Classes/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Mapbox
import MapLibreAnnotationExtension

/*
* The mapping is based on the values defined here:
Expand Down
Loading
Loading