Graphics overlay dictionary renderer 3D

View on GitHub
Sample viewer app

Display MIL-STD-2525. military symbology in 3D.

Image of graphics overlay dictionary renderer 3D

Use case

Use a dictionary renderer on a graphics overlay to display more transient data, such as military messages coming through a local tactical network.

How to use the sample

When launched, this sample displays a scene with a dictionary renderer. Pan and zoom to explore the scene.

How it works

  1. Create a SymbolDictionary from a dictionary (stylx) file.
  2. Create a DictionaryRenderer with the symbol dictionary.
  3. Set the renderer on a graphics overlay with graphicsOverlay.setRenderer(dictionaryRenderer).
  4. Parse an XML file conforming to the specification. It should have key-value pairs to use as attributes for each graphic:

    • Use the name of the XML node as the attribute key and the content of the node as the attribute value.
    • Get the WKID and coordinates from the XML to create the graphic's geometry.
  5. The other attributes such as "symbolentity" and "symbolset" will describe the symbology for the graphic.
  6. Create the graphic with the geometry and attributes and add it to the graphics overlay.

Relevant API

  • GraphicsOverlay
  • DictionaryRenderer
  • DictionarySymbolStyle

Additional information

The dictionary renderer creates these graphics using a local mil2525d style file included in the SDK's resources/symbols directory plus an XML file with key-value attributes for each graphic.

Tags

defense, military, situational awareness, tactical, visualization

Sample Code

GraphicsOverlayDictionaryRenderer3DSample.java
                                                                                                                                                                                             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * Copyright 2018 Esri.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.esri.samples.graphics_overlay_dictionary_renderer_3D;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import com.esri.arcgisruntime.geometry.GeometryEngine;
import com.esri.arcgisruntime.geometry.Multipoint;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.PointCollection;
import com.esri.arcgisruntime.geometry.SpatialReference;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.Graphic;
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
import com.esri.arcgisruntime.mapping.view.SceneView;
import com.esri.arcgisruntime.symbology.DictionaryRenderer;
import com.esri.arcgisruntime.symbology.DictionarySymbolStyle;
import static org.joox.JOOX.$;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class GraphicsOverlayDictionaryRenderer3DSample extends Application {

  private SceneView sceneView;

  @Override
  public void start(Stage stage) {
    try {
      // create stack pane and application scene
      StackPane stackPane = new StackPane();
      Scene fxScene = new Scene(stackPane);

      // set title, size, and add scene to stage
      stage.setTitle("Graphics Overlay Dictionary Renderer 3D Sample");
      stage.setWidth(800);
      stage.setHeight(700);
      stage.setScene(fxScene);
      stage.show();

      // create a scene and add a basemap to it
      sceneView = new SceneView();
      ArcGISScene scene = new ArcGISScene(Basemap.Type.IMAGERY);
      sceneView.setArcGISScene(scene);

      stackPane.getChildren().add(sceneView);

      GraphicsOverlay graphicsOverlay = new GraphicsOverlay(GraphicsOverlay.RenderingMode.DYNAMIC);
      sceneView.getGraphicsOverlays().add(graphicsOverlay);

      // create symbol dictionary from specification
      // the specification style file comes with the SDK in the resources/symbols directory
      // see this directory for other specification types
      File stylxFile = new File(System.getProperty("data.dir"), "./samples-data/stylx/mil2525d.stylx");
      DictionarySymbolStyle symbolDictionary = DictionarySymbolStyle.createFromFile(stylxFile.getAbsolutePath());

      // tells graphics overlay how to render graphics with symbol dictionary attributes set
      DictionaryRenderer renderer = new DictionaryRenderer(symbolDictionary);
      graphicsOverlay.setRenderer(renderer);

      // parse graphic attributes from a XML file following the mil2525d specification
      List<Map<String, Object>> messages = parseMessages();

      // create graphics with attributes and add to graphics overlay
      List<Graphic> graphics = messages.stream()
          .map(GraphicsOverlayDictionaryRenderer3DSample::createGraphic)
          .collect(Collectors.toList());

      graphicsOverlay.getGraphics().addAll(graphics);

      // when the scene loads and the sceneview has a spatial reference, move the camera to show the graphics
      sceneView.setViewpointCamera(new Camera((graphicsOverlay.getGraphics().get(0).getGeometry()).getExtent().getCenter(), 15000, 0, 70, 0));

      // add the scene view to the stack pane
    } catch (Exception ex) {
      // on any exception, print the stacktrace
      ex.printStackTrace();
    }
  }

  /**
   * Parses a XML file following the mil2525d specification and creates a message for each block of attributes found.
   */
  private List<Map<String, Object>> parseMessages() throws Exception {

    File mil2525dFile = new File(System.getProperty("data.dir"), "./samples-data/xml/Mil2525DMessages.xml");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(mil2525dFile);
    document.getDocumentElement().normalize();

    final List<Map<String, Object>> messages = new ArrayList<>();

    for (int i = 0; i < document.getElementsByTagName("message").getLength() ; i++) {
      Node message = document.getElementsByTagName("message").item(i);

      Map<String, Object> attributes = new HashMap<>();

      NodeList childNodes = message.getChildNodes();
      for (int j = 0; j < childNodes.getLength() ; j++) {
        attributes.put(childNodes.item(j).getNodeName(), childNodes.item(j).getTextContent());
      }
      messages.add(attributes);
    }

    return messages;
  }

  /**
   * Creates a graphic using a symbol dictionary and the attributes that were passed.
   *
   * @param attributes tells symbol dictionary what symbol to apply to graphic
   */
  private static Graphic createGraphic(Map<String, Object> attributes) {
    // get spatial reference
    int wkid = Integer.parseInt((String) attributes.get("_wkid"));
    SpatialReference sr = SpatialReference.create(wkid);

    // get points from the coordinate string in the "_control_points" attribute (delimited with ';')
    String[] coordinates = ((String) attributes.get("_control_points")).split(";");
    List<Point> points = Stream.of(coordinates)
        .map(cs -> cs.split(",")) // get each ordinate
        .map(c -> new Point(Double.valueOf(c[0]), Double.valueOf(c[1]), sr))// create a Point with the ordinates
        .map(c -> (Point) GeometryEngine.project(c, SpatialReferences.getWgs84())) // project to display in scene
        .collect(Collectors.toList());

    // create a point collection with the points
    PointCollection pointCollection = new PointCollection(SpatialReferences.getWgs84());
    pointCollection.addAll(points);

    // remove unneeded attributes, use geometry for graphic positioning instead
    attributes.remove("_control_points");
    attributes.remove("_wkid");

    // return a graphic with a multipoint geometry (some have more than one point)
    return new Graphic(new Multipoint(pointCollection), attributes);
  }

  /**
   * Stops and releases all resources used in application.
   */
  @Override
  public void stop() {

    if (sceneView != null) {
      sceneView.dispose();
    }
  }

  /**
   * Opens and runs application.
   *
   * @param args arguments passed to this application
   */
  public static void main(String[] args) {

    Application.launch(args);
  }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.