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
Contributor
Posts: 11
Registered: ‎08-18-2010
My Device: Not Specified

MapField with Multiple markers Scrolling Error

Hi all,

I have customized the MapField as below. It is using BitmapFields as markers..My code is MapCustom.java and MapDemoScreen.java and MyBitmapField.java while scrolling i am not getting  Map.but BitmapFields are adding to screen.plz  give me solution is there any error in my classes....plzzzzzzzzz .

 

Thanks in Advance

Alla.Suman

 

 

	package com.winit.maps;
	
	import java.util.Vector;

import javax.microedition.location.Coordinates;

import net.rim.device.api.lbs.MapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYPoint;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.VerticalFieldManager;
	
	public class MapCustom extends VerticalFieldManager 
		{
	 private MapField mMapField;
	 private MyBitMapField mButton[];
	 private Vector verCoor;
	 private Bitmap bm,mapBm;
	 private BitmapField mapBmf;
	 
	 public MapCustom() 
	 {  
	      super(USE_ALL_HEIGHT|USE_ALL_WIDTH|NO_VERTICAL_SCROLL);
	     
	      mMapField = new MapField();        	
	      bm = Bitmap.getBitmapResource("point.png");

verCoor = new Vector(); } public int getPreferredHeight() { return getScreen().getHeight(); } public int getPreferredWidth() { return getScreen().getWidth(); } public void setZoom(Vector v) { this.verCoor = v; mMapField.setZoom(2); mMapField.moveTo((Coordinates)verCoor.elementAt(0)); this.add(mMapField); moveToView(); } public void setZoomIn() { mMapField.setZoom(Math.max(mMapField.getZoom() - 1, mMapField.getMinZoom())); moveToView(); } public void setZoomOut() { mMapField.setZoom(Math.min(mMapField.getZoom() + 1, mMapField.getMaxZoom())); moveToView(); } protected boolean move(int x, int y) { mMapField.move(x, y); moveToSwipe(); return true; } protected boolean navigationMovement(int dx, int dy, int status, int time) { dx = dx << 3; dy = dy << 3; mMapField.move(dx, dy); moveToSwipe(); return true; } private void moveToSwipe() { mButton = new MyBitMapField[verCoor.size()]; for(int i=0;i<verCoor.size();i++) { mButton[i] = new MyBitMapField("MyBitmap"+i,bm,bm); this.add(mButton[i]); } } public void moveToView() { mButton = new MyBitMapField[verCoor.size()]; for(int i=0;i<verCoor.size();i++) { mButton[i] = new MyBitMapField("MyBitmap"+i,bm,bm); this.add(mButton[i]); // invalidate(); } } /*******************************************************************/ protected void sublayout(int maxWidth, int maxHeight) { int width = mMapField.getPreferredWidth(); int height = mMapField.getPreferredHeight(); layoutChild(mMapField, width, height); setPositionChild(mMapField, 0, 0); for(int i=0 ; i< verCoor.size(); i++) { XYPoint fieldOut = new XYPoint(); mMapField.convertWorldToField((Coordinates)verCoor.elementAt(i), fieldOut ); int xPos = fieldOut.x - mButton[i].mWidth / 2; int yPos = fieldOut.y - mButton[i].mHeight ; layoutChild(mButton[i], mButton[i].mWidth/2, mButton[i].mHeight/2); setPositionChild(mButton[i], xPos, yPos); } setExtent(maxWidth, maxHeight); // invalidate(); } protected void paint(Graphics graphics) { super.paint(graphics); invalidate(); } }

 

package com.winit.maps;

import java.util.Vector;

import javax.microedition.location.Coordinates;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.TouchGesture;
import net.rim.device.api.ui.Trackball;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class MapDemoScreen extends MainScreen implements FieldChangeListener
{
	private  Vector v ;
	MapCustom cmf ;
	Bitmap bm ,bm1 ;
	ButtonField btn1,btn2 ;
	VerticalFieldManager vfmhead,vfm ;
	HorizontalFieldManager hfm ;
	
	public MapDemoScreen()
	{		
		super(NO_VERTICAL_SCROLL);
		cmf = new MapCustom();
	
		vfm = new VerticalFieldManager(USE_ALL_WIDTH|USE_ALL_HEIGHT|NO_VERTICAL_SCROLL)
	   	{
	   		protected void sublayout(int maxWidth, int maxHeight) 
	   		{
	   			setPositionChild(getField(0), 0, 0);
	   			layoutChild(getField(0),getScreen().getWidth(),getScreen().getHeight()-36);
	   			
	   			int y= Tools.getHeightByOrientation()-36;
	   			setPositionChild(getField(1), 0, y);	   			
	   			layoutChild(getField(1),getScreen().getWidth(),getScreen().getHeight());
	   			
	   			setExtent(maxWidth, maxHeight);	   			
	   		}
	   	};		
		
		Coordinates cor1 = new Coordinates(43.48645156501891, -80.52758037942554,0);
		Coordinates cor2 = new Coordinates(43.48623388220653, -80.52779806223793, 0);
		Coordinates cor3 = new Coordinates(43.48758593723019, -80.52744600721427,0);
		Coordinates cor4 = new Coordinates(43.48894874161948, -80.52708320282498,0);
		Coordinates cor5 = new Coordinates(43.48995874161948, -80.52718320282498,0);
		Coordinates cor6 = new Coordinates(43.48096874161948, -80.52728320282498,0);
		Coordinates cor7 = new Coordinates(43.48647874161948, -80.52738320282498,0);
		
	     v = new Vector();
	     v.addElement(cor1);
	     v.addElement(cor2);
	     v.addElement(cor3);
	     v.addElement(cor4);
	     v.addElement(cor5);
	     v.addElement(cor6);
	     v.addElement(cor7);
	     
		hfm = new HorizontalFieldManager();
		btn1 = new ButtonField("in",ButtonField.CONSUME_CLICK|Field.FOCUSABLE);
		btn1.setChangeListener(this);
		btn2 = new ButtonField("out",ButtonField.CONSUME_CLICK|Field.FOCUSABLE);
		btn2.setChangeListener(this);
		hfm.add(btn1);
		hfm.add(btn2);
		
		vfmhead = new VerticalFieldManager(NO_VERTICAL_SCROLL);//VERTICAL_SCROLL);
		
		cmf.setZoom(v);
		vfmhead.add(cmf);
		vfm.add(vfmhead);
		vfm.add(hfm);
		
		add(vfm);
	}
	protected boolean navigationMovement(int dx, int dy, int status, int time) 
    {
		boolean b = false;
		// Allows smoother panning on the map.
            if (Trackball.isSupported()) 
            {            	     	
                // Adjust the filter.
                getScreen().setTrackballFilter(Trackball.FILTER_NO_TIME_WINDOW | Trackball.FILTER_ACCELERATION);
            }  
            	vfmhead.deleteAll();
            	cmf.deleteRange(1, v.size());
	    	 	b = cmf.navigationMovement(dx, dy, status, time);
	    	 	vfmhead.add(cmf);       
        
        // Delegates this task to the map instance.
        return  b;
    }   
		protected boolean touchEvent(TouchEvent message) 
		{
			boolean isConsumed = false;			
	        
	        TouchGesture touchGesture = message.getGesture();           
	        if (touchGesture != null)
	        {                
	            // If the user has performed a swipe gesture we will move the
	            // map accordingly.
	            if (touchGesture.getEvent() == TouchGesture.SWIPE)
	            {      
	                // Retrieve the swipe magnitude so we know how
	                // far to move the map.
	                int magnitude = touchGesture.getSwipeMagnitude();
	                
	                // Move the map in the direction of the swipe.
	                vfmhead.deleteAll();
    	    	 	cmf.deleteRange(1, v.size());
    	    	 	
	                switch(touchGesture.getSwipeDirection())
	                {
	                    case TouchGesture.SWIPE_NORTH:	                    	
	        	    	 	isConsumed = cmf.move(0,- magnitude);      	    	 	    	 	   
	                        break;
	                    case TouchGesture.SWIPE_SOUTH:
	        	    	 	isConsumed = cmf.move(0, magnitude);       	    	 	    	 	   
	        	    	 	break;
	                    case TouchGesture.SWIPE_EAST:
	        	    	 	isConsumed = cmf.move(- magnitude, 0);        	    	 	    	 	   
	                        break;
	                    case TouchGesture.SWIPE_WEST:
	        	    	 	isConsumed = cmf.move(magnitude, 0);        	    	 	    	 	   
	                        break; 
	                    default:
	                    	isConsumed = cmf.move(0, 0);
	                    	break;
	                }
	                vfmhead.add(cmf);
	                isConsumed = true; // We've consumed the touch event.              
	            }
	        }     
	        return isConsumed; 
		}

		protected void paint(Graphics graphics) 
		{
			super.paint(graphics);
//			invalidate();
		}
	public void fieldChanged(Field field, int context) 
	{
		if(field instanceof ButtonField)
		{			
			if(field == btn1)
			{
		    	 vfmhead.deleteAll();
		    	 cmf.deleteRange(1, v.size());
		    	 cmf.setZoomIn();
		    	 vfmhead.add(cmf);		    	 
			}
			else if(field == btn2)
			{
				 vfmhead.deleteAll();			 
		    	 cmf.deleteRange(1, v.size());
		    	 cmf.setZoomOut();
		    	 vfmhead.add(cmf);
			}	
		}
		else if(field instanceof MyBitMapField)
		{
			MyBitMapField f = (MyBitMapField)cmf.getLeafFieldWithFocus();
	         final int h = f.getContentTop() - f.getManager().getVerticalScroll();
	         final int l = f.getContentLeft() - f.getManager().getHorizontalScroll();
	         final String Name = f.name ;
	         
	         UiApplication.getUiApplication().invokeLater(new Runnable()
	         {
	             public void run()
	             {
	                 UiApplication.getUiApplication().pushScreen(new PopupTest(l,h,Name));
	             }
	          });
		}  
	      
	}
}

 

package com.winit.maps;

import javax.microedition.location.Coordinates;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.decor.BorderFactory;

public class MyBitMapField extends BitmapField 
{
	Bitmap mNormal;
	Bitmap mFocused;
	String name;
	Coordinates coordinates;
	public int mWidth;
	public int mHeight;

	public MyBitMapField(String Name,Bitmap normal, Bitmap focused)
	{
		super( normal);//,Field.FOCUSABLE);
		mNormal = normal;
		mFocused = focused;
		name = Name;

		mWidth = focused.getWidth();
		mHeight = focused.getHeight();
		setMargin(0, 0, 0, 0);
		setPadding(0, 0, 0, 0);
		setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
		setBorder(VISUAL_STATE_ACTIVE, BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
	}

	protected void paint(Graphics graphics) 
	{
		Bitmap bitmap = mNormal;		
		graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),bitmap, 0, 0);
		
	}
	
	public int getPreferredWidth() {
		return mWidth;
	}

	public int getPreferredHeight() {
		return mHeight;
	}

	protected void layout(int width, int height)
	{		
		setExtent(mWidth, mHeight);
	}

	protected void applyTheme(Graphics arg0, boolean arg1) 
	{
	}	

	protected void drawFocus(Graphics graphics, boolean on) {
		
		super.drawFocus(graphics, on);
	}
}

 

 

 

 

 

Highlighted
Contributor
Posts: 10
Registered: ‎11-11-2011
My Device: NA
My Carrier: NA

Re: MapField with Multiple markers Scrolling Error

[ Edited ]

What is this Tools in your code?