【问题标题】:How can I change an overlay's icon from Android's MapView class?如何从 Android MapView 类更改覆盖图标?
【发布时间】:2011-09-05 07:06:30
【问题描述】:

我正在使用 Android 制作地图,上面有几个覆盖图标。我的问题是每个叠加层的图标都是静态的,并且在放大和缩小时不会随着地图的其余部分调整大小。如果用户放大或缩小太多并且图标显得太大或太小,这可能会变得很尴尬。

我的解决方案是创建多个每个图标大小不同的图像文件。但是,在我已经从我的(扩展的)MapView 类中创建了这些图标之后,我不确定如何引用它们:

public class Map extends MapActivity {
    ...
    public onCreate() {
        ...
        //Very simplified copy of my working code:

        Drawable defaultDrawable = this.getResources().getDrawable(R.drawable.myicon);
        List<Overlay> mapOverlays = mapView.getOverlays();
        ItemizedOverlay overlayManager = new OverlayManager(defaultDrawable, this);
        OverlayItem myOverlay =  new OverlayItem(...);
        overlayManager.addOverlay(myOverlay);
    }
}

我扩展了MapView 类,以便触发缩放事件。 dispatchDraw() 方法是我计划放置图标替换代码的地方,但我不确定如何从此处访问地图的现有叠加层及其图标(并更改 just 他们的图标) :

public class ZoomSensitiveMapView extends MapView {

    private int oldZoomLevel;

    ...

    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (getZoomLevel() != oldZoomLevel) {

            if (getZoomLevel() > 15) {
                //Zoomed in closer
                //Replace icons with bigger copies
            }
            else {
                //Zoomed out further
                //Replace icons with smaller copies
            }
            oldZoomLevel = getZoomLevel();
        }
    }
}

我在想getOverlays() 可能在这里工作,但这似乎只返回叠加层本身,而不是它们的图标。

我在正确的轨道上吗?如何在不调整覆盖坐标等的情况下替换图标?任何帮助或建议将不胜感激! (希望我的解释足够清楚;如果没有,请让我澄清!)提前感谢您的帮助!

【问题讨论】:

    标签: android maps android-mapview mapactivity


    【解决方案1】:

    这里你可以换行 ::

    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    

    只需将您自己的图标放在可绘制文件夹中并更新

    Drawable drawable = this.getResources().getDrawable(R.drawable.yourIcon);
    

    更多信息 :: get from here

    【讨论】:

    • 感谢您的建议,但我最初可以很好地创建叠加层(在我的 Map 课程中)。我只是无法从我的ZoomSensitiveMapView 替换他们的图标。如果我不清楚,我很抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    相关资源
    最近更新 更多