MapsForge 0.4.0:是否有可能implelment一个标记的事件的onTap? [英] MapsForge 0.4.0: is it possible to implelment a Marker 's onTap event?

查看:250
本文介绍了MapsForge 0.4.0:是否有可能implelment一个标记的事件的onTap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MapsForge最新的分支(主),我想实现一个标记的事件的onTap。
我认为这是可能的0.3.0,而是因为我使用不同的可绘制在地图上标记每一个我无法使用0.3.0。

i'm using MapsForge latest branch (master) and i'd like to implement a Marker's onTap event. I think it was possible on 0.3.0, but i can't use 0.3.0 because i use a different Drawable for each Marker on the map.

ArrayList<Monument> monuments = getMonuments(); 

mListOverlay = new ListOverlay();
ArrayList<OverlayItem> markers = new ArrayList<OverlayItem>();          

for(Monument m : monuments){
    GeoPoint gp = new GeoPoint(m.getLat(), m.getLon());
    Marker m = createCustomMarker(R.drawable.marker, gp, p.getNumber()));
    markers.add(m);     
}

mListOverlay.getOverlayItems().addAll(markers);

mMapView.getOverlays().add(mListOverlay);

createCustomMarker返回使用的可绘制在上面数字的标记。

"createCustomMarker" returns a Marker that uses a Drawable with a number on top.

任何人知道如何我可以覆盖的M,当它被点击的行为?

Anyone knows how i can override the behaviour of "m" when it is tapped?

记住:分支高手! 0.3.0不!

Remember: branch master! not 0.3.0!!

感谢

推荐答案

创建从标记继承的类并覆盖onTab,下面的方法。
该解决方案检查该选项卡是层的位图(加10%)的范围内。
如果这是真的了Runnable动作将被调用。

Create a class that inherits from Marker and overwrite onTab, the following way. This solution checks if the tab was within the bounds of the Layer's bitmap (plus 10%). If this is true the Runnable action will be called.

在Mapsforge每个标记只是一个简单的层而被堆叠在地图上的顶部。每个选项卡将调用最顶层的ontab。如果返回false,接下来最顶层的ontab将被调用,除非函数返回true或最后一层已经达到了。

In Mapsforge each Marker is just a simple Layer which are stacked on top of the map. Each tab will call the topmost layer's ontab. If that returns false, the next topmost layer's ontab will be called, unless the function returned true or the last layer has been reached.

public class InfoMarker extends Marker {

    private Runnable action;

    public InfoMarker(LatLong latLong, org.mapsforge.core.graphics.Bitmap bitmap, int horizontalOffset, int verticalOffset) {
        super(latLong, bitmap, horizontalOffset, verticalOffset);
    }


    public void setOnTabAction(Runnable action){

        this.action = action;
    }

    @Override
    public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {


        double centerX = layerXY.x + getHorizontalOffset();
        double centerY = layerXY.y + getVerticalOffset();

        double radiusX = (getBitmap().getWidth() / 2) *1.1;
        double radiusY = (getBitmap().getHeight() / 2) *1.1;


        double distX = Math.abs(centerX - tapXY.x);
        double distY = Math.abs(centerY - tapXY.y);


        if( distX < radiusX && distY < radiusY){

            if(action != null){
                action.run();
                return true;
            }
        }


        return false;
    }

}

这篇关于MapsForge 0.4.0:是否有可能implelment一个标记的事件的onTap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