Skip to content

Commit 270bf04

Browse files
authored
Merge pull request #204 from Esri/tschie/wms-layer-url
Initial implementation of WMS layer URL sample
2 parents 51d6a28 + 6aa11f5 commit 270bf04

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<h1>WMS Layer URL</h1>
2+
3+
<p>Shows how to display a WMS layer from a URL.</p>
4+
5+
<p><img src="WmsLayerUrl.png"/></p>
6+
7+
<h2>How it works</h2>
8+
9+
<p>To create a <code>WmsLayer</code> from a URL and display it:</p>
10+
11+
<ol>
12+
<li>Create a <code>WmsLayer</code> specifying the URL of the service and the layer names you want <code>new
13+
WmsLayer(url, names)</code>.</li>
14+
<li>To display it, add it to the map as an operational layer <code>map.getOperationalLayers().add(wmsLayer)</code>.</li>
15+
</ol>
16+
17+
<h2>Features</h2>
18+
19+
<ul>
20+
<li>ArcGISMap</li>
21+
<li>MapView</li>
22+
<li>WmsLayer</li>
23+
</ul>
437 KB
Loading
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright 2017 Esri.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.esri.samples.ogc.wms_layer_url;
18+
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
import javafx.application.Application;
23+
import javafx.scene.Scene;
24+
import javafx.scene.control.Alert;
25+
import javafx.scene.layout.StackPane;
26+
import javafx.stage.Stage;
27+
28+
import com.esri.arcgisruntime.layers.WmsLayer;
29+
import com.esri.arcgisruntime.layers.WmtsLayer;
30+
import com.esri.arcgisruntime.loadable.LoadStatus;
31+
import com.esri.arcgisruntime.mapping.ArcGISMap;
32+
import com.esri.arcgisruntime.mapping.Basemap;
33+
import com.esri.arcgisruntime.mapping.Viewpoint;
34+
import com.esri.arcgisruntime.mapping.view.MapView;
35+
import com.esri.arcgisruntime.ogc.wmts.WmtsLayerInfo;
36+
import com.esri.arcgisruntime.ogc.wmts.WmtsService;
37+
import com.esri.arcgisruntime.ogc.wmts.WmtsServiceInfo;
38+
39+
public class WmsLayerUrlSample extends Application {
40+
41+
private MapView mapView;
42+
43+
@Override
44+
public void start(Stage stage) throws Exception {
45+
46+
try {
47+
// create stack pane and application scene
48+
StackPane stackPane = new StackPane();
49+
Scene scene = new Scene(stackPane);
50+
51+
// set title, size, and add scene to stage
52+
stage.setTitle("WMS Layer URL Sample");
53+
stage.setWidth(800);
54+
stage.setHeight(700);
55+
stage.setScene(scene);
56+
stage.show();
57+
58+
// create a map and add it to the map view
59+
ArcGISMap map = new ArcGISMap(Basemap.createImagery());
60+
mapView = new MapView();
61+
mapView.setMap(map);
62+
63+
// create a WMS layer
64+
List<String> wmsLayerNames = Collections.singletonList("0");
65+
String url = "https://certmapper.cr.usgs.gov/arcgis/services/geology/africa/MapServer/WMSServer?request=GetCapabilities&service=WMS";
66+
WmsLayer wmsLayer = new WmsLayer(url, wmsLayerNames);
67+
// load the layer and add it as an operational layer
68+
wmsLayer.addDoneLoadingListener(() -> {
69+
if (wmsLayer.getLoadStatus() == LoadStatus.LOADED) {
70+
map.getOperationalLayers().add(wmsLayer);
71+
mapView.setViewpoint(new Viewpoint(wmsLayer.getFullExtent()));
72+
} else {
73+
Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to load WMS layer");
74+
alert.show();
75+
}
76+
});
77+
wmsLayer.loadAsync();
78+
79+
// add the map view to stack pane
80+
stackPane.getChildren().addAll(mapView);
81+
} catch (Exception e) {
82+
// on any error, display the stack trace.
83+
e.printStackTrace();
84+
}
85+
}
86+
87+
/**
88+
* Stops and releases all resources used in application.
89+
*/
90+
@Override
91+
public void stop() throws Exception {
92+
93+
if (mapView != null) {
94+
mapView.dispose();
95+
}
96+
}
97+
98+
/**
99+
* Opens and runs application.
100+
*
101+
* @param args arguments passed to this application
102+
*/
103+
public static void main(String[] args) {
104+
105+
Application.launch(args);
106+
}
107+
108+
}

0 commit comments

Comments
 (0)