MapBox Event

      在〈MapBox Event〉中尚無留言

MapBox Event

MapBox10.0版的官網說明,其實寫的非常不完整,所以本人也只能猜測寫下本篇

地圖事件

想要在地圖加上click事件,需將 getMapboxMap().loadStyleUri 變成 getMapboxMap().apply

class MahalMap(context: Context, val resId:Int): MapView(context), OnMapClickListener {
    init{
        this.getMapboxMap().setCamera(
            CameraOptions.Builder()
                .zoom(14.0)
                .build()
        )
        /*
        this.getMapboxMap().loadStyleUri(Style.MAPBOX_STREETS) {
            initLocationComponent()
        }
        */
        this.getMapboxMap().apply{
            loadStyleUri(Style.MAPBOX_STREETS){
                addOnMapClickListener(this@MahalMap)
                initLocationComponent()
            }
        }

    }
    override fun onMapClick(point: Point): Boolean {
        //addViewAnnotation(point)
        initLocationComponent()
        Log.d("Thomas", "%f:%f".format(point.latitude(),point.longitude()))
        return true
    }
}

todo

點一下回復預設

在 init 中 getMapboxMap().apply{} 加入了 addOnMapClickListener 後,需把 setupGesturesListener 移到 initLocationComponent()之內。

🔒 底下內容僅限會員閱讀。

立即登入

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *