Skip to content

Commit

Permalink
Update Offline Map example to show Standard style (#2303)
Browse files Browse the repository at this point in the history
Co-authored-by: Release SDK bot for Maps SDK team <[email protected]>
  • Loading branch information
pjleonard37 and Release SDK bot for Maps SDK team authored Sep 20, 2024
1 parent 31743ba commit 841e4f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="p6J-Gi-W7S">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23089" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="p6J-Gi-W7S">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23077"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -19,6 +19,16 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="t7M-79-XaT">
<rect key="frame" x="0.0" y="0.0" width="414" height="493"/>
<subviews>
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="uz5-CQ-u1Q">
<rect key="frame" x="97" y="393" width="221" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
<segment title="Standard Style"/>
<segment title="Satellite Style"/>
</segments>
</segmentedControl>
</subviews>
<color key="backgroundColor" systemColor="systemGray5Color"/>
</view>
<view contentMode="scaleToFill" verticalHuggingPriority="1000" translatesAutoresizingMaskIntoConstraints="NO" id="9fO-jU-7Bj" userLabel="Progress Container">
Expand Down Expand Up @@ -101,6 +111,7 @@ Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed
<outlet property="mapViewContainer" destination="t7M-79-XaT" id="qVz-A2-2Dc"/>
<outlet property="progressContainer" destination="9fO-jU-7Bj" id="kuk-4G-pfO"/>
<outlet property="stylePackProgressView" destination="tTi-kr-gUv" id="Puh-FW-RqG"/>
<outlet property="styleSelection" destination="uz5-CQ-u1Q" id="k1K-Q8-J2r"/>
<outlet property="tileRegionProgressView" destination="XK3-DS-3sZ" id="mwN-Gm-2ld"/>
</connections>
</viewController>
Expand All @@ -111,7 +122,7 @@ Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed
</scenes>
<resources>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
42 changes: 28 additions & 14 deletions Apps/Examples/Examples/All Examples/OfflineManagerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {
@IBOutlet private var stylePackProgressView: UIProgressView!
@IBOutlet private var tileRegionProgressView: UIProgressView!
@IBOutlet private var progressContainer: UIView!
@IBOutlet private var styleSelection: UISegmentedControl!

private var style: StyleURI {
if styleSelection.selectedSegmentIndex == 0 {
return .standard
} else {
return .satelliteStreets
}
}

private var mapView: MapView?
private var tileStore: TileStore?
Expand All @@ -27,10 +36,10 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {

// Default MapInitOptions. If you use a custom path for a TileStore, you would
// need to create a custom MapInitOptions to reference that TileStore.
private lazy var mapInitOptions: MapInitOptions = {
MapInitOptions(cameraOptions: CameraOptions(center: tokyoCoord, zoom: tokyoZoom),
styleURI: .satelliteStreets)
}()
private var mapInitOptions: MapInitOptions {
MapInitOptions(cameraOptions: CameraOptions(center: tokyoCoord, zoom: tokyoZoom, bearing: tokyoBearing, pitch: tokyoPitch),
styleURI: style)
}

private lazy var offlineManager: OfflineManager = {
return OfflineManager()
Expand All @@ -39,8 +48,10 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {
// Regions and style pack downloads
private var downloads: [Cancelable] = []

private let tokyoCoord = CLLocationCoordinate2D(latitude: 35.682027, longitude: 139.769305)
private let tokyoZoom: CGFloat = 12
private let tokyoCoord = CLLocationCoordinate2D(latitude: 35.692897, longitude: 139.750451)
private let tokyoPitch = 65.0
private let tokyoBearing = 127.2
private let tokyoZoom: CGFloat = 16
private let tileRegionId = "myTileRegion"

private enum State {
Expand Down Expand Up @@ -83,10 +94,10 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {

// 1. Create style package with loadStylePack() call.
let stylePackLoadOptions = StylePackLoadOptions(glyphsRasterizationMode: .ideographsRasterizedLocally,
metadata: ["tag": "my-satellite-style-pack"])!
metadata: ["tag": "my-style-pack"])!

dispatchGroup.enter()
let stylePackDownload = offlineManager.loadStylePack(for: .satelliteStreets, loadOptions: stylePackLoadOptions) { [weak self] progress in
let stylePackDownload = offlineManager.loadStylePack(for: style, loadOptions: stylePackLoadOptions) { [weak self] progress in
// These closures do not get called from the main thread. In this case
// we're updating the UI, so it's important to dispatch to the main
// queue.
Expand Down Expand Up @@ -118,19 +129,19 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {

// - - - - - - - -

// 2. Create an offline region with tiles for the satellite streets style.
// 2. Create an offline region with tiles for the Standard or Satellite-Streets style.
// If you are using a raster tileset you may need to set a different pixelRatio. The default is UIScreen.main.scale.
let satelliteOptions = TilesetDescriptorOptions(styleURI: .satelliteStreets,
let styleOptions = TilesetDescriptorOptions(styleURI: style,
zoomRange: 0...16,
tilesets: nil)

let satelliteDescriptor = offlineManager.createTilesetDescriptor(for: satelliteOptions)
let styleDescriptor = offlineManager.createTilesetDescriptor(for: styleOptions)

// Load the tile region
let tileRegionLoadOptions = TileRegionLoadOptions(
geometry: .point(Point(tokyoCoord)),
descriptors: [satelliteDescriptor],
metadata: ["tag": "my-satellite-tile-region"],
descriptors: [styleDescriptor],
metadata: ["tag": "my-tile-region"],
acceptExpired: true)!

// Use the the default TileStore to load this region. You can create
Expand Down Expand Up @@ -232,7 +243,7 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {
// Note this will not remove the downloaded style pack, instead, it will
// just mark the resources as not a part of the existing style pack. The
// resources still exists in the disk cache.
offlineManager.removeStylePack(for: .satelliteStreets)
offlineManager.removeStylePack(for: style)
}

// MARK: - State changes
Expand Down Expand Up @@ -273,6 +284,7 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {
OfflineSwitch.shared.isMapboxStackConnected = true

case (.initial, .downloading):
styleSelection.isHidden = true
// Can cancel
button.setTitle("Cancel Downloads", for: .normal)

Expand Down Expand Up @@ -307,6 +319,8 @@ final class OfflineManagerExample: UIViewController, NonMapViewExampleProtocol {

button.setTitle("Start Downloads", for: .normal)

styleSelection.isHidden = false

mapView?.removeFromSuperview()
mapView = nil
}
Expand Down

0 comments on commit 841e4f9

Please sign in to comment.