|
| 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 Add3DTilesLayerView: View { |
| 19 | + /// A scene with dark gray basemap and an OGC 3D tiles layer. |
| 20 | + @State private var scene: ArcGIS.Scene = { |
| 21 | + // Creates a scene and sets an initial viewpoint. |
| 22 | + let scene = Scene(basemapStyle: .arcGISDarkGray) |
| 23 | + let camera = Camera( |
| 24 | + latitude: 48.84553, |
| 25 | + longitude: 9.16275, |
| 26 | + altitude: 350, |
| 27 | + heading: 0, |
| 28 | + pitch: 75, |
| 29 | + roll: 0 |
| 30 | + ) |
| 31 | + scene.initialViewpoint = Viewpoint(boundingGeometry: camera.location, camera: camera) |
| 32 | + |
| 33 | + // Creates a surface and adds an elevation source. |
| 34 | + let surface = Surface() |
| 35 | + surface.addElevationSource(ArcGISTiledElevationSource(url: .worldElevationService)) |
| 36 | + |
| 37 | + // Sets the surface to the scene's base surface. |
| 38 | + scene.baseSurface = surface |
| 39 | + |
| 40 | + // Adds a OGC 3D tiles layer from a URL to the scene's operational layers. |
| 41 | + scene.addOperationalLayer(OGC3DTilesLayer(url: .stuttgart3DTiles)) |
| 42 | + return scene |
| 43 | + }() |
| 44 | + |
| 45 | + var body: some View { |
| 46 | + SceneView(scene: scene) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +private extension URL { |
| 51 | + /// The URL of a Stuttgart, Germany city scene service. |
| 52 | + static var stuttgart3DTiles: URL { |
| 53 | + URL(string: "https://tiles.arcgis.com/tiles/N82JbI5EYtAkuUKU/arcgis/rest/services/Stuttgart/3DTilesServer/tileset.json")! |
| 54 | + } |
| 55 | + |
| 56 | + /// The URL of the Terrain 3D ArcGIS REST Service. |
| 57 | + static var worldElevationService: URL { |
| 58 | + URL(string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")! |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +#Preview { |
| 63 | + Add3DTilesLayerView() |
| 64 | +} |
0 commit comments