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

Make __map private #374

Merged
merged 15 commits into from
May 25, 2021
75 changes: 50 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,35 +355,60 @@ jobs:
name: Install Device Farm Dependencies
command: make install-devicefarm-dependencies
- install-dependencies

# There's a command for this, but it only works if run *after* the build.
# In this case, we need to determine the derived data path *before* building.
- run:
name: Locate derived data directory
command: |
xcodebuild \
-showBuildSettings \
-project Mapbox/MapboxMaps.xcodeproj \
-scheme 'MapboxTestHost' \
| sed -n 's:^ *BUILD_DIR = \(.*\)/Build/Products$:export DERIVED_DATA_PATH="\1":p' \
>> $BASH_ENV
- run:
name: Testing << parameters.scheme >> on AWS Device Farm
command: make test-with-device-farm SCHEME=<< parameters.scheme >> APP_NAME=<< parameters.app-name >> CONFIGURATION=Release
command: |
make test-with-device-farm \
SCHEME=<< parameters.scheme >> \
APP_NAME=<< parameters.app-name >> \
CONFIGURATION=Release \
BUILD_DIR="$DERIVED_DATA_PATH"
when: always
# get xcresults here, may be zipped with more than one result
- run:
name: "Gathering results"
command: make gather-results
command: make gather-results BUILD_DIR="$DERIVED_DATA_PATH"
when: always
- run:
name: "Parsing xcresults for errors"
command: |
RESULTS=`find build/testruns -name '*.xcresult'`
xargs swift run --package-path scripts/xcparty xcparty \<<< "$RESULTS" | tee build/testruns/failures.txt
RESULTS=`find "$DERIVED_DATA_PATH/testruns" -name '*.xcresult'`
xargs swift run --package-path scripts/xcparty xcparty \<<< "$RESULTS" | tee "$DERIVED_DATA_PATH/testruns/failures.txt"
when: on_fail
- run:
name: Symbolicate crash logs
command: make symbolicate SCHEME=<< parameters.scheme >> APP_NAME=<< parameters.app-name >> CONFIGURATION=Release
when: always
# - run:
# name: Converting and uploading coverage
# command: |
# make device-update-codecov-with-profdata \
# SCHEME=<< parameters.scheme >> \
# APP_NAME=<< parameters.app-name >> \
# CONFIGURATION=Release \
# COVERAGE_MAPBOX_MAPS_DEVICE=build/Build/Products/Release-iphoneos/MapboxMaps.framework/MapboxMaps
- store-device-farm-artifacts
- store-logs
command: |
make symbolicate \
SCHEME=<< parameters.scheme >> \
APP_NAME=<< parameters.app-name >> \
CONFIGURATION=Release \
BUILD_DIR="$DERIVED_DATA_PATH"
when: always
- run:
name: Converting and uploading coverage
command: |
make device-update-codecov-with-profdata \
SCHEME=<< parameters.scheme >> \
APP_NAME=<< parameters.app-name >> \
CONFIGURATION=Release \
BUILD_DIR="$DERIVED_DATA_PATH" \
COVERAGE_MAPBOX_MAPS_DEVICE="$DERIVED_DATA_PATH/Build/Products/Release-iphoneos/MapboxMaps.framework/MapboxMaps"
- store-device-farm-artifacts:
derived_data_path: $DERIVED_DATA_PATH
- store-logs:
derived_data_path: $DERIVED_DATA_PATH
- report-failure:
report_failure: << parameters.report_failure >>
message: "<< parameters.scheme >> device tests"
Expand Down Expand Up @@ -440,15 +465,15 @@ jobs:
CONFIGURATION=Release \
BUILD_DIR="$DERIVED_DATA_PATH"
when: always
# - run:
# name: Converting and uploading coverage
# command: |
# pip3 install awscli gitpython
# make device-update-codecov-with-profdata \
# SCHEME=<< parameters.scheme >> \
# APP_NAME=<< parameters.app-name >> \
# CONFIGURATION=Release \
# BUILD_DIR="$DERIVED_DATA_PATH"
- run:
name: Converting and uploading coverage
command: |
pip3 install awscli gitpython
make device-update-codecov-with-profdata \
SCHEME=<< parameters.scheme >> \
APP_NAME=<< parameters.app-name >> \
CONFIGURATION=Release \
BUILD_DIR="$DERIVED_DATA_PATH"
- store-device-farm-artifacts:
derived_data_path: $DERIVED_DATA_PATH
- store-logs:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Mapbox welcomes participation and contributions from everyone.
- Introduced separate minZoom/maxZoom fields into CustomGeometrySourceOptions API instead of the formerly used `zoomRange`
- Improved zooming performance.
- Fixed terrain transparency issue when a sky layer is not used.
- `MapboxMap.__map` is now private. ([#374](https://github.com/mapbox/mapbox-maps-ios/pull/374))
- Added `CameraManagerProtocol.setCameraBounds`, `MapboxMap.prefetchZoomDelta`, `MapboxMap.options`, `MapboxMap.reduceMemoryUse()`, `MapboxMap.resourceOptions` and `MapboxMap.elevation(at:)`. ([#374](https://github.com/mapbox/mapbox-maps-ios/pull/374))
- Removed `OfflineError.invalidResult` and `OfflineError.typeMismatch`. ([#374](https://github.com/mapbox/mapbox-maps-ios/pull/374))

### Features ✨ and improvements 🏁

Expand Down
52 changes: 39 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ $(DEVICE_FARM_UPLOAD_IPA): $(XCTESTRUN_PACKAGE) | $(DEVICE_TEST_PATH) $(PAYLOAD_

# Creating IPA package for upload
cp -R $(BUILT_DEVICE_PRODUCTS_DIR)/$(APP_NAME).app $(PAYLOAD_DIR)

# Test moving frameworks for AWS to re-codesign (if they exist)
mv $(PAYLOAD_DIR)/$(APP_NAME).app/Frameworks/*.framework/Frameworks/*.framework $(PAYLOAD_DIR)/$(APP_NAME).app/Frameworks || true

cp $(XCTESTRUN_PACKAGE) $(PAYLOAD_DIR)/$(APP_NAME).app/xctestrun.zip

-rm $(DEVICE_FARM_UPLOAD_IPA)
Expand Down Expand Up @@ -389,26 +393,48 @@ COVERAGE_ROOT_DIR ?= $(BUILD_DIR)/Build/ProfileData
COVERAGE_MAPBOX_MAPS ?= $(BUILD_DIR)/Build/Products/$(CONFIGURATION)-iphonesimulator/MapboxMaps.o
COVERAGE_ARCH ?= x86_64

# .PHONY: update-codecov-with-profdata
# update-codecov-with-profdata:
# curl -sSfL --retry 5 --connect-timeout 5 https://codecov.io/bash > /tmp/codecov.sh
# @PROF_DATA=`find $(COVERAGE_ROOT_DIR) -regex '.*\.profraw'` ; \
# for RESULT in $${PROF_DATA[@]} ; \
# do \
# echo "Generating $${RESULT}.lcov" ; \
# xcrun llvm-profdata merge -o $${RESULT}.profdata $${RESULT} ; \
# xcrun llvm-cov export \
# $(COVERAGE_MAPBOX_MAPS) \
# -instr-profile=$${RESULT}.profdata \
# -arch=$(COVERAGE_ARCH) \
# -format=lcov > $${RESULT}.lcov ; \
# echo "Uploading $${RESULT}.lcov to CodeCov.io" ; \
# bash /tmp/codecov.sh \
# -f $${RESULT}.lcov \
# -t $(CODECOV_TOKEN) \
# -J '^MapboxMaps$$' \
# -n $${RESULT}.lcov \
# -F "$$(echo '$(SCHEME)' | sed 's/[[:upper:]]/_&/g;s/^_//' | tr '[:upper:]' '[:lower:]')" ; \
# echo "Generating lcov JSON" ; \
# xcrun llvm-cov export \
# $(COVERAGE_MAPBOX_MAPS) \
# -instr-profile=$${RESULT}.profdata \
# -arch=$(COVERAGE_ARCH) \
# -format=text | python3 -m json.tool > $${RESULT}.json ; \
# echo "Uploading to S3" ; \
# python3 ./scripts/code-coverage/parse-code-coverage.py \
# -g . \
# -c MapboxMaps \
# --scheme $(SCHEME) \
# --report $${RESULT}.json ; \
# done
# @echo "Done"

.PHONY: update-codecov-with-profdata
update-codecov-with-profdata:
curl -sSfL --retry 5 --connect-timeout 5 https://codecov.io/bash > /tmp/codecov.sh
@PROF_DATA=`find $(COVERAGE_ROOT_DIR) -regex '.*\.profraw'` ; \
for RESULT in $${PROF_DATA[@]} ; \
do \
echo "Generating $${RESULT}.lcov" ; \
xcrun llvm-profdata merge -o $${RESULT}.profdata $${RESULT} ; \
xcrun llvm-cov export \
$(COVERAGE_MAPBOX_MAPS) \
-instr-profile=$${RESULT}.profdata \
-arch=$(COVERAGE_ARCH) \
-format=lcov > $${RESULT}.lcov ; \
echo "Uploading $${RESULT}.lcov to CodeCov.io" ; \
bash /tmp/codecov.sh \
-f $${RESULT}.lcov \
-t $(CODECOV_TOKEN) \
-J '^MapboxMaps$$' \
-n $${RESULT}.lcov \
-F "$$(echo '$(SCHEME)' | sed 's/[[:upper:]]/_&/g;s/^_//' | tr '[:upper:]' '[:lower:]')" ; \
echo "Generating lcov JSON" ; \
xcrun llvm-cov export \
$(COVERAGE_MAPBOX_MAPS) \
Expand Down
4 changes: 3 additions & 1 deletion Mapbox/MapboxMaps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
CA99A8702540CD1900D16C78 /* StyleLoadIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA99A86E2540CD1900D16C78 /* StyleLoadIntegrationTests.swift */; };
CA9F8CE32641F95C00A8BCB6 /* StyleManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9F8CE22641F95C00A8BCB6 /* StyleManagerProtocol.swift */; };
CAA73A9D256F750B00E14EE0 /* FlyToTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA73A9B256F750B00E14EE0 /* FlyToTests.swift */; };
CAB77E3D2654AB310071D74C /* MapboxCoreMaps in Frameworks */ = {isa = PBXBuildFile; productRef = CAB77E3C2654AB310071D74C /* MapboxCoreMaps */; };
CAB77E3D2654AB310071D74C /* MapboxCoreMaps in Frameworks */ = {isa = PBXBuildFile; productRef = CAB77E3C2654AB310071D74C /* MapboxCoreMaps */; settings = {ATTRIBUTES = (Required, ); }; };
CAB77E402654AB4F0071D74C /* MapboxMobileEvents in Frameworks */ = {isa = PBXBuildFile; productRef = CAB77E3F2654AB4F0071D74C /* MapboxMobileEvents */; };
CAB77E432654AB6E0071D74C /* Turf in Frameworks */ = {isa = PBXBuildFile; productRef = CAB77E422654AB6E0071D74C /* Turf */; };
CAB77E452654AC5E0071D74C /* CameraAnimationsManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAB77E442654AC5E0071D74C /* CameraAnimationsManagerProtocol.swift */; };
Expand Down Expand Up @@ -1750,6 +1750,8 @@
CA952ED0251C30B80099C080 /* PBXTargetDependency */,
);
name = MapboxTestHost;
packageProductDependencies = (
);
productName = MapboxMapsTestHost;
productReference = CA4453C52436E71500477B4F /* MapboxTestHost.app */;
productType = "com.apple.product-type.application";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CameraAnimationsManager {
minZoom: options.minimumZoomLevel as NSNumber,
maxPitch: options.maximumPitch as NSNumber,
minPitch: options.minimumPitch as NSNumber)
mapView?.mapboxMap.__map.setBoundsFor(boundOptions)
try? mapView?.mapboxMap.setCameraBounds(for: boundOptions)
}
}

Expand Down
4 changes: 4 additions & 0 deletions Sources/MapboxMaps/Foundation/CameraManagerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ internal protocol CameraManagerProtocol {
/// Returns the bounds of the map.
var cameraBounds: CameraBounds { get }

/// Sets the camera bounds using a `CameraBoundsOptions`
/// - Parameter options: `CameraBoundsOptions` - `nil` parameters take no effect.
func setCameraBounds(for options: CameraBoundsOptions) throws

// MARK: - Drag API

/// Prepares the drag gesture to use the provided screen coordinate as a pivot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,16 @@ public extension MapEvents {
case mapIdle

/**
* The requested style data has been loaded. The 'type' property defines what kind of style data has been loaded.
* The requested style data has been loaded. The 'type' property defines
* what kind of style data has been loaded.
* Event may be emitted synchronously, for example, when StyleManager#setStyleJSON is used to load style.
*
* Based on an event data 'type' property value, following use-cases may be implemented:
* - 'style': Style is parsed, style layer properties could be read and modified, style layers and sources could be
* added or removed before rendering is started.
* - 'sprite': Style's sprite sheet is parsed and it is possible to add or update images.
* - 'sources': All sources defined by the style are loaded and their properties could be read and updated if needed.
* *
* Event data format (Object):
* ```
* .
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapboxMaps/Foundation/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class MapView: UIView {

public var options = RenderOptions() {
didSet {
mapboxMap.__map.setPrefetchZoomDeltaForDelta(options.prefetchZoomDelta)
mapboxMap.prefetchZoomDelta = options.prefetchZoomDelta
preferredFPS = options.preferredFramesPerSecond
metalView?.presentsWithTransaction = options.presentsWithTransaction
}
Expand Down Expand Up @@ -148,11 +148,11 @@ open class MapView: UIView {
}

if let cameraOptions = resolvedMapInitOptions.cameraOptions {
mapboxMap.__map.setCameraFor(MapboxCoreMaps.CameraOptions(cameraOptions))
mapboxMap._setCamera(to: cameraOptions)
}

// Set prefetchZoomDelta
mapboxMap.__map.setPrefetchZoomDeltaForDelta(options.prefetchZoomDelta)
mapboxMap.prefetchZoomDelta = options.prefetchZoomDelta

// Set preferrredFPS
preferredFPS = options.preferredFramesPerSecond
Expand Down
74 changes: 73 additions & 1 deletion Sources/MapboxMaps/Foundation/MapboxMap.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// swiftlint:disable file_length
import MapboxCoreMaps
import Turf
import UIKit
@_implementationOnly import MapboxCommon_Private

public final class MapboxMap {
/// The underlying renderer object responsible for rendering the map
public let __map: Map
private let __map: Map

internal var size: CGSize {
get {
Expand Down Expand Up @@ -87,6 +88,57 @@ public final class MapboxMap {
__map.setStyleJSONForJson(JSON)
}

// MARK: - Prefetching

/// When loading a map, if `prefetchZoomDelta` is set to any number greater
/// than 0, the map will first request a tile for `zoom - prefetchZoomDelta`
/// in an attempt to display a full map at lower resolution as quick as
/// possible.
///
/// It will get clamped at the tile source minimum zoom. The default delta
/// is 4.
public var prefetchZoomDelta: UInt8 {
get {
return __map.getPrefetchZoomDelta()
}
set {
__map.setPrefetchZoomDeltaForDelta(newValue)
}
}

/// Returns the map's options
public var options: MapOptions {
return __map.getOptions()
}

/// Reduces memory use. Useful to call when the application gets paused or
/// sent to background.
internal func reduceMemoryUse() {
__map.reduceMemoryUse()
}

/// Gets the resource options for the map.
///
/// All optional fields of the returned object are initialized with the
/// actual values.
///
/// - Note: The result of this property is different from the `ResourceOptions`
/// that were provided to the map's initializer.
public var resourceOptions: ResourceOptions {
return __map.getResourceOptions()
}

/// Gets elevation for the given coordinate.
///
/// - Note: Elevation is only available for the visible region on the screen.
///
/// - Parameter coordinate: Coordinate for which to return the elevation.
/// - Returns: Elevation (in meters) multiplied by current terrain
/// exaggeration, or empty if elevation for the coordinate is not available.
public func elevation(at coordinate: CLLocationCoordinate2D) -> Double? {
return __map.getElevationFor(coordinate)?.doubleValue
}

// MARK: - Camera Fitting

/// Transforms a view's frame into a set of coordinate bounds
Expand Down Expand Up @@ -231,6 +283,20 @@ extension MapboxMap: CameraManagerProtocol {
return __map.getBounds()
}

/// Sets the bounds of the map.
///
/// - Parameter options: New camera bounds. Nil values will not take effect.
/// - Throws: `MapError`
public func setCameraBounds(for options: CameraBoundsOptions) throws {
let expected = __map.setBoundsFor(options)

if expected.isError() {
// swiftlint:disable force_cast
throw MapError(coreError: expected.error as! NSString)
// swiftlint:enable force_cast
}
}

// MARK: - Drag API

public func dragStart(for point: CGPoint) {
Expand Down Expand Up @@ -357,3 +423,9 @@ extension MapboxMap: MapEventsObservable {
return handler
}
}

extension MapboxMap {
internal var __testingMap: Map {
return __map
}
}
Loading