Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ jobs:
- name: Show toolchain
run: xcodebuild -version && swift --version

# Package.swift は `../ios-sdk-core` があればそれを使い、無ければ released 版
# (`from: "1.1.4"`)へ解決する。CI はこのリポジトリしか checkout しないので
# 常に released 版になり、**コアの未リリースな変更に追随する PR は永久に赤いまま**
# になっていた(CameraBearing をコアへ足したときに踏んだ)。
# 隣に置いてローカル開発と同じ経路に乗せる。同名ブランチがあればそちらを使う。
- name: Check out MapConductorCore next to this package
env:
HEAD_REF: ${{ github.head_ref }}
run: |
url=https://github.com/MapConductor/ios-sdk-core.git
if [ -n "$HEAD_REF" ] && git ls-remote --exit-code --heads "$url" "$HEAD_REF" >/dev/null 2>&1; then
echo "ios-sdk-core: matching branch $HEAD_REF"
git clone --depth 1 --branch "$HEAD_REF" "$url" ../ios-sdk-core
else
echo "ios-sdk-core: default branch"
git clone --depth 1 "$url" ../ios-sdk-core
fi
test -f ../ios-sdk-core/Package.swift

- name: Build
run: |
scheme=$(sed -n 's/^[[:space:]]*name: "\([^"]*\)".*/\1/p' Package.swift | head -1)
Expand Down
20 changes: 14 additions & 6 deletions Sources/MapConductorForMapKit/MapCameraPositionExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import MapKit
import MapConductorCore
@_spi(MapConductorDriver) import MapConductorCore

private let converter = MapKitZoomAltitudeConverter(zoom0Altitude: 171_319_879.0)
private let mapKitMaxPitch: Double = 80.9
Expand Down Expand Up @@ -30,7 +30,7 @@ public extension MapCameraPosition {
? Spherical.computeOffset(
origin: position,
distance: distance * tan(pitchRadians),
heading: bearing
heading: CameraBearing.toNativeHeading(bearing)
)
: position

Expand All @@ -42,7 +42,7 @@ public extension MapCameraPosition {
),
fromDistance: distance,
pitch: nativePitch,
heading: bearing
heading: CameraBearing.toNativeHeading(bearing)
)
}
}
Expand All @@ -54,7 +54,11 @@ public extension MKMapView {
visibleRegion: VisibleRegion? = nil
) -> MapCameraPosition {
let cameraAltitude = camera.altitude
let pitchRadians = camera.pitch * .pi / 180.0
// `MKMapCamera.pitch` は CGFloat。CGFloat と Double の暗黙変換に任せると
// CoreGraphics の `cos(CGFloat)` と Foundation の `cos(Double)` が両方候補になり、
// ツールチェーンによっては `ambiguous use of 'cos'` で落ちる(CI の macos-15 で踏んだ)。
// 手元の Xcode では通ってしまうので、Double へ明示的に寄せておく。
let pitchRadians = Double(camera.pitch) * .pi / 180.0
// Recover the slant distance set via MKMapCamera(fromDistance:) — the inverse of toMKMapCamera().
let slantDistance = cameraAltitude / max(cos(pitchRadians), minCosTilt)
var position = GeoPoint(
Expand Down Expand Up @@ -95,7 +99,7 @@ public extension MKMapView {
return MapCameraPosition(
position: position,
zoom: zoom,
bearing: camera.heading,
bearing: CameraBearing.bearingFromNativeHeading(camera.heading),
tilt: logicalTilt,
visibleRegion: visibleRegion
)
Expand Down Expand Up @@ -154,7 +158,11 @@ private extension MKMapView {
/// from whatever camera happens to be set and reused to place the next one.
func metersPerPointPerDistance() -> Double? {
guard let metersPerPoint = measuredMetersPerPointAtCenter() else { return nil }
let pitchRadians = camera.pitch * .pi / 180.0
// `MKMapCamera.pitch` は CGFloat。CGFloat と Double の暗黙変換に任せると
// CoreGraphics の `cos(CGFloat)` と Foundation の `cos(Double)` が両方候補になり、
// ツールチェーンによっては `ambiguous use of 'cos'` で落ちる(CI の macos-15 で踏んだ)。
// 手元の Xcode では通ってしまうので、Double へ明示的に寄せておく。
let pitchRadians = Double(camera.pitch) * .pi / 180.0
let slantDistance = camera.altitude / max(cos(pitchRadians), minCosTilt)
guard slantDistance > 0 else { return nil }
let factor = metersPerPoint / slantDistance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import CoreLocation
import MapKit
import MapConductorCore
@_spi(MapConductorDriver) import MapConductorCore
import QuartzCore
import UIKit

Expand Down Expand Up @@ -228,12 +228,12 @@ final class MapKitViewController: MapViewControllerProtocol {
// Use UIView.animate to respect the specified duration
UIView.animate(withDuration: duration) {
mapView.setVisibleMapRect(rect, edgePadding: .zero, animated: false)
Self.applyHeading(position.bearing, center: centerCoordinate, to: mapView, animated: false)
Self.applyHeading(CameraBearing.toNativeHeading(position.bearing), center: centerCoordinate, to: mapView, animated: false)
}
} else {
// Use MapKit's default animation or no animation
mapView.setVisibleMapRect(rect, edgePadding: .zero, animated: animated)
Self.applyHeading(position.bearing, center: centerCoordinate, to: mapView, animated: animated)
Self.applyHeading(CameraBearing.toNativeHeading(position.bearing), center: centerCoordinate, to: mapView, animated: animated)
}

return true
Expand Down
Loading