Adding fields on top of a map

You can use the RichMapField class to display a map, which can be part of a screen that includes one or more UI components. You can add fields that are not part of the map by invoking RichMapField.add(). The fields are overlays that are not directly rendered on the map.

When a RichMapField instance is in a container that contains other UI components (for example, in a dialog box), by default, RichMapField shares focus with the other UI components, which allows a BlackBerry device user to move from RichMapField to the other UI components on the screen. If you want to make RichMapField the exclusive field on the screen (for example, the map is the full screen), you must disable the shared focus by invoking disableOperationMode(MapConstants.MODE_SHARED_FOCUS).

You can use MapConstants.MODE_FOCUS_ACTIVE to specify that RichMapField has focus, and still shares focus with the other UI components. When RichMapField has focus, RichMapField actively consumes all input events, such as a user clicking the trackpad. Giving focus to RichMapField allows a user to pan and zoom the map without inadvertently exiting the map and moving to other components on the screen. When RichMapField does not have focus, RichMapField does not consume any input events and a user can pan the map and move focus to another field on the screen.

For more information about UI components, see the BlackBerry Java SDK UI Component Quick Reference Guide.

Code sample: Adding a field on top of a map

RichMapField map = MapFactory.getInstance().generateRichMapField();
ButtonField button = new ButtonField( "Click Here", Field.FOCUSABLE);
button.setChangeListener( new FieldChangeListener()
    public void fieldChanged( Field field, int context )
        Dialog.alert( "Button clicked." );
} );
map.add( button, 50, 50 );

Code sample: Setting the RichMapField as the exclusive field on the screen

RichMapField richMapField = MapFactory.getInstance().generateRichMapField();
MapField map = richMapField.getMapField();
map.getAction().disableOperationMode( MapConstants.MODE_SHARED_FOCUS );

Was this information helpful? Send us your comments.