From b0b4fd3530760cc23d9318d6059800f681bbe37b Mon Sep 17 00:00:00 2001 From: Gary Sheppard Date: Tue, 8 Jan 2019 16:27:50 -0500 Subject: [PATCH] Added KML Part of #153 --- README.md | 2 +- .../Java/Exercise 3 Operational Layers.md | 38 ++++++++++++++++--- .../java/com/esri/wdc/geodev/WorkshopApp.java | 2 +- .../java/com/esri/wdc/geodev/WorkshopApp.java | 2 +- .../java/com/esri/wdc/geodev/WorkshopApp.java | 16 +++++++- .../java/com/esri/wdc/geodev/WorkshopApp.java | 16 +++++++- .../java/com/esri/wdc/geodev/WorkshopApp.java | 16 +++++++- 7 files changed, 78 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1b28878..add6504 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Lab exercises for Esri GeoDev events held in the Washington, D.C., area. ## Licensing -Copyright 2016-2018 Esri +Copyright 2016-2019 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 diff --git a/runtime-workshop/exercises/Java/Exercise 3 Operational Layers.md b/runtime-workshop/exercises/Java/Exercise 3 Operational Layers.md index 2c84930..7600fd2 100644 --- a/runtime-workshop/exercises/Java/Exercise 3 Operational Layers.md +++ b/runtime-workshop/exercises/Java/Exercise 3 Operational Layers.md @@ -3,6 +3,7 @@ This exercise walks you through the following: - Add a layer from a mobile map package to the 2D map - Add a scene layer to the 3D scene +- Add a KML layer to the 2D map and 3D scene Prerequisites: - Complete [Exercise 2](Exercise%202%20Zoom%20Buttons.md), or get the Exercise 2 code solution compiling and running properly, preferably in an IDE. @@ -50,18 +51,18 @@ ArcGIS Runtime provides a variety of ways to add **operational layers** to the m Web scene layers are cached web layers that are optimized for displaying a large amount of 2D and 3D features. Scene layers can be viewed in a variety of ArcGIS clients, including ArcGIS Runtime. Here you will add a scene layer to your 3D scene. -1. Declare a constant value to specify the URL of a scene service. You can use a `SceneServer` URL or an ArcGIS Online or Portal for ArcGIS item URL that represents a scene service. The following URL shows plain gray buildings in Washington, D.C.: +1. Declare a constant value to specify the URL of a scene service. You can use a `SceneServer` URL or an ArcGIS Online or Portal for ArcGIS item URL that represents a scene service. The following URL shows buildings in San Francisco: ``` private static final String SCENE_SERVICE_URL - = "https://www.arcgis.com/home/item.html?id=606596bae9e44394b42621e099ba392a"; + = "https://www.arcgis.com/home/item.html?id=943d302fd85b4b6dbd35f399cfb9a4a8"; ``` The following URL shows photo-realistic buildings in Philadelphia: ``` private static final String SCENE_SERVICE_URL - = "https://www.arcgis.com/home/item.html?id=a7419641a50e412c980cf242c29aa3c0"; + = "https://www.arcgis.com/home/item.html?id=2c9286dfc69349408764e09022b1f52e"; ``` 1. In your 2D/3D toggle button event handler method, after you instantiate your `ArcGISScene`, set its basemap and surface, and instantiate your `SceneView`, create a new `ArcGISSceneLayer` based on the scene service, give the layer an event handler for when it is done loading, and add the layer to the scene: @@ -97,12 +98,39 @@ Web scene layers are cached web layers that are optimized for displaying a large 1. Compile and run your app. Verify that when you switch to 3D, the 3D features display and the view is rotated and pitched. Also try the built-in 3D navigation by holding the right mouse button and moving the mouse: ![3D scene pitched and rotated](07-scene-layer-rotated.jpg) - + +## Add a KML layer to the 2D map and 3D scene + +Most organizations use a mix of ArcGIS and non-ArcGIS data formats. Many organizations distribute mapping data in the Keyhole Markup Language (KML) format. Here you will use a KML URL to add a layer to your 2D map and 3D scene. + +1. Declare a constant value to specify the URL of a KML file or network link. The following URL shows earthquakes of magnitude 1.0 or greater in the past seven days, colored by age: + + ``` + private static final String KML_URL + = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week_age_link.kml"; + ``` + +1. You added a listener to the mobile map package to set up the map after the mobile map package loads. In that listener, after setting the map and the basemap, create a KML layer and add it to the map: + + ``` + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + map.getOperationalLayers().add(kmlLayer); + ``` + +1. In your 2D/3D toggle button handler, you added a scene layer to the scene. After that, create a KML layer and add it to the scene: + + ``` + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + scene.getOperationalLayers().add(kmlLayer); + ``` + +1. Compile and run your app. Zoom out and verify that the earthquake dots appear on the 2D map. Switch to 3D and verify that the earthquake dots appear on the 3D scene. + ## How did it go? If you have trouble, **refer to the solution code**, which is linked near the beginning of this exercise. You can also **submit an issue** in this repo to ask a question or report a problem. If you are participating live with Esri presenters, feel free to **ask a question** of the presenters. -If you completed the exercise, congratulations! You learned how to add a local feature layer from a mobile map package to a 2D map and a scene layer to a 3D scene. +If you completed the exercise, congratulations! You learned how to add a local feature layer from a mobile map package to a 2D map and a scene layer to a 3D scene. You also learned how to add KML to a 2D map and a 3D scene. Ready for more? Choose from the following: diff --git a/runtime-workshop/solutions/Java/Ex1_MapAndScene/src/main/java/com/esri/wdc/geodev/WorkshopApp.java b/runtime-workshop/solutions/Java/Ex1_MapAndScene/src/main/java/com/esri/wdc/geodev/WorkshopApp.java index 6f42605..1091b05 100644 --- a/runtime-workshop/solutions/Java/Ex1_MapAndScene/src/main/java/com/esri/wdc/geodev/WorkshopApp.java +++ b/runtime-workshop/solutions/Java/Ex1_MapAndScene/src/main/java/com/esri/wdc/geodev/WorkshopApp.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2016-2017 Esri + * Copyright 2016-2019 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/runtime-workshop/solutions/Java/Ex2_ZoomButtons/src/main/java/com/esri/wdc/geodev/WorkshopApp.java b/runtime-workshop/solutions/Java/Ex2_ZoomButtons/src/main/java/com/esri/wdc/geodev/WorkshopApp.java index 1bd45e9..2c67c40 100644 --- a/runtime-workshop/solutions/Java/Ex2_ZoomButtons/src/main/java/com/esri/wdc/geodev/WorkshopApp.java +++ b/runtime-workshop/solutions/Java/Ex2_ZoomButtons/src/main/java/com/esri/wdc/geodev/WorkshopApp.java @@ -1,5 +1,5 @@ /** ***************************************************************************** - * Copyright 2016-2017 Esri + * Copyright 2016-2019 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/runtime-workshop/solutions/Java/Ex3_OperationalLayers/src/main/java/com/esri/wdc/geodev/WorkshopApp.java b/runtime-workshop/solutions/Java/Ex3_OperationalLayers/src/main/java/com/esri/wdc/geodev/WorkshopApp.java index 967df98..0adc963 100644 --- a/runtime-workshop/solutions/Java/Ex3_OperationalLayers/src/main/java/com/esri/wdc/geodev/WorkshopApp.java +++ b/runtime-workshop/solutions/Java/Ex3_OperationalLayers/src/main/java/com/esri/wdc/geodev/WorkshopApp.java @@ -1,5 +1,5 @@ /** ***************************************************************************** - * Copyright 2016-2017 Esri + * Copyright 2016-2019 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import com.esri.arcgisruntime.geometry.LinearUnitId; import com.esri.arcgisruntime.geometry.Point; import com.esri.arcgisruntime.layers.ArcGISSceneLayer; +import com.esri.arcgisruntime.layers.KmlLayer; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.ArcGISScene; import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource; @@ -36,6 +37,7 @@ import com.esri.arcgisruntime.mapping.view.MapView; import com.esri.arcgisruntime.mapping.view.OrbitLocationCameraController; import com.esri.arcgisruntime.mapping.view.SceneView; +import com.esri.arcgisruntime.ogc.kml.KmlDataset; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -60,7 +62,9 @@ public class WorkshopApp extends Application { // Exercise 3: Specify operational layer paths private static final String MMPK_PATH = "../../../data/DC_Crime_Data.mmpk"; private static final String SCENE_SERVICE_URL - = "https://www.arcgis.com/home/item.html?id=a7419641a50e412c980cf242c29aa3c0"; + = "https://www.arcgis.com/home/item.html?id=2c9286dfc69349408764e09022b1f52e"; + private static final String KML_URL + = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week_age_link.kml"; // Exercise 1: Declare and instantiate fields, including UI components private final MapView mapView = new MapView(); @@ -122,6 +126,10 @@ public WorkshopApp() { mapView.setMap(map); } map.setBasemap(Basemap.createTopographicVector()); + + // Exercise 3: Add a KML layer to the map + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + map.getOperationalLayers().add(kmlLayer); }); mmpk.loadAsync(); } @@ -198,6 +206,10 @@ private void button_toggle2d3d_onAction() { }); scene.getOperationalLayers().add(sceneLayer); + // Exercise 3: Add a KML layer to the scene + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + scene.getOperationalLayers().add(kmlLayer); + sceneView.setArcGISScene(scene); AnchorPane.setLeftAnchor(sceneView, 0.0); AnchorPane.setRightAnchor(sceneView, 0.0); diff --git a/runtime-workshop/solutions/Java/Ex4_BufferAndQuery/src/main/java/com/esri/wdc/geodev/WorkshopApp.java b/runtime-workshop/solutions/Java/Ex4_BufferAndQuery/src/main/java/com/esri/wdc/geodev/WorkshopApp.java index 8c48343..546d6b5 100644 --- a/runtime-workshop/solutions/Java/Ex4_BufferAndQuery/src/main/java/com/esri/wdc/geodev/WorkshopApp.java +++ b/runtime-workshop/solutions/Java/Ex4_BufferAndQuery/src/main/java/com/esri/wdc/geodev/WorkshopApp.java @@ -1,5 +1,5 @@ /** ***************************************************************************** - * Copyright 2016-2017 Esri + * Copyright 2016-2019 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.esri.arcgisruntime.geometry.Polygon; import com.esri.arcgisruntime.layers.ArcGISSceneLayer; import com.esri.arcgisruntime.layers.FeatureLayer; +import com.esri.arcgisruntime.layers.KmlLayer; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.ArcGISScene; import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource; @@ -44,6 +45,7 @@ import com.esri.arcgisruntime.mapping.view.MapView; import com.esri.arcgisruntime.mapping.view.OrbitLocationCameraController; import com.esri.arcgisruntime.mapping.view.SceneView; +import com.esri.arcgisruntime.ogc.kml.KmlDataset; import com.esri.arcgisruntime.symbology.SimpleFillSymbol; import com.esri.arcgisruntime.symbology.SimpleLineSymbol; import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol; @@ -75,7 +77,9 @@ public class WorkshopApp extends Application { // Exercise 3: Specify operational layer paths private static final String MMPK_PATH = "../../../data/DC_Crime_Data.mmpk"; private static final String SCENE_SERVICE_URL - = "https://www.arcgis.com/home/item.html?id=a7419641a50e412c980cf242c29aa3c0"; + = "https://www.arcgis.com/home/item.html?id=2c9286dfc69349408764e09022b1f52e"; + private static final String KML_URL + = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week_age_link.kml"; // Exercise 4: Create symbols for click and buffer private static final SimpleMarkerSymbol CLICK_SYMBOL @@ -152,6 +156,10 @@ public WorkshopApp() { mapView.setMap(map); } map.setBasemap(Basemap.createTopographicVector()); + + // Exercise 3: Add a KML layer to the map + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + map.getOperationalLayers().add(kmlLayer); }); mmpk.loadAsync(); @@ -239,6 +247,10 @@ private void button_toggle2d3d_onAction() { }); scene.getOperationalLayers().add(sceneLayer); + // Exercise 3: Add a KML layer to the scene + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + scene.getOperationalLayers().add(kmlLayer); + /** * Exercise 4: Set the SceneView's onMouseClicked event handler * if the buffer and query button is already selected. diff --git a/runtime-workshop/solutions/Java/Ex5_Routing/src/main/java/com/esri/wdc/geodev/WorkshopApp.java b/runtime-workshop/solutions/Java/Ex5_Routing/src/main/java/com/esri/wdc/geodev/WorkshopApp.java index dfefcda..e24a886 100644 --- a/runtime-workshop/solutions/Java/Ex5_Routing/src/main/java/com/esri/wdc/geodev/WorkshopApp.java +++ b/runtime-workshop/solutions/Java/Ex5_Routing/src/main/java/com/esri/wdc/geodev/WorkshopApp.java @@ -1,5 +1,5 @@ /** ***************************************************************************** - * Copyright 2016-2017 Esri + * Copyright 2016-2019 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import com.esri.arcgisruntime.geometry.Polygon; import com.esri.arcgisruntime.layers.ArcGISSceneLayer; import com.esri.arcgisruntime.layers.FeatureLayer; +import com.esri.arcgisruntime.layers.KmlLayer; import com.esri.arcgisruntime.mapping.ArcGISMap; import com.esri.arcgisruntime.mapping.ArcGISScene; import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource; @@ -46,6 +47,7 @@ import com.esri.arcgisruntime.mapping.view.MapView; import com.esri.arcgisruntime.mapping.view.OrbitLocationCameraController; import com.esri.arcgisruntime.mapping.view.SceneView; +import com.esri.arcgisruntime.ogc.kml.KmlDataset; import com.esri.arcgisruntime.security.UserCredential; import com.esri.arcgisruntime.symbology.SimpleFillSymbol; import com.esri.arcgisruntime.symbology.SimpleLineSymbol; @@ -84,7 +86,9 @@ public class WorkshopApp extends Application { // Exercise 3: Specify operational layer paths private static final String MMPK_PATH = "../../../data/DC_Crime_Data.mmpk"; private static final String SCENE_SERVICE_URL - = "https://www.arcgis.com/home/item.html?id=a7419641a50e412c980cf242c29aa3c0"; + = "https://www.arcgis.com/home/item.html?id=2c9286dfc69349408764e09022b1f52e"; + private static final String KML_URL + = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week_age_link.kml"; // Exercise 4: Create symbols for click and buffer private static final SimpleMarkerSymbol CLICK_SYMBOL @@ -181,6 +185,10 @@ public WorkshopApp() { mapView.setMap(map); } map.setBasemap(Basemap.createTopographicVector()); + + // Exercise 3: Add a KML layer to the map + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + map.getOperationalLayers().add(kmlLayer); }); mmpk.loadAsync(); @@ -312,6 +320,10 @@ private void button_toggle2d3d_onAction() { }); scene.getOperationalLayers().add(sceneLayer); + // Exercise 3: Add a KML layer to the scene + KmlLayer kmlLayer = new KmlLayer(new KmlDataset(KML_URL)); + scene.getOperationalLayers().add(kmlLayer); + // Exercise 5: Add a GraphicsOverlay to the scene for the routing sceneRouteGraphics.getSceneProperties().setSurfacePlacement(SurfacePlacement.DRAPED); sceneView.getGraphicsOverlays().add(sceneRouteGraphics);