|
| 1 | +/* |
| 2 | + * Copyright 2006-2009, 2017, 2020 United States Government, as represented by the |
| 3 | + * Administrator of the National Aeronautics and Space Administration. |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * The NASA World Wind Java (WWJ) platform is licensed under the Apache License, |
| 7 | + * Version 2.0 (the "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software distributed |
| 12 | + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 13 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 14 | + * specific language governing permissions and limitations under the License. |
| 15 | + * |
| 16 | + * NASA World Wind Java (WWJ) also contains the following 3rd party Open Source |
| 17 | + * software: |
| 18 | + * |
| 19 | + * Jackson Parser – Licensed under Apache 2.0 |
| 20 | + * GDAL – Licensed under MIT |
| 21 | + * JOGL – Licensed under Berkeley Software Distribution (BSD) |
| 22 | + * Gluegen – Licensed under Berkeley Software Distribution (BSD) |
| 23 | + * |
| 24 | + * A complete listing of 3rd Party software notices and licenses included in |
| 25 | + * NASA World Wind Java (WWJ) can be found in the WorldWindJava-v2.2 3rd-party |
| 26 | + * notices and licenses PDF found in code directory. |
| 27 | + */ |
| 28 | +package gov.nasa.worldwindx.examples; |
| 29 | + |
| 30 | +import gov.nasa.worldwind.View; |
| 31 | +import gov.nasa.worldwind.WorldWind; |
| 32 | +import gov.nasa.worldwind.WorldWindow; |
| 33 | +import gov.nasa.worldwind.avlist.AVKey; |
| 34 | +import gov.nasa.worldwind.geom.Angle; |
| 35 | +import gov.nasa.worldwind.geom.Position; |
| 36 | +import gov.nasa.worldwind.layers.*; |
| 37 | +import gov.nasa.worldwind.render.*; |
| 38 | +import gov.nasa.worldwind.util.*; |
| 39 | +import java.awt.BorderLayout; |
| 40 | +import java.awt.Color; |
| 41 | +import java.awt.GridLayout; |
| 42 | +import java.awt.event.ActionEvent; |
| 43 | + |
| 44 | +import java.util.*; |
| 45 | +import javax.swing.BorderFactory; |
| 46 | +import javax.swing.JButton; |
| 47 | +import javax.swing.JPanel; |
| 48 | +import javax.swing.JTextField; |
| 49 | +import javax.swing.border.CompoundBorder; |
| 50 | +import javax.swing.border.TitledBorder; |
| 51 | + |
| 52 | +public class VerticalExaggeration extends ApplicationTemplate { |
| 53 | + |
| 54 | + public static class AppFrame extends ApplicationTemplate.AppFrame { |
| 55 | + |
| 56 | + class VEInputPanel extends JPanel { |
| 57 | + |
| 58 | + private final WorldWindow wwd; |
| 59 | + private JTextField veInput; |
| 60 | + |
| 61 | + public VEInputPanel(WorldWindow wwd) { |
| 62 | + super(new GridLayout(0, 1, 0, 0)); |
| 63 | + this.wwd = wwd; |
| 64 | + this.makePanel(); |
| 65 | + } |
| 66 | + |
| 67 | + private JPanel makePanel() { |
| 68 | + JPanel controlPanel = this; |
| 69 | + |
| 70 | + JPanel vePanel = new JPanel(new GridLayout(0, 1, 0, 0)); |
| 71 | + vePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
| 72 | + this.veInput = new JTextField(10); |
| 73 | + this.veInput.setToolTipText("Enter Vertical Exaggeration value and press Enter"); |
| 74 | + this.veInput.setText(String.valueOf(wwd.getSceneController().getVerticalExaggeration())); |
| 75 | + this.veInput.addActionListener((ActionEvent event) -> { |
| 76 | + double newVE = Double.parseDouble(this.veInput.getText()); |
| 77 | + this.wwd.getSceneController().setVerticalExaggeration(newVE); |
| 78 | + this.wwd.redraw(); |
| 79 | + }); |
| 80 | + vePanel.add(this.veInput); |
| 81 | + |
| 82 | + JPanel veButtonPanel = new JPanel(new GridLayout(0, 1, 0, 0)); |
| 83 | + veButtonPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); |
| 84 | + JButton gotoButton = new JButton("Update Vertical Exaggeration"); |
| 85 | + gotoButton.addActionListener((ActionEvent event) -> { |
| 86 | + double newVE = Double.parseDouble(this.veInput.getText()); |
| 87 | + this.wwd.getSceneController().setVerticalExaggeration(newVE); |
| 88 | + this.wwd.redraw(); |
| 89 | + }); |
| 90 | + veButtonPanel.add(gotoButton); |
| 91 | + |
| 92 | + controlPanel.add(vePanel); |
| 93 | + controlPanel.add(veButtonPanel); |
| 94 | + controlPanel.setBorder( |
| 95 | + new CompoundBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9), new TitledBorder("Vertical Exaggeration"))); |
| 96 | + return controlPanel; |
| 97 | + } |
| 98 | + |
| 99 | + } |
| 100 | + |
| 101 | + public AppFrame() { |
| 102 | + super(true, true, false); |
| 103 | + |
| 104 | + // Add a dragger to enable shape dragging |
| 105 | + this.getWwd().addSelectListener(new BasicDragger(this.getWwd())); |
| 106 | + |
| 107 | + RenderableLayer layer = new RenderableLayer(); |
| 108 | + |
| 109 | + // Create and set an attribute bundle. |
| 110 | + ShapeAttributes attrs = new BasicShapeAttributes(); |
| 111 | + attrs.setOutlineMaterial(new Material(Color.YELLOW)); |
| 112 | + attrs.setOutlineWidth(2d); |
| 113 | + |
| 114 | + ShapeAttributes cylinderAttrs = new BasicShapeAttributes(); |
| 115 | + cylinderAttrs.setInteriorMaterial(Material.YELLOW); |
| 116 | + cylinderAttrs.setDrawOutline(false); |
| 117 | + cylinderAttrs.setEnableLighting(true); |
| 118 | + |
| 119 | + // Create a path, set some of its properties and set its attributes. |
| 120 | + ArrayList<Position> pathPositions = new ArrayList<>(); |
| 121 | + double lat = 35.327; |
| 122 | + double lon = -111.677; |
| 123 | + double altitude = 1000; |
| 124 | + pathPositions.add(Position.fromDegrees(lat, lon - 0.1, altitude)); |
| 125 | + pathPositions.add(Position.fromDegrees(lat, lon, altitude)); |
| 126 | + pathPositions.add(Position.fromDegrees(lat, lon + 0.1, altitude)); |
| 127 | + Path path = new Path(pathPositions); |
| 128 | + path.setAttributes(attrs); |
| 129 | + path.setVisible(true); |
| 130 | + path.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); |
| 131 | + path.setPathType(AVKey.GREAT_CIRCLE); |
| 132 | + path.setValue(AVKey.DISPLAY_NAME, "Yellow Path, relative to ground. Altitude: " + altitude + " meters."); |
| 133 | + layer.addRenderable(path); |
| 134 | + |
| 135 | + Cylinder cylinder = new Cylinder(Position.fromDegrees(lat, lon, altitude), 500, 500, 500); |
| 136 | + cylinder.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); |
| 137 | + cylinder.setAttributes(cylinderAttrs); |
| 138 | + cylinder.setVisible(true); |
| 139 | + cylinder.setValue(AVKey.DISPLAY_NAME, "Yellow cylinder, relative to ground. Altitude: " + altitude + " meters."); |
| 140 | + layer.addRenderable(cylinder); |
| 141 | + |
| 142 | + double polygonAltitude = 3000; |
| 143 | + ArrayList<Position> boundaries = new ArrayList<>(); |
| 144 | + boundaries.add(Position.fromDegrees(lat, lon - 0.05, polygonAltitude)); |
| 145 | + boundaries.add(Position.fromDegrees(lat, lon + 0.05, polygonAltitude)); |
| 146 | + boundaries.add(Position.fromDegrees(lat + 0.05, lon, polygonAltitude)); |
| 147 | + |
| 148 | + Polygon polygon = new Polygon(boundaries); |
| 149 | + polygon.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); |
| 150 | + polygon.setValue(AVKey.DISPLAY_NAME, "Yellow polygon, relative to ground. Altitude: " + polygonAltitude + " meters."); |
| 151 | + |
| 152 | + ShapeAttributes polygonAttributes = new BasicShapeAttributes(); |
| 153 | + polygonAttributes.setDrawInterior(true); |
| 154 | + polygonAttributes.setDrawOutline(true); |
| 155 | + polygonAttributes.setOutlineMaterial(Material.YELLOW); |
| 156 | + polygonAttributes.setInteriorMaterial(Material.YELLOW); |
| 157 | + polygonAttributes.setEnableLighting(true); |
| 158 | + polygon.setAttributes(polygonAttributes); |
| 159 | + |
| 160 | + layer.addRenderable(polygon); |
| 161 | + |
| 162 | + attrs = new BasicShapeAttributes(attrs); |
| 163 | + attrs.setOutlineMaterial(new Material(Color.RED)); |
| 164 | + pathPositions = new ArrayList<>(); |
| 165 | + lat -= 0.01; |
| 166 | + pathPositions.add(Position.fromDegrees(lat, lon - 0.1, altitude)); |
| 167 | + pathPositions.add(Position.fromDegrees(lat, lon, altitude)); |
| 168 | + pathPositions.add(Position.fromDegrees(lat, lon + 0.1, altitude)); |
| 169 | + path = new Path(pathPositions); |
| 170 | + path.setAttributes(attrs); |
| 171 | + path.setVisible(true); |
| 172 | + path.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); |
| 173 | + path.setPathType(AVKey.GREAT_CIRCLE); |
| 174 | + path.setValue(AVKey.DISPLAY_NAME, "Red Path, clamp to ground. Altitude: " + altitude + " meters."); |
| 175 | + layer.addRenderable(path); |
| 176 | + |
| 177 | + cylinderAttrs = new BasicShapeAttributes(cylinderAttrs); |
| 178 | + cylinderAttrs.setInteriorMaterial(Material.RED); |
| 179 | + |
| 180 | + cylinder = new Cylinder(Position.fromDegrees(lat, lon, altitude), 500, 500, 500); |
| 181 | + cylinder.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); |
| 182 | + cylinder.setAttributes(cylinderAttrs); |
| 183 | + cylinder.setVisible(true); |
| 184 | + cylinder.setValue(AVKey.DISPLAY_NAME, "Red cylinder, clamp to ground. Altitude: " + altitude + " meters."); |
| 185 | + layer.addRenderable(cylinder); |
| 186 | + |
| 187 | + polygonAltitude+= 500; |
| 188 | + boundaries = new ArrayList<>(); |
| 189 | + boundaries.add(Position.fromDegrees(lat, lon - 0.2, polygonAltitude)); |
| 190 | + boundaries.add(Position.fromDegrees(lat, lon + 0.2, polygonAltitude)); |
| 191 | + boundaries.add(Position.fromDegrees(lat + 0.2, lon, polygonAltitude)); |
| 192 | + |
| 193 | + polygon = new Polygon(boundaries); |
| 194 | + polygon.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); |
| 195 | + polygon.setValue(AVKey.DISPLAY_NAME, "Red polygon, clamp to ground. Altitude: " + polygonAltitude + " meters."); |
| 196 | + |
| 197 | + polygonAttributes = new BasicShapeAttributes(polygonAttributes); |
| 198 | + polygonAttributes.setOutlineMaterial(Material.RED); |
| 199 | + polygonAttributes.setInteriorMaterial(Material.RED); |
| 200 | + polygon.setAttributes(polygonAttributes); |
| 201 | + |
| 202 | + layer.addRenderable(polygon); |
| 203 | + |
| 204 | + attrs = new BasicShapeAttributes(attrs); |
| 205 | + attrs.setOutlineMaterial(new Material(Color.MAGENTA)); |
| 206 | + pathPositions = new ArrayList<>(); |
| 207 | + lat += 0.02; |
| 208 | + altitude = 5000; |
| 209 | + pathPositions.add(Position.fromDegrees(lat, lon - 0.1, altitude)); |
| 210 | + pathPositions.add(Position.fromDegrees(lat, lon, altitude)); |
| 211 | + pathPositions.add(Position.fromDegrees(lat, lon + 0.1, altitude)); |
| 212 | + path = new Path(pathPositions); |
| 213 | + path.setAttributes(attrs); |
| 214 | + path.setVisible(true); |
| 215 | + path.setAltitudeMode(WorldWind.ABSOLUTE); |
| 216 | + path.setPathType(AVKey.GREAT_CIRCLE); |
| 217 | + path.setValue(AVKey.DISPLAY_NAME, "Magenta Path, absolute altitude mode. Altitude: " + altitude + " meters."); |
| 218 | + layer.addRenderable(path); |
| 219 | + |
| 220 | + cylinderAttrs = new BasicShapeAttributes(cylinderAttrs); |
| 221 | + cylinderAttrs.setInteriorMaterial(Material.MAGENTA); |
| 222 | + |
| 223 | + cylinder = new Cylinder(Position.fromDegrees(lat, lon, altitude), 500, 500, 500); |
| 224 | + cylinder.setAltitudeMode(WorldWind.ABSOLUTE); |
| 225 | + cylinder.setAttributes(cylinderAttrs); |
| 226 | + cylinder.setVisible(true); |
| 227 | + cylinder.setValue(AVKey.DISPLAY_NAME, "Magenta cylinder, absolute altitude mode. Altitude: " + altitude + " meters."); |
| 228 | + layer.addRenderable(cylinder); |
| 229 | + |
| 230 | + polygonAltitude+= 500; |
| 231 | + boundaries = new ArrayList<>(); |
| 232 | + boundaries.add(Position.fromDegrees(lat, lon - 0.05, polygonAltitude)); |
| 233 | + boundaries.add(Position.fromDegrees(lat, lon + 0.05, polygonAltitude)); |
| 234 | + boundaries.add(Position.fromDegrees(lat + 0.05, lon, polygonAltitude)); |
| 235 | + |
| 236 | + polygon = new Polygon(boundaries); |
| 237 | + polygon.setAltitudeMode(WorldWind.ABSOLUTE); |
| 238 | + polygon.setValue(AVKey.DISPLAY_NAME, "Magenta polygon, absolute altitude mode. Altitude: " + polygonAltitude + " meters."); |
| 239 | + |
| 240 | + polygonAttributes = new BasicShapeAttributes(polygonAttributes); |
| 241 | + polygonAttributes.setOutlineMaterial(Material.MAGENTA); |
| 242 | + polygonAttributes.setInteriorMaterial(Material.MAGENTA); |
| 243 | + polygon.setAttributes(polygonAttributes); |
| 244 | + |
| 245 | + layer.addRenderable(polygon); |
| 246 | + |
| 247 | + insertBeforeCompass(getWwd(), layer); |
| 248 | + View view = this.getWwd().getView(); |
| 249 | + view.setEyePosition(Position.fromDegrees(35.4, -111.669, 20000)); |
| 250 | + view.setPitch(Angle.fromDegrees(70)); |
| 251 | + this.getControlPanel().add(new VEInputPanel(this.getWwd()), BorderLayout.SOUTH); |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + public static void main(String[] args) { |
| 256 | + ApplicationTemplate.start("WorldWind Paths", AppFrame.class); |
| 257 | + } |
| 258 | +} |
0 commit comments