Skip to content

Merge master into dev #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,190 @@
/*
* Copyright 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
*
* 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.ogc.browse_wfs_layers;

import com.esri.arcgisruntime.data.QueryParameters;
import com.esri.arcgisruntime.data.ServiceFeatureTable;
import com.esri.arcgisruntime.layers.FeatureLayer;
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.wfs.OgcAxisOrder;
import com.esri.arcgisruntime.ogc.wfs.WfsFeatureTable;
import com.esri.arcgisruntime.ogc.wfs.WfsLayerInfo;
import com.esri.arcgisruntime.ogc.wfs.WfsService;
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
import com.esri.arcgisruntime.symbology.SimpleRenderer;

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.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.util.List;

public class BrowseWfsLayersSample extends Application {

private MapView mapView;
private ArcGISMap map;
private ProgressIndicator progressIndicator;

@Override
public void start(Stage stage) throws Exception {

// create stack pane and JavaFX app scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());

// set title, size, and add JavaFX scene to stage
stage.setTitle("Browse WFS Layers");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// create a list view to show all of the layers in a WFS service
ListView<WfsLayerInfo> wfsLayerNamesListView = new ListView<>();
wfsLayerNamesListView.setMaxSize(200, 160);

// create a progress indicator
progressIndicator = new ProgressIndicator();
progressIndicator.setVisible(false);

// create an ArcGISMap with topographic basemap and set it to the map view
map = new ArcGISMap(Basemap.createImagery());
mapView = new MapView();
mapView.setMap(map);

// create a WFS service with a URL and load it
WfsService wfsService = new WfsService("https://dservices2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/services/Seattle_Downtown_Features/WFSServer?service=wfs&request=getcapabilities");
wfsService.loadAsync();

// when the WFS service has loaded, add its layer information to the list view for browsing
wfsService.addDoneLoadingListener(() -> {
if (wfsService.getLoadStatus() == LoadStatus.LOADED) {
// add the list of WFS layers to the list view
List<WfsLayerInfo> wfsLayerInfos = wfsService.getServiceInfo().getLayerInfos();
wfsLayerNamesListView.getItems().addAll(wfsLayerInfos);
} else {
Alert alert = new Alert(Alert.AlertType.ERROR, "WFS Service Failed to Load!");
alert.show();
}
});

// populate the list view with layer names
wfsLayerNamesListView.setCellFactory(list -> new ListCell<>() {

@Override
protected void updateItem(WfsLayerInfo wfsLayerInfo, boolean bln) {
super.updateItem(wfsLayerInfo, bln);
if (wfsLayerInfo != null) {
String fullNameOfWfsLayer = wfsLayerInfo.getName();
String[] split = fullNameOfWfsLayer.split(":");
String smallName = split[1];
setText(smallName);
}
}
});

// load the selected layer from the list view when the layer is selected
wfsLayerNamesListView.getSelectionModel().selectedItemProperty().addListener(observable ->
updateMap(wfsLayerNamesListView.getSelectionModel().getSelectedItem())
);

// add the controls to the stack pane
stackPane.getChildren().addAll(mapView, wfsLayerNamesListView, progressIndicator);
StackPane.setAlignment(wfsLayerNamesListView, Pos.TOP_LEFT);
StackPane.setMargin(wfsLayerNamesListView, new Insets(10));
}

/**
* Adds a WfsLayerInfo to the map's operational layers, with a random color renderer.
* @param wfsLayerInfo the WfsLayerInfo that the map will display
*/
private void updateMap(WfsLayerInfo wfsLayerInfo){

progressIndicator.setVisible(true);

// clear the map's operational layers
map.getOperationalLayers().clear();

// create a WFSFeatureTable from the WFSLayerInfo
WfsFeatureTable wfsFeatureTable = new WfsFeatureTable(wfsLayerInfo);

// set the feature request mode to manual. The table must be manually populated as panning and zooming won't request features automatically.
wfsFeatureTable.setFeatureRequestMode(ServiceFeatureTable.FeatureRequestMode.MANUAL_CACHE);
// define the coordinate order for the WFS service
wfsFeatureTable.setAxisOrder(OgcAxisOrder.NO_SWAP);

// create a feature layer to visualize the WFS features
FeatureLayer wfsFeatureLayer = new FeatureLayer(wfsFeatureTable);

// populate the table and then remove progress indicator and set the viewpoint to that of the layer's full extent when done.
wfsFeatureTable.populateFromServiceAsync(new QueryParameters(), false, null ).addDoneListener(()->{
progressIndicator.setVisible(false);
mapView.setViewpointGeometryAsync(wfsFeatureLayer.getFullExtent(), 50);
});

// apply a renderer to the feature layer once the table is loaded (the renderer is based on the table's geometry type)
wfsFeatureTable.addDoneLoadingListener(()->{
switch (wfsFeatureTable.getGeometryType()) {
case POINT:
wfsFeatureLayer.setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xff00f5ff, 4)));
break;
case POLYGON:
wfsFeatureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xfff8ff00, null)));
break;
case POLYLINE:
wfsFeatureLayer.setRenderer(new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xffff0000, 2)));
break;
}
});

