### Setting JVM Arguments for GDAL Deployment Source: https://github.com/worldwindearth/worldwindjava/blob/develop/GDAL_README.txt Example of setting essential JVM arguments for deploying applications that use GDAL. It includes setting the classpath for 'gdal.jar' and the Java library path for native libraries, which is crucial for the application to find and load the GDAL JNI components. ```bash # Example for Windows: java -classpath "C:\\Program Files\\GDAL\\java\\gdal.jar" -Djava.library.path="C:\\Program Files\\GDAL" YourApplication # Example for Linux (paths may vary): java -classpath "/path/to/gdal.jar" -Djava.library.path="/path/to/native/libs" YourApplication ``` -------------------------------- ### Manage OpenGL Drawing State (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Build-a-Custom-Renderable Handles the setup and restoration of OpenGL drawing states for rendering. It uses `glPushAttrib` and `glPopAttrib` to save and restore attributes, and `dc.beginStandardLighting()` and `dc.endStandardLighting()` for lighting state management. ```java protected void beginDrawing(DrawContext dc) { GL2 gl = dc.getGL().getGL2(); int attrMask = GL2.GL_CURRENT_BIT | GL.GL_COLOR_BUFFER_BIT; gl.glPushAttrib(attrMask); if (!dc.isPickingMode()) dc.beginStandardLighting(); } protected void endDrawing(DrawContext dc) { GL2 gl = dc.getGL().getGL2(); if (!dc.isPickingMode()) dc.endStandardLighting(); gl.glPopAttrib(); } ``` -------------------------------- ### Gradle Dependency Configuration for Local GDAL JAR Source: https://github.com/worldwindearth/worldwindjava/blob/develop/GDAL_README.txt This snippet shows how to configure a Gradle build script to use a local 'gdal.jar' file instead of fetching it from Maven or JCenter. This is useful when you have a specific version of the GDAL JAR you want to include directly in your project. ```gradle dependencies { ... compile files('gdal.jar') ... } ``` -------------------------------- ### Example: Create and Display a MIL-STD-2525 Phase Line Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Graphics Demonstrates the process of creating a tactical graphic (a phase line) using MilStd2525GraphicFactory and adding it to a WorldWind RenderableLayer. It shows how to specify control points, modifiers, and add the graphic to the WorldWindow for display. ```java // Create a graphic factory for MIL-STD-2525 TacticalGraphicFactory factory = new MilStd2525GraphicFactory(); // Specify the control points for the line List positions = Arrays.asList( Position.fromDegrees(34.7327, -117.8347, 0), Position.fromDegrees(34.7328, -117.7305, 0)); // Specify a text modifier AVList modifiers = new AVListImpl(); modifiers.setValue(SymbologyConstants.UNIQUE_DESIGNATION, "Alpha"); // Create a graphic for a MIL-STD-2525 hostile phase line. The first argument is the // symbol identification code (SIDC) that identifies the type of graphic to create. TacticalGraphic graphic = factory.createGraphic("GHGAGLP----AUSX", positions, modifiers); // Create a renderable layer to display the tactical graphic. This example adds only a // single graphic, but many graphics can be added to a single layer. RenderableLayer layer = new RenderableLayer(); layer.addRenderable(graphic); // Add the layer to the WorldWindow's model and request that the layer redraw itself. // The WorldWindow draws the graphic on the globe at the specified position. Interactions // between the graphic and the cursor are returned in the WorldWindow's picked object // list, and reported to the WorldWindow's select listeners. WorldWindow wwd = ... // A reference to your application's WorldWindow instance. wwd.getModel().getLayers().add(layer); wwd.redraw(); ``` -------------------------------- ### Eclipse Java Build Path Configuration for GDAL Source: https://github.com/worldwindearth/worldwindjava/blob/develop/GDAL_README.txt Instructions for configuring Eclipse to use external GDAL JARs and native libraries. This involves removing existing entries, adding the GDAL JAR, and setting the native library location, which implicitly adds '-Djava.library.path' to JVM arguments. ```plaintext Project Properties -> Java Build Path -> Libraries tab 1. Remove existing 'gdal.jar' entry. 2. Use 'Add External Jar' to point to your installed GDAL jar location. 3. Edit 'Native Library Location' for the new entry to point to the native libraries. This will add '-Djava.library.path=' to JVM args. ``` -------------------------------- ### Render 3D Paths with Altitude and Terrain Following (Java) Source: https://context7.com/worldwindearth/worldwindjava/llms.txt Creates a WorldWind RenderableLayer containing three different types of paths: an elevated great-circle path, a surface-following path draped on terrain, and an extruded path creating vertical walls. It utilizes `gov.nasa.worldwind` classes for geometry and rendering. This example requires WorldWind Java SDK. ```java import gov.nasa.worldwind.WorldWind; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.geom.Position; import gov.nasa.worldwind.layers.RenderableLayer; import gov.nasa.worldwind.render.*; import java.awt.Color; import java.util.ArrayList; import java.util.Arrays; public class PathRenderingExample { public static RenderableLayer createPathLayer() { RenderableLayer layer = new RenderableLayer(); layer.setName("Flight Paths"); // Path 1: Elevated path with relative altitude ArrayList positions1 = new ArrayList<>(Arrays.asList( Position.fromDegrees(28.0, -102.0, 10000.0), // lat, lon, altitude (meters) Position.fromDegrees(30.0, -100.0, 15000.0), Position.fromDegrees(35.0, -100.0, 10000.0) )); Path path1 = new Path(positions1); path1.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); // height above terrain path1.setPathType(AVKey.GREAT_CIRCLE); // curve follows Earth's surface BasicShapeAttributes attrs1 = new BasicShapeAttributes(); attrs1.setOutlineMaterial(new Material(Color.YELLOW)); attrs1.setOutlineWidth(3.0); attrs1.setOutlineOpacity(0.8); path1.setAttributes(attrs1); layer.addRenderable(path1); // Path 2: Terrain-following surface path ArrayList positions2 = new ArrayList<>(Arrays.asList( Position.fromDegrees(28.0, -106.0, 0.0), Position.fromDegrees(35.0, -104.0, 0.0) )); Path path2 = new Path(positions2); path2.setSurfacePath(true); // drapes path directly on terrain BasicShapeAttributes attrs2 = new BasicShapeAttributes(); attrs2.setOutlineMaterial(new Material(Color.RED)); attrs2.setOutlineWidth(2.0); path2.setAttributes(attrs2); layer.addRenderable(path2); // Path 3: Extruded path (creates vertical curtain to ground) ArrayList positions3 = new ArrayList<>(Arrays.asList( Position.fromDegrees(28.0, -106.0, 40000.0), Position.fromDegrees(35.0, -104.0, 40000.0), Position.fromDegrees(35.0, -107.0, 40000.0) )); Path path3 = new Path(positions3); path3.setAltitudeMode(WorldWind.ABSOLUTE); // altitude from sea level path3.setExtrude(true); // create vertical walls BasicShapeAttributes attrs3 = new BasicShapeAttributes(); attrs3.setOutlineMaterial(new Material(Color.BLUE)); attrs3.setInteriorMaterial(new Material(Color.CYAN)); attrs3.setInteriorOpacity(0.5); attrs3.setOutlineWidth(2.0); path3.setAttributes(attrs3); layer.addRenderable(path3); return layer; // Expected output: Three paths rendered on globe - yellow elevated great circle, // red surface-draped line, and cyan extruded vertical curtain } public static void addToGlobe(WorldWindow wwd) { RenderableLayer layer = createPathLayer(); wwd.getModel().getLayers().add(layer); } } ``` -------------------------------- ### Create MIL-STD-2525C Icon with No Fill using MilStd2525IconRetriever Source: https://github.com/worldwindearth/worldwindjava/wiki/Icon-Retriever This example shows how to create a tactical symbol icon with specific rendering parameters, in this case, disabling the fill. It utilizes the MilStd2525IconRetriever and an AVList to pass rendering options. The result is a BufferedImage of the symbol without a fill. ```java import gov.nasa.worldwind.ogc.kml.impl.KMLExtension; import gov.nasa.worldwind.symbology.milstd2525.* import gov.nasa.worldwind.util.WWUtil; import gov.nasa.worldwind.avlst.AVList; import gov.nasa.worldwind.avlst.AVListImpl; // ... other imports if needed VList params = new AVListImpl(); params.setValue(SymbologyConstants.SHOW_FILL, false); IconRetriever retriever = new MilStd2525IconRetriever(MilStd2525Constants.DEFAULT_ICON_RETRIEVER_PATH); BufferedImage icon = retriever.createIcon("SFAPMFQM--GIUSA", params); ``` -------------------------------- ### Extract 64-bit JOGL Native Libraries on Windows Source: https://github.com/worldwindearth/worldwindjava/wiki/Common-Problems Provides command-line instructions to extract the correct 64-bit JOGL and GlueGen runtime libraries for Windows from WorldWind JAR files. This is necessary to resolve 'Cannot load IA 32-bit .dll on a AMD 64-bit platform' errors in older WorldWind versions. ```bash cd to the WorldWind release folder jar xf jogl-natives-windows-amd64.jar jar xf gluegen-rt-natives-windows-amd64.jar ``` -------------------------------- ### Create MIL-STD-2525C Icon with MilStd2525IconRetriever Source: https://github.com/worldwindearth/worldwindjava/wiki/Icon-Retriever This snippet demonstrates how to create an IconRetriever for MIL-STD-2525C symbols and retrieve a specific symbol's icon. It requires the MilStd2525IconRetriever class and a valid SIDC. The output is a BufferedImage representing the icon. ```java import gov.nasa.worldwind.ogc.kml.impl.KMLExtension; import gov.nasa.worldwind.symbology.milstd2525.* import gov.nasa.worldwind.util.WWUtil; import gov.nasa.worldwind.avlst.AVList; import gov.nasa.worldwind.avlst.AVListImpl; // ... other imports if needed // Create an icon retriever to fetch symbols from the WorldWind server IconRetriever retriever = new MilStd2525IconRetriever(MilStd2525Constants.DEFAULT_ICON_RETRIEVER_PATH); BufferedImage icon = retriever.createIcon("SFAPMFQM--GIUSA", null); ``` -------------------------------- ### Initialize WorldWindow and Display 3D Globe in Java Source: https://context7.com/worldwindearth/worldwindjava/llms.txt This Java code snippet demonstrates how to create and configure the primary WorldWindowGLCanvas for rendering a 3D globe. It sets up the model, configures the initial camera view using BasicOrbitView, and embeds the WorldWindow within a Swing JFrame. The expected output is an interactive 3D globe that users can navigate. ```java import gov.nasa.worldwind.*; import gov.nasa.worldwind.awt.WorldWindowGLCanvas; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.geom.Position; import gov.nasa.worldwind.layers.*; import gov.nasa.worldwind.view.orbit.BasicOrbitView; import javax.swing.*; import java.awt.*; public class BasicGlobeApplication { public static void main(String[] args) { // Create the WorldWindow (OpenGL canvas) WorldWindowGLCanvas wwd = new WorldWindowGLCanvas(); wwd.setPreferredSize(new Dimension(1000, 800)); // Load default model from configuration (includes Earth globe and standard layers) Model model = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME); wwd.setModel(model); // Configure initial camera view BasicOrbitView view = new BasicOrbitView(); view.setEyePosition(Position.fromDegrees(38.0, -105.0, 19_070_000.0)); // lat, lon, altitude in meters wwd.setView(view); // Create Swing window JFrame frame = new JFrame("WorldWind Java Application"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(wwd, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); // Expected output: Interactive 3D globe centered over Colorado at 19,000km altitude // User can rotate, pan, and zoom with mouse/keyboard controls } } ``` -------------------------------- ### Set Tactical Symbol Position (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols Demonstrates how to create a TacticalSymbol with an initial position and how to update its position after creation using the setPosition method. The Position class uses degrees for latitude and longitude, and meters for altitude. ```java // Create a tactical symbol for the MIL-STD-2525 symbology set. The symbol is // initially positioned near Los Angeles. TacticalSymbol symbol = new MilStd2525TacticalSymbol("SFAPMFQM------A", Position.fromDegrees(34.7327, -117.8347, 1000)); // Move the tactical symbol from Los Angeles to Afghanistan, and set its altitude to // 3km above sea level. symbol.setPosition(Position.fromDegrees(32.4520, 63.44553, 3000)); ``` -------------------------------- ### Configure WorldWind Layer by Name (Java) Source: https://context7.com/worldwindearth/worldwindjava/llms.txt This Java method allows for dynamic configuration of WorldWind layers. It searches for a layer by its name and updates its enabled state and opacity. The method prints status messages to the console and redraws the WorldWind display upon successful configuration. It requires the WorldWind (wwd) object, layer name, enabled status, and opacity value as input. ```java public void configureLayer(String layerName, boolean enabled, double opacity) { LayerList layers = wwd.getModel().getLayers(); for (Layer layer : layers) { if (layer.getName().equals(layerName)) { layer.setEnabled(enabled); layer.setOpacity(opacity); System.out.printf("Configured %s: enabled=%b, opacity=%.2f%n", layerName, enabled, opacity); // Expected output: "Configured US States: enabled=true, opacity=0.70" wwd.redraw(); return; } } System.out.println("Layer not found: " + layerName); } } ``` -------------------------------- ### Configure Tactical Symbol Altitude Modes Automatically (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols Shows how to create TacticalSymbols where the altitude mode is automatically determined by the symbol identifier. MIL-STD-2525 symbol identifiers encode information about whether the object is air (ABSOLUTE) or ground (CLAMP_TO_GROUND). ```java // Create an air tactical symbol for the MIL-STD-2525 symbology set. This symbol // identifier specifies a MIL-STD-2525 friendly Special Operations Forces Drone // Aircraft. MilStd2525TacticalSymbol automatically sets the altitude mode to // WorldWind.ABSOLUTE. TacticalSymbol airSymbol = new MilStd2525TacticalSymbol("SFAPMFQM------A", Position.fromDegrees(32.4520, 63.44553, 3000)); // Create a ground tactical symbol for the MIL-STD-2525 symbology set. This symbol // identifier specifies multiple hostile Self-Propelled Rocket Launchers. // MilStd2525TacticalSymbol automatically sets the altitude mode to // WorldWind.CLAMP_TO_GROUND. TacticalSymbol groundSymbol = new MilStd2525TacticalSymbol("SHGPUCFRMS----G", Position.fromDegrees(32.4, 63.4, 0)); ``` -------------------------------- ### Handle Mouse Clicks, Rollovers, and Box Selection in WorldWind Java Source: https://context7.com/worldwindearth/worldwindjava/llms.txt This Java code demonstrates how to set up listeners for various mouse interactions within the WorldWind Java framework. It covers handling left clicks, right clicks, rollovers, and drag-based box selection, allowing developers to respond to user selections and hover events on rendered objects. Dependencies include WorldWind core libraries for event handling and rendering. ```java import gov.nasa.worldwind.WorldWindow; import gov.nasa.worldwind.avlist.AVKey; import gov.nasa.worldwind.event.*; import gov.nasa.worldwind.geom.Position; import gov.nasa.worldwind.pick.PickedObject; import gov.nasa.worldwind.pick.PickedObjectList; import gov.nasa.worldwind.render.Renderable; public class InteractionExample { public static void setupInteractionListeners(WorldWindow wwd) { // Selection listener - handles mouse clicks and rollovers wwd.addSelectListener(new SelectListener() { @Override public void selected(SelectEvent event) { if (event.getEventAction().equals(SelectEvent.LEFT_CLICK)) { // Handle left click PickedObject topObject = event.getTopPickedObject(); if (topObject != null && topObject.getObject() instanceof Renderable) { Renderable shape = (Renderable) topObject.getObject(); String name = (String) topObject.getValue(AVKey.DISPLAY_NAME); Position pos = topObject.getPosition(); System.out.println("Clicked: " + name + " at " + pos); // Expected output: "Clicked: Flight Path at (38.5°, -104.2°, 10000m)" } } else if (event.getEventAction().equals(SelectEvent.RIGHT_CLICK)) { // Handle right click (context menu) PickedObject topObject = event.getTopPickedObject(); if (topObject != null) { showContextMenu(event, topObject); } } else if (event.getEventAction().equals(SelectEvent.ROLLOVER)) { // Handle mouse hover PickedObject topObject = event.getTopPickedObject(); if (topObject != null) { highlightObject(topObject); } } } }); // Position listener - tracks cursor position on globe wwd.addPositionListener(new PositionListener() { @Override public void moved(PositionEvent event) { Position cursorPos = event.getPosition(); if (cursorPos != null) { double lat = cursorPos.getLatitude().getDegrees(); double lon = cursorPos.getLongitude().getDegrees(); double elev = cursorPos.getElevation(); System.out.printf("Cursor: %.4f°, %.4f°, %.0fm%n", lat, lon, elev); // Expected output: "Cursor: 38.5234°, -104.8267°, 2145m" } } }); // Rendering listener - monitors frame rendering stages wwd.addRenderingListener(new RenderingListener() { private long frameCount = 0; @Override public void stageChanged(RenderingEvent event) { if (event.getStage().equals(RenderingEvent.AFTER_BUFFER_SWAP)) { frameCount++; if (frameCount % 60 == 0) { System.out.println("Rendered " + frameCount + " frames"); // Expected output: "Rendered 60 frames" (every 60 frames) } } } }); // Rendering exception listener - handles rendering errors wwd.addRenderingExceptionListener(new RenderingExceptionListener() { @Override public void exceptionThrown(Throwable t) { System.err.println("Rendering error: " + t.getMessage()); t.printStackTrace(); } }); // Box selection listener - handles drag-select wwd.addSelectListener(new SelectListener() { @Override public void selected(SelectEvent event) { if (event.getEventAction().equals(SelectEvent.BOX_ROLLOVER)) { PickedObjectList objects = wwd.getObjectsInSelectionBox(); if (objects != null && objects.size() > 0) { System.out.println("Box contains " + objects.size() + " objects"); for (PickedObject obj : objects) { String name = (String) obj.getValue(AVKey.DISPLAY_NAME); System.out.println(" - " + name); } // Expected output: // "Box contains 3 objects" // " - Flight Path A" // " - Airport Marker" // " - Restricted Airspace" } } } }); } // Placeholder methods for context menu and highlighting private static void showContextMenu(SelectEvent event, PickedObject topObject) { System.out.println("Showing context menu for: " + topObject.getValue(AVKey.DISPLAY_NAME)); } private static void highlightObject(PickedObject topObject) { System.out.println("Highlighting object: " + topObject.getValue(AVKey.DISPLAY_NAME)); } } ``` -------------------------------- ### Enable OpenGL Debugger in JVM Arguments Source: https://github.com/worldwindearth/worldwindjava/wiki/Common-Problems Shows how to enable the OpenGL debugger by adding a JVM argument. This helps identify problematic OpenGL calls that cause errors, which are then caught by WorldWind and logged. ```properties -Djogl.debug.DebugGL ``` -------------------------------- ### Construct and Display MIL-STD-2525 Tactical Symbol in Java Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols Demonstrates the creation and display of a MIL-STD-2525 tactical symbol using `MilStd2525TacticalSymbol`. The symbol is defined by its identifier and position, then added to a `RenderableLayer` which is subsequently added to the WorldWind instance. This process visualizes the symbol on the globe. ```java import gov.nasa.worldwind.geom.Position; import gov.nasa.worldwind.layers.RenderableLayer; import gov.nasa.worldwind.symbology.milstd2525.MilStd2525TacticalSymbol; import gov.nasa.worldwind.WorldWindow; // Create a tactical symbol for the MIL-STD-2525 symbology set. The symbol identifier specifies a MIL-STD-2525 friendly Special Operations Forces Drone Aircraft. The position places the tactical symbol at 1km above mean sea level. TacticalSymbol symbol = new MilStd2525TacticalSymbol("SFAPMFQM------A", Position.fromDegrees(34.7327, -117.8347, 1000)); // Create a renderable layer to display the tactical symbol. This example adds // only a single symbol, but many symbols can be added to a single layer. Note // that Tactical symbols and tactical graphics can be combined in a single layer. RenderableLayer symbolLayer = new RenderableLayer(); symbolLayer.addRenderable(symbol); // Add the layer to the WorldWindow's model and request that the layer redraw // itself. The WorldWindow draws the symbol on the globe at the specified // position. Interactions between the symbol and the cursor are returned in the // WorldWindow's picked object list, and reported to the WorldWindow's select // listeners. WorldWindow wwd = ... // A reference to your application's WorldWind instance. wwd.getModel().getLayers().add(symbolLayer); wwd.redraw(); ``` -------------------------------- ### Configure Camera View Parameters and Limits Source: https://context7.com/worldwindearth/worldwindjava/llms.txt Sets the camera's orbiting center, zoom level, heading, pitch, and roll. Also configures view limits for panning, zooming, and pitch, and retrieves the field of view. Requires WorldWind Java libraries. ```java import gov.nasa.worldwind.WorldWindow; import gov.nasa.worldwind.geom.*; import gov.nasa.worldwind.view.orbit.*; public class CameraControlExample { // ... animateCameraToLocation method ... public static void configureCameraView(WorldWindow wwd) { OrbitView view = (OrbitView) wwd.getView(); // Set center point (what the camera orbits around) Position centerPosition = Position.fromDegrees(38.0, -105.0, 0); view.setCenterPosition(centerPosition); // Set zoom distance from center point view.setZoom(100000.0); // meters // Set viewing angles view.setHeading(Angle.fromDegrees(45.0)); // compass direction view.setPitch(Angle.fromDegrees(60.0)); // tilt angle from vertical view.setRoll(Angle.ZERO); // bank angle // Get current eye position Position eyePos = view.getEyePosition(); System.out.printf("Eye at: %.4f°, %.4f°, %.0fm%n", eyePos.getLatitude().degrees, eyePos.getLongitude().degrees, eyePos.getElevation()); // Expected output: "Eye at: 38.5234°, -104.4567°, 100000m" // Set view limits BasicOrbitViewLimits limits = new BasicOrbitViewLimits(); limits.setCenterLocationLimits( Sector.fromDegrees(30.0, 45.0, -120.0, -95.0) // restrict pan area ); limits.setZoomLimits(1000.0, 10_000_000.0); // min/max altitude limits.setPitchLimits(Angle.fromDegrees(0.0), Angle.fromDegrees(90.0)); view.setOrbitViewLimits(limits); // Compute field of view Angle fov = view.getFieldOfView(); System.out.printf("Field of view: %.1f°%n", fov.degrees); // Expected output: "Field of view: 45.0°" wwd.redraw(); } // ... other methods ... } ``` -------------------------------- ### Highlight Tactical Symbol with Custom Attributes (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols Demonstrates how to highlight a TacticalSymbol with custom attributes. This involves creating a TacticalSymbol, defining highlight attributes (scale, opacity), and applying them to the symbol. It's useful for visually emphasizing specific symbols when needed. ```java import gov.nasa.worldwind.geom.Position; import gov.nasa.worldwind.symbology.TacticalSymbol; import gov.nasa.worldwind.symbology.TacticalSymbolAttributes; import gov.nasa.worldwind.symbology.milstd2525.MilStd2525TacticalSymbol; import gov.nasa.worldwind.symbology.milstd2525.basic.BasicTacticalSymbolAttributes; // Create a tactical symbol for the MIL-STD-2525 symbology set. TacticalSymbol symbol = new MilStd2525TacticalSymbol("SFAPMFQM------A", Position.fromDegrees(34.7327, -117.8347, 1000)); // Create an attribute bundle and use it as the symbol's highlight attributes. TacticalSymbolAttributes highlightAttrs = new BasicTacticalSymbolAttributes(); highlightAttrs.setScale(2.0); // 200% of normal size when highlighted. highlightAttrs.setOpacity(1.0); // 100% opaque when highlighted. symbol.setHighlightAttributes(highlightAttrs); // To actually highlight the symbol, you would typically call: symbol.setHighlighted(true); // Or if using HighlightController, it might happen automatically. ``` -------------------------------- ### Display Context Menu for Picked Object (Java) Source: https://context7.com/worldwindearth/worldwindjava/llms.txt This method displays a context menu when a user interacts with a picked object. It takes a SelectEvent and the PickedObject as input and prints the display name of the object to the console. Dependencies include the WorldWind AVKey class. ```java private static void showContextMenu(SelectEvent event, PickedObject object) { // Context menu implementation System.out.println("Show context menu for: " + object.getValue(AVKey.DISPLAY_NAME)); } ``` -------------------------------- ### Set Tactical Symbol Size and Opacity (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols This code demonstrates how to control the visual scale and transparency of a TacticalSymbol using the `TacticalSymbolAttributes` interface. By creating a `BasicTacticalSymbolAttributes` object, you can set specific scale and opacity values that apply to both the symbol graphic and its modifiers. ```java // Create a tactical symbol for the MIL-STD-2525 symbology set. TacticalSymbol symbol = new MilStd2525TacticalSymbol("SFAPMFQM------A", Position.fromDegrees(34.7327, -117.8347, 1000)); // Create an attribute bundle and use it as the symbol's normal attributes. TacticalSymbolAttributes attrs = new BasicTacticalSymbolAttributes(); attrs.setScale(0.75); // Make the symbol 75% its normal size. attrs.setOpacity(0.5); // Make the symbol 50% transparent. symbol.setAttributes(attrs); ``` -------------------------------- ### Implement Picking for Cube in Java Source: https://github.com/worldwindearth/worldwindjava/wiki/Build-a-Custom-Renderable This Java method enhances the rendering process to support object picking. When in picking mode, it assigns a unique color to the cube and registers it with `PickSupport`. This allows WorldWind to identify the cube when it's under the cursor based on its assigned color. ```java protected PickSupport pickSupport = new PickSupport(); public void render(DrawContext dc) { GL2 gl = dc.getGL().getGL2(); this.beginDrawing(dc); try { if (dc.isPickingMode()) { Color pickColor = dc.getUniquePickColor(); this.pickSupport.addPickableObject(pickColor.getRGB(), this, this.position); gl.glColor3ub((byte) pickColor.getRed(), (byte) pickColor.getGreen(), (byte) pickColor.getBlue()); } gl.glScaled(this.size, this.size, this.size); this.drawUnitCube(dc); } finally { this.endDrawing(dc); } } ``` -------------------------------- ### Manually Set Tactical Symbol Altitude Mode (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols Illustrates how to manually override the automatically determined altitude mode of a TacticalSymbol by calling the setAltitudeMode method. This is useful when the default behavior needs to be adjusted. Recognized modes include WorldWind.ABSOLUTE, WorldWind.RELATIVE_TO_GROUND, and WorldWind.CLAMP_TO_GROUND. ```java // Set the ground symbol's altitude mode. groundSymbol.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); ``` -------------------------------- ### Create MilStd2525TacticalSymbol Instance (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Adding-New-Tactical-Symbols Demonstrates how to create a new `MilStd2525TacticalSymbol` instance in Java. This requires a Symbol Identification Code (SIDC) and a position. The icon files for this symbol should be placed in the 'icons/war/' directory of the symbology zip file or a local symbol directory. ```java import gov.nasa.worldwind.symbology.milstd2525.MilStd2525TacticalSymbol; import gov.nasa.worldwind.geom.Position; // ... inside a method or constructor ... // Example SIDC for a friendly, anticipated, position, area symbol String sidc = "SFAPZA--------A"; Position position = new Position(34.0, -118.0, 0); MILStd2525TacticalSymbol symbol = new MILStd2525TacticalSymbol(sidc, position); ``` -------------------------------- ### Set Tactical Symbol Modifiers After Construction (Java) Source: https://github.com/worldwindearth/worldwindjava/wiki/Tactical-Symbols This code shows how to modify an existing TacticalSymbol's attributes after it has been created. The `setModifier` method allows you to add or change modifiers, and specific flags like `setShowLocation(false)` can be used to control the visibility of implicit modifiers. ```java // Set the ground symbol's Direction of Movement (heading) and Echelon modifiers. groundSymbol.setModifier(SymbologyConstants.DIRECTION_OF_MOVEMENT, Angle.fromDegrees(50)); groundSymbol.setModifier(SymbologyConstants.ECHELON, SymbologyConstants.ECHELON_TEAM_CREW); ```