Skip to content

Commit 83e4a2b

Browse files
authored
Merge pull request #527 from Esri/Caleb/New-AddTiledLayerAsBasemap
[New] Add tiled layer as basemap
2 parents dc733e1 + 9ea826a commit 83e4a2b

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@
261261
D71D516F2B51D87700B2A2BE /* SearchForWebMapView.Views.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D71D516D2B51D7B600B2A2BE /* SearchForWebMapView.Views.swift */; };
262262
D71FCB8A2AD6277F000E517C /* CreateMobileGeodatabaseView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */; };
263263
D71FCB8B2AD628B9000E517C /* CreateMobileGeodatabaseView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */; };
264+
D7201CDA2CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */; };
265+
D7201CDB2CC6B72A004BDB7D /* AddTiledLayerAsBasemapView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */; };
264266
D721EEA82ABDFF550040BE46 /* LothianRiversAnno.mmpk in Resources */ = {isa = PBXBuildFile; fileRef = D721EEA72ABDFF550040BE46 /* LothianRiversAnno.mmpk */; settings = {ASSET_TAGS = (ShowMobileMapPackageExpirationDate, ); }; };
265267
D722BD222A420DAD002C2087 /* ShowExtrudedFeaturesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */; };
266268
D722BD232A420DEC002C2087 /* ShowExtrudedFeaturesView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */; };
@@ -435,7 +437,7 @@
435437
D7C16D282AC5FEB700689E89 /* Hawaii.csv in Resources */ = {isa = PBXBuildFile; fileRef = D7C16D272AC5FEB600689E89 /* Hawaii.csv */; settings = {ASSET_TAGS = (Animate3DGraphic, ); }; };
436438
D7C3AB4A2B683291008909B9 /* SetFeatureRequestModeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C3AB472B683291008909B9 /* SetFeatureRequestModeView.swift */; };
437439
D7C3AB4D2B6832B7008909B9 /* SetFeatureRequestModeView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7C3AB472B683291008909B9 /* SetFeatureRequestModeView.swift */; };
438-
D7C523402BED9BBF00E8221A /* SanFrancisco.tpkx in Resources */ = {isa = PBXBuildFile; fileRef = D7C5233E2BED9BBF00E8221A /* SanFrancisco.tpkx */; settings = {ASSET_TAGS = (EditAndSyncFeaturesWithFeatureService, ); }; };
440+
D7C523402BED9BBF00E8221A /* SanFrancisco.tpkx in Resources */ = {isa = PBXBuildFile; fileRef = D7C5233E2BED9BBF00E8221A /* SanFrancisco.tpkx */; settings = {ASSET_TAGS = (AddTiledLayerAsBasemap, EditAndSyncFeaturesWithFeatureService, ); }; };
439441
D7C6420C2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C6420B2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift */; };
440442
D7C6420D2B4F5DDB0042B8F7 /* SearchForWebMapView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7C6420B2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift */; };
441443
D7C97B562B75C10C0097CDA1 /* ValidateUtilityNetworkTopologyView.Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C97B552B75C10C0097CDA1 /* ValidateUtilityNetworkTopologyView.Views.swift */; };
@@ -562,6 +564,7 @@
562564
dstPath = "";
563565
dstSubfolderSpec = 7;
564566
files = (
567+
D7201CDB2CC6B72A004BDB7D /* AddTiledLayerAsBasemapView.swift in Copy Source Code Files */,
565568
D7BE7E722CC19CE5006DDB0C /* AddTiledLayerView.swift in Copy Source Code Files */,
566569
D7BEBAD52CBDFE3900F882E7 /* DisplayAlternateSymbolsAtDifferentScalesView.swift in Copy Source Code Files */,
567570
D7BEBAC62CBDC11600F882E7 /* AddElevationSourceFromTilePackageView.swift in Copy Source Code Files */,
@@ -926,6 +929,7 @@
926929
D71C909D2C6C249B0018C63E /* StyleGeometryTypesWithSymbolsView.Views.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleGeometryTypesWithSymbolsView.Views.swift; sourceTree = "<group>"; };
927930
D71D516D2B51D7B600B2A2BE /* SearchForWebMapView.Views.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchForWebMapView.Views.swift; sourceTree = "<group>"; };
928931
D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateMobileGeodatabaseView.Model.swift; sourceTree = "<group>"; };
932+
D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddTiledLayerAsBasemapView.swift; sourceTree = "<group>"; };
929933
D721EEA72ABDFF550040BE46 /* LothianRiversAnno.mmpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = LothianRiversAnno.mmpk; sourceTree = "<group>"; };
930934
D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowExtrudedFeaturesView.swift; sourceTree = "<group>"; };
931935
D7232EE02AC1E5AA0079ABFF /* PlayKMLTourView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayKMLTourView.swift; sourceTree = "<group>"; };
@@ -1211,6 +1215,7 @@
12111215
955271622C0E6750009B1ED4 /* Add raster from service */,
12121216
E066DD3E28610F3F004D3D5B /* Add scene layer from service */,
12131217
D7BE7E6E2CC19CC3006DDB0C /* Add tiled layer */,
1218+
D7201CD72CC6B710004BDB7D /* Add tiled layer as basemap */,
12141219
3E54CF202C66AFA400DD2F18 /* Add web tiled layer */,
12151220
D7E557602A1D743100B9FB09 /* Add WMS layer */,
12161221
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */,
@@ -2052,6 +2057,14 @@
20522057
path = "Style geometry types with symbols";
20532058
sourceTree = "<group>";
20542059
};
2060+
D7201CD72CC6B710004BDB7D /* Add tiled layer as basemap */ = {
2061+
isa = PBXGroup;
2062+
children = (
2063+
D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */,
2064+
);
2065+
path = "Add tiled layer as basemap";
2066+
sourceTree = "<group>";
2067+
};
20552068
D721EEA62ABDFF550040BE46 /* 174150279af74a2ba6f8b87a567f480b */ = {
20562069
isa = PBXGroup;
20572070
children = (
@@ -3077,6 +3090,7 @@
30773090
AddKmlLayer,
30783091
AddPointCloudLayerFromFile,
30793092
AddRasterFromFile,
3093+
AddTiledLayerAsBasemap,
30803094
Animate3DGraphic,
30813095
AnimateImagesWithImageOverlay,
30823096
ApplyScheduledUpdatesToPreplannedMapArea,
@@ -3304,6 +3318,7 @@
33043318
D7CDD38B2CB86F0A00DE9766 /* AddPointCloudLayerFromFileView.swift in Sources */,
33053319
D7BA38912BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift in Sources */,
33063320
10D321962BDB1CB500B39B1B /* GenerateOfflineMapWithLocalBasemapView.swift in Sources */,
3321+
D7201CDA2CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift in Sources */,
33073322
D73723792AF5ADD800846884 /* FindRouteInMobileMapPackageView.MobileMapView.swift in Sources */,
33083323
E004A6E028466279002A1FE6 /* ShowCalloutView.swift in Sources */,
33093324
E000E763286A0B18005D87C5 /* CutGeometryView.swift in Sources */,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2024 Esri
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import ArcGIS
16+
import SwiftUI
17+
18+
struct AddTiledLayerAsBasemapView: View {
19+
/// A map of the streets in San Francisco.
20+
@State private var map: Map = {
21+
// Creates a tile cache using a URL to a local tile package file.
22+
let tileCache = TileCache(fileURL: .sanFranciscoStreetsTilePackage)
23+
24+
// Creates a tiled layer using the tile cache.
25+
let tiledLayer = ArcGISTiledLayer(tileCache: tileCache)
26+
27+
// Creates a basemap using the layer.
28+
let basemap = Basemap(baseLayer: tiledLayer)
29+
30+
// Creates a map using the basemap.
31+
return Map(basemap: basemap)
32+
}()
33+
34+
var body: some View {
35+
// Displays the map using a map view.
36+
MapView(map: map)
37+
}
38+
}
39+
40+
private extension URL {
41+
/// The URL to the local tile package file with street data for San Francisco, CA, USA.
42+
static var sanFranciscoStreetsTilePackage: URL {
43+
Bundle.main.url(forResource: "SanFrancisco", withExtension: "tpkx")!
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Add tiled layer as basemap
2+
3+
Load an offline copy of a tiled map service as a basemap.
4+
5+
![Screenshot of Add tiled layer as basemap sample](add-tiled-layer-as-basemap.png)
6+
7+
## Use case
8+
9+
Constructing a tiled layer from a local tile package (.tpk & .tpkx) allows you to use that basemap tiled service when the application is offline. Dividing a raster into tiles allows the map to provide relevant tiles and level of detail to the user when panning and zooming. For example, when working in an environment that has no connectivity, this could provide access to a map for navigating your surroundings.
10+
11+
## How to use the sample
12+
13+
Launch the app to view the "San Francisco offline tile package" as the basemap.
14+
15+
## How it works
16+
17+
1. Create a `TileCache`, specifying the path to the local tile package.
18+
2. Create an `ArcGISTiledLayer` with the tile cache.
19+
3. Create a `Basemap` with the tiled layer.
20+
4. Create a `Map` with the basemap and pass it to a MapView.
21+
22+
## Relevant API
23+
24+
* ArcGISTiledLayer
25+
* Basemap
26+
* Map
27+
* TileCache
28+
29+
## Offline data
30+
31+
This sample uses the [San Francisco offline tile package](https://www.arcgis.com/home/item.html?id=e4a398afe9a945f3b0f4dca1e4faccb5). It is downloaded from ArcGIS Online automatically.
32+
33+
## About the data
34+
35+
The map opens to a view of the city of San Francisco, CA. In a disconnected environment, this basemap tile service would be fully accessible to zoom and pan as if you were connected to an online service.
36+
37+
## Additional information
38+
39+
`ArcGISTiledLayer` and `TileCache` supports both .tpk and .tpkx file formats.
40+
41+
## Tags
42+
43+
cache, layers, offline, tile
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"category": "Edit and Manage Data",
3+
"description": "Load an offline copy of a tiled map service as a basemap.",
4+
"ignore": false,
5+
"images": [
6+
"add-tiled-layer-as-basemap.png"
7+
],
8+
"keywords": [
9+
"cache",
10+
"layers",
11+
"offline",
12+
"tile",
13+
"ArcGISTiledLayer",
14+
"Basemap",
15+
"Map",
16+
"TileCache"
17+
],
18+
"offline_data": [
19+
"e4a398afe9a945f3b0f4dca1e4faccb5"
20+
],
21+
"redirect_from": [],
22+
"relevant_apis": [
23+
"ArcGISTiledLayer",
24+
"Basemap",
25+
"Map",
26+
"TileCache"
27+
],
28+
"snippets": [
29+
"AddTiledLayerAsBasemapView.swift"
30+
],
31+
"title": "Add tiled layer as basemap"
32+
}
140 KB
Loading

0 commit comments

Comments
 (0)