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

[New] Add tiled layer as basemap #527

Merged
merged 5 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 16 additions & 1 deletion Samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@
D71D516F2B51D87700B2A2BE /* SearchForWebMapView.Views.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D71D516D2B51D7B600B2A2BE /* SearchForWebMapView.Views.swift */; };
D71FCB8A2AD6277F000E517C /* CreateMobileGeodatabaseView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */; };
D71FCB8B2AD628B9000E517C /* CreateMobileGeodatabaseView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */; };
D7201CDA2CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */; };
D7201CDB2CC6B72A004BDB7D /* AddTiledLayerAsBasemapView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */; };
D721EEA82ABDFF550040BE46 /* LothianRiversAnno.mmpk in Resources */ = {isa = PBXBuildFile; fileRef = D721EEA72ABDFF550040BE46 /* LothianRiversAnno.mmpk */; settings = {ASSET_TAGS = (ShowMobileMapPackageExpirationDate, ); }; };
D722BD222A420DAD002C2087 /* ShowExtrudedFeaturesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */; };
D722BD232A420DEC002C2087 /* ShowExtrudedFeaturesView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */; };
Expand Down Expand Up @@ -435,7 +437,7 @@
D7C16D282AC5FEB700689E89 /* Hawaii.csv in Resources */ = {isa = PBXBuildFile; fileRef = D7C16D272AC5FEB600689E89 /* Hawaii.csv */; settings = {ASSET_TAGS = (Animate3DGraphic, ); }; };
D7C3AB4A2B683291008909B9 /* SetFeatureRequestModeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C3AB472B683291008909B9 /* SetFeatureRequestModeView.swift */; };
D7C3AB4D2B6832B7008909B9 /* SetFeatureRequestModeView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7C3AB472B683291008909B9 /* SetFeatureRequestModeView.swift */; };
D7C523402BED9BBF00E8221A /* SanFrancisco.tpkx in Resources */ = {isa = PBXBuildFile; fileRef = D7C5233E2BED9BBF00E8221A /* SanFrancisco.tpkx */; settings = {ASSET_TAGS = (EditAndSyncFeaturesWithFeatureService, ); }; };
D7C523402BED9BBF00E8221A /* SanFrancisco.tpkx in Resources */ = {isa = PBXBuildFile; fileRef = D7C5233E2BED9BBF00E8221A /* SanFrancisco.tpkx */; settings = {ASSET_TAGS = (AddTiledLayerAsBasemap, EditAndSyncFeaturesWithFeatureService, ); }; };
D7C6420C2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C6420B2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift */; };
D7C6420D2B4F5DDB0042B8F7 /* SearchForWebMapView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7C6420B2B4F47E10042B8F7 /* SearchForWebMapView.Model.swift */; };
D7C97B562B75C10C0097CDA1 /* ValidateUtilityNetworkTopologyView.Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C97B552B75C10C0097CDA1 /* ValidateUtilityNetworkTopologyView.Views.swift */; };
Expand Down Expand Up @@ -562,6 +564,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
D7201CDB2CC6B72A004BDB7D /* AddTiledLayerAsBasemapView.swift in Copy Source Code Files */,
D7BE7E722CC19CE5006DDB0C /* AddTiledLayerView.swift in Copy Source Code Files */,
D7BEBAD52CBDFE3900F882E7 /* DisplayAlternateSymbolsAtDifferentScalesView.swift in Copy Source Code Files */,
D7BEBAC62CBDC11600F882E7 /* AddElevationSourceFromTilePackageView.swift in Copy Source Code Files */,
Expand Down Expand Up @@ -926,6 +929,7 @@
D71C909D2C6C249B0018C63E /* StyleGeometryTypesWithSymbolsView.Views.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleGeometryTypesWithSymbolsView.Views.swift; sourceTree = "<group>"; };
D71D516D2B51D7B600B2A2BE /* SearchForWebMapView.Views.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchForWebMapView.Views.swift; sourceTree = "<group>"; };
D71FCB892AD6277E000E517C /* CreateMobileGeodatabaseView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateMobileGeodatabaseView.Model.swift; sourceTree = "<group>"; };
D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddTiledLayerAsBasemapView.swift; sourceTree = "<group>"; };
D721EEA72ABDFF550040BE46 /* LothianRiversAnno.mmpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = LothianRiversAnno.mmpk; sourceTree = "<group>"; };
D722BD212A420DAD002C2087 /* ShowExtrudedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowExtrudedFeaturesView.swift; sourceTree = "<group>"; };
D7232EE02AC1E5AA0079ABFF /* PlayKMLTourView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayKMLTourView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1211,6 +1215,7 @@
955271622C0E6750009B1ED4 /* Add raster from service */,
E066DD3E28610F3F004D3D5B /* Add scene layer from service */,
D7BE7E6E2CC19CC3006DDB0C /* Add tiled layer */,
D7201CD72CC6B710004BDB7D /* Add tiled layer as basemap */,
3E54CF202C66AFA400DD2F18 /* Add web tiled layer */,
D7E557602A1D743100B9FB09 /* Add WMS layer */,
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */,
Expand Down Expand Up @@ -2052,6 +2057,14 @@
path = "Style geometry types with symbols";
sourceTree = "<group>";
};
D7201CD72CC6B710004BDB7D /* Add tiled layer as basemap */ = {
isa = PBXGroup;
children = (
D7201CD42CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift */,
);
path = "Add tiled layer as basemap";
sourceTree = "<group>";
};
D721EEA62ABDFF550040BE46 /* 174150279af74a2ba6f8b87a567f480b */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3077,6 +3090,7 @@
AddKmlLayer,
AddPointCloudLayerFromFile,
AddRasterFromFile,
AddTiledLayerAsBasemap,
Animate3DGraphic,
AnimateImagesWithImageOverlay,
ApplyScheduledUpdatesToPreplannedMapArea,
Expand Down Expand Up @@ -3304,6 +3318,7 @@
D7CDD38B2CB86F0A00DE9766 /* AddPointCloudLayerFromFileView.swift in Sources */,
D7BA38912BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift in Sources */,
10D321962BDB1CB500B39B1B /* GenerateOfflineMapWithLocalBasemapView.swift in Sources */,
D7201CDA2CC6B710004BDB7D /* AddTiledLayerAsBasemapView.swift in Sources */,
D73723792AF5ADD800846884 /* FindRouteInMobileMapPackageView.MobileMapView.swift in Sources */,
E004A6E028466279002A1FE6 /* ShowCalloutView.swift in Sources */,
E000E763286A0B18005D87C5 /* CutGeometryView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ArcGIS
import SwiftUI

struct AddTiledLayerAsBasemapView: View {
/// A map of the streets in San Francisco.
@State private var map: Map = {
// Creates a tile cache using a URL to a local tile package file.
let tileCache = TileCache(fileURL: .sanFranciscoStreetsTilePackage)

// Creates a tiled layer using the tile cache.
let tiledLayer = ArcGISTiledLayer(tileCache: tileCache)

// Creates a basemap using the layer.
let basemap = Basemap(baseLayer: tiledLayer)

// Creates a map using the basemap.
return Map(basemap: basemap)
}()

var body: some View {
// Displays the map using a map view.
MapView(map: map)
}
}

private extension URL {
/// The URL to the local tile package file with street data for San Francisco, CA, USA.
static var sanFranciscoStreetsTilePackage: URL {
Bundle.main.url(forResource: "SanFrancisco", withExtension: "tpkx")!
}
}
43 changes: 43 additions & 0 deletions Shared/Samples/Add tiled layer as basemap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Add tiled layer as basemap

Load an offline copy of a tiled map service as a basemap.

![Screenshot of Add tiled layer as basemap sample](add-tiled-layer-as-basemap.png)

## Use case

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.

## How to use the sample

Launch the app to view the "San Francisco offline tile package" as the basemap.

## How it works

1. Create a `TileCache`, specifying the path to the local tile package.
2. Create an `ArcGISTiledLayer` with the tile cache.
3. Create a `Basemap` with the tiled layer.
4. Create an `ArcGISMap` with the basemap and pass it to a MapView.
CalebRas marked this conversation as resolved.
Show resolved Hide resolved

## Relevant API

* ArcGISTiledLayer
* Basemap
* Map
* TileCache

## Offline data

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.

## About the data

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.

## Additional information

`ArcGISTiledLayer` and `TileCache` supports both .tpk and .tpkx file formats.

## Tags

cache, layers, offline, tile
32 changes: 32 additions & 0 deletions Shared/Samples/Add tiled layer as basemap/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"category": "Edit and Manage Data",
"description": "Load an offline copy of a tiled map service as a basemap.",
"ignore": false,
"images": [
"add-tiled-layer-as-basemap.png"
],
"keywords": [
"cache",
"layers",
"offline",
"tile",
"ArcGISTiledLayer",
"Basemap",
"Map",
"TileCache"
],
"offline_data": [
"e4a398afe9a945f3b0f4dca1e4faccb5"
],
"redirect_from": [],
"relevant_apis": [
"ArcGISTiledLayer",
"Basemap",
"Map",
"TileCache"
],
"snippets": [
"AddTiledLayerAsBasemapView.swift"
],
"title": "Add tiled layer as basemap"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading