|
| 1 | +/* |
| 2 | + * Copyright 2016 Esri. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.esri.samples.scene.terrain_exaggeration; |
| 18 | + |
| 19 | +import javafx.fxml.FXML; |
| 20 | +import javafx.scene.control.Slider; |
| 21 | + |
| 22 | +import com.esri.arcgisruntime.geometry.Point; |
| 23 | +import com.esri.arcgisruntime.layers.ArcGISMapImageLayer; |
| 24 | +import com.esri.arcgisruntime.mapping.ArcGISScene; |
| 25 | +import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource; |
| 26 | +import com.esri.arcgisruntime.mapping.Basemap; |
| 27 | +import com.esri.arcgisruntime.mapping.Surface; |
| 28 | +import com.esri.arcgisruntime.mapping.view.Camera; |
| 29 | +import com.esri.arcgisruntime.mapping.view.SceneView; |
| 30 | + |
| 31 | +public class TerrainExaggerationController { |
| 32 | + |
| 33 | + @FXML private SceneView sceneView; |
| 34 | + @FXML private Slider exaggerationSlider; |
| 35 | + |
| 36 | + public void initialize() { |
| 37 | + |
| 38 | + try { |
| 39 | + |
| 40 | + // create a scene and add a basemap to it |
| 41 | + ArcGISScene scene = new ArcGISScene(); |
| 42 | + scene.setBasemap(Basemap.createNationalGeographic()); |
| 43 | + |
| 44 | + // add the SceneView to the stack pane |
| 45 | + sceneView.setArcGISScene(scene); |
| 46 | + |
| 47 | + // add base surface for elevation data |
| 48 | + Surface surface = new Surface(); |
| 49 | + final String elevationImageService = |
| 50 | + "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"; |
| 51 | + surface.getElevationSources().add(new ArcGISTiledElevationSource(elevationImageService)); |
| 52 | + scene.setBaseSurface(surface); |
| 53 | + |
| 54 | + // add terrain layer to scene |
| 55 | + final String imageLayer = |
| 56 | + "https://gis.grantcountywa.gov:6443/arcgis/rest/services/EveryoneData/SlopePercent/MapServer"; |
| 57 | + ArcGISMapImageLayer layer = new ArcGISMapImageLayer(imageLayer); |
| 58 | + layer.loadAsync(); |
| 59 | + scene.getOperationalLayers().add(layer); |
| 60 | + |
| 61 | + // set exaggeration of surface to the value the user selected |
| 62 | + exaggerationSlider.valueChangingProperty().addListener(o -> { |
| 63 | + if (!exaggerationSlider.isValueChanging()) { |
| 64 | + surface.setElevationExaggeration((float) exaggerationSlider.getValue()); |
| 65 | + } |
| 66 | + }); |
| 67 | + // add a camera and initial camera position |
| 68 | + Point initialLocation = new Point(-119.94891542688772, 46.75792111605992, 0, sceneView.getSpatialReference()); |
| 69 | + Camera camera = new Camera(initialLocation, 15000.0, 40.0, 60.0, 0.0); |
| 70 | + sceneView.setViewpointCamera(camera); |
| 71 | + |
| 72 | + } catch (Exception e) { |
| 73 | + // on any exception, print the stack trace |
| 74 | + e.printStackTrace(); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Disposes application resources. |
| 80 | + */ |
| 81 | + void terminate() { |
| 82 | + if (sceneView != null) { |
| 83 | + sceneView.dispose(); |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments