/** @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(Field, int) */ public void fieldChanged(final Field field, final int context) { if (field == _map.getMapField()) { // Get the map's current dimensions final MapDimensions dim = _map.getMapField().getDimensions(); switch (context) { case MapAction.ACTION_CENTER_CHANGE: _latField.setText("Latitude: " + dim.getCenter().getLat()); _lonField.setText("Longitude: " + dim.getCenter().getLon()); break; case MapAction.ACTION_ZOOM_CHANGE: _zoomField.setText("Zoom Level: " + dim.getZoom()); break; } } }
/** @see net.rim.device.api.ui.Screen#onClose() */ public boolean onClose() { try { // Properly clean up any resources used _map.close(); } catch (final Exception e) { } return super.onClose(); }
/** @see net.rim.device.api.ui.Screen#onUiEngineAttached(boolean) */ protected void onUiEngineAttached(final boolean attached) { super.onUiEngineAttached(attached); if (attached) { // Set the location of the map to some random // location and set zoom to 5 (this zoom level // will be overriden by this application's // RestrictedMapAction class). _map.getMapField().getAction().setCenterAndZoom(new MapPoint(0, 0), 5); } }
/** Creates a new MapActionDemoScreen object */ public MapActionDemoScreen() { super(Screen.DEFAULT_CLOSE | Screen.DEFAULT_MENU | Manager.NO_VERTICAL_SCROLL); setTitle("Map Action Demo"); // Activate pinch gesturing if (Touchscreen.isSupported()) { final InputSettings is = TouchscreenSettings.createEmptySet(); is.set(TouchscreenSettings.DETECT_PINCH, 1); this.addInputSettings(is); } _map = MapFactory.getInstance().generateRichMapField(); _map.getMapField() .setDimensions(new MapDimensions(Display.getWidth(), Display.getHeight() - 130)); // Register for field updates (when the center and zoom changes) _map.getMapField().addChangeListener(this); // Change the MapAction class the MapField uses _restrictedMapAction = new RestrictedMapAction(); _map.getMapField().setAction(_restrictedMapAction); // Disable shared mode _map.getAction().disableOperationMode(MapConstants.MODE_SHARED_FOCUS); // Label fields to show the user location info _latField = new LabelField("Latitude: "); _lonField = new LabelField("Longitude: "); _zoomField = new LabelField("Zoom: "); add(_map); add(_latField); add(_lonField); add(_zoomField); }