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 web tiled layer #492

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 14 additions & 0 deletions Samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
1CAF831F2A20305F000E1E60 /* ShowUtilityAssociationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CAF831B2A20305F000E1E60 /* ShowUtilityAssociationsView.swift */; };
218F35B829C28F4A00502022 /* AuthenticateWithOAuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */; };
218F35C229C290BF00502022 /* AuthenticateWithOAuthView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */; };
3E26AFB62C627F0900BD2CBC /* AddWebTiledLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */; };
3E7183942C643C9200154294 /* AddWebTiledLayerView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */; };
4D126D6D29CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */; };
4D126D7229CA1E1800CFB7A7 /* FileNMEASentenceReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D126D7129CA1E1800CFB7A7 /* FileNMEASentenceReader.swift */; };
4D126D7329CA1EFD00CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */; };
Expand Down Expand Up @@ -527,6 +529,7 @@
dstPath = "";
dstSubfolderSpec = 7;
files = (
3E7183942C643C9200154294 /* AddWebTiledLayerView.swift in Copy Source Code Files */,
D78FA4952C3C8E8A0079313E /* CreateDynamicBasemapGalleryView.Views.swift in Copy Source Code Files */,
D79482D72C35D8A3006521CD /* CreateDynamicBasemapGalleryView.swift in Copy Source Code Files */,
003B36F92C5042BA00A75F66 /* ShowServiceAreaView.swift in Copy Source Code Files */,
Expand Down Expand Up @@ -811,6 +814,7 @@
1CAB8D472A3CEAB0002AA649 /* RunValveIsolationTraceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RunValveIsolationTraceView.swift; sourceTree = "<group>"; };
1CAF831B2A20305F000E1E60 /* ShowUtilityAssociationsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowUtilityAssociationsView.swift; sourceTree = "<group>"; };
218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticateWithOAuthView.swift; sourceTree = "<group>"; };
3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebTiledLayerView.swift; sourceTree = "<group>"; };
4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowDeviceLocationWithNMEADataSourcesView.swift; sourceTree = "<group>"; };
4D126D7129CA1E1800CFB7A7 /* FileNMEASentenceReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileNMEASentenceReader.swift; sourceTree = "<group>"; };
4D126D7B29CA3E6000CFB7A7 /* Redlands.nmea */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Redlands.nmea; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1134,6 +1138,7 @@
F19A316128906F0D003B7EF9 /* Add raster from file */,
955271622C0E6750009B1ED4 /* Add raster from service */,
E066DD3E28610F3F004D3D5B /* Add scene layer from service */,
3E26AFB42C627EAE00BD2CBC /* Add web tiled layer */,
D7E557602A1D743100B9FB09 /* Add WMS layer */,
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */,
D7C16D172AC5F6C100689E89 /* Animate 3D graphic */,
Expand Down Expand Up @@ -1634,6 +1639,14 @@
path = "Authenticate with OAuth";
sourceTree = "<group>";
};
3E26AFB42C627EAE00BD2CBC /* Add web tiled layer */ = {
isa = PBXGroup;
children = (
3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */,
);
path = "Add web tiled layer";
sourceTree = "<group>";
};
4D126D6829CA1B6000CFB7A7 /* Show device location with NMEA data sources */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3117,6 +3130,7 @@
0074ABCD2817BCC30037244A /* SamplesApp+Samples.swift.tache in Sources */,
D79EE76E2A4CEA5D005A52AE /* SetUpLocationDrivenGeotriggersView.Model.swift in Sources */,
D74F03F02B609A7D00E83688 /* AddFeaturesWithContingentValuesView.Model.swift in Sources */,
3E26AFB62C627F0900BD2CBC /* AddWebTiledLayerView.swift in Sources */,
E004A6F3284E4FEB002A1FE6 /* ShowResultOfSpatialOperationsView.swift in Sources */,
955AFAC42C10FD6F009C8FE5 /* ApplyMosaicRuleToRastersView.swift in Sources */,
D751018E2A2E962D00B8FA48 /* IdentifyLayerFeaturesView.swift in Sources */,
Expand Down
67 changes: 67 additions & 0 deletions Shared/Samples/Add web tiled layer/AddWebTiledLayerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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 AddWebTiledLayerView: View {
/// The view model for the sample.
@StateObject private var model = Model()

var body: some View {
VStack {
fcamas marked this conversation as resolved.
Show resolved Hide resolved
MapView(map: model.map)
}
}
}

private extension AddWebTiledLayerView {
// MARK: - Model

/// The view model for the sample.
final class Model: ObservableObject {
@Published var map: Map
fcamas marked this conversation as resolved.
Show resolved Hide resolved

init() {
self.map = Model.makeMap()
}

/// A map with a web tiled layer as basemap.
static func makeMap() -> Map {
let webTiledLayer = webTiledLayer()
let basemap = Basemap(baseLayer: webTiledLayer)
let map = Map(basemap: basemap)
return map
}

static func webTiledLayer() -> WebTiledLayer {
let worldTileServiceURL = "https://server.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{level}/{row}/{col}.jpg"

let attribution = """
Map tiles by <a href="https://livingatlas.arcgis.com">ArcGIS Living Atlas of the World</a>, under <a href="https://www.esri.com/en-us/legal/terms/full-master-agreement">Esri Master License Agreement</a>. Data by Esri, Garmin, GEBCO, NOAA NGDC, and other contributors.
"""

// Build the web tiled layer from ArcGIS Living Atlas of the World tile service url.
let webTiledLayer = WebTiledLayer(urlTemplate: worldTileServiceURL)
// Set the attribution on the layer.
webTiledLayer.setAttribution(attribution)

return webTiledLayer
}
}
}

#Preview {
AddWebTiledLayerView()
}
45 changes: 45 additions & 0 deletions Shared/Samples/Add web tiled layer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Add web tiled layer

Display a tiled web layer.

![Image of Add web tiled layer](add-web-tiled-layer.png)
fcamas marked this conversation as resolved.
Show resolved Hide resolved

## Use case

Tiled map services are a set of pre-generated images (e.g. "tiles") arranged in folders for each row, column, and zoom level. As you navigate the map, map tiles are requested for the current extent. `ArcGISTiledLayer` and `WMTSLayer` are types of tiled map services used for specific data types. `WebTiledLayer` is useful for displaying other data sources that contain tiles arranged in a row/column/level directory structure, such as OpenStreetMap.
fcamas marked this conversation as resolved.
Show resolved Hide resolved

## How to use the sample

Run the sample and a map will appear. As you navigate the map, map tiles will be fetched automatically and displayed on the map.

## How it works

Web tiled services use a uniform addressing scheme with pre-rendered tiles. Image tiles are accessed via a URL template string, with parameters for subdomain, level, column, and row.

* Subdomain is optional and allows the Maps SDK to balance requests among multiple servers for enhanced performance.
* Level, row, and column select the tiles to load based on the visible extent of the map.

To display the web tiled layer, this sample:

1. Creates a `WebTiledLayer` from a URL.
2. Creates a new `Basemap` from the layer.
3. Updates the attribution on the layer. Note: this is a necessary step because web tiled services don't have associated service metadata.
4. Displays the basemap.

For more information about web tiled layers, see the following resources:

* [Wikipedia: tiled web maps](https://en.wikipedia.org/wiki/Tiled_web_map)
* [ArcGIS Pro: Share a web tile layer](http://pro.arcgis.com/en/pro-app/help/sharing/overview/web-tile-layer.htm)
fcamas marked this conversation as resolved.
Show resolved Hide resolved

## Relevant API

* Basemap
* WebTiledLayer

## About the data

The basemap in this sample is provided by [ArcGIS Living Atlas of the World](https://www.arcgis.com/home/item.html?id=1e126e7520f9466c9ca28b8f28b5e500). ArcGIS Living Atlas of the World provides tiled services with several unique styles.

## Tags

layer, OGC, tiled, tiles
25 changes: 25 additions & 0 deletions Shared/Samples/Add web tiled layer/README.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"category": "Layers",
"description": "Display a tiled web layer.",
"ignore": false,
"images": [
"add-web-tiled-layer.png"
],
"keywords": [
"OGC",
"layer",
"tiled",
"tiles",
"Basemap",
"WebTiledLayer"
],
"redirect_from": [],
"relevant_apis": [
"Basemap",
"WebTiledLayer"
],
"snippets": [
"AddWebTiledLayerView.swift"
],
"title": "Add web tiled layer"
}
fcamas marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading