osmdroid 解决经典标记重叠的方法

max*_*uts 2 android map osmdroid

我正在使用 osmdroid 和 osm 奖励包开发 Android 离线地图应用程序,并从外部存储加载图块和数据。现在,随着数据的增长,标记开始变得拥挤起来,我什至有两个地方在同一建筑物上的情况。我知道这种问题以前被问过很多次,我的问题是关于我正在考虑实施的一个简单的临时解决方法。如果两个地方足够近(就在彼此的顶部!),标准信息窗口会作为一个 ListView 弹出,每一行都设计成标准气泡(图像、标题、更多信息按钮)。

我的问题是:关于如何创建新的bonuspack_bubble.xml 布局文件的一些想法或建议。

nig*_*xed 5

不知道这对你有没有帮助。我需要CustomInfoBubble为我的项目创建一个。我所做的是扩展InfoWindow默认类,并将我的自定义气泡布局传递给它。像这样:http : //mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/

我的 Java 类MapCustomInfoBubble如下所示:

public class MapCustomInfoBubble extends InfoWindow {

    public MapCustomInfoBubble(MapView mapView) {
        super(R.layout.map_infobubble_black, mapView);//my custom layout and my mapView
    }

    @Override
    public void onClose() {
      //by default, do nothing
    }

    @Override
    public void onOpen(Object item) {
        Marker marker = (Marker)item; //the marker on which you click to open the bubble    

        String title = marker.getTitle();
        if (title == null)
                title = "";

        Button moreInfo = (Button)mView.findViewById(R.id.bubble_moreinfo);//the button that I have in my XML; 
        moreInfo.setText(title);
        moreInfo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
             gotoMoreInfoWindow();//custom method; starts another activity
            }
        });
    }

}
Run Code Online (Sandbox Code Playgroud)

在我的 XML 文件中,我有:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:background="@drawable/map_infobubble_black" >
        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:orientation="horizontal" >
            <TextView android:id="@+id/bubble_title" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF" 
                android:maxEms="17"
                android:layout_gravity="left"
                android:layout_weight="1"
                android:text="Title" />
            <Button android:id="@+id/bubble_moreinfo" 
                android:background="@drawable/map_btn_moreinfo"
                android:visibility="visible"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:layout_gravity="right"
                android:layout_weight="0" />
        </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在我的代码中的其他地方,然后我使用:

Marker wp = new Marker(mapView);
wp.setPosition(new GeoPoint(mylocation.getMyLocation()));
wp.setTitle(editTextName.getText().toString());
wp.setInfoWindow(new MapCustomInfoBubble(mapView));
mapView.getOverlays().add(wp);
mapView.invalidate();
Run Code Online (Sandbox Code Playgroud)

在我的代码中,我button使用Marker的标题设置了文本。这Marker是我单击的项目。如果您想将有关更多标记的信息放在同一个InfoWindow(在 a 内ListView),我认为您需要提前知道这些信息是什么。

我相信,你可以在里面放任何你想要的代码onOpen(),但是,我不太确定这是否是一个好的做法。您可以尝试创建自定义Constructor并将您的逻辑放在那里。它应该工作。您需要将Resource Id(layout) andmapView传递给超级构造函数,以便它返回一个有效的mView对象。