osmdroid解决方法的经典标志重叠解决方法、标志、经典、osmdroid

2023-09-07 22:27:38 作者:错过世界遇见你

我使用osmdroid和OSM奖金包和加载瓷砖和数据从外部存储开发一个Android离线地图应用。眼下,随着数据的增长,指标也开始变得拥挤起来,我甚至有在同一建筑物两个地方的情况。我知道,这种问题已经被问了很多之前,我的是关于一个简单的时间解决方法我想实现的。怎么样,如果两个地方足够近(就在对方!顶部)标准的信息窗口弹出与设计像标准泡泡(图像,标题,moreInfoButton)每行一个ListView。

I am developing an Android offline mapping application using osmdroid and osm bonus pack and loading the tiles and data from external storage. Right now, as the data grows, markers are starting to get cramped together, I even have the situation of two places on the same building. I know this kind of issue has been asked a lot before, mine is about a simple temporal workaround I'm thinking of implementing. How about if two places are near enough(right in top of each other!) the standard info window pops up as a ListView with each row designed like the standard bubble(image, title, moreInfoButton).

我的问题是:如何创建新的bonuspack_bubble.xml布局文件中的一些想法和建议

My question is: some thoughts or advices on how to create the new bonuspack_bubble.xml layout file.

推荐答案

我不知道这是否会帮助你。 我需要创建一个 CustomInfoBubble 我的项目。我所做的就是,延长信息窗口默认类,并传递给它我的自定义泡沫布局。事情是这样的: http://mobiledevstories.word$p$pss.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/

I don't know if this will help you. I needed to create a CustomInfoBubble for my project. What I did was, to extend the InfoWindow default class, and pass to it my custom bubble layout. Something like this: http://mobiledevstories.wordpress.com/2014/03/01/osmdroid-bonus-pack-markers-with-clickable-infowindows/

我的Java类 MapCustomInfoBubble 是这样的:

My Java class MapCustomInfoBubble looks like this:

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

}

在我的XML文件中,我有:

In my XML file, I have:

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

在其他地方,在我的code,然后我用:

Somewhere else in my code, I then use:

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

在我的code,我设置了按钮标记的标题文本。 该标记是我点击的项目。如果你想要把更多的标记信息在同一个信息窗口(在的ListView ),我认为你需要提前知道哪些信息会。

In my code, I set the text on the button with the Marker's title. The Marker is the item on which I click. If you want to put info about more markers in the same InfoWindow (inside a ListView), I think you would need to know in advance what the info will be.

我相信,你可以把任何code您想在的OnOpen(),但是,我不敢肯定,如果它是一个很好的做法。你可以尝试创建一个自定义的构造,并把你的逻辑在那里。它应该工作。 您需要将资源ID传递(布局)和图形页面的超级构造函数,所以它会返回一个有效的 MVIEW 对象。

I believe that, You can put whatever code you want inside onOpen(), however, I am not so sure if it's a good practice. You could try creating a custom Constructor and put your logic there. It should work. You need to pass the Resource Id (layout) and mapView to the super constructor, so it returns a valid mView object.