// add the layer to the map's operational layers
map.getOperationalLayers().add(wfsFeatureLayer);
}

/**
* 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);
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/esri/samples/ogc/browse_wfs_layers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<h1>Browse WFS layers</h1>

<p>Browse a WFS service for layers and add them to the map.</p>

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

<h2>Use case</h2>

<p>Services often have multiple layers available for display. For example, a feature service for a city might have layers representing roads, land masses, building footprints, parks, and facilities. A user can choose to only show the road network and parks for a park accessibility analysis. </p>

<h2>How to use the sample</h2>

<p>A list of layers in the WFS service will be shown. Select a layer to display it.</p>

<p>Some WFS services return coordinates in X,Y order, while others return coordinates in lat/long (Y,X) order. If you don't see features rendered or you see features in the wrong location, use the checkbox to swap the coordinate order and reload. Note: the WFS service in this sample does not require coordinate swapping.</p>

<h2>How it works</h2>

<ol>
<li>Create a <code>WfsService</code> object with a URL to a WFS feature service.</li>

<li>Obtain a list of <code>WfsLayerInfo</code> from the WFS service with <code>getServiceInfo().getLayerInfos()</code>.</li>

<li>Create a <code>WfsFeatureTable</code> from the <code>WfsLayerInfo</code>.

<ul>
<li>Set the axis order of the table if necessary.</li></ul>
</li>

<li>Create a <code>FeatureLayer</code> from the WSF feature table.</li>

<li>Add the feature layer to the map.

<ul>
<li>The sample uses randomly-generated symbology, similar to the behavior in ArcGIS Pro.</li></ul>
</li>
</ol>

<h2>Relevant API</h2>

<ul>

<li>FeatureLayer</li>

<li>WfsFeatureTable</li>

<li>WfsLayerInfo</li>

<li>WfsService</li>

<li>WfsServiceInfo</li>

</ul>

<h2>About the data</h2>

<p>This service shows features for downtown Seattle. For additional information, see the underlying service on <a href="https://arcgisruntime.maps.arcgis.com/home/item.html?id=1b81d35c5b0942678140efc29bc25391">ArcGIS Online</a>.</p>

<h2>Tags</h2>

<p>OGC, WFS, feature, web, service, layers, browse, catalog</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1>Token authentication</h1>

<p>Access a map service that is secured with an ArcGIS token-based authentication.</p>

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

<h2>Use case</h2>

<p>Applications often require accessing data from private map services on remote servers. A token authentication system can be used to allow app users who hold a valid username and password to access the remote service. </p>

<h2>How to use the sample</h2>

<p>When starting the sample, the user is challenged for an ArcGIS Online login to view the protected map service. Enter a username and password for an ArcGIS Online named user account (such as your ArcGIS for Developers account). Upon successful authentication, the protected map service will display in the map.</p>

<h2>How it works</h2>

<ol>
<li>Create an <code>AuthenticationChallengeHandler</code> using the <code>DefaultAuthenticationChallengeHandler</code> to handle the challenges sent by the protected map service.</li>
<li>Set the <code>AuthenticationChallengeHandler</code> used by the <code>AuthenticationManager</code>.</li>
<li>Create a <code>Portal</code> to ArcGIS Online.</li>
<li>Create a <code>PortalItem</code> for the protected web map using the <code>Portal</code> and Item ID of the protected map service as parameters</li>
<li>Create an <code>ArcGISMap</code> from the portal item, and display it in a <code>MapView</code></li>
<li>Set the map to display in the map view.</li>
</ol>

<h2>Relevant API</h2>

<ul>
<li>AuthenticationChallengeHandler</li>
<li>AuthenticationManager</li>
<li>DefaultAuthenticationChallengeHandler</li>
<li>Map</li>
<li>MapView</li>
<li>Portal</li>
<li>PortalItem</li>
</ul>

<h2>Tags</h2>

<p>authentication, map service, security, token</p>
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,97 @@
/*
* Copyright 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
*
* 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.portal.token_authentication;

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

import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;
import com.esri.arcgisruntime.security.AuthenticationChallengeHandler;
import com.esri.arcgisruntime.security.AuthenticationManager;
import com.esri.arcgisruntime.security.DefaultAuthenticationChallengeHandler;

public class TokenAuthenticationSample 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("Token Authentication Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// set up an authentication handler to take credentials for access to the protected map service
AuthenticationChallengeHandler authenticationChallengeHandler = new DefaultAuthenticationChallengeHandler();
AuthenticationManager.setAuthenticationChallengeHandler(authenticationChallengeHandler);

// create a portal to ArcGIS Online
Portal portal = new Portal("https://www.arcgis.com/");

// create a portal item using the portal and the item id of a protected map service
PortalItem portalItem = new PortalItem(portal, "e5039444ef3c48b8a8fdc9227f9be7c1");

// create a map with the portal item
ArcGISMap map = new ArcGISMap(portalItem);

// set the map to be displayed in the map view
mapView = new MapView();
mapView.setMap(map);

// add the map view to stack pane
stackPane.getChildren().add(mapView);

} 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 (mapView != null) {
mapView.dispose();
}
}

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

Application.launch(args);
}
}
Loading