Programming with JViews Maps > Creating a Map Application Using the API > Using the GUI Beans > 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 Figure 3.23.

annotationtoolbar.png

Figure 3.23 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.

Including the Bean in an Application

The Annotations Toolbar Bean is an extension of JToolBar.

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.
// Set the size of the buttons.
annotations.setButtonSize(new Dimension(25, 25));
// Prevent the toolbar being dragged elsewhere.
annotations.setFloatable(false);
    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.
    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));
    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);
    String s = "A Label";
    IlvFeatureAttributeProperty properties = new
       IlvFeatureAttributeProperty(IlvMapAnnotationModel.info,
          new IlvFeatureAttribute[] { new IlvStringAttribute(s)});
    m.setNamedProperty(properties);
    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();