Skip to content

Commit 4ab157a

Browse files
authored
Merge pull request #108 from Esri/john0005/TerrainExaggeration
Surface Terrain Exaggeration Sample
2 parents 9f735b7 + 063a98c commit 4ab157a

File tree

6 files changed

+197
-0
lines changed

6 files changed

+197
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<h1>Terrain Exaggeration</h1>
2+
3+
<p>Demonstrates how to add vertical exaggeration to a scene's surface.</p>
4+
5+
<p><img src="TerrainExaggeration.gif"/></p>
6+
7+
<h2>How to use the sample</h2>
8+
9+
<p>Selecting an exaggeration amount from the slider will apply that to the scene's surface.</p>
10+
11+
<h2>How it works</h2>
12+
13+
<p>To exaggerate a <code>Scene</code>'s <code>Surface</code>:</p>
14+
15+
<ol>
16+
<li>Create an elevated surface and add it to the scene, <code>Surface.getElevationSources().add("elevationURL")</code></li>
17+
<li>Add surface to the scene, <code> scene.setBaseSurface(Surface)</code></li>
18+
<li>Set exaggeration amount of the surface, <code>Surface.setElevationExaggeration(exaggeration)</code></li>
19+
</ol>
20+
21+
<h2>Features</h2>
22+
23+
<ul>
24+
<li>ArcGISScene</li>
25+
<li>Surface</li>
26+
<li>ArcGISTiledElevationSource</li>
27+
</ul>
1.07 MB
Loading
287 KB
Loading
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
package com.esri.samples.scene.terrain_exaggeration;
17+
18+
import java.io.IOException;
19+
20+
import javafx.application.Application;
21+
import javafx.fxml.FXMLLoader;
22+
import javafx.scene.Parent;
23+
import javafx.scene.Scene;
24+
import javafx.stage.Stage;
25+
26+
public class TerrainExaggerationSample extends Application {
27+
28+
private static TerrainExaggerationController controller;
29+
30+
@Override
31+
public void start(Stage stage) throws IOException {
32+
// set up the scene
33+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/terrain_exaggeration.fxml"));
34+
Parent root = loader.load();
35+
controller = loader.getController();
36+
Scene scene = new Scene(root);
37+
38+
// set up the stage
39+
stage.setTitle("Terrain Exaggeration Sample");
40+
stage.setWidth(800);
41+
stage.setHeight(700);
42+
stage.setScene(scene);
43+
stage.show();
44+
}
45+
46+
/**
47+
* Stops and releases all resources used in application.
48+
*/
49+
@Override
50+
public void stop() {
51+
controller.terminate();
52+
}
53+
54+
/**
55+
* Opens and runs application.
56+
*
57+
* @param args arguments passed to this application
58+
*/
59+
public static void main(String[] args) {
60+
61+
Application.launch(args);
62+
}
63+
64+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.control.Slider?>
5+
<?import javafx.scene.layout.StackPane?>
6+
<?import javafx.scene.layout.VBox?>
7+
8+
<?import com.esri.arcgisruntime.mapping.view.SceneView?>
9+
10+
<StackPane fx:controller="com.esri.samples.scene.terrain_exaggeration.TerrainExaggerationController" xmlns:fx="http://javafx.com/fxml"
11+
stylesheets="/css/style.css">
12+
<!--SDK SceneView-->
13+
<SceneView fx:id="sceneView"/>
14+
<!--Slider box-->
15+
<VBox StackPane.alignment="TOP_LEFT" maxWidth="200" maxHeight="50" spacing="5" styleClass="panel-region">
16+
<Label text="Exaggeration"/>
17+
<Slider fx:id="exaggerationSlider" max="5" majorTickUnit="1" minorTickCount="0" showTickMarks="true"
18+
showTickLabels="true" snapToTicks="true"/>
19+
</VBox>
20+
</StackPane>

0 commit comments

Comments
 (0)