문제

iOS에서는 다음을 호출하여 마커에 대한 설명을 쉽게 설정할 수 있습니다.

[marker setCanShowCallout:YES];
[marker setRightCalloutAccessoryView:YOUR_BUTTON];
.

그러나 MapBox Android SDK에 대한이 기능을 찾을 수 없습니다.나는 콜 아웃 뷰에서 촉감을 감지하지만 콜 아웃 이미지 / 버튼을 어떻게 설정할 수 있는가?

Marker marker = new Marker(p.getTitle(), p.getCatagoryName(), new LatLng(p.getLatitude(), p.getLongitude()));
                        marker.setMarker(getResources().getDrawable(getResources().getIdentifier(string, "drawable", getActivity().getPackageName())));
                                mMapView.addMarker(marker);

                        InfoWindow toolTip = marker.getToolTip(mMapView);
                        View view = toolTip.getView();
                        // view.setBackgroundResource(R.drawable.callout_button); THIS DOES NOT WORK
                        view.setOnTouchListener(new View.OnTouchListener() {
                            @Override
                            public boolean onTouch(View view, MotionEvent motionEvent) {
                                Log.e(TAG, "onTouch");

                                return true;
                            }
                        });
.

도움이 되었습니까?

해결책

Ryansh의 탁월한 응답은 IDS ToolTip_title 및 ToolTip_Description이 포함 된 TextViews를 사용자 정의 레이아웃에 포함시키는 데 필요합니다.나는 또한 세 번째 ToolTip_Subdescription TextView를 추가해야했습니다.기본 InfoWindow 코드는 이러한보기가 존재하고 그렇지 않은 경우 충돌 할 것입니다.자세한 내용은 InfoWindow를 확장하고 OnOpen을 재정의하고 툴팁을 원하는 레이아웃을 사용할 수있었습니다.확장 된 마커 클래스에서 재정의 된 CreateToolTip의 경우 자연스럽게 인스턴스화되어 확장 된 InfoWindow 객체를 반환합니다.

업데이트.다음은 마커 & InfoWindow를 확장하여 사용자 정의 툴팁을 지원하는 예입니다.

public class MapboxMarker extends Marker {
    private MyInfoWindow mInfoWindow;

    public class MyInfoWindow extends InfoWindow {

        public MyInfoWindow(int layoutResId, MapView mapView) {
            super(layoutResId, mapView);
        }

        public void onOpen(Marker overlayItem) {
            //
            //  Set data on mInfoWindow.getView()
            //
        }

    }

    public MapboxMarker(MapView mv, LatLng aLatLng, MapController mapController){
        super(mv, "Title", "Description", aLatLng);
    }

    @Override
    protected InfoWindow createTooltip(MapView mv) {
        mInfoWindow = new MyInfoWindow(R.layout.custom_tooltip_layout, mv);
        return mInfoWindow;
    }
}
.

다른 팁

이 기능을 직접 구축해야하지만 사용자 정의 마커 및 툴팁 레이아웃을 정의하여 실제로 수행하기가 쉽습니다.

툴팁 레이아웃을 정의하여 시작하십시오. 콜 아웃 이미지를 배치하는 것은 분명히 relativeLayout이어야합니다. 마커를 만드는 모든 활동에 대한 컨텍스트를 설정하십시오. 커스텀 툴팁의 크기 조정을 제어하기 때문에 하단의 TipView가 포함되어야합니다.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    android:id="@+id/parent_layout"
    android:padding="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="com.XXX.MainActivity">

    <TextView
        android:id="@+id/tooltip_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:textSize="18sp"
        android:maxEms="17"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:text="@string/toolTipTitle"/>

    <TextView
        android:id="@+id/tooltip_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:textSize="14sp"
        android:maxEms="17"
        android:text="@string/toolTipDescription"
        android:layout_below="@+id/tooltip_title"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/marker_about"
        android:src="@drawable/ic_action_about"
        android:layout_toEndOf="@+id/tooltip_description"
        android:layout_toRightOf="@+id/tooltip_description"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="10dp" />

    <com.mapbox.mapboxsdk.views.TipView
            android:layout_width="132dp"
            android:layout_height="10dp"/>
</RelativeLayout>
. 그런 다음

사용자 정의 마커 클래스를 만들고 CreateToolTip 메서드를 재정의하여 새 레이아웃으로 InfoWindow를 반환합니다.

public class CustomMarker extends Marker {

    public CustomMarker(MapView mv, String aTitle, String aDescription, LatLng aLatLng){
        super(mv, aTitle, aDescription, aLatLng);
    }

    @Override
    protected InfoWindow createTooltip(MapView mv) {
        return new InfoWindow(R.layout.custom_tooltip, mv);
    }
}
.

다른 기능을 변경해서는 안됩니다. 그래서 귀하가 가진 코드는 여전히 작동합니다. 마커를 사용자 정의 클래스 이름으로 변경하면 설정해야합니다.

편집 : 실제로 사용자 정의자와 InfoWindow를 내지도로 설정하는 코드가 있습니다. 클릭하면 다른 활동을 시작하고 마커에 대한 사용자 정의 아이콘을 설정했는지 확인하고 있습니다.

        CustomMarker m =
                new CustomMarker(mv, report.issue, report.getFormattedDateString(), latLng);
        m.setIcon(new Icon(this, Icon.Size.LARGE, "oil-well", "FF0000"));
        //get the InfoWindow's view so that you can set a touch listener which will switch
        //to the marker's detailed view when clicked
        final InfoWindow infoWindow = m.getToolTip(mv);
        View view = infoWindow.getView();
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                //make sure to choose action down or up, otherwise the intent will launch twice
                if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
                    startActivity(intent);
                    //close the InfoWindow so it's not still open when coming back to the map
                    infoWindow.close();
                }
                return true;
            }
        });
        mv.addMarker(m);
.

SDK 0.5.0 스냅 샷을 사용하고 있습니다. 이전 버전의 SDK 에서이 작업이 작동하는지 확실하지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top