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
cherylleack
Posts: 13
Registered: ‎04-12-2011
My Device: BlackBerry Curve 8500 Series
Accepted Solution

MapField Overlay

Hi all,

 

I'm trying to develop a Custom MapField with as much user functionality as possible, but I'm struggling to get it anywhere near the functionality of the Blackberry Maps. I'm using JDE 5.0.

 

I have my class CustomMapField that extends MapField. I have overwritten the paint() method to display multiple markers, user's current location etc. I have also overwritten navigationMovement() to allow panning of the map.

 

What I would like to do is that if the user pans over one of my markers, a transparent 'callout bubble' appears with the name of that marker. I have defined a 'highlightable' area for each of my markers and can detect if the user is hovering over this area, but I can't find a way to place anything, let alone a transparent callout, on top of my MapField!!

 

I would also like to detect when a user clicks a marker. I have found many forums that suggest overwriting the TouchEvent, but this does nothing.

 

Any advice would be greatly appreciated, I've been struggling on this for days!

 

 

New Developer
aroundzw
Posts: 13
Registered: ‎07-02-2010
My Device: 9780

Re: MapField Overlay

I have the same problem. Any advice would be highly appreciated!! Thanks!

Contributor
cherylleack
Posts: 13
Registered: ‎04-12-2011
My Device: BlackBerry Curve 8500 Series

Re: MapField Overlay

Hi aroundzw,

 

I eventually solved this problem using a custom Manager. I overwrote the sublayout to define where I wanted the objects I was adding to go. Please see the code below:

 

public class MapFieldManager extends Manager
{
	public MapFieldManager()
	{
		super(Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH);	
	}

	protected void sublayout(int width, int height) 
	{
		Field field;

		int numberOfFields = getFieldCount();

		for (int i = 0; i < numberOfFields; i++) 
		{
			field = getField(i); //get the field
			
			if (i == 0)
				setPositionChild(field,0,0); 
			else
				setPositionChild(field, MapScreen.startX, MapScreen.startY);
			
	        layoutChild(field, width, height); //lay out the field
	    }
	    setExtent(width, height);
	}
}

 

This probably isn't the best or most sophisticated way of doing this but it worked for me.

 

Basically, I check the order that the objects are added to the manager. The first element is always added to the top right corner of the screen, any other elements added are positioned at the screen location I define (this only works because I know I'm always adding the MapField first).

 

In the screen that has my MapField I put: _mapManager.add(_map);

 

public CustomMapField _map = new CustomMapField;
public MapFieldManager _mapManager = new MapFieldManager();
.
.
.
_mapManager.add(_map);
.
.
.

 

 

I have overwritten the navigationMovement method on the screen so that if the user is hovering over my pin (defined with a 'highlightable area'), I add a custom TextField to the map like below:

 

CustomTextField name = new CustomTextField(highlightedObject.getName());
	        
XYPoint fieldOut = new XYPoint();
_map.convertWorldToField(new Coordinates(highlightedObject.getLatitude(), highlightedObject.getLongitude(), 0), fieldOut);
			
startX = fieldOut.x;
startY = fieldOut.y;	            
	        
_mapManager.add(dealerName);

 

Then you just need to put checks in so that when the user pans away from your marker the TextField disappears. The only way I found to do this was to delete all elements from _mapManager and then re-add just the map.

 

It's not the best looking solution, it only shows a TextField with a white background, but hopefully it will assist you.