|
| 1 | +/* |
| 2 | + * Copyright 2017 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.feature_layer_rendering_mode_scene; |
| 18 | + |
| 19 | +import javafx.application.Application; |
| 20 | +import javafx.scene.Scene; |
| 21 | +import javafx.scene.control.Button; |
| 22 | +import javafx.scene.layout.BorderPane; |
| 23 | +import javafx.stage.Stage; |
| 24 | + |
| 25 | +import com.esri.arcgisruntime.concurrent.ListenableFuture; |
| 26 | +import com.esri.arcgisruntime.data.ServiceFeatureTable; |
| 27 | +import com.esri.arcgisruntime.geometry.Point; |
| 28 | +import com.esri.arcgisruntime.geometry.SpatialReferences; |
| 29 | +import com.esri.arcgisruntime.layers.FeatureLayer; |
| 30 | +import com.esri.arcgisruntime.mapping.ArcGISScene; |
| 31 | +import com.esri.arcgisruntime.mapping.view.Camera; |
| 32 | +import com.esri.arcgisruntime.mapping.view.SceneView; |
| 33 | + |
| 34 | +public class FeatureLayerRenderingModeSceneSample extends Application { |
| 35 | + |
| 36 | + private SceneView sceneViewTop; |
| 37 | + private SceneView sceneViewBottom; |
| 38 | + |
| 39 | + @Override |
| 40 | + public void start(Stage stage) throws Exception { |
| 41 | + |
| 42 | + try { |
| 43 | + |
| 44 | + // create border pane and JavaFX app scene |
| 45 | + BorderPane borderPane = new BorderPane(); |
| 46 | + Scene fxScene = new Scene(borderPane); |
| 47 | + |
| 48 | + // set title, size, and add JavaFX scene to stage |
| 49 | + stage.setTitle("Feature Layer Rendering Mode Scene Sample"); |
| 50 | + stage.setWidth(800); |
| 51 | + stage.setHeight(700); |
| 52 | + stage.setScene(fxScene); |
| 53 | + stage.show(); |
| 54 | + |
| 55 | + // create a scene (top) and set it to render all features in static rendering mode |
| 56 | + ArcGISScene sceneTop = new ArcGISScene(); |
| 57 | + sceneTop.getLoadSettings().setPreferredPointFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC); |
| 58 | + sceneTop.getLoadSettings().setPreferredPolylineFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC); |
| 59 | + sceneTop.getLoadSettings().setPreferredPolygonFeatureRenderingMode(FeatureLayer.RenderingMode.STATIC); |
| 60 | + |
| 61 | + // create a scene (bottom) and set it to render all features in dynamic rendering mode |
| 62 | + ArcGISScene sceneBottom = new ArcGISScene(); |
| 63 | + sceneBottom.getLoadSettings().setPreferredPointFeatureRenderingMode(FeatureLayer.RenderingMode.DYNAMIC); |
| 64 | + sceneBottom.getLoadSettings().setPreferredPolylineFeatureRenderingMode(FeatureLayer.RenderingMode.DYNAMIC); |
| 65 | + sceneBottom.getLoadSettings().setPreferredPolygonFeatureRenderingMode(FeatureLayer.RenderingMode.DYNAMIC); |
| 66 | + |
| 67 | + // creating top scene view |
| 68 | + sceneViewTop = new SceneView(); |
| 69 | + sceneViewTop.setMinHeight(stage.getHeight() / 2); |
| 70 | + sceneViewTop.setArcGISScene(sceneTop); |
| 71 | + borderPane.setTop(sceneViewTop); |
| 72 | + // creating bottom scene view |
| 73 | + sceneViewBottom = new SceneView(); |
| 74 | + sceneViewTop.setMinHeight(stage.getHeight() / 2); |
| 75 | + sceneViewBottom.setArcGISScene(sceneBottom); |
| 76 | + borderPane.setCenter(sceneViewBottom); |
| 77 | + |
| 78 | + // create service feature table using a point, polyline, and polygon service |
| 79 | + ServiceFeatureTable poinServiceFeatureTable = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/0"); |
| 80 | + ServiceFeatureTable polylineServiceFeatureTable = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/8"); |
| 81 | + ServiceFeatureTable polygonServiceFeatureTable = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9"); |
| 82 | + |
| 83 | + // create feature layer from service feature tables |
| 84 | + FeatureLayer pointFeatureLayer = new FeatureLayer(poinServiceFeatureTable); |
| 85 | + FeatureLayer polylineFeatureLayer = new FeatureLayer(polylineServiceFeatureTable); |
| 86 | + FeatureLayer polygonFeatureLayer = new FeatureLayer(polygonServiceFeatureTable); |
| 87 | + |
| 88 | + // add each layer to top and bottom scene |
| 89 | + sceneTop.getOperationalLayers().add(pointFeatureLayer); |
| 90 | + sceneTop.getOperationalLayers().add(polylineFeatureLayer); |
| 91 | + sceneTop.getOperationalLayers().add(polygonFeatureLayer); |
| 92 | + sceneBottom.getOperationalLayers().add(pointFeatureLayer.copy()); |
| 93 | + sceneBottom.getOperationalLayers().add(polylineFeatureLayer.copy()); |
| 94 | + sceneBottom.getOperationalLayers().add(polygonFeatureLayer.copy()); |
| 95 | + |
| 96 | + // camera locations for camera to zoom in and out to |
| 97 | + Camera zoomOutCamera = new Camera(new Point(-118.37, 34.46, SpatialReferences.getWgs84()), 42000, 0, 0, 0); |
| 98 | + Camera zoomInCamera = new Camera(new Point(-118.45, 34.395, SpatialReferences.getWgs84()), 2500, 90, 75, 90); |
| 99 | + sceneViewTop.setViewpointCamera(zoomOutCamera); |
| 100 | + sceneViewBottom.setViewpointCamera(zoomOutCamera); |
| 101 | + |
| 102 | + Button zoomButton = new Button("Start Zoom"); |
| 103 | + zoomButton.setOnAction(e -> { |
| 104 | + zoomButton.setDisable(true); |
| 105 | + // zoom in for five seconds |
| 106 | + zoomTo(zoomInCamera, 5).addDoneListener(() -> { |
| 107 | + // wait for three seconds before returning |
| 108 | + zoomTo(zoomInCamera, 3).addDoneListener(() -> { |
| 109 | + // zoom out for five seconds |
| 110 | + zoomTo(zoomOutCamera, 5).addDoneListener(() -> { |
| 111 | + zoomButton.setDisable(false); |
| 112 | + }); |
| 113 | + }); |
| 114 | + }); |
| 115 | + }); |
| 116 | + zoomButton.setMaxWidth(Double.MAX_VALUE); |
| 117 | + borderPane.setBottom(zoomButton); |
| 118 | + |
| 119 | + } catch (Exception e) { |
| 120 | + // on any error, display the stack trace. |
| 121 | + e.printStackTrace(); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Sets both Sceneviews to a ViewpointCamera over a number of seconds. |
| 127 | + * |
| 128 | + * @param camera to which both SceneViews should be set. |
| 129 | + * @param seconds over which the viewpoint is asynchronously set. |
| 130 | + * |
| 131 | + * @return a ListenableFuture representing the result of the Viewpoint change. |
| 132 | + */ |
| 133 | + private ListenableFuture<Boolean> zoomTo(Camera camera, int seconds) { |
| 134 | + ListenableFuture<Boolean> setViewpointFuture = sceneViewTop.setViewpointCameraAsync(camera, seconds); |
| 135 | + sceneViewBottom.setViewpointCameraAsync(camera, seconds); |
| 136 | + return setViewpointFuture; |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Stops and releases all resources used in application. |
| 141 | + */ |
| 142 | + @Override |
| 143 | + public void stop() { |
| 144 | + |
| 145 | + if (sceneViewTop != null) { |
| 146 | + sceneViewTop.dispose(); |
| 147 | + } |
| 148 | + if (sceneViewBottom != null) { |
| 149 | + sceneViewBottom.dispose(); |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Opens and runs application. |
| 155 | + * |
| 156 | + * @param args arguments passed to this application |
| 157 | + */ |
| 158 | + public static void main(String[] args) { |
| 159 | + |
| 160 | + Application.launch(args); |
| 161 | + } |
| 162 | + |
| 163 | +} |
0 commit comments