Skip to content

Commit

Permalink
Added KML
Browse files Browse the repository at this point in the history
Part of #153
  • Loading branch information
Gary Sheppard committed Jan 8, 2019
1 parent b12b51f commit b0b4fd3
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 33 additions & 5 deletions runtime-workshop/exercises/Java/Exercise 3 Operational Layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b0b4fd3

Please sign in to comment.