package com.abbidot.tracker.ui.fragment.map.googlemap

import android.annotation.SuppressLint
import android.content.Context
import com.abbidot.tracker.deprecated.ui.activity.map.MapLiveActivity
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.LatLng

/**
 *Created  by .yzq on 2022/1/13/013.
 * @link
 * @description:实时跟踪map谷歌地图
 */
class MapLiveGoogleMapFragment : BaseGoogleMapFragment() {

    private lateinit var mMapLiveActivity: MapLiveActivity

    //启动动画移动地图摄像机
    private var isMoveCamera = true
    private var mPetCurrentLatLng: LatLng? = null

    companion object {
        @JvmStatic
        fun newInstance(context: Context) = MapLiveGoogleMapFragment().apply {
            mContext = context
        }
    }

    override fun initData() {
        mMapLiveActivity = mActivity as MapLiveActivity
        super.initData()
        setGoogleMapZoom(14f)
    }

    @SuppressLint("MissingPermission")
    override fun onMapLoadOk(googleMap: GoogleMap) {

//        initFenceList()

        //先开始获取围栏数据
        mMapLiveActivity.mFencesManageViewModel.getFenceList(mMapLiveActivity,
                mMapLiveActivity.mPet.deviceId)
    }

    /**
     * 刷新当前宠物位置
     */
    fun refreshPetCurrentLocation() {
        mPetCurrentLatLng?.let {
            refreshPetCurrentLocation(it)
        }
    }

    /**
     * 画线
     */
    fun addLine(latLng: LatLng) {
        mPetCurrentLatLng = latLng
        addPolyline(mGoogleMap!!, latLng)
        refreshPetCurrentLocation(latLng, needMoveCamera = isMoveCamera)
        isMoveCamera = false
    }
}