Map API

Nutiteq Maps Lib SDK enables developing advanced mobile mapping applications.
Platforms: Android, RIM BlackBerry, Java ME (J2ME)
Download maps API SDK »
Untitled Document

Products

» View demos
» Downloads

Latest news

Last at Tue, 6 Dec 2011 18:37:53
Topic: New BlackBerry sample app
See more news »

Blackberry map slower panning issue

3 replies [Last post]
abhirama
User offline. Last seen 1 year 7 weeks ago. Offline
Joined: 07/17/2009

Hi,

I have used map canvas with MapComponent. On blackberry, when I pan the map using trackball, it pans 1pixel. I need some accelerate strategy, where initially it starts pan by 1px but increase (accelerate) on further panning.

I have tried both panning strategies (EventDriven and ThreadDriven) but nothing works.

Please suggest how to achieve accelerate panning experience on Blackberry with trackball.

Thx

jaak
User offline. Last seen 1 day 10 hours ago. Offline
Joined: 06/19/2008

If you use RIM UIApplication API, then you should implement navitationMovement. It just pans map 10 pixels per trackball moving, of course you can have more sophisticated acceleration solution:

protected boolean navigationMovement(final int dx, 
  final int dy, final int status, 
  final int time) {
    mapComponent.panMap(dx * 10, dy * 10);
    invalidate();
    return true;
}

Or if you use Midlet then you can have own handler for navigation keypresses to get similar effect. Something like following:

	protected void keyPressed(final int keyCode) {
  	   int code = keyHandler.getKeyActionCode(keyCode);
		int speed = 10;
		switch (code) {
		case ControlKeys.MOVE_DOWN_KEY:
			map.panMap(0, speed);
			break;

		case ControlKeys.MOVE_UP_KEY:
			map.panMap(0, -speed);
			break;
		case ControlKeys.MOVE_RIGHT_KEY:
			map.panMap(speed, 0);
			break;
		case ControlKeys.MOVE_LEFT_KEY:
			map.panMap(-speed, 0);
			break;
		default:
			map.keyPressed(keyCode);
			break;
		}
		 
	}

	protected void keyReleased(final int keyCode) {
		map.keyReleased(keyCode);
	}

	protected void keyRepeated(final int keyCode) {
		
		  int code = keyHandler.getKeyActionCode(keyCode);
		int speed = 10;
		switch (code) {
		case ControlKeys.MOVE_DOWN_KEY:
			map.panMap(0, speed);
			break;

		case ControlKeys.MOVE_UP_KEY:
			map.panMap(0, -speed);
			break;
		case ControlKeys.MOVE_RIGHT_KEY:
			map.panMap(speed, 0);
			break;
		case ControlKeys.MOVE_LEFT_KEY:
			map.panMap(-speed, 0);
			break;
		default:
			map.keyRepeated(keyCode);
			break;
		}
		 
	}

/JaakL

jaak
User offline. Last seen 1 day 10 hours ago. Offline
Joined: 06/19/2008

More systematic way, and independent on your application type would be to implement and use own PanningStrategy. Following example to accelerates also movement to 10 pixels. Note that this could have side-effects, like movement with other possible keys is also faster. I have not tested it, please let me know if it works.

public class MyPanning implements PanningStrategy {
  private Pannable pannable;
  private int xMove;
  private int yMove;
  private int count;

  public boolean isPanning() {
    return false;
  }

  public void quit() {

  }

  public void start() {

  }

  public void startPanning(final int xMove, final int yMove, final boolean panningWithKeys) {
    this.xMove = xMove;
    this.yMove = yMove;
// following line is accelerating movement to 10 pixels per keyevent
    pannable.panMap(xMove * 10, yMove * 10);
    count = 1;
  }

  public void stopPanning() {

  }
// Note: I'm not sure if BB trackball gives keyRepeated events at all
  public void keyRepeated(final int keyCode) {
    count++;
    int dx = xMove;
    int dy = yMove;

    if (count >= 5 && count < 10) {
      dx = dx * 2;
      dy = dy * 2;
    } else if (count >= 10 && count < 15) {
      dx = dx * 4;
      dy = dy * 4;
    } else if (count >= 15 && count < 30) {
      dx = dx * 8;
      dy = dy * 8;
    } else if (count >= 30) {
      dx = dx * 16;
      dy = dy * 16;
    }

    pannable.panMap(dx, dy);
  }

  public void setMapComponent(final Pannable mapComponent) {
    pannable = mapComponent;
  }
}

/JaakL

abhirama
User offline. Last seen 1 year 7 weeks ago. Offline
Joined: 07/17/2009

Thx! Jaak for multiple solutions. Your last solution would have been working, but BB trackball doesn't gives repeat event.
First two solutions have constant jump factor(10), so I ended up using timer to track repeat event in keypress and subsequently increase the jump factor. This works well, but i am sure there should be some better solution (without timer).