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>
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
29 changes: 15 additions & 14 deletions ios/Classes/Convert.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Mapbox
import MapLibreAnnotationExtension

class Convert {
class func interpretMapboxMapOptions(options: Any?, delegate: MapboxMapOptionsSink) {
Expand Down Expand Up @@ -71,6 +70,19 @@ class Convert {
delegate.setAttributionButtonPosition(position: position)
}
}

class func parseCameraPadding(cameraUpdate: [Any]) -> UIEdgeInsets? {
if cameraUpdate.count < 6 {
return nil
}

guard let paddingLeft = cameraUpdate[2] as? CGFloat else { return nil }
guard let paddingTop = cameraUpdate[3] as? CGFloat else { return nil }
guard let paddingRight = cameraUpdate[4] as? CGFloat else { return nil }
guard let paddingBottom = cameraUpdate[5] as? CGFloat else { return nil }

return UIEdgeInsets(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight)
}

class func parseCameraUpdate(cameraUpdate: [Any], mapView: MGLMapView) -> MGLMapCamera? {
guard let type = cameraUpdate[0] as? String else { return nil }
Expand All @@ -85,19 +97,8 @@ class Convert {
return camera
case "newLatLngBounds":
guard let bounds = cameraUpdate[1] as? [[Double]] else { return nil }
guard let paddingLeft = cameraUpdate[2] as? CGFloat else { return nil }
guard let paddingTop = cameraUpdate[3] as? CGFloat else { return nil }
guard let paddingRight = cameraUpdate[4] as? CGFloat else { return nil }
guard let paddingBottom = cameraUpdate[5] as? CGFloat else { return nil }
return mapView.cameraThatFitsCoordinateBounds(
MGLCoordinateBounds.fromArray(bounds),
edgePadding: UIEdgeInsets(
top: paddingTop,
left: paddingLeft,
bottom: paddingBottom,
right: paddingRight
)
)

return mapView.cameraThatFitsCoordinateBounds(MGLCoordinateBounds.fromArray(bounds))
case "newLatLngZoom":
guard let coordinate = cameraUpdate[1] as? [Double] else { return nil }
guard let zoom = cameraUpdate[2] as? Double else { return nil }
Expand Down
1 change: 0 additions & 1 deletion ios/Classes/LayerPropertyConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// ./scripts/lib/generate.dart

import Mapbox
import MapLibreAnnotationExtension

class LayerPropertyConverter {
class func addSymbolProperties(symbolLayer: MGLSymbolStyleLayer, properties: [String: String]) {
Expand Down
68 changes: 25 additions & 43 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Flutter
import Mapbox
import MapLibreAnnotationExtension

class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, MapboxMapOptionsSink,
UIGestureRecognizerDelegate
Expand Down Expand Up @@ -85,6 +84,9 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
direction: camera.heading,
animated: false
)
if let bounds = cameraTargetBounds {
mapView.setLatLngBounds(bounds)
}
initialTilt = camera.pitch
}
// if let onAttributionClickOverride = args["onAttributionClickOverride"] as? Bool {
Expand All @@ -106,11 +108,6 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
mapView.addGestureRecognizer(pan)
}
}
func removeAllForController(controller: MGLAnnotationController, ids: [String]){
let idSet = Set(ids)
let annotations = controller.styleAnnotations()
controller.removeStyleAnnotations(annotations.filter { idSet.contains($0.identifier) })
}

func gestureRecognizer(
_: UIGestureRecognizer,
Expand Down Expand Up @@ -310,6 +307,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
case "camera#move":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return }

if let camera = Convert
.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView)
{
Expand All @@ -319,19 +317,25 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
case "camera#animate":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return }
if let camera = Convert
.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView)
{
if let duration = arguments["duration"] as? TimeInterval {
mapView.setCamera(camera, withDuration: TimeInterval(duration / 1000),
animationTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName
.easeInEaseOut))
result(nil)
guard let camera = Convert.parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) else { return }


let completion = {
result(nil)
}

if let duration = arguments["duration"] as? TimeInterval {
if let padding = Convert.parseCameraPadding(cameraUpdate: cameraUpdate) {
mapView.fly(to: camera, edgePadding: padding, withDuration: duration, completionHandler: completion)
} else {
mapView.setCamera(camera, animated: true)
mapView.fly(to: camera, withDuration: duration,completionHandler: completion)
}
} else {
mapView.setCamera(camera, animated: true)
completion()
}
result(nil)



case "symbolLayer#add":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
Expand Down Expand Up @@ -633,7 +637,6 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
if let maxzoom = maxzoom {
layer.maximumZoomLevel = Float(maxzoom)
}

mapView.style?.insertLayer(layer, below: belowLayer)
result(nil)

Expand Down Expand Up @@ -1037,32 +1040,6 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
return loadIconImage(name: name)
}

func mapView(_ mapView: MGLMapView, shouldChangeFrom _: MGLMapCamera,
to newCamera: MGLMapCamera) -> Bool
{
guard let bbox = cameraTargetBounds else { return true }

// Get the current camera to restore it after.
let currentCamera = mapView.camera

// From the new camera obtain the center to test if it’s inside the boundaries.
let newCameraCenter = newCamera.centerCoordinate

// Set the map’s visible bounds to newCamera.
mapView.camera = newCamera
let newVisibleCoordinates = mapView.visibleCoordinateBounds

// Revert the camera.
mapView.camera = currentCamera

// Test if the newCameraCenter and newVisibleCoordinates are inside bbox.
let inside = MGLCoordinateInCoordinateBounds(newCameraCenter, bbox)
let intersects = MGLCoordinateInCoordinateBounds(newVisibleCoordinates.ne, bbox) &&
MGLCoordinateInCoordinateBounds(newVisibleCoordinates.sw, bbox)

return inside && intersects
}

func mapView(_: MGLMapView, didUpdate userLocation: MGLUserLocation?) {
if let channel = channel, let userLocation = userLocation,
let location = userLocation.location
Expand Down Expand Up @@ -1475,6 +1452,11 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
*/
func setCameraTargetBounds(bounds: MGLCoordinateBounds?) {
cameraTargetBounds = bounds
if let bounds = bounds {
mapView.setLatLngBounds(bounds)
} else {
mapView.clearLatLnBounds()
}
}

func setCompassEnabled(compassEnabled: Bool) {
Expand Down
5 changes: 2 additions & 3 deletions ios/maplibre_gl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ A new Flutter plugin.
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'MapLibreAnnotationExtension', '~> 0.0.1-beta.2'
s.dependency 'MapLibre', '~> 5.12.2'
s.dependency 'MapLibre', '5.14.0-pre1'
s.swift_version = '4.2'
s.ios.deployment_target = '9.0'
s.ios.deployment_target = '12.0'
end