|
| 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 | +} |
0 commit comments