[ios] Add easy to use demo app for developers (#10524)

This updates the package script to include a pre-built iOS app in the published assets of the dynamic SDK. It symlinks the Mapbox.framework in that dynamic build to the demo app so the only real increase in size is the demo Xcode project itself.

The addtional step in the publish script checks that the Mapbox.framework that is symlinked in for building in the demo project can actually be built. If it cannot, then the step is skipped and the build will continue as it normally would. Since the demo app is currently not required for publishing it should not block publishing a build.
This commit is contained in:
Jesse Bounds
2017-11-22 10:28:43 -08:00
committed by GitHub
parent 8f4c07c5b8
commit bcfe51c16c
11 changed files with 996 additions and 0 deletions

View File

@@ -242,6 +242,23 @@ fi
if [[ ${BUILD_DYNAMIC} == true && ${BUILD_FOR_DEVICE} == true ]]; then
step "Copying bitcode symbol maps…"
find "${PRODUCTS}/${BUILDTYPE}-iphoneos" -name '*.bcsymbolmap' -type f -exec cp -pv {} "${OUTPUT}/dynamic/" \;
step "Copying demo project and sym linking to published framework…"
cp -rv platform/ios/scripts/script_resources/MapboxDemo "${OUTPUT}"
cd "${OUTPUT}/MapboxDemo"
ln -sv "../dynamic/${NAME}.framework"
cd -
step "Building demo project…"
xcodebuild -quiet -project build/ios/pkg/MapboxDemo/MapboxDemo.xcodeproj -scheme MapboxDemo build ONLY_ACTIVE_ARCH=YES -destination 'platform=iOS Simulator,name=iPhone 7' clean build &> /tmp/iosdemobuildoutput || true
if grep -Fxq "** BUILD FAILED **" /tmp/iosdemobuildoutput
then
echo "Could not build demo project with this version of the SDK."
rm -rf "${OUTPUT}/MapboxDemo"
else
echo "Built and packaged demo project."
fi
rm /tmp/iosdemobuildoutput
fi
sed -n -e '/^## /,$p' platform/ios/CHANGELOG.md > "${OUTPUT}/CHANGELOG.md"

View File

@@ -0,0 +1,366 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 48;
objects = {
/* Begin PBXBuildFile section */
40625C791FB5340B00B90D3E /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40625C781FB5340B00B90D3E /* Mapbox.framework */; };
40625C7A1FB5340B00B90D3E /* Mapbox.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 40625C781FB5340B00B90D3E /* Mapbox.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
40625C9B1FBA59B800B90D3E /* yose.geojson in Resources */ = {isa = PBXBuildFile; fileRef = 40625C9A1FBA59B800B90D3E /* yose.geojson */; };
40B9C65E1FB380E3002B6532 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B9C65D1FB380E3002B6532 /* AppDelegate.swift */; };
40B9C6601FB380E3002B6532 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B9C65F1FB380E3002B6532 /* ViewController.swift */; };
40B9C6631FB380E3002B6532 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 40B9C6611FB380E3002B6532 /* Main.storyboard */; };
40B9C6651FB380E3002B6532 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 40B9C6641FB380E3002B6532 /* Assets.xcassets */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
40B9C6721FB3810B002B6532 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
40625C7A1FB5340B00B90D3E /* Mapbox.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
40625C6F1FB5336D00B90D3E /* MapboxDemo.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = MapboxDemo.xcodeproj; sourceTree = "<group>"; };
40625C781FB5340B00B90D3E /* Mapbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Mapbox.framework; path = ../dynamic/Mapbox.framework; sourceTree = "<group>"; };
40625C9A1FBA59B800B90D3E /* yose.geojson */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = yose.geojson; path = MapboxDemo/data/yose.geojson; sourceTree = SOURCE_ROOT; };
40B9C65A1FB380E3002B6532 /* MapboxDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MapboxDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
40B9C65D1FB380E3002B6532 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
40B9C65F1FB380E3002B6532 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
40B9C6621FB380E3002B6532 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
40B9C6641FB380E3002B6532 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
40B9C6691FB380E3002B6532 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
40B9C6571FB380E3002B6532 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
40625C791FB5340B00B90D3E /* Mapbox.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
40625C701FB5336D00B90D3E /* Products */ = {
isa = PBXGroup;
name = Products;
sourceTree = "<group>";
};
40625C9C1FBA59C300B90D3E /* data */ = {
isa = PBXGroup;
children = (
40625C9A1FBA59B800B90D3E /* yose.geojson */,
);
path = data;
sourceTree = "<group>";
};
40B9C6511FB380E3002B6532 = {
isa = PBXGroup;
children = (
40625C781FB5340B00B90D3E /* Mapbox.framework */,
40625C6F1FB5336D00B90D3E /* MapboxDemo.xcodeproj */,
40B9C65C1FB380E3002B6532 /* MapboxDemo */,
40B9C65B1FB380E3002B6532 /* Products */,
);
sourceTree = "<group>";
};
40B9C65B1FB380E3002B6532 /* Products */ = {
isa = PBXGroup;
children = (
40B9C65A1FB380E3002B6532 /* MapboxDemo.app */,
);
name = Products;
sourceTree = "<group>";
};
40B9C65C1FB380E3002B6532 /* MapboxDemo */ = {
isa = PBXGroup;
children = (
40625C9C1FBA59C300B90D3E /* data */,
40B9C65D1FB380E3002B6532 /* AppDelegate.swift */,
40B9C65F1FB380E3002B6532 /* ViewController.swift */,
40B9C6611FB380E3002B6532 /* Main.storyboard */,
40B9C6641FB380E3002B6532 /* Assets.xcassets */,
40B9C6691FB380E3002B6532 /* Info.plist */,
);
path = MapboxDemo;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
40B9C6591FB380E3002B6532 /* MapboxDemo */ = {
isa = PBXNativeTarget;
buildConfigurationList = 40B9C66C1FB380E3002B6532 /* Build configuration list for PBXNativeTarget "MapboxDemo" */;
buildPhases = (
40B9C6561FB380E3002B6532 /* Sources */,
40B9C6571FB380E3002B6532 /* Frameworks */,
40B9C6581FB380E3002B6532 /* Resources */,
40B9C6721FB3810B002B6532 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = MapboxDemo;
productName = MapboxDemo;
productReference = 40B9C65A1FB380E3002B6532 /* MapboxDemo.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
40B9C6521FB380E3002B6532 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0910;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = Mapbox;
TargetAttributes = {
40B9C6591FB380E3002B6532 = {
CreatedOnToolsVersion = 9.1;
ProvisioningStyle = Manual;
};
};
};
buildConfigurationList = 40B9C6551FB380E3002B6532 /* Build configuration list for PBXProject "MapboxDemo" */;
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 40B9C6511FB380E3002B6532;
productRefGroup = 40B9C65B1FB380E3002B6532 /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 40625C701FB5336D00B90D3E /* Products */;
ProjectRef = 40625C6F1FB5336D00B90D3E /* MapboxDemo.xcodeproj */;
},
);
projectRoot = "";
targets = (
40B9C6591FB380E3002B6532 /* MapboxDemo */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
40B9C6581FB380E3002B6532 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
40B9C6651FB380E3002B6532 /* Assets.xcassets in Resources */,
40B9C6631FB380E3002B6532 /* Main.storyboard in Resources */,
40625C9B1FBA59B800B90D3E /* yose.geojson in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
40B9C6561FB380E3002B6532 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
40B9C6601FB380E3002B6532 /* ViewController.swift in Sources */,
40B9C65E1FB380E3002B6532 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
40B9C6611FB380E3002B6532 /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
40B9C6621FB380E3002B6532 /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
40B9C66A1FB380E3002B6532 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.1;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
40B9C66B1FB380E3002B6532 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
40B9C66D1FB380E3002B6532 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Manual;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
);
INFOPLIST_FILE = MapboxDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxMapsSDKDemoiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
40B9C66E1FB380E3002B6532 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Manual;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
);
INFOPLIST_FILE = MapboxDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxMapsSDKDemoiOS;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
40B9C6551FB380E3002B6532 /* Build configuration list for PBXProject "MapboxDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
40B9C66A1FB380E3002B6532 /* Debug */,
40B9C66B1FB380E3002B6532 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
40B9C66C1FB380E3002B6532 /* Build configuration list for PBXNativeTarget "MapboxDemo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
40B9C66D1FB380E3002B6532 /* Debug */,
40B9C66E1FB380E3002B6532 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 40B9C6521FB380E3002B6532 /* Project object */;
}

View File

@@ -0,0 +1,12 @@
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}

View File

@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Screen Shot 2017-11-20 at 1.43.33 PM.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13528" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina5_9" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13526"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="MapboxDemo" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XSu-1W-VIV" userLabel="Map View Container">
<rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lwK-ip-Hxt" userLabel="Annotation Context View">
<rect key="frame" x="8" y="589" width="359" height="184"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="4" translatesAutoresizingMaskIntoConstraints="NO" id="ZvJ-iH-zYi">
<rect key="frame" x="9" y="20" width="212" height="39"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Yosemite National Park" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zmm-Me-fJ7">
<rect key="frame" x="0.0" y="0.0" width="212" height="19.333333333333332"/>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="National park in California" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="b0i-sD-LX4">
<rect key="frame" x="0.0" y="23.333333333333371" width="182" height="15.666666666666664"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="b0i-sD-LX4" secondAttribute="trailing" constant="30" id="Ip7-ua-rFe"/>
<constraint firstItem="b0i-sD-LX4" firstAttribute="top" secondItem="Zmm-Me-fJ7" secondAttribute="bottom" constant="4" id="Pfr-mw-dJ8"/>
<constraint firstAttribute="bottom" secondItem="b0i-sD-LX4" secondAttribute="bottom" id="RSc-NM-RIj"/>
<constraint firstAttribute="trailing" secondItem="Zmm-Me-fJ7" secondAttribute="trailing" id="oLM-SU-yfO"/>
<constraint firstItem="Zmm-Me-fJ7" firstAttribute="leading" secondItem="ZvJ-iH-zYi" secondAttribute="leading" id="pfX-hL-BN7"/>
<constraint firstItem="Zmm-Me-fJ7" firstAttribute="top" secondItem="ZvJ-iH-zYi" secondAttribute="top" id="uYT-ZJ-thB"/>
<constraint firstItem="b0i-sD-LX4" firstAttribute="leading" secondItem="ZvJ-iH-zYi" secondAttribute="leading" id="uy9-B6-Yam"/>
</constraints>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="N94-jc-tmy">
<rect key="frame" x="9" y="90.666666666666629" width="212" height="63"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KZr-jR-aVQ">
<rect key="frame" x="0.0" y="0.0" width="117.33333333333333" height="15.666666666666666"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Address:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2tA-7E-47j">
<rect key="frame" x="0.0" y="0.0" width="58" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="California" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="82x-XH-DQ9">
<rect key="frame" x="58" y="0.0" width="59.333333333333343" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qlW-uF-qaD">
<rect key="frame" x="0.0" y="23.666666666666742" width="90.666666666666671" height="15.666666666666664"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Area:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7Ch-ww-vSu">
<rect key="frame" x="0.0" y="0.0" width="34.666666666666664" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="1,169 mi²" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="K7u-ik-UvN">
<rect key="frame" x="34.666666666666664" y="0.0" width="55.999999999999993" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6te-N3-8us">
<rect key="frame" x="0.0" y="47.333333333333371" width="179.33333333333334" height="15.666666666666664"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Established:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qtG-X7-FOk">
<rect key="frame" x="0.0" y="0.0" width="80" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="October 1, 1890" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Cqi-cb-JwT">
<rect key="frame" x="80" y="0.0" width="99.333333333333314" height="15.666666666666666"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="13"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</stackView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="yose" translatesAutoresizingMaskIntoConstraints="NO" id="rd3-Yy-cvo">
<rect key="frame" x="221" y="17" width="130" height="150"/>
<constraints>
<constraint firstAttribute="width" constant="130" id="OCo-25-BHY"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstItem="rd3-Yy-cvo" firstAttribute="leading" secondItem="ZvJ-iH-zYi" secondAttribute="trailing" id="I9D-Re-tKL"/>
<constraint firstAttribute="bottom" secondItem="rd3-Yy-cvo" secondAttribute="bottom" constant="17" id="PCX-nz-oO0"/>
<constraint firstItem="N94-jc-tmy" firstAttribute="trailing" secondItem="ZvJ-iH-zYi" secondAttribute="trailing" id="XNb-sa-t8f"/>
<constraint firstAttribute="height" constant="184" id="cft-d6-DqS"/>
<constraint firstItem="ZvJ-iH-zYi" firstAttribute="leading" secondItem="lwK-ip-Hxt" secondAttribute="leading" constant="9" id="dUn-Jr-sKC"/>
<constraint firstItem="rd3-Yy-cvo" firstAttribute="top" secondItem="lwK-ip-Hxt" secondAttribute="top" constant="17" id="e1r-Un-sYD"/>
<constraint firstItem="N94-jc-tmy" firstAttribute="leading" secondItem="ZvJ-iH-zYi" secondAttribute="leading" id="lhD-Zk-Q6J"/>
<constraint firstItem="ZvJ-iH-zYi" firstAttribute="top" secondItem="lwK-ip-Hxt" secondAttribute="top" constant="20" id="ntM-Gm-41V"/>
<constraint firstAttribute="trailing" secondItem="rd3-Yy-cvo" secondAttribute="trailing" constant="8" id="s43-oz-imQ"/>
<constraint firstItem="N94-jc-tmy" firstAttribute="top" secondItem="ZvJ-iH-zYi" secondAttribute="bottom" constant="31.5" id="xGe-aO-CeH"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3ue-Nm-4DV">
<rect key="frame" x="8" y="45" width="359" height="64"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="748" text="Using demo access token" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YI7-EJ-eE0">
<rect key="frame" x="8" y="7.9999999999999982" width="343" height="25.333333333333329"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="21"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Add your token to Info.plist to remove this warning" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dSA-EU-IHj">
<rect key="frame" x="8" y="38.666666666666671" width="343" height="17.333333333333329"/>
<fontDescription key="fontDescription" type="system" weight="thin" pointSize="13"/>
<color key="textColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="0.20988883259999999" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="dSA-EU-IHj" firstAttribute="leading" secondItem="3ue-Nm-4DV" secondAttribute="leading" constant="8" id="0R9-qo-Q1i"/>
<constraint firstAttribute="height" constant="64" id="7R5-Pe-rmK"/>
<constraint firstItem="YI7-EJ-eE0" firstAttribute="top" secondItem="3ue-Nm-4DV" secondAttribute="top" constant="8" id="9pK-2q-O4h"/>
<constraint firstAttribute="trailing" secondItem="dSA-EU-IHj" secondAttribute="trailing" constant="8" id="GLP-Pa-Zch"/>
<constraint firstItem="dSA-EU-IHj" firstAttribute="top" secondItem="YI7-EJ-eE0" secondAttribute="bottom" constant="6" id="SHC-aF-NJl"/>
<constraint firstItem="YI7-EJ-eE0" firstAttribute="leading" secondItem="3ue-Nm-4DV" secondAttribute="leading" constant="8" id="Wrd-dd-wPi"/>
<constraint firstItem="dSA-EU-IHj" firstAttribute="top" secondItem="YI7-EJ-eE0" secondAttribute="bottom" constant="6" id="j4p-FY-LtB"/>
<constraint firstAttribute="bottom" secondItem="dSA-EU-IHj" secondAttribute="bottom" constant="8" id="oWc-uF-wN0"/>
<constraint firstAttribute="trailing" secondItem="YI7-EJ-eE0" secondAttribute="trailing" constant="8" id="zkN-O6-Ia3"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="3ue-Nm-4DV" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="1" id="8JX-S2-WBd"/>
<constraint firstAttribute="bottom" secondItem="XSu-1W-VIV" secondAttribute="bottom" id="GQ6-Tb-oi2"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="lwK-ip-Hxt" secondAttribute="bottom" constant="5" id="P10-zJ-xYw"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="3ue-Nm-4DV" secondAttribute="trailing" constant="8" id="PVA-pw-f68"/>
<constraint firstItem="3ue-Nm-4DV" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="8" id="WzU-Nx-XQs"/>
<constraint firstItem="lwK-ip-Hxt" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="8" id="bHF-Am-EVL"/>
<constraint firstItem="XSu-1W-VIV" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="fbC-je-nE9"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="lwK-ip-Hxt" secondAttribute="trailing" constant="8" id="gPG-VH-Rc9"/>
<constraint firstItem="XSu-1W-VIV" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="l7b-3R-yTd"/>
<constraint firstItem="XSu-1W-VIV" firstAttribute="trailing" secondItem="6Tk-OE-BBY" secondAttribute="trailing" id="qSW-PH-cqC"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="accessTokenWarningView" destination="3ue-Nm-4DV" id="p7e-Ux-82T"/>
<outlet property="annotationContextView" destination="lwK-ip-Hxt" id="53f-xt-pJT"/>
<outlet property="mapViewContainer" destination="XSu-1W-VIV" id="CyQ-EP-Qwf"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="132.26600985221674"/>
</scene>
</scenes>
<resources>
<image name="yose" width="234" height="209"/>
</resources>
</document>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>MGLMapboxAccessToken</key>
<string>pk.eyJ1IjoibWFwYm94IiwiYSI6ImNqYThuNnZ3NTA5MGMyd3F1cmF1eW1xaGEifQ.TdBTSHHPeT1pfLZ_6x_1vA</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,239 @@
import UIKit
import Mapbox
/*
A simple example that uses the Mapbox Outdoors style to view
Yosemite National Park, USA with a polygon visualization of the
park boundary that can be interacted with.
A demo access token has been provided for convenience and it may
stop working in the future.
You can obtain your own access token from the
[Mapbox account page](https://www.mapbox.com/studio/account/tokens/)
and add it to this application's Info.plist as the value for
MGLMapboxAccessToken
*/
class ViewController: UIViewController {
@IBOutlet weak var mapViewContainer: UIView!
@IBOutlet weak var annotationContextView: UIView!
@IBOutlet weak var accessTokenWarningView: UIView!
var mapView: MGLMapView!
// Define a name for our annotation
let annotationIdentifier = "yosemite-fill-layer"
// Define the name of the map label layer we will want our annotation to be placed under
let styleLabelLayer = "mountain-peak-label"
// The initial center geometric coordinate for the map to display - this is Yosemite National Park, USA
let centerCoordinate = CLLocationCoordinate2DMake(37.742241, -119.576923)
// MARK: - View controller life cycle
override func viewDidLoad() {
super.viewDidLoad()
setupAnnotationContextView()
setupAndAddMapView()
setupGestureHandling()
}
// MARK: - Map object interaction
@objc func didTapMap(sender: UITapGestureRecognizer) {
// Search for annotation at tap point
// If the annotation is found at the tap point then modify some of its properties
// If the annotation is not found at the tap point, reset the annotation back to the way it was when originally added
if let layer = mapView.style?.layer(withIdentifier: annotationIdentifier) as? MGLFillExtrusionStyleLayer {
let point = sender.location(in: mapView)
let features = mapView.visibleFeatures(at: point, styleLayerIdentifiers: [annotationIdentifier])
if features.count > 0 {
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.9)
layer.fillExtrusionHeight = MGLStyleValue(rawValue: 5000)
let camera = MGLMapCamera(lookingAtCenter: centerCoordinate, fromDistance: 100000, pitch: 60, heading: 180)
mapView.fly(to: camera, withDuration: 8, completionHandler: nil)
annotationContextView.alpha = 1.0
} else {
layer.fillExtrusionOpacity = MGLStyleValue(rawValue: 0.5)
layer.fillExtrusionHeight = MGLStyleValue(rawValue: 0)
let camera = MGLMapCamera(lookingAtCenter: centerCoordinate, fromDistance: 100000, pitch: 60, heading: 0)
mapView.fly(to: camera, withDuration: 1, completionHandler: nil)
annotationContextView.alpha = 0
}
}
}
// MARK: - Initialization and setup
/*
Simple (but somewhat styled) stub of a view to present
contextual information about tapped objects on the map.
*/
fileprivate func setupAnnotationContextView() {
annotationContextView.alpha = 0
let blurView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
blurView.frame = annotationContextView.bounds
blurView.layer.cornerRadius = 5
blurView.clipsToBounds = true
blurView.translatesAutoresizingMaskIntoConstraints = false
annotationContextView.insertSubview(blurView, at: 0)
blurView.topAnchor.constraint(equalTo: annotationContextView.topAnchor).isActive = true
blurView.leftAnchor.constraint(equalTo: annotationContextView.leftAnchor).isActive = true
blurView.rightAnchor.constraint(equalTo: annotationContextView.rightAnchor).isActive = true
blurView.bottomAnchor.constraint(equalTo: annotationContextView.bottomAnchor).isActive = true
}
/*
Create and add a Mapbox map view to the the view
intended to contain it. Setup with the style, initial
location in the world, and make this object the delegate
of the map. Finally, set up a camera to control how the
user will view the map initially.
*/
fileprivate func setupAndAddMapView() {
mapView = MGLMapView(frame: mapViewContainer.bounds)
mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
mapView.styleURL = MGLStyle.outdoorsStyleURL(withVersion: 10)
mapView.setCenter(centerCoordinate, zoomLevel: 10, animated: false)
mapView.delegate = self
mapViewContainer.addSubview(mapView)
accessTokenWarningView.layer.cornerRadius = 5
accessTokenWarningView.isHidden = true
// This demo access token has been provided for convenience and it may
// stop working in the future.
// You can obtain your own access token from the
// [Mapbox account page](https://www.mapbox.com/studio/account/tokens/)
// and add it to this application's Info.plist as the value for MGLMapboxAccessToken
if MGLAccountManager.accessToken() == "pk.eyJ1IjoibWFwYm94IiwiYSI6ImNqYThuNnZ3NTA5MGMyd3F1cmF1eW1xaGEifQ.TdBTSHHPeT1pfLZ_6x_1vA" {
accessTokenWarningView.isHidden = false
}
let camera = MGLMapCamera(lookingAtCenter: centerCoordinate, fromDistance: 100000, pitch: 60, heading: 0)
mapView.setCamera(camera, animated: false)
}
/*
Add a gesture recognizer that will be used to handle user
interactions with the map.
*/
fileprivate func setupGestureHandling() {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapMap))
mapView.addGestureRecognizer(tapGestureRecognizer)
}
}
/*
Implementation of Mapbox map view delegate methods relevant to this application
*/
extension ViewController: MGLMapViewDelegate {
/*
When the map has finished loading the style it's a great time
to do work like adding annotations.
*/
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
// This project's bundle contains a geojson file that represents the park boundary of Yosemite National Park in the USA
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "yose", ofType: "geojson")!)
// Create an instance of a structure to represent a polygon
// fill visualization that can be injeced into the map's style layers
var annotation = StyledAnnotation(identifier: annotationIdentifier, resource: url, type: .extrusion)
annotation.color = UIColor(red:1.00, green:0.95, blue:0.75, alpha:1.0)
annotation.opacity = 0.75
annotation.transitionDuration = 0.35
// Inject the annotation below the label layer so some map labels
// are still visible
mapView.addStyledAnnotation(annotation, belowLayer: styleLabelLayer)
// Alternatively, a more traditional annotation / marker API
let pointFeatureAnnotation = MGLPointFeature()
let offsetCoordinate = CLLocationCoordinate2D(latitude: centerCoordinate.latitude+0.1, longitude: centerCoordinate.longitude-0.01)
pointFeatureAnnotation.coordinate = offsetCoordinate
mapView.addAnnotation(pointFeatureAnnotation)
}
}
/*
An extention of the Mapbox map view class that offers a simplified
API for a small subset of the runtime styling APIs used in this application.
This could be extended.
*/
extension MGLMapView {
func addStyledAnnotation(_ annotation: StyledAnnotation, belowLayer layerName: String) {
if let labelsLayer = self.style?.layer(withIdentifier: "mountain-peak-label") {
let source = addSource(for: annotation)
let layer = addLayer(for: annotation, source: source)
self.style?.insertLayer(layer, below: labelsLayer)
}
}
func addStyledAnnotation(_ annotation: StyledAnnotation) {
let source = addSource(for: annotation)
let layer = addLayer(for: annotation, source: source)
self.style?.addLayer(layer)
}
func addSource(for styledAnnotation: StyledAnnotation) -> MGLSource {
let source = MGLShapeSource(identifier: UUID().uuidString, url: styledAnnotation.resource, options: nil)
self.style?.addSource(source)
return source
}
func addLayer(for styledAnnotation: StyledAnnotation, source: MGLSource) -> MGLStyleLayer {
switch styledAnnotation.type {
case .extrusion:
let layer = MGLFillExtrusionStyleLayer(identifier: styledAnnotation.identifier, source: source)
if let height = styledAnnotation.height {
layer.fillExtrusionHeight = MGLStyleValue<NSNumber>(rawValue: NSNumber(floatLiteral: Double(height)))
}
if let color = styledAnnotation.color {
layer.fillExtrusionColor = MGLStyleValue(rawValue: color)
}
if let opacity = styledAnnotation.opacity {
layer.fillExtrusionOpacity = MGLStyleValue<NSNumber>(rawValue: NSNumber(floatLiteral: Double(opacity)))
}
if let duration = styledAnnotation.transitionDuration {
layer.fillExtrusionHeightTransition = MGLTransitionMake(Double(duration), 0)
layer.fillExtrusionOpacityTransition = MGLTransitionMake(Double(duration), 0)
}
return layer
}
}
}
/*
A struct to represent a small subset of the annotations that
are possible to add to a Mapbox map. This could be extended.
*/
struct StyledAnnotation {
enum StyledAnnotationType {
case extrusion
}
init(identifier: String, resource: URL, type: StyledAnnotationType) {
self.identifier = identifier
self.resource = resource
self.type = type
}
var identifier: String
var resource: URL
var type: StyledAnnotationType
var height: Float?
var color: UIColor?
var opacity: Float?
var transitionDuration: Float?
}

File diff suppressed because one or more lines are too long