Skip to content

Commit d6cd4e9

Browse files
authored
Merge pull request #245 from Esri/geodesic-sectors
geodesic sectors sample
2 parents 4ec26dd + 99d6b98 commit d6cd4e9

File tree

5 files changed

+357
-0
lines changed

5 files changed

+357
-0
lines changed
540 KB
Loading
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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.geodesic_sector_and_ellipse;
18+
19+
import javafx.fxml.FXML;
20+
import javafx.geometry.Point2D;
21+
import javafx.scene.control.ComboBox;
22+
import javafx.scene.control.Slider;
23+
import javafx.scene.control.Spinner;
24+
import javafx.scene.input.MouseButton;
25+
26+
import com.esri.arcgisruntime.geometry.GeodesicEllipseParameters;
27+
import com.esri.arcgisruntime.geometry.GeodesicSectorParameters;
28+
import com.esri.arcgisruntime.geometry.Geometry;
29+
import com.esri.arcgisruntime.geometry.GeometryEngine;
30+
import com.esri.arcgisruntime.geometry.GeometryType;
31+
import com.esri.arcgisruntime.geometry.Point;
32+
import com.esri.arcgisruntime.geometry.SpatialReference;
33+
import com.esri.arcgisruntime.mapping.ArcGISMap;
34+
import com.esri.arcgisruntime.mapping.Basemap;
35+
import com.esri.arcgisruntime.mapping.Viewpoint;
36+
import com.esri.arcgisruntime.mapping.view.Graphic;
37+
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
38+
import com.esri.arcgisruntime.mapping.view.MapView;
39+
import com.esri.arcgisruntime.symbology.FillSymbol;
40+
import com.esri.arcgisruntime.symbology.LineSymbol;
41+
import com.esri.arcgisruntime.symbology.MarkerSymbol;
42+
import com.esri.arcgisruntime.symbology.SimpleFillSymbol;
43+
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
44+
import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;
45+
46+
public class GeodesicSectorAndEllipseController {
47+
48+
@FXML private MapView mapView;
49+
@FXML private Slider axisDirectionSlider;
50+
@FXML private Spinner<Integer> maxPointCountSpinner;
51+
@FXML private Slider maxSegmentLengthSlider;
52+
@FXML private ComboBox<GeometryType> geometryTypeComboBox;
53+
@FXML private Slider sectorAngleSlider;
54+
@FXML private Slider semiAxis1LengthSlider;
55+
@FXML private Slider semiAxis2LengthSlider;
56+
@FXML private Slider startDirectionSlider;
57+
58+
private Point center;
59+
private Graphic sectorGraphic;
60+
private Graphic ellipseGraphic;
61+
private FillSymbol sectorFillSymbol;
62+
private LineSymbol sectorLineSymbol;
63+
private MarkerSymbol sectorMarkerSymbol;
64+
65+
public void initialize() {
66+
// initialize a map to a viewpoint and set it to the map view
67+
ArcGISMap map = new ArcGISMap(Basemap.createImagery());
68+
center = new Point(-13574921.207495, 4378809.903179, SpatialReference.create
69+
(3857));
70+
map.setInitialViewpoint(new Viewpoint(center, 10000));
71+
mapView.setMap(map);
72+
73+
// create a graphics overlay for showing the geometries as graphics
74+
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
75+
mapView.getGraphicsOverlays().add(graphicsOverlay);
76+
77+
// create a graphic to show the geodesic sector geometry
78+
sectorGraphic = new Graphic();
79+
graphicsOverlay.getGraphics().add(sectorGraphic);
80+
81+
// create green symbols for each sector output geometry type
82+
sectorFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x8800FF00, null);
83+
sectorLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0x8800FF00, 3);
84+
sectorMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0x8800FF00, 3);
85+
86+
// create a red dotted outline graph for showing the geodesic ellipse geometry
87+
SimpleLineSymbol ellipseLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DOT, 0xFFFF0000, 2);
88+
ellipseGraphic = new Graphic();
89+
ellipseGraphic.setSymbol(ellipseLineSymbol);
90+
graphicsOverlay.getGraphics().add(ellipseGraphic);
91+
92+
// set the center of the sector and ellipse where the user clicks on the map
93+
mapView.setOnMouseClicked(e -> {
94+
if (e.isStillSincePress() && e.getButton() == MouseButton.PRIMARY) {
95+
Point2D point2D = new Point2D(e.getX(), e.getY());
96+
center = mapView.screenToLocation(point2D);
97+
updateSector();
98+
}
99+
});
100+
101+
// set up the controls with some default parameters
102+
GeodesicSectorParameters defaultParameters = new GeodesicSectorParameters(center, 100.0, 100.0, 15.0, 0.0);
103+
axisDirectionSlider.setValue(defaultParameters.getAxisDirection());
104+
maxPointCountSpinner.getValueFactory().setValue(Long.valueOf(defaultParameters.getMaxPointCount()).intValue());
105+
maxSegmentLengthSlider.setValue(defaultParameters.getMaxSegmentLength());
106+
geometryTypeComboBox.getItems().addAll(GeometryType.POLYGON, GeometryType.POLYLINE, GeometryType.MULTIPOINT);
107+
geometryTypeComboBox.getSelectionModel().select(GeometryType.POLYGON);
108+
sectorAngleSlider.setValue(defaultParameters.getSectorAngle());
109+
semiAxis1LengthSlider.setValue(defaultParameters.getSemiAxis1Length());
110+
semiAxis2LengthSlider.setValue(defaultParameters.getSemiAxis2Length());
111+
startDirectionSlider.setValue(defaultParameters.getStartDirection());
112+
113+
// call updateSector when any of the controls change their value
114+
axisDirectionSlider.valueProperty().addListener(e -> updateSector());
115+
maxPointCountSpinner.valueProperty().addListener(e -> updateSector());
116+
maxSegmentLengthSlider.valueProperty().addListener(e -> updateSector());
117+
geometryTypeComboBox.valueProperty().addListener(e -> updateSector());
118+
sectorAngleSlider.valueProperty().addListener(e -> updateSector());
119+
semiAxis1LengthSlider.valueProperty().addListener(e -> updateSector());
120+
semiAxis2LengthSlider.valueProperty().addListener(e -> updateSector());
121+
startDirectionSlider.valueProperty().addListener(e -> updateSector());
122+
123+
// update the sector with the default parameters
124+
updateSector();
125+
}
126+
127+
/**
128+
* Updates the sector and ellipse graphics using the controls' values.
129+
*/
130+
private void updateSector() {
131+
132+
// create geodesic sector parameters
133+
GeodesicSectorParameters geodesicSectorParameters = new GeodesicSectorParameters();
134+
geodesicSectorParameters.setCenter(center);
135+
geodesicSectorParameters.setAxisDirection(axisDirectionSlider.getValue());
136+
geodesicSectorParameters.setMaxPointCount(maxPointCountSpinner.getValue());
137+
geodesicSectorParameters.setMaxSegmentLength(maxSegmentLengthSlider.getValue());
138+
geodesicSectorParameters.setGeometryType(geometryTypeComboBox.getSelectionModel().getSelectedItem());
139+
geodesicSectorParameters.setSectorAngle(sectorAngleSlider.getValue());
140+
geodesicSectorParameters.setSemiAxis1Length(semiAxis1LengthSlider.getValue());
141+
geodesicSectorParameters.setSemiAxis2Length(semiAxis2LengthSlider.getValue());
142+
geodesicSectorParameters.setStartDirection(startDirectionSlider.getValue());
143+
144+
// create the geodesic sector parameter
145+
Geometry sectorGeometry = GeometryEngine.sectorGeodesic(geodesicSectorParameters);
146+
// set the sector graphic's geometry to the sector
147+
sectorGraphic.setGeometry(sectorGeometry);
148+
// update the graphic's symbol depending on the chosen output geometry type
149+
switch (sectorGeometry.getGeometryType()) {
150+
case MULTIPOINT:
151+
sectorGraphic.setSymbol(sectorMarkerSymbol);
152+
break;
153+
case POLYGON:
154+
sectorGraphic.setSymbol(sectorFillSymbol);
155+
break;
156+
case POLYLINE:
157+
sectorGraphic.setSymbol(sectorLineSymbol);
158+
break;
159+
}
160+
161+
// create geodesic ellipse parameters using the same values from the geodesic sector parameters
162+
// use one of the constructors that sets some defaults for you
163+
GeodesicEllipseParameters geodesicEllipseParameters = new GeodesicEllipseParameters(center, semiAxis1LengthSlider
164+
.getValue(), semiAxis2LengthSlider.getValue());
165+
geodesicEllipseParameters.setAxisDirection(axisDirectionSlider.getValue());
166+
// show the geodesic ellipse that the sector is in
167+
Geometry ellipseGeometry = GeometryEngine.ellipseGeodesic(geodesicEllipseParameters);
168+
ellipseGraphic.setGeometry(ellipseGeometry);
169+
}
170+
171+
/**
172+
* Disposes of application resources.
173+
*/
174+
void terminate() {
175+
176+
if (mapView != null) {
177+
mapView.dispose();
178+
}
179+
}
180+
181+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.geodesic_sector_and_ellipse;
18+
19+
import java.io.IOException;
20+
21+
import javafx.application.Application;
22+
import javafx.fxml.FXMLLoader;
23+
import javafx.scene.Parent;
24+
import javafx.scene.Scene;
25+
import javafx.stage.Stage;
26+
27+
public class GeodesicSectorAndEllipseSample extends Application {
28+
29+
private static GeodesicSectorAndEllipseController controller;
30+
31+
@Override
32+
public void start(Stage stage) throws IOException {
33+
// set up the scene
34+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/geodesic_sector_and_ellipse.fxml"));
35+
Parent root = loader.load();
36+
controller = loader.getController();
37+
Scene scene = new Scene(root);
38+
39+
// set up the stage
40+
stage.setTitle("Geodesic Sector And Ellipse Sample");
41+
stage.setWidth(800);
42+
stage.setHeight(700);
43+
stage.setScene(scene);
44+
stage.show();
45+
}
46+
47+
/**
48+
* Stops and releases all resources used in application.
49+
*/
50+
@Override
51+
public void stop() {
52+
controller.terminate();
53+
}
54+
55+
/**
56+
* Opens and runs application.
57+
*
58+
* @param args arguments passed to this application
59+
*/
60+
public static void main(String[] args) {
61+
62+
Application.launch(args);
63+
}
64+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<h1>Project</h1>
2+
3+
<p>This sample demonstrates how to create and display geodesic sectors and ellipses.</p>
4+
5+
<p>Geodesic sectors and ellipses can be used in a wide range of analyses ranging from antenna coverage to projectile landing zones.</p>
6+
7+
<p><img src="GeodesicSectorAndEllipse.png"/></p>
8+
9+
<h2>How to use the sample</h2>
10+
11+
<p>The geodesic sector and ellipse will display with default parameters at the start. Click anywhere on the map to change the center of the geometries. Adjust any of the controls to see how they affect the sector and ellipse on the fly.</p>
12+
13+
<h2 id="howitworks">How it works</h2>
14+
15+
<p>To create a geodesic sector and ellipse:</p>
16+
17+
<ol>
18+
<li>Create <code>GeodesicSectorParameters</code> and <code>GeodesicEllipseParameters</code> using one of the constructors with default values or using each setter individually.</li>
19+
20+
<li>Set the <code>center</code>, <code>axisDirection</code>, <code>semiAxis1Length</code>, and the <code>semiAxis2Length</code> properties to change the general ellipse position, shape, and orientation.</li>
21+
22+
<li>Set the <code>sectorAngle</code> and <code>startDirection</code> angles to change the sector's shape and orientation.</li>
23+
24+
<li>Set the <code>maxPointCount</code> and <code>maxSegmentLength</code> properties to control the complexity of the geometries and the approximation of the ellipse curve.</li>
25+
26+
<li>Specify the <code>geometryType</code> to either <code>POLYGON</code>, <code>POLYLINE</code>, or <code>MULTIPOINT</code> to change the result geometry type.</li>
27+
28+
<li>Pass the parameters to the related static methods: <code>GeometryEngine.ellipseGeodesic(geodesicEllipseParameters)</code> and <code>GeometryEngine.sectorGeodesic(geodesicSectorParameters)</code>. The returned value will be a <code>Geometry</code> of the type specified by the <code>geometryType</code> parameter.</li>
29+
</ol>
30+
31+
<h2>Features</h2>
32+
33+
<ul>
34+
<li>GeodesicEllipseParameters</li>
35+
36+
<li>GeodesicSectorParameters</li>
37+
38+
<li>GeometryEngine</li>
39+
40+
<li>GeometryType</li>
41+
</ul>
42+
43+
<h2 id="additionalinformation">Additional information</h2>
44+
45+
<p>To create a circle instead of an ellipse, simply set <code>semiAxis2Length</code> to 0.0 and <code>semiAxis1Length</code> to the desired radius of the circle. This eliminates the need to update both parameters to the same value.</p>
46+
47+
<h2>Tags</h2>
48+
49+
<ul>
50+
51+
<p>GeometryEngine</p>
52+
53+
</ul>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2018 Esri.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
~ use this file except in compliance with the License. You may obtain a copy of
7+
~ the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
~ License for the specific language governing permissions and limitations under
15+
~ the License.
16+
-->
17+
18+
<?import javafx.scene.control.ComboBox?>
19+
<?import javafx.scene.control.Label?>
20+
<?import javafx.scene.control.Slider?>
21+
<?import javafx.scene.control.Spinner?>
22+
<?import javafx.scene.layout.*?>
23+
<?import com.esri.arcgisruntime.mapping.view.MapView?>
24+
<StackPane fx:controller="com.esri.samples.geometry.geodesic_sector_and_ellipse.GeodesicSectorAndEllipseController" xmlns:fx="http://javafx.com/fxml"
25+
stylesheets="/css/style.css">
26+
<MapView fx:id="mapView"/>
27+
<VBox StackPane.alignment="TOP_LEFT" maxWidth="350" maxHeight="300" styleClass="panel-region" spacing="10"
28+
alignment="CENTER">
29+
<GridPane hgap="10" vgap="10">
30+
<columnConstraints>
31+
<ColumnConstraints percentWidth="50"/>
32+
<ColumnConstraints percentWidth="50"/>
33+
</columnConstraints>
34+
<Label text="Axis Direction" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
35+
<Slider fx:id="axisDirectionSlider" max="360" showTickLabels="true" majorTickUnit="90"
36+
GridPane.rowIndex="0" GridPane.columnIndex="1"/>
37+
<Label text="Max Point Count" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
38+
<Spinner fx:id="maxPointCountSpinner" editable="true" max="20000" GridPane.rowIndex="1"
39+
GridPane.columnIndex="1"/>
40+
<Label text="Max Segment Length" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
41+
<Slider fx:id="maxSegmentLengthSlider" min="1" max="1000" showTickLabels="true" majorTickUnit="100"
42+
GridPane.rowIndex="2" GridPane.columnIndex="1"/>
43+
<Label text="Geometry Type" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
44+
<ComboBox fx:id="geometryTypeComboBox" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
45+
<Label text="Sector Angle" GridPane.rowIndex="4" GridPane.columnIndex="0"/>
46+
<Slider fx:id="sectorAngleSlider" max="360" showTickLabels="true" majorTickUnit="90" GridPane.rowIndex="4"
47+
GridPane.columnIndex="1"/>
48+
<Label text="Semi Axis 1 Length" GridPane.rowIndex="5" GridPane.columnIndex="0"/>
49+
<Slider fx:id="semiAxis1LengthSlider" min="1" max="1000" showTickLabels="true" majorTickUnit="100"
50+
GridPane.rowIndex="5" GridPane.columnIndex="1"/>
51+
<Label text="Semi Axis 2 Length" GridPane.rowIndex="6" GridPane.columnIndex="0"/>
52+
<Slider fx:id="semiAxis2LengthSlider" max="1000" showTickLabels="true" majorTickUnit="100"
53+
GridPane.rowIndex="6" GridPane.columnIndex="1"/>
54+
<Label text="Start Direction Angle" GridPane.rowIndex="7" GridPane.columnIndex="0"/>
55+
<Slider fx:id="startDirectionSlider" max="360" showTickLabels="true" majorTickUnit="90"
56+
GridPane.rowIndex="7" GridPane.columnIndex="1"/>
57+
</GridPane>
58+
</VBox>
59+
</StackPane>

0 commit comments

Comments
 (0)