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
Developer
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Custom Map to set images on map

Hi, I want to set images on map so can anyone please help that how should i set image on map.
Developer
Posts: 254
Registered: ‎03-15-2011
My Device: simulator
My Carrier: simulator

Re: Custom Map to set images on map

I think it might be possible by extending the MapField / RichMapField and overriding the paint() method. (I have not tried it yet )

------------------------------------------------------------------------------------------------
Click "Accept as Solution" if post was what you needed. Give kudos if you feel response is helpful.

Developer
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Custom Map to set images on map

Hi,Thanks for reply. I tried by extending map field. but I can't get it properly so if possible can you helpful me with some code if you have some code of it. & I cant extend Rich map Field. Thanks & Regards.
Developer
Posts: 254
Registered: ‎03-15-2011
My Device: simulator
My Carrier: simulator

Re: Custom Map to set images on map

This is just some sample code to extend MapField. This MapField in OS 5 and I have used this to place more than one marker in the Map. (As it is not possible in MapField OS 5)..

 

But in your case you can not use this code as according to my understanding u want to place your own icon replacing the original in buit marker..

 

Try if you could repaint and if you find the solution do share that it might be helpful to many at some point of time.

 

------------------------------------------------------------------------------------------------
Click "Accept as Solution" if post was what you needed. Give kudos if you feel response is helpful.

Developer
Posts: 201
Registered: ‎12-17-2010
My Device: Not Specified

Re: Custom Map to set images on map

Hi,Thanks for reply. but where was the code? I didn't get any code .
Highlighted
Developer
Posts: 254
Registered: ‎03-15-2011
My Device: simulator
My Carrier: simulator

Re: Custom Map to set images on map

Sorry.. Here is the code

 

public class MultiMapField extends MapField {
    Coordinates[] mPoints = new Coordinates[0];
    Bitmap mPoint; // This variable has the marker bitmap in it which is set in the calling screen
    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()); // first sets the maximum zoom thats possible and later this will be reduced to zoom level that fits the screen

     // 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); // converts coordinate to pixel that fits the screen
      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];
      }
     }

     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); // To set the center of the screen
     // 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;
      }
     }
   //  if(!outOfBounds)
    	 zoom++;
     setZoom(zoom); // final zoom level is set here
    }

    protected void repaintPoints() { // To place the marker circle and the text describing it on the particular coordinate
     mPointsBitmap = new Bitmap(getWidth(), getHeight());
     mPointsBitmap.createAlpha(Bitmap.ALPHA_BITDEPTH_8BPP);
     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);
       g.setColor(Color.DARKRED);
       String text = "Position "+(i+1);
     //  g.setFont(Font.SIZE_SMALL);
       g.setFont(Font.getDefault().derive(Font.BOLD, 15));
       if(Display.getWidth()- mPointDest[i].x >=100)
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x, mPointDest[i].y, g.FULL_WHITE, 100); 
       else if(Display.getWidth()- mPointDest[i].x >=80) // To have a text marker for the point that is marked
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x - 10, mPointDest[i].y+10, g.FULL_WHITE, 100); 
       else if(Display.getWidth()- mPointDest[i].x >=60) // To have a text marker for the point that is marked
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x - 30, mPointDest[i].y+10, g.FULL_WHITE, 100); 
       else if(Display.getWidth()- mPointDest[i].x >=40) // To have a text marker for the point that is marked
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x - 50, mPointDest[i].y+10, g.FULL_WHITE, 100); 
       else if(Display.getWidth()- mPointDest[i].x >=20) // To have a text marker for the point that is marked
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x - 70, mPointDest[i].y+10, g.FULL_WHITE, 100); 
       else
    	   g.drawText(text.toCharArray(), 0, text.length(), mPointDest[i].x - 80, mPointDest[i].y+10, g.FULL_WHITE, 100); // placing the marker in the right most of the screen properly
      }
     }
    }
    /**
     * 
     */

    protected void paint(Graphics graphics) { // To paint the basic map
     super.paint(graphics);
     if (null != mPointsBitmap) {
      graphics.setGlobalAlpha(135);// this sets the transparency level of graphics we use with the map.
      graphics.drawBitmap(mDest, mPointsBitmap, 0, 0);
     }
    }
}

 

------------------------------------------------------------------------------------------------
Click "Accept as Solution" if post was what you needed. Give kudos if you feel response is helpful.