Using annotations

The Annotations Toolbar bean is represented by the IlvMapAnnotationToolBar class. You can annotate maps using predefined annotations created by the Annotations Toolbar. The toolbar can be used interactively to add a point, polyline, or polygon annotation. An example of the Annotations Toolbar is shown in Annotations toolbar.
annotationtoolbar.png
Annotations toolbar
An annotation is a drawing made on the top of a map to describe or provide additional information about a specific zone of a map. Annotations are labeled and are projected with respect to the coordinate system of the map, which is stored in the manager as an IlvCoordinateSystemProperty. In JViews Maps, annotations are dedicated IlvGraphic objects. Labels can be displayed to provide text information and are labeled using the JViews Maps labeling mechanism.
The Annotations Toolbar bean is an extension of JToolBar .
To include the bean in an application:
  1. To include the Annotations Toolbar bean in your application, write the following lines of code:
    IlvMapAnnotationToolBar annotations =new IlvMapAnnotationToolBar();
    annotations.setView(view);
    
    The toolbar is ready for interactive creation of annotation objects. You can also add annotations to a map using the API. The objects used to display annotations are specialized IlvGraphics.
  2. You can customize certain properties of the Annotations Toolbar using the following code:
    // Set the size of the buttons.
    annotations.setButtonSize(new Dimension(25, 25));
    // Prevent the toolbar being dragged elsewhere.
    annotations.setFloatable(false);
    
  3. If you want your annotations to be managed as nodes, in order to make it possible for you to create link annotations, you need to indicate it through:
    annotations.setGrapherMode(true);
  4. Create the annotation as an IlvMapAnnotationToolBar.MapMarker:
  5.     IlvPoint p = new IlvPoint(10, 50);
        IlvMapAnnotationToolBar.MapMarker m = new
           IlvMapAnnotationToolBar.MapMarker(p);
    
    These graphic objects are stored in an IlvGraphicLayerDataSource. The IlvMapAnnotationModel class can provide such a data source.
  6. Get the IlvGraphicLayerDataSource data source:
        IlvMapAnnotationModel model =
           IlvMapAnnotationProperty.GetMapAnnotationModel(manager);
        IlvGraphicLayerDataSource dataSource = model.getDataSource(manager,
           "TEST");
        String name = "TEST" + " Annotation";
        dataSource.getInsertionLayer().setName(name);
        dataSource.add(m,
           IlvCoordinateSystemProperty.GetCoordinateSystem(manager));
    
  7. Set the style for the layer in which the annotation is to be inserted. The following piece of code also sets the label attribute so that the annotation is labeled accordingly:
        if (dataSource.getInsertionLayer().getStyle() == null) {
          IlvMapStyle style = new IlvPointStyle();
          style.setAttributeInfo(IlvMapAnnotationModel.info);
          style.setLabelAttribute(IlvMapAnnotationModel.info.getAttributeName(0));
          dataSource.getInsertionLayer().setStyle(style);
        }
        IlvPointStyle ps =
           (IlvPointStyle)dataSource.getInsertionLayer().getStyle();
        m.setStyle(ps);
        ps.setSize(5);
        ps.setType(IlvMarker.IlvMarkerFilledDiamond);
        ps.setForeground(Color.pink);
    
  8. Attach the feature attribute property; the string A Label will be displayed as the annotation label:
        String s = "A Label";
        IlvFeatureAttributeProperty properties = new
           IlvFeatureAttributeProperty(IlvMapAnnotationModel.info,
              new IlvFeatureAttribute[] { new IlvStringAttribute(s)});
        m.setNamedProperty(properties);
    
  9. Start the data source to add the annotation to the manager. The labeler may also need to be started:
        try {
         
        manager.setInsertionLayer(dataSource.getInsertionLayer().getManagerLayer().
           getIndex());
          dataSource.start();
        } catch (Exception e) {
          e.printStackTrace();
        }
        IlvMapLabeler labeler = IlvMapLabelerProperty.GetMapLabeler(manager);
        labeler.setView(view);
        labeler.addLayer(dataSource.getInsertionLayer());
        labeler.performLabeling();