Skip to content

Commit 345583b

Browse files
committed
Merge branch 'master' into 100.3.0
2 parents 815f052 + e1bb07d commit 345583b

File tree

16 files changed

+890
-1
lines changed

16 files changed

+890
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h1>Show Labels on Layer</h1>
2+
3+
<p>Demonstrates how to show labels on a feature layer.</p>
4+
5+
<p><img src="ShowLabelsOnLayer.png"/></p>
6+
7+
<h2>How it works</h2>
8+
9+
<p>To show labels on a feature layer:</p>
10+
11+
<ol>
12+
<li>First, create a <code>FeatureLayer</code> with a <code>ServiceFeatureTable</code> using an online feature
13+
service.</li>
14+
<li>Create a <code>TextSymbol</code> to use for displaying the label text.</li>
15+
<li>Create a JSON string for the label definition.
16+
<ul>
17+
<li> Set the "LabelExpressionInfo.expression" key to express what the text the label should display. You can
18+
use fields of the feature by using <code>$feature.field_name</code> in the expression.
19+
<li>To use the text symbol, set the "symbol" key to the symbol's JSON representation using <code>textSymbol.toJson()</code>.</li>
20+
</ul>
21+
</li>
22+
<li>Create a label definition from the JSON using <code>LabelDefinition.fromJson(json)</code>.</code>
23+
<li>Add the definition to the feature layer with <code>featureLayer.getLabelDefinitions().add(labelDefinition)
24+
</code>.</li>
25+
<li>Lastly, enable labels on the layer using <code>featureLayer.setLabelsEnabled()</code>.</li>
26+
</ol>
27+
28+
<h2>Features</h2>
29+
30+
<ul>
31+
<li>FeatureLayer</li>
32+
<li>LabelDefinition</li>
33+
<li>TextSymbol</li>
34+
</ul>
198 KB
Loading
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2018 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.displayinformation.show_labels_on_layer;
18+
19+
import javafx.application.Application;
20+
import javafx.scene.Scene;
21+
import javafx.scene.control.Alert;
22+
import javafx.scene.layout.StackPane;
23+
import javafx.stage.Stage;
24+
25+
import com.google.gson.JsonObject;
26+
import com.google.gson.JsonParser;
27+
import com.google.gson.JsonPrimitive;
28+
29+
import com.esri.arcgisruntime.arcgisservices.LabelDefinition;
30+
import com.esri.arcgisruntime.data.ServiceFeatureTable;
31+
import com.esri.arcgisruntime.layers.FeatureLayer;
32+
import com.esri.arcgisruntime.loadable.LoadStatus;
33+
import com.esri.arcgisruntime.mapping.ArcGISMap;
34+
import com.esri.arcgisruntime.mapping.Basemap;
35+
import com.esri.arcgisruntime.mapping.view.MapView;
36+
import com.esri.arcgisruntime.symbology.TextSymbol;
37+
38+
public class ShowLabelsOnLayerSample extends Application {
39+
40+
private MapView mapView;
41+
42+
@Override
43+
public void start(Stage stage) throws Exception {
44+
45+
try {
46+
// create stack pane and application scene
47+
StackPane stackPane = new StackPane();
48+
Scene scene = new Scene(stackPane);
49+
50+
// size the stage, add a title, and set scene to stage
51+
stage.setTitle("Show Labels on Layer Sample");
52+
stage.setHeight(700);
53+
stage.setWidth(800);
54+
stage.setScene(scene);
55+
stage.show();
56+
57+
// create a map view and set a map
58+
mapView = new MapView();
59+
ArcGISMap map = new ArcGISMap(Basemap.createLightGrayCanvas());
60+
mapView.setMap(map);
61+
62+
// create a feature layer from an online feature service of US Highways
63+
String serviceUrl = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/1";
64+
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(serviceUrl);
65+
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
66+
map.getOperationalLayers().add(featureLayer);
67+
68+
// zoom to the layer when it's done loading
69+
featureLayer.addDoneLoadingListener(() -> {
70+
if (featureLayer.getLoadStatus() == LoadStatus.LOADED) {
71+
mapView.setViewpointGeometryAsync(featureLayer.getFullExtent());
72+
} else {
73+
new Alert(Alert.AlertType.ERROR, featureLayer.getLoadError().getMessage()).show();
74+
}
75+
});
76+
77+
// use large blue text with a yellow halo for the labels
78+
TextSymbol textSymbol = new TextSymbol();
79+
textSymbol.setSize(20);
80+
textSymbol.setColor(0xFF0000FF);
81+
textSymbol.setHaloColor(0xFFFFFF00);
82+
textSymbol.setHaloWidth(2);
83+
84+
// construct the label definition json
85+
JsonObject json = new JsonObject();
86+
// prepend 'I - ' (for Interstate) to the route number for the label
87+
JsonObject expressionInfo = new JsonObject();
88+
expressionInfo.add("expression", new JsonPrimitive("'I -' + $feature.rte_num1"));
89+
json.add("labelExpressionInfo", expressionInfo);
90+
// position the label above and along the direction of the road
91+
json.add("labelPlacement", new JsonPrimitive("esriServerLinePlacementAboveAlong"));
92+
// only show labels on the interstate highways (others have an empty rte_num1 attribute)
93+
json.add("where", new JsonPrimitive("$feature.rte_num1 <> ' '"));
94+
// set the text symbol as the label symbol
95+
json.add("symbol", new JsonParser().parse(textSymbol.toJson()));
96+
97+
// create a label definition from the JSON string
98+
LabelDefinition labelDefinition = LabelDefinition.fromJson(json.toString());
99+
// add the definition to the feature layer and enable labels on it
100+
featureLayer.getLabelDefinitions().add(labelDefinition);
101+
featureLayer.setLabelsEnabled(true);
102+
103+
// add the map view to stack pane
104+
stackPane.getChildren().add(mapView);
105+
106+
} catch (Exception e) {
107+
// on any error, display stack trace
108+
e.printStackTrace();
109+
}
110+
}
111+
112+
/**
113+
* Stops and releases all resources used in application.
114+
*
115+
* @throws Exception if security manager doesn't allow JVM to exit with
116+
* current status
117+
*/
118+
@Override
119+
public void stop() throws Exception {
120+
121+
// release resources when the application closes
122+
if (mapView != null) {
123+
mapView.dispose();
124+
}
125+
}
126+
127+
/**
128+
* Opens and runs application.
129+
*
130+
* @param args arguments passed to this application
131+
*/
132+
public static void main(String[] args) {
133+
134+
Application.launch(args);
135+
}
136+
}
388 KB
Loading
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright 2018 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.geometry.clip_geometry;
18+
19+
import javafx.application.Application;
20+
import javafx.geometry.Insets;
21+
import javafx.geometry.Pos;
22+
import javafx.scene.Scene;
23+
import javafx.scene.control.Button;
24+
import javafx.scene.layout.StackPane;
25+
import javafx.stage.Stage;
26+
27+
import com.esri.arcgisruntime.geometry.Envelope;
28+
import com.esri.arcgisruntime.geometry.Geometry;
29+
import com.esri.arcgisruntime.geometry.GeometryEngine;
30+
import com.esri.arcgisruntime.geometry.Point;
31+
import com.esri.arcgisruntime.geometry.SpatialReferences;
32+
import com.esri.arcgisruntime.mapping.ArcGISMap;
33+
import com.esri.arcgisruntime.mapping.Basemap;
34+
import com.esri.arcgisruntime.mapping.view.Graphic;
35+
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
36+
import com.esri.arcgisruntime.mapping.view.MapView;
37+
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
38+
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
39+
40+
public class ClipGeometrySample extends Application {
41+
42+
private MapView mapView;
43+
44+
@Override
45+
public void start(Stage stage) {
46+
47+
try {
48+
// create stack pane and application scene
49+
StackPane stackPane = new StackPane();
50+
Scene scene = new Scene(stackPane);
51+
52+
// set title, size, and add scene to stage
53+
stage.setTitle("Clip Geometry Sample");
54+
stage.setWidth(800);
55+
stage.setHeight(700);
56+
stage.setScene(scene);
57+
stage.show();
58+
59+
// create a map with a basemap and add it to the map view
60+
ArcGISMap map = new ArcGISMap(SpatialReferences.getWebMercator());
61+
map.setBasemap(Basemap.createTopographic());
62+
mapView = new MapView();
63+
mapView.setMap(map);
64+
65+
// create a graphics overlay to contain the geometry to clip
66+
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
67+
mapView.getGraphicsOverlays().add(graphicsOverlay);
68+
69+
// create a blue graphic of Colorado
70+
Envelope colorado = new Envelope(new Point(-11362327.128340, 5012861.290274),
71+
new Point(-12138232.018408, 4441198.773776));
72+
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x220000FF,
73+
new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 2));
74+
Graphic coloradoGraphic = new Graphic(colorado, fillSymbol);
75+
graphicsOverlay.getGraphics().add(coloradoGraphic);
76+
77+
// create a graphics overlay to contain the clipping envelopes
78+
GraphicsOverlay envelopesOverlay = new GraphicsOverlay();
79+
mapView.getGraphicsOverlays().add(envelopesOverlay);
80+
81+
// create a dotted red outline symbol
82+
SimpleLineSymbol redOutline = new SimpleLineSymbol(SimpleLineSymbol.Style.DOT, 0xFFFF0000, 3);
83+
84+
// create a envelope outside Colorado
85+
Envelope outsideEnvelope =
86+
new Envelope(new Point(-11858344.321294, 5147942.225174), new Point(-12201990.219681, 5297071.577304));
87+
Graphic outside = new Graphic(outsideEnvelope, redOutline);
88+
envelopesOverlay.getGraphics().add(outside);
89+
90+
// create a envelope intersecting Colorado
91+
Envelope intersectingEnvelope =
92+
new Envelope(new Point(-11962086.479298, 4566553.881363), new Point(-12260345.183558, 4332053.378376));
93+
Graphic intersecting = new Graphic(intersectingEnvelope, redOutline);
94+
envelopesOverlay.getGraphics().add(intersecting);
95+
96+
// create a envelope inside Colorado
97+
Envelope containedEnvelope =
98+
new Envelope(new Point(-11655182.595204, 4741618.772994), new Point(-11431488.567009, 4593570.068343));
99+
Graphic contained = new Graphic(containedEnvelope, redOutline);
100+
envelopesOverlay.getGraphics().add(contained);
101+
102+
// zoom to show the polygon graphic
103+
mapView.setViewpointGeometryAsync(coloradoGraphic.getGeometry(), 200);
104+
105+
// create a graphics overlay to contain the clipped areas
106+
GraphicsOverlay clipAreasOverlay = new GraphicsOverlay();
107+
mapView.getGraphicsOverlays().add(clipAreasOverlay);
108+
109+
// create a button to perform the clip operation
110+
Button clipButton = new Button("Clip");
111+
clipButton.setOnAction(e -> {
112+
// for each envelope, clip the Colorado geometry and show the result as a green graphic
113+
SimpleFillSymbol clippedAreaSymbol =
114+
new SimpleFillSymbol(SimpleFillSymbol.Style.DIAGONAL_CROSS, 0xFF00FF00, null);
115+
envelopesOverlay.getGraphics().forEach(graphic -> {
116+
Geometry geometry = GeometryEngine.clip(coloradoGraphic.getGeometry(), (Envelope) graphic.getGeometry());
117+
if (geometry != null) {
118+
Graphic clippedGraphic = new Graphic(geometry, clippedAreaSymbol);
119+
clipAreasOverlay.getGraphics().add(clippedGraphic);
120+
}
121+
});
122+
// only clip once
123+
clipButton.setDisable(true);
124+
});
125+
126+
// add the map view to the stack pane
127+
stackPane.getChildren().addAll(mapView, clipButton);
128+
StackPane.setAlignment(clipButton, Pos.TOP_LEFT);
129+
StackPane.setMargin(clipButton, new Insets(10, 0, 0, 10));
130+
} catch (Exception e) {
131+
// on any error, display the stack trace.
132+
e.printStackTrace();
133+
}
134+
}
135+
136+
/**
137+
* Stops and releases all resources used in application.
138+
*/
139+
@Override
140+
public void stop() {
141+
142+
if (mapView != null) {
143+
mapView.dispose();
144+
}
145+
}
146+
147+
/**
148+
* Opens and runs application.
149+
*
150+
* @param args arguments passed to this application
151+
*/
152+
public static void main(String[] args) {
153+
154+
Application.launch(args);
155+
}
156+
157+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<h1>Clip Geometry</h1>
2+
3+
<p>Demonstrates how to clip a geometry with an envelope using the GeometryEngine.</p>
4+
5+
<p><img src="ClipGeometry.png"/></p>
6+
7+
<h2>How to use the sample</h2>
8+
9+
<p>Click the "Clip" button to clip the blue graphic with each of the red envelopes and see the resulting geometries as
10+
green graphics.</p>
11+
12+
<h2>How it works</h2>
13+
14+
<p>To clip a <code>Geometry</code> with an <code>Envelope</code>:</p>
15+
16+
<ol>
17+
<li>Use the static method <code>GeometryEngine.clip(geometry, envelope)</code>.</li>
18+
<li>Keep in mind that the resulting <code>Geometry</code> may be null if the envelope does not intersect the
19+
geometry you are clipping</li>.</code>
20+
</ol>
21+
22+
<h2>Features</h2>
23+
24+
<ul>
25+
<li>ArcGISMap</li>
26+
<li>Basemap</li>
27+
<li>Envelope</li>
28+
<li>Geometry</li>
29+
<li>GeometryEngine</li>
30+
<li>Graphic</li>
31+
<li>GraphicsOverlay</li>
32+
<li>MapView</li>
33+
<li>Point</li>
34+
<li>PointCollection</li>
35+
<li>Polygon</li>
36+
<li>Polyline</li>
37+
<li>SimpleFillSymbol</li>
38+
<li>SimpleLineSymbol</li>
39+
<li>SpatialReferences</li>
40+
</ul>

src/main/java/com/esri/samples/geometry/cut_geometry/CutGeometrySample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void start(Stage stage) {
7575
.SOLID, 0x220000FF, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 2)));
7676
graphicsOverlay.getGraphics().add(polygonGraphic);
7777

78-
// create a red poyline graphic to cut the polygon
78+
// create a red polyline graphic to cut the polygon
7979
Graphic polylineGraphic = new Graphic(createBorder(), new SimpleLineSymbol(SimpleLineSymbol.Style.DOT,
8080
0xFFFF0000, 3));
8181
graphicsOverlay.getGraphics().add(polylineGraphic);
215 KB
Loading
377 KB
Loading

0 commit comments

Comments
 (0)