package com.navinfo.outdoor.util;

import android.content.Context;

import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;

public class MapManager {
    private static MapManager instance;
    private TencentMap tencentMap;
    private Context mContext;

    public static MapManager getInstance() {
        if (instance == null) {
            instance = new MapManager();
        }
        return instance;
    }

    public void init(Context mContext, TencentMap map) {
        this.mContext = mContext;
        this.tencentMap = map;
    }

    public TencentMap getTencentMap() {
        return tencentMap;
    }

    // 将地图顶部中心定位到指定位置
    public void animateMapLocation2TopCenter(LatLng latLng, float x, float y) {
        if (tencentMap!=null) {
            tencentMap.setMapCenterAndScale(x, y, tencentMap.getCameraPosition().zoom);
            CameraUpdate cameraSigma = CameraUpdateFactory.newCameraPosition(new CameraPosition(
                    latLng, //中心点坐标，地图目标经纬度
                    tencentMap.getCameraPosition().zoom,  //目标缩放级别
                    tencentMap.getCameraPosition().tilt, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                    tencentMap.getCameraPosition().bearing)); //目标旋转角 0~360° (正北方为0)
            tencentMap.animateCamera(cameraSigma);
        }
    }
    public void moveLatlng(LatLng latLng, TencentMap.CancelableCallback cancelableCallback) {
        CameraUpdate cameraSigma = CameraUpdateFactory.newCameraPosition(new CameraPosition(
                latLng, //中心点坐标，地图目标经纬度
                tencentMap.getCameraPosition().zoom,  //目标缩放级别
                tencentMap.getCameraPosition().tilt, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                tencentMap.getCameraPosition().bearing)); //目标旋转角 0~360° (正北方为0)
        tencentMap.animateCamera(cameraSigma, cancelableCallback);
    }
}
