调整 Mapfield 中放大和缩小的位置标记

发布于 2024-11-27 12:13:53 字数 1298 浏览 1 评论 0原文

H 我编写了一段代码来在 MapField 上绘制两个自定义位置标记。但是当我放大和缩小时,位置标记的大小相同,我希望位置标记根据缩放级别进行调整。有人可以帮我穿上这个吗?

BR, Suppi

编辑:

到目前为止我能够做到这一点,

 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);

对于缩放:

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);
    }

在此之后我想知道如何根据缩放级别调整位图。有人可以给我一些想法吗?

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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间海 2024-12-04 12:13:53

缩放只会影响地图本身。如果您想更改自己图形的大小,则需要自己手动缩放它们。例如,您可以在项目中包含多种尺寸的“location.png”资源,然后根据缩放级别选择合适的尺寸,或者使用 Bitmap.scaleInto() 方法动态缩放图形。

请注意,与包含多个尺寸的原始图形相比,动态方法会产生较低质量的结果(好吧,我假设您有一个高分辨率的原始图形,您正在缩小该原始图形以包含在您的项目中)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文