Skip to content

Commit b75c958

Browse files
authored
Merge pull request #492 from Esri/Fredy/New-AddWebTiledLayer
[New] Add web tiled layer
2 parents def2a79 + 76d6dfa commit b75c958

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
1CAF831F2A20305F000E1E60 /* ShowUtilityAssociationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CAF831B2A20305F000E1E60 /* ShowUtilityAssociationsView.swift */; };
139139
218F35B829C28F4A00502022 /* AuthenticateWithOAuthView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */; };
140140
218F35C229C290BF00502022 /* AuthenticateWithOAuthView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */; };
141+
3E26AFB62C627F0900BD2CBC /* AddWebTiledLayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */; };
142+
3E7183942C643C9200154294 /* AddWebTiledLayerView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */; };
141143
4D126D6D29CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */; };
142144
4D126D7229CA1E1800CFB7A7 /* FileNMEASentenceReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D126D7129CA1E1800CFB7A7 /* FileNMEASentenceReader.swift */; };
143145
4D126D7329CA1EFD00CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */; };
@@ -527,6 +529,7 @@
527529
dstPath = "";
528530
dstSubfolderSpec = 7;
529531
files = (
532+
3E7183942C643C9200154294 /* AddWebTiledLayerView.swift in Copy Source Code Files */,
530533
D78FA4952C3C8E8A0079313E /* CreateDynamicBasemapGalleryView.Views.swift in Copy Source Code Files */,
531534
D79482D72C35D8A3006521CD /* CreateDynamicBasemapGalleryView.swift in Copy Source Code Files */,
532535
003B36F92C5042BA00A75F66 /* ShowServiceAreaView.swift in Copy Source Code Files */,
@@ -811,6 +814,7 @@
811814
1CAB8D472A3CEAB0002AA649 /* RunValveIsolationTraceView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RunValveIsolationTraceView.swift; sourceTree = "<group>"; };
812815
1CAF831B2A20305F000E1E60 /* ShowUtilityAssociationsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowUtilityAssociationsView.swift; sourceTree = "<group>"; };
813816
218F35B329C28F4A00502022 /* AuthenticateWithOAuthView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthenticateWithOAuthView.swift; sourceTree = "<group>"; };
817+
3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebTiledLayerView.swift; sourceTree = "<group>"; };
814818
4D126D6929CA1B6000CFB7A7 /* ShowDeviceLocationWithNMEADataSourcesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowDeviceLocationWithNMEADataSourcesView.swift; sourceTree = "<group>"; };
815819
4D126D7129CA1E1800CFB7A7 /* FileNMEASentenceReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileNMEASentenceReader.swift; sourceTree = "<group>"; };
816820
4D126D7B29CA3E6000CFB7A7 /* Redlands.nmea */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Redlands.nmea; sourceTree = "<group>"; };
@@ -1134,6 +1138,7 @@
11341138
F19A316128906F0D003B7EF9 /* Add raster from file */,
11351139
955271622C0E6750009B1ED4 /* Add raster from service */,
11361140
E066DD3E28610F3F004D3D5B /* Add scene layer from service */,
1141+
3E26AFB42C627EAE00BD2CBC /* Add web tiled layer */,
11371142
D7E557602A1D743100B9FB09 /* Add WMS layer */,
11381143
1C3B7DC22A5F64FC00907443 /* Analyze network with subnetwork trace */,
11391144
D7C16D172AC5F6C100689E89 /* Animate 3D graphic */,
@@ -1634,6 +1639,14 @@
16341639
path = "Authenticate with OAuth";
16351640
sourceTree = "<group>";
16361641
};
1642+
3E26AFB42C627EAE00BD2CBC /* Add web tiled layer */ = {
1643+
isa = PBXGroup;
1644+
children = (
1645+
3E26AFB52C627F0900BD2CBC /* AddWebTiledLayerView.swift */,
1646+
);
1647+
path = "Add web tiled layer";
1648+
sourceTree = "<group>";
1649+
};
16371650
4D126D6829CA1B6000CFB7A7 /* Show device location with NMEA data sources */ = {
16381651
isa = PBXGroup;
16391652
children = (
@@ -3117,6 +3130,7 @@
31173130
0074ABCD2817BCC30037244A /* SamplesApp+Samples.swift.tache in Sources */,
31183131
D79EE76E2A4CEA5D005A52AE /* SetUpLocationDrivenGeotriggersView.Model.swift in Sources */,
31193132
D74F03F02B609A7D00E83688 /* AddFeaturesWithContingentValuesView.Model.swift in Sources */,
3133+
3E26AFB62C627F0900BD2CBC /* AddWebTiledLayerView.swift in Sources */,
31203134
E004A6F3284E4FEB002A1FE6 /* ShowResultOfSpatialOperationsView.swift in Sources */,
31213135
955AFAC42C10FD6F009C8FE5 /* ApplyMosaicRuleToRastersView.swift in Sources */,
31223136
D751018E2A2E962D00B8FA48 /* IdentifyLayerFeaturesView.swift in Sources */,
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 AddWebTiledLayerView: View {
19+
/// A map with web tiled layer.
20+
@State private var map: Map = {
21+
// Build the web tiled layer from ArcGIS Living Atlas of the World tile service url.
22+
let webTiledLayer = WebTiledLayer(urlTemplate: .worldTileServiceStringURL)
23+
webTiledLayer.setAttribution(.attributionString)
24+
25+
let basemap = Basemap(baseLayer: webTiledLayer)
26+
let map = Map(basemap: basemap)
27+
map.initialViewpoint = Viewpoint(
28+
center: Point(x: -1e6, y: 1e6),
29+
scale: 15e7
30+
)
31+
return map
32+
}()
33+
34+
var body: some View {
35+
MapView(map: map)
36+
}
37+
}
38+
39+
private extension String {
40+
/// The attribution string for the ArcGIS Living Atlas of the World.
41+
static let attributionString = """
42+
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.
43+
"""
44+
/// The web tile service url from ArcGIS Living Atlas of the World.
45+
static let worldTileServiceStringURL = "https://services.arcgisonline.com/ArcGIS/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{level}/{row}/{col}.jpg"
46+
}
47+
48+
#Preview {
49+
AddWebTiledLayerView()
50+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Add web tiled layer
2+
3+
Display a tiled web layer.
4+
5+
![Image of Add web tiled layer sample](add-web-tiled-layer.png)
6+
7+
## Use case
8+
9+
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.
10+
11+
## How to use the sample
12+
13+
Run the sample and a map will appear. As you navigate the map, map tiles will be fetched automatically and displayed on the map.
14+
15+
## How it works
16+
17+
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.
18+
19+
* Subdomain is optional and allows the Maps SDK to balance requests among multiple servers for enhanced performance.
20+
* Level, row, and column select the tiles to load based on the visible extent of the map.
21+
22+
To display the web tiled layer, this sample:
23+
24+
1. Creates a `WebTiledLayer` from a URL.
25+
2. Creates a new `Basemap` from the layer.
26+
3. Updates the attribution on the layer. Note: this is a necessary step because web tiled services don't have associated service metadata.
27+
4. Displays the basemap.
28+
29+
For more information about web tiled layers, see the following resources:
30+
31+
* [Wikipedia: tiled web maps](https://en.wikipedia.org/wiki/Tiled_web_map)
32+
* [ArcGIS Pro: Share a web tile layer](https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/web-tile-layer.htm)
33+
34+
## Relevant API
35+
36+
* Basemap
37+
* WebTiledLayer
38+
39+
## About the data
40+
41+
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.
42+
43+
## Tags
44+
45+
layer, OGC, tiled, tiles
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"category": "Layers",
3+
"description": "Display a tiled web layer.",
4+
"ignore": false,
5+
"images": [
6+
"add-web-tiled-layer.png"
7+
],
8+
"keywords": [
9+
"OGC",
10+
"layer",
11+
"tiled",
12+
"tiles",
13+
"Basemap",
14+
"WebTiledLayer"
15+
],
16+
"redirect_from": [],
17+
"relevant_apis": [
18+
"Basemap",
19+
"WebTiledLayer"
20+
],
21+
"snippets": [
22+
"AddWebTiledLayerView.swift"
23+
],
24+
"title": "Add web tiled layer"
25+
}
259 KB
Loading

0 commit comments

Comments
 (0)