06-17-2010 10:57 PM
Hello,
I want to use MapField in my applciation and i m adding this mapfield in a verticalfieldmanager.
Right now i m able to show one Pointer on the location, zoom in zoom out functionality by menu, click event on the pointer.
MY CODE:
Coordinates ghar = new Coordinates(51.507778, -0.128056, 0);
CustomMapField mMapField = new CustomMapField();
Bitmap icoNormal = Bitmap.getBitmapResource("greenman.png");
Bitmap icoActive = Bitmap.getBitmapResource("greenman_h.png");
String link = "http://www.Pinch.com";
String description = "Pinch";
mMapField.moveTo(ghar, icoNormal, icoActive, link, description);
I am only getting problem to show the multiple pointers on the mapfield.
Please provide me solution for the same.
Thanks
Zahid
06-17-2010 11:38 PM
if you have the coordinates in a vector... so put this code inside in a bucle... for(i=0;etc..)
06-17-2010 11:42 PM
06-17-2010 11:43 PM - edited 06-17-2010 11:59 PM
look at the attached code....
this is what i m using
and i m adding in a verticalfieldmanager this map field
tabArea = new Scr();
// tabArea is a verticalfieldmanager.
package com.pinch.ui.fields;
import javax.microedition.location.Coordinates;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.VerticalFieldManag
public class Scr extends VerticalFieldManager {
// test coordinates:
// London
// 51.507778, -0.128056
Coordinates ghar = new Coordinates(51.507778, -0.128056, 0);
// Liverpool
// 53.4, -2.983333
Coordinates mLiverpoolC = new Coordinates(53.4, -2.983333, 0);
// Sheffield
// 53.385833, -1.469444
Coordinates mSheffieldC = new Coordinates(53.385833, -1.469444, 0);
MultyMapField mMultyMapField;
public Scr() {
MultyMapField mMultyMapField = new MultyMapField();
mMultyMapField.addCoordinates(ghar);
mMultyMapField.addCoordinates(mLiverpoolC);
mMultyMapField.addCoordinates(mSheffieldC);
add(mMultyMapField);
mMultyMapField.mPoint = createPointBitmap();
}
/*protected void onUiEngineAttached(boolean attached) {
// super.onUiEngineAttached(attached);
if (attached) {
mMultyMapField.addCoordinates(ghar);
mMultyMapField.addCoordinates(mLiverpoolC);
mMultyMapField.addCoordinates(mSheffieldC);
}
}*/
private Bitmap createPointBitmap() {
// int r = 10;
Bitmap result = Bitmap.getBitmapResource("point.png");
result.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
Graphics g = new Graphics(result);
g.setColor(Color.BLACK);
//g.fillEllipse(r, r, 2 * r, r, r, 2 * r, 0, 360);
g.setColor(Color.YELLOW);
// g.fillEllipse(r, r, r + (r - 2), r, r, r + (r - 2), 0, 360);
return result;
}
/**
* Method to create dynamic menu items on screen.
*
* @param menu
* @param instance
*/
public void makeMenu(Menu menu, int instance) {
menu.add(new MenuItem("Zoom", 1, 0) {
public void run() {
mMultyMapField.setZoom(5);
}
});
}
}
package com.pinch.ui.fields;
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.XYRect;
import net.rim.device.api.util.Arrays;
class MultyMapField extends MapField {
Coordinates[] mPoints = new Coordinates[0];
Bitmap mPoint;
Bitmap mPointsBitmap;
XYRect mDest;
XYRect[] mPointDest;
public void addCoordinates(Coordinates coordinates) {
Arrays.add(mPoints, coordinates);
zoomToFitPoints();
repaintPoints();
}
protected void zoomToFitPoints() {
// zoom to max
setZoom(getMaxZoom());
// get pixels of all points
int minLeft = getWidth();
int minUp = getHeight();
int maxRight = 0;
int maxDown = 0;
Coordinates minLeftCoordinates = null;
Coordinates minUpCoordinates = null;
Coordinates maxRightCoordinates = null;
Coordinates maxDownCoordinates = null;
for (int i = 0; i < mPoints.length; i++) {
XYPoint point = new XYPoint();
convertWorldToField(mPoints[i], point);
if (point.x <= minLeft) {
minLeft = point.x;
minLeftCoordinates = mPoints[i];
}
if (point.x >= maxRight) {
maxRight = point.x;
maxRightCoordinates = mPoints[i];
}
if (point.y <= minUp) {
minUp = point.y;
minUpCoordinates = mPoints[i];
}
if (point.y >= maxDown) {
maxDown = point.y;
maxDownCoordinates = mPoints[i];
}
}
// GIVING ERROR IN THIS LINE COZ MAXdOWNcOORDINATES IS NULL
double moveToLat = maxDownCoordinates.getLatitude() + (minUpCoordinates.getLatitude() - maxDownCoordinates.getLatitude()) / 2;
double moveToLong = minLeftCoordinates.getLongitude() + (maxRightCoordinates.getLongitude() - minLeftCoordinates.getLongitude()) / 2;
Coordinates moveTo = new Coordinates(moveToLat, moveToLong, 0);
moveTo(moveTo);
// zoom to min left up, max right down pixels + 1
int zoom = getZoom();
boolean outOfBounds = false;
while (!outOfBounds && zoom > getMinZoom()) {
zoom--;
setZoom(zoom);
XYPoint point = new XYPoint();
try {
convertWorldToField(minLeftCoordinates, point);
if (point.x < 0)
outOfBounds = true;
convertWorldToField(minUpCoordinates, point);
if (point.y < 0)
outOfBounds = true;
convertWorldToField(maxRightCoordinates, point);
if (point.x > getWidth())
outOfBounds = true;
convertWorldToField(maxDownCoordinates, point);
if (point.y > getHeight())
outOfBounds = true;
} catch (IllegalArgumentException ex) {
outOfBounds = true;
}
}
zoom++;
setZoom(zoom);
}
protected void repaintPoints() {
mPointsBitmap = new Bitmap(getWidth(), getHeight());
mPointsBitmap.createAlpha(Bitmap.ALPHA_BITDEPTH_8B
mDest = new XYRect(0, 0, mPointsBitmap.getWidth(), mPointsBitmap
.getHeight());
Graphics g = new Graphics(mPointsBitmap);
if (null != mPoint) {
mPointDest = new XYRect[mPoints.length];
for (int i = 0; i < mPoints.length; i++) {
if (null == mPointDest[i]) {
XYPoint fieldOut = new XYPoint();
convertWorldToField(mPoints[i], fieldOut);
int imgW = mPoint.getWidth();
int imgH = mPoint.getHeight();
mPointDest[i] = new XYRect(fieldOut.x - imgW / 2,
fieldOut.y - imgH, imgW, imgH);
}
g.drawBitmap(mPointDest[i], mPoint, 0, 0);
}
}
}
protected void paint(Graphics graphics) {
super.paint(graphics);
if (null != mPointsBitmap) {
graphics.setGlobalAlpha(100);
graphics.drawBitmap(mDest, mPointsBitmap, 0, 0);
}
}
}
03-12-2012 07:15 AM
Hi,
Did you manage to sort this issue. When add points inside ONUIAttached it is working but otherwise I am getting the same error.
Janaka