1

H I have written a code to draw two custom location markers on the MapField. But when i zoom in and zoom out, the location marker is of the same size, I want the location marker to adjust according the zoom level. Could someone please help me put on this??

BR, Suppi

edit:

So far am able to do this,

 mPointDest = new XYRect[mPoints.length];
            for (int i = 0; i < mPoints.length; i++) {
            XYPoint fieldOut = new XYPoint();
            convertWorldToField(mPoints[i], fieldOut);
            mIcon = Bitmap.getBitmapResource("location.png");
        int imgW = mIcon.getWidth();
        int imgH = mIcon.getHeight();
        mPointDest[i] = new XYRect(fieldOut.x - imgW / 2,
                    fieldOut.y - imgH, imgW, imgH);
            graphics.drawBitmap(mPointDest[i], mIcon, 0, 0);

and for zoom :

protected boolean keyChar(char character, int status, int time) 
    {
        // 'i' will zoom in.
        if (character == 'i') 
        {

                mMapField.setZoom(Math.max(mMapField.getZoom() - 1, mMapField.getMinZoom()));
                return true;

        }
        // 'o' will zoom out
        if (character == 'o') 
        {

            mMapField.setZoom(Math.min(mMapField.getZoom() + 1, mMapField.getMaxZoom()));
            return true;
        }

        return super.keyChar(character, status, time);
    }

After this am wondering how to go about adjusting the bitmap based on the zoom level. Can someone please give me some idea??

Suppi
  • 630
  • 1
  • 7
  • 21
  • okay, so you want your "location.png" graphic to zoom (get larger/smaller) based on zoom level of the map? – Scott W Aug 01 '11 at 19:16
  • yeah exactly, i have also drawn a circle on the mapfield, i need to adjust the circle based on the zoom level. – Suppi Aug 01 '11 at 20:13
  • see my answer for http://stackoverflow.com/questions/6939882/blackberry-mapview-plot-coords/7207092#7207092 on other solutions for this – Gabor Aug 26 '11 at 15:46

1 Answers1

1

Zooming only impacts the map itself. If you want to change the size of your own graphics, you will need to manually scale them yourself. For example, you might either include multiple sizes of the "location.png" resource in your project and then choose the appropriate one based on the zoom level, or use the Bitmap.scaleInto() method to zoom your graphic on the fly.

Note that the on-the-fly method will yield a lower quality result than including multiple sizes of the original graphic (well, I am presuming that you have a high-res original that you are shrinking for inclusion in your project).

Scott W
  • 9,742
  • 2
  • 38
  • 53
  • Thanks alot for the reply, Now this is with respect to an image. What if i am drawing a circle around the location point. How will i change the bitmap?? or for that matter a route from a to b. You mean to say for every zoom level i should get the pixels from the map, and based on that redraw the bitmap. – Suppi Aug 02 '11 at 12:53
  • Yes, exactly. Everything you draw is with respect to the field, not the world. Hence the `convertWorldToField()` and `convertFieldToWorld()` methods. – Scott W Aug 02 '11 at 14:35
  • I tried using ConvertWorldtoField() for every zoom level, the output from this doesnt seem to change. Should it change? – Suppi Aug 06 '11 at 09:45
  • It depends what lat/lon point you are converting. For example, the lat/lon that is in the exact center of your view on the map will always convert to the exact center of your field. – Scott W Aug 07 '11 at 00:15
  • So what factor do i consider to change the bitmap for every zoom level, is it possible if i can send my code to you so that you can have a look at it. If its possible, please send me ur id to supriya.dinakaran@gmail.com – Suppi Aug 07 '11 at 01:02
  • It all depends what your objective is. If you want your bitmap to scale at the same rate as the map, then you could simply calculate all of your bitmaps points as lat/lon and then convert to field before rendering. If you want it to scale at a different rate, you will have to figure out your own conversion factor/ratio. Trial and error is probably your best bet here. – Scott W Aug 08 '11 at 12:37