Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 98
Registered: ‎03-10-2011
My Device: 9700 Bold

Maps

Hi,

 

I have implemented a simple map within an application of mine however I am unsure how to add interaction with the map so a user is able to pan around the map or zoom in and out. The code I have implemented is as follows:

 

 

MapField _mapField;

       int _prevZoom = 3;
       
       Coordinates c = new Coordinates(51.554928, -0.108361, 0);
       _mapField = new MapField(Field.FOCUSABLE){
    	   protected void paint(Graphics graphics) {
    		   Bitmap mIcon = Bitmap.getBitmapResource("stadium_icon.png");;
    		   XYRect mDest = null;
    	    	super.paint(graphics);
    	    	if (null != mIcon) {
    	    		if (null == mDest) {
    	    			XYPoint fieldOut = new XYPoint();
    	    			convertWorldToField(getCoordinates(), fieldOut);
    	    			int imgW = mIcon.getWidth();
    	    			int imgH = mIcon.getHeight();
    	    			mDest = new XYRect(fieldOut.x - imgW / 2, 
    	    			fieldOut.y - imgH, imgW, imgH);
    	    		}
    	    		graphics.drawBitmap(mDest, mIcon, 0, 0);
    	    	}
    	    }
       };
       
       _mapField.setPreferredSize(440,300);
       _mapField.moveTo(c);
       _mapField.setMargin(30,0,20,20);
       _mapField.setZoom(_prevZoom);
       
       backgroundManager.add(_mapField);

 

 

How do I add zoom and pan usability to this code?

 

Thanks

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Maps

If it were me, would probably override navigationMovement() in order to detect the trackball movement, then adjust the map center position accordingly (translating the dx/dy values into map coordinates).

 

For zoom, you might detect navigationClick() to toggle between pan and zoom modes, then use your navigationMovement to adjust the zoom level.