diff --git a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3d.png b/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3d.png deleted file mode 100644 index 37f89a3a57..0000000000 Binary files a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3d.png and /dev/null differ diff --git a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dController.java b/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dController.java deleted file mode 100644 index 7db8ca81e6..0000000000 --- a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dController.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright 2017 Esri. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.esri.samples.scene.calculate_distance_3d; - -import javafx.animation.Animation; -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; -import javafx.beans.property.LongProperty; -import javafx.beans.property.SimpleLongProperty; -import javafx.fxml.FXML; -import javafx.geometry.Point3D; -import javafx.scene.control.Label; -import javafx.util.Duration; - -import com.esri.arcgisruntime.geometry.Point; -import com.esri.arcgisruntime.geometry.SpatialReference; -import com.esri.arcgisruntime.geometry.SpatialReferences; -import com.esri.arcgisruntime.mapping.ArcGISScene; -import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource; -import com.esri.arcgisruntime.mapping.Basemap; -import com.esri.arcgisruntime.mapping.Surface; -import com.esri.arcgisruntime.mapping.view.Camera; -import com.esri.arcgisruntime.mapping.view.DrawStatus; -import com.esri.arcgisruntime.mapping.view.DrawStatusChangedEvent; -import com.esri.arcgisruntime.mapping.view.DrawStatusChangedListener; -import com.esri.arcgisruntime.mapping.view.Graphic; -import com.esri.arcgisruntime.mapping.view.GraphicsOverlay; -import com.esri.arcgisruntime.mapping.view.LayerSceneProperties.SurfacePlacement; -import com.esri.arcgisruntime.mapping.view.SceneView; -import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol; - -public class CalculateDistance3dController { - - @FXML private Label txtDistance; - private LongProperty distance; - private Timeline animation; - // distance to move graphics each key frame - private double xOffset = -0.1; - - @FXML private SceneView sceneView; - private Point redPoint; - private Point greenPoint; - private SimpleMarkerSymbol redSymbol; - private SimpleMarkerSymbol greenSymbol; - private Graphic redGraphic; - private Graphic greenGraphic; - private final SpatialReference sr = SpatialReferences.getWgs84(); - - private static final String ELEVATION_IMAGE_SERVICE = - "http://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"; - - /** - * Called after FXML loads. Sets up scene and map and configures property bindings. - */ - public void initialize() { - - try { - // create a scene and add to view - ArcGISScene scene = new ArcGISScene(); - scene.setBasemap(Basemap.createImagery()); - sceneView.setArcGISScene(scene); - - // adds elevation to surface - Surface surface = new Surface(); - surface.getElevationSources().add(new ArcGISTiledElevationSource(ELEVATION_IMAGE_SERVICE)); - scene.setBaseSurface(surface); - - createGraphics(); - - // set viewpoint of camera above graphics - Camera camera = new Camera(39, -101, 10000000, 10.0, 0.0, 0.0); - sceneView.setViewpointCamera(camera); - - setupAnimation(); - - // automatically updates distance between graphics to view - distance = new SimpleLongProperty(); - txtDistance.textProperty().bind(distance.asString()); - // set beginning distance of two graphics - distance.set(Math.round(calculateDirectLinearDistance(redPoint, greenPoint))); - - } catch (Exception e) { - // on any error, display the stack trace. - e.printStackTrace(); - } - } - - /** - * Create red and green triangle graphics and displays them to the view. - */ - private void createGraphics() { - - // applies graphics to the view who's altitude is increased by surface's elevation - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); - graphicsOverlay.getSceneProperties().setSurfacePlacement(SurfacePlacement.ABSOLUTE); - sceneView.getGraphicsOverlays().add(graphicsOverlay); - - // creating graphics for view - redPoint = new Point(-77.69531409620706, 40.25390707699415, 900, sr); - redSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, 0xFFFF0000, 20); - redGraphic = new Graphic(redPoint, redSymbol); - graphicsOverlay.getGraphics().add(redGraphic); - - greenPoint = new Point(-120.05859621653715, 38.847657048103514, 1000, sr); - greenSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, 0xFF00FF00, 20); - greenSymbol.setAngle(30); - greenGraphic = new Graphic(greenPoint, greenSymbol); - graphicsOverlay.getGraphics().add(greenGraphic); - } - - /** - * Sets graphic animation to keep running every 100 milliseconds. - *

- * The animation will play once the view is done loading. - */ - private void setupAnimation() { - - animation = new Timeline(new KeyFrame(Duration.millis(100), e -> animate())); - animation.setCycleCount(Animation.INDEFINITE); - - // listener for the view to stop loading - DrawStatusChangedListener listener = new DrawStatusChangedListener() { - - @Override - public void drawStatusChanged(DrawStatusChangedEvent drawStatusChangedEvent) { - if (drawStatusChangedEvent.getDrawStatus() == DrawStatus.COMPLETED) { - // start animation - animation.play(); - // stop listening for the view to load - sceneView.removeDrawStatusChangedListener(this); - } - } - }; - sceneView.addDrawStatusChangedListener(listener); - } - - /** - * Moves graphics along the X axis and calculates distance between them. - */ - private void animate() { - - // changes direction of graphics once they reach their boundary - if (redPoint.getX() <= -120) { - xOffset = 0.1; - redSymbol.setAngle(180); - greenSymbol.setAngle(210); - } else if (redPoint.getX() >= -77) { - xOffset = -0.1; - redSymbol.setAngle(0); - greenSymbol.setAngle(30); - } - - // update red graphic's position - redPoint = new Point(redPoint.getX() + xOffset, redPoint.getY(), redPoint.getZ(), sr); - redGraphic.setGeometry(redPoint); - - //update green graphic's position - greenPoint = new Point(greenPoint.getX() - xOffset, greenPoint.getY(), greenPoint.getZ(), sr); - greenGraphic.setGeometry(greenPoint); - - // updates distance between graphics to view - distance.set(Math.round(calculateDirectLinearDistance(redPoint, greenPoint))); - } - - /** - * Calculates the distance, in meters, between two Points in 3D space. - * - * @param point1 first point - * @param point2 second point - * @return distance, in meters, between the two points - */ - private double calculateDirectLinearDistance(Point point1, Point point2) { - - return convertToCartesianPoint(point1).distance(convertToCartesianPoint(point2)); - } - - /** - * Converts a Point to the Cartesian coordinate system. - * - * @param point point to convert - * @return a 3D point in Cartesian coordinates - */ - private Point3D convertToCartesianPoint(Point point) { - - double x = convertToRadians(point.getY()); - double y = convertToRadians(point.getX()); - double z = point.getZ(); - - // in meters - int earthRadius = 6371000; - double radius = z + earthRadius; - double radCosLat = radius * Math.cos(y); - - double p1 = radCosLat * Math.sin(x); - double p2 = radCosLat * Math.cos(x); - double p3 = radius * Math.sin(y); - - return new Point3D(p1, p2, p3); - } - - /** - * Converts degrees to radians. - * - * @param degrees degree to convert - * @return the converted degrees - */ - private double convertToRadians(double degrees) { - - return degrees * (Math.PI / 180); - } - - /** - * Stops the animation and disposes of application resources. - */ - void terminate() { - - // stop the animation - animation.stop(); - - if (sceneView != null) { - sceneView.dispose(); - } - } -} diff --git a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dSample.java b/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dSample.java deleted file mode 100644 index 80ff416daf..0000000000 --- a/src/main/java/com/esri/samples/scene/calculate_distance_3d/CalculateDistance3dSample.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2017 Esri. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.esri.samples.scene.calculate_distance_3d; - -import java.io.IOException; - -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -public class CalculateDistance3dSample extends Application { - - private static CalculateDistance3dController controller; - - @Override - public void start(Stage stage) throws IOException { - // set up the scene - FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/calculate_distance_3d.fxml")); - Parent root = loader.load(); - controller = loader.getController(); - Scene scene = new Scene(root); - - // set up the stage - stage.setTitle("Calculate Distance 3d Sample"); - stage.setWidth(800); - stage.setHeight(700); - stage.setScene(scene); - stage.show(); - } - - /** - * Stops and releases all resources used in application. - */ - @Override - public void stop() { - controller.terminate(); - } - - /** - * Opens and runs application. - * - * @param args arguments passed to this application - */ - public static void main(String[] args) { - - Application.launch(args); - } -} diff --git a/src/main/java/com/esri/samples/scene/calculate_distance_3d/README.md b/src/main/java/com/esri/samples/scene/calculate_distance_3d/README.md deleted file mode 100644 index e5927f7982..0000000000 --- a/src/main/java/com/esri/samples/scene/calculate_distance_3d/README.md +++ /dev/null @@ -1,31 +0,0 @@ -

Calculate Distance 3d

- -

Calculate the 3D distance between two graphics.

- -

- -

How to use the sample

- -

Once the SceneView has loaded the Graphic's animation will begin. The distance between the two Graphics will be displayed at the top of the application and will be updated when the Graphic's animation starts.

- -

How it works

- -

To calculate the distance between two Graphics in 3D space:

- -
    -
  1. Create a GraphicsOverlay and attach it to the SceneView.
  2. -
  3. Create the two graphics and add to graphics overlay. -
  4. -
  5. Convert each graphic's point to the Cartesian coordinate system
  6. -
  7. Create a JavaFX Point3D from the Cartesian x,y, and z value.
  8. -
  9. Then get the distance between each of the JavaFX Point3Ds, Point3D.distance(Point3D).
  10. -
- -

Relevant API

- - diff --git a/src/main/resources/fxml/calculate_distance_3d.fxml b/src/main/resources/fxml/calculate_distance_3d.fxml deleted file mode 100644 index 015d60adf8..0000000000 --- a/src/main/resources/fxml/calculate_distance_3d.fxml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file