Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tschie committed Oct 16, 2018
2 parents c4df7e7 + 5f13686 commit 605dc70
Show file tree
Hide file tree
Showing 20 changed files with 730 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
}
}

arcgis.version = '100.3.0'
arcgis.version = '100.4.0'

idea.module.downloadJavadoc = true
eclipse.classpath.downloadJavadoc = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public void start(Stage stage) {
// create a feature layer from service feature table
featureLayer = new FeatureLayer(featureTable);

// selection options
featureLayer.setSelectionColor(0xff0000ff);
featureLayer.setSelectionWidth(10);

// add the feature layer to the ArcGISMap
map.getOperationalLayers().add(featureLayer);

Expand All @@ -143,6 +139,9 @@ public void start(Stage stage) {
// set ArcGISMap to be displayed in the view
mapView.setMap(map);

// set selection color
mapView.getSelectionProperties().setColor(0xff0000ff);

mapView.setOnMouseClicked(event -> {
if (event.isStillSincePress() && event.getButton() == MouseButton.PRIMARY) {
// create a map point from a point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public void start(Stage stage) {
String damageAssessmentFeatureService = "https://services1.arcgis.com/4yjifSiIG17X0gW4/arcgis/rest/services/GDP_per_capita_1960_2016/FeatureServer/0";
final ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(damageAssessmentFeatureService);

// create the feature layer and set its selection color
// create the feature layer
final FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
featureLayer.setSelectionColor(0xFF00FFFF); // cyan color
featureLayer.setSelectionWidth(3);

// add the layer to the ArcGISMap
map.getOperationalLayers().add(featureLayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void start(Stage stage) {
tempFile.deleteOnExit();

// create and start the job
GenerateGeodatabaseJob job = syncTask.generateGeodatabaseAsync(parameters, tempFile.getAbsolutePath());
GenerateGeodatabaseJob job = syncTask.generateGeodatabase(parameters, tempFile.getAbsolutePath());
job.start();

// show progress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public void start(Stage stage) {
mapView = new MapView();
mapView.setMap(map);

// make selection outline yellow (0xFFFFFF00)
mapView.getSelectionProperties().setColor(0xFFFFFF00);

// hide the progress indicator when the layer is done drawing
mapView.addDrawStatusChangedListener(drawStatusChangedEvent -> {
if (drawStatusChangedEvent.getDrawStatus() == DrawStatus.COMPLETED) {
Expand All @@ -94,10 +97,6 @@ public void start(Stage stage) {
// get the first feature layer for querying
FeatureLayer featureLayer = (FeatureLayer) map.getOperationalLayers().get(0);

// make selection outline yellow (0xFFFFFF00) and thick
featureLayer.setSelectionColor(0xFFFFFF00);
featureLayer.setSelectionWidth(5);

mapView.setOnMouseClicked(event -> {
// check for primary or secondary mouse click
if (event.isStillSincePress() && event.getButton() == MouseButton.PRIMARY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public void start(Stage stage) {
// create a graphics overlay
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
graphicsOverlay.setSelectionColor(0xFFFFFF00);

// make selection outline yellow (0xFFFFFF00)
mapView.getSelectionProperties().setColor(0xFFFFFF00);

// create a polygon graphic
PointCollection polygonPoints = new PointCollection(SpatialReferences.getWebMercator());
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 148 additions & 0 deletions src/main/java/com/esri/samples/kml/display_kml/DisplayKMLSample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2018 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.kml.display_kml;

import java.io.File;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import com.esri.arcgisruntime.geometry.Envelope;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.layers.KmlLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.ogc.kml.KmlDataset;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class DisplayKMLSample extends Application {

private MapView mapView;

@Override
public void start(Stage stage) {

try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);

// set title, size, and add scene to stage
stage.setTitle("Display KML Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// create a map and add it to the map view
ArcGISMap map = new ArcGISMap(Basemap.createDarkGrayCanvasVector());
mapView = new MapView();
mapView.setMap(map);

// start zoomed in over the US
mapView.setViewpointGeometryAsync(new Envelope(-19195297.778679, 512343.939994, -3620418.579987, 8658913.035426, 0.0, 0.0, SpatialReferences.getWebMercator()));

// show a combo box with the different KML data source options
ComboBox<KmlDatasourceType> kmlSourceComboBox = new ComboBox<>();
kmlSourceComboBox.getItems().addAll(KmlDatasourceType.values());

// show the KML layer when the data source option is shown
kmlSourceComboBox.getSelectionModel().selectedItemProperty().addListener(o -> {
// clear previous layer
map.getOperationalLayers().clear();
// create a KML layer based on the source type
KmlDatasourceType kmlSourceType = kmlSourceComboBox.getSelectionModel().getSelectedItem();
try {
KmlLayer kmlLayer = null;
switch (kmlSourceType) {
case URL:
KmlDataset urlKmlDataset = new KmlDataset("https://www.wpc.ncep.noaa.gov/kml/noaa_chart/WPC_Day1_SigWx.kml");
kmlLayer = new KmlLayer(urlKmlDataset);
break;
case PORTAL_ITEM:
Portal portal = new Portal("https://arcgisruntime.maps.arcgis.com");
PortalItem portalItem = new PortalItem(portal, "9fe0b1bfdcd64c83bd77ea0452c76253");
kmlLayer = new KmlLayer(portalItem);
break;
case LOCAL_FILE:
File kmlFile = new File("./samples-data/kml/US_State_Capitals.kml");
KmlDataset fileKmlDataset = new KmlDataset(kmlFile.getAbsolutePath());
kmlLayer = new KmlLayer(fileKmlDataset);
break;
}
// add the KML layer as an operational layer
map.getOperationalLayers().add(kmlLayer);

KmlLayer finalKmlLayer = kmlLayer;
kmlLayer.addDoneLoadingListener(() -> {
if (finalKmlLayer.getLoadStatus() != LoadStatus.LOADED) {
new Alert(Alert.AlertType.ERROR, "Error loading KML layer").show();
}
});
} catch (Exception e) {
new Alert(Alert.AlertType.ERROR, "Error creating KML layer").show();
}
});

// start with the URL data source chosen
kmlSourceComboBox.getSelectionModel().select(0);

// add the map view to stack pane
stackPane.getChildren().addAll(mapView, kmlSourceComboBox);
StackPane.setAlignment(kmlSourceComboBox, Pos.TOP_LEFT);
StackPane.setMargin(kmlSourceComboBox, new Insets(10));
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}

private enum KmlDatasourceType {
URL, PORTAL_ITEM, LOCAL_FILE
}

/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {

if (mapView != null) {
mapView.dispose();
}
}

/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/
public static void main(String[] args) {

Application.launch(args);
}

}
25 changes: 25 additions & 0 deletions src/main/java/com/esri/samples/kml/display_kml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1>Display KML</h1>

<p>Display a KML layer from a URL, portal item, or local KML file.</p>

<p><img src="DisplayKML.png"/></p>

<h2>How it works</h2>

<p>To display a <code>KMLLayer</code>:</p>

<ol>
<li>To create a KML layer from a URL, create a <code>KMLDataset</code> using the URL to the KML file. Then pass the dataset to the <code>KmlLayer</code> constructor.</li>
<li>To create a KML layer from a portal item, construct a <code>PortalItem</code> with a portal and the KML portal item. Pass the portal item to the <code>KmlLayer</code> constructor.</li>
<li>To create a KML layer from a local file, create a <code>KMLDataset</code> using the absolute file path to the local KML file. Then pass the dataset to the <code>KmlLayer</code> constructor.</li>
<li>Add the layer as an operational layer to the map with <code>map.getOperationalLayers().add(kmlLayer)</code>.</li>
</ol>

<h2>Relevant API</h2>

<ul>
<li>KmlDataset</li>
<li>KmlLayer</li>
<li>Portal</li>
<li>PortalItem</li>
</ul>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2018 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.kml.display_kml_network_links;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.layers.KmlLayer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.SceneView;
import com.esri.arcgisruntime.ogc.kml.KmlDataset;

public class DisplayKMLNetworkLinksSample extends Application {

private SceneView sceneView;

@Override
public void start(Stage stage) {

try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene fxScene = new Scene(stackPane);
fxScene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());

// set title, size, and add scene to stage
stage.setTitle("Display KML Network Links Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(fxScene);
stage.show();

// create a map and add it to the map view
ArcGISScene scene = new ArcGISScene(Basemap.createImageryWithLabels());
sceneView = new SceneView();
sceneView.setArcGISScene(scene);

// start centered over Germany
sceneView.setViewpoint(new Viewpoint(new Point(8.150526, 50.472421, SpatialReferences.getWgs84()), 2000000));

// create a KML dataset from KML hosted at a URL
KmlDataset kmlDataset = new KmlDataset("https://www.arcgis.com/sharing/rest/content/items/600748d4464442288f6db8a4ba27dc95/data");

// show an alert when any network link messages are received
kmlDataset.addKmlNetworkLinkMessageReceivedListener(kmlNetworkLinkMessageReceivedEvent -> {
Alert alert = new Alert(Alert.AlertType.INFORMATION, kmlNetworkLinkMessageReceivedEvent.getMessage());
alert.setHeaderText("KML Network Link Message");
alert.initOwner(sceneView.getScene().getWindow());
alert.show();
});

// add the KML layer as an operational layer and check if it is loaded correctly
KmlLayer kmlLayer = new KmlLayer(kmlDataset);
scene.getOperationalLayers().add(kmlLayer);
kmlLayer.addDoneLoadingListener(() -> {
if (kmlLayer.getLoadStatus() != LoadStatus.LOADED) {
new Alert(Alert.AlertType.ERROR, "Error loading KML layer").show();
}
});

// add the map view and list view to the stack pane
stackPane.getChildren().add(sceneView);
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}

/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {

if (sceneView != null) {
sceneView.dispose();
}
}

/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/
public static void main(String[] args) {

Application.launch(args);
}

}
Loading

0 comments on commit 605dc70

Please sign in to comment.