package com.abbidot.tracker.ui.common.map

import android.content.Context
import androidx.fragment.app.Fragment
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.ui.fragment.map.baidumap.MapLiveBaiduMapFragment
import com.abbidot.tracker.ui.fragment.map.googlemap.MapLiveGoogleMapFragment
import com.google.android.gms.maps.model.LatLng

/**
 *Created  by .yzq on 2022/7/5/005.
 * @link
 * @description:
 */
class MapLiveCommon {

    private var mMapLiveGoogleMapFragment: MapLiveGoogleMapFragment? = null
    private var mMapLiveBaiduMapFragment: MapLiveBaiduMapFragment? = null

    fun getMapFragment(context: Context, imageUrl: String): Fragment {
        return if (AppUtils.isChina(AppUtils.SWITCH_MAP_TYPE)) {
            mMapLiveBaiduMapFragment = MapLiveBaiduMapFragment.newInstance(context)
            mMapLiveBaiduMapFragment!!.mPetHeadUrl = imageUrl
            mMapLiveBaiduMapFragment!!
        } else {
            mMapLiveGoogleMapFragment = MapLiveGoogleMapFragment.newInstance(context)
            mMapLiveGoogleMapFragment!!.mPetHeadUrl = imageUrl
            mMapLiveGoogleMapFragment!!
        }
    }

    fun addLine(latitude: Double, longitude: Double) {
        if (null != mMapLiveBaiduMapFragment) {
            mMapLiveBaiduMapFragment!!.addLine(latitude, longitude)
        } else if (null != mMapLiveGoogleMapFragment) {
            mMapLiveGoogleMapFragment!!.addLine(LatLng(latitude, longitude))
        }
    }

    fun refreshPetCurrentLocation() {
        if (null != mMapLiveBaiduMapFragment) {
            mMapLiveBaiduMapFragment!!.refreshPetCurrentLocation()
        } else if (null != mMapLiveGoogleMapFragment) {
            mMapLiveGoogleMapFragment!!.refreshPetCurrentLocation()
        }
    }
}