package com.navinfo.outdoor.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Point;
import android.location.Location;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.RecyclerView;

import com.github.lazylibrary.util.DensityUtil;
import com.google.gson.Gson;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.kongzue.dialog.interfaces.OnDialogButtonClickListener;
import com.kongzue.dialog.util.BaseDialog;
import com.kongzue.dialog.util.DialogSettings;
import com.kongzue.dialog.v3.MessageDialog;
import com.kongzue.dialog.v3.ShareDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.activity.FragmentManagement;
import com.navinfo.outdoor.api.Constant;
import com.navinfo.outdoor.base.BaseDrawerFragment;
import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.bean.JobSearchBean;
import com.navinfo.outdoor.bean.RoadExtend;
import com.navinfo.outdoor.bean.UserBean;
import com.navinfo.outdoor.http.Callback;
import com.navinfo.outdoor.http.DialogCallback;
import com.navinfo.outdoor.http.HttpInterface;
import com.navinfo.outdoor.http.OkGoBuilder;
import com.navinfo.outdoor.room.ChargingPileEntity;
import com.navinfo.outdoor.room.InsertAndUpdateUtils;
import com.navinfo.outdoor.room.PoiDao;
import com.navinfo.outdoor.room.PoiDatabase;
import com.navinfo.outdoor.room.PoiEntity;
import com.navinfo.outdoor.util.Base64;
import com.navinfo.outdoor.util.Geohash;
import com.navinfo.outdoor.util.GeometryTools;
import com.navinfo.outdoor.util.MapManager;
import com.navinfo.outdoor.util.MyTecentLocationSource;
import com.navinfo.outdoor.util.NetWorkUtils;
import com.navinfo.outdoor.util.ToastUtil;
import com.sothree.slidinguppanel.ScrollableViewHelper;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdate;
import com.tencent.tencentmap.mapsdk.maps.CameraUpdateFactory;
import com.tencent.tencentmap.mapsdk.maps.MapView;
import com.tencent.tencentmap.mapsdk.maps.TencentMap;
import com.tencent.tencentmap.mapsdk.maps.UiSettings;
import com.tencent.tencentmap.mapsdk.maps.interfaces.Removable;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptor;
import com.tencent.tencentmap.mapsdk.maps.model.BitmapDescriptorFactory;
import com.tencent.tencentmap.mapsdk.maps.model.CameraPosition;
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
import com.tencent.tencentmap.mapsdk.maps.model.Marker;
import com.tencent.tencentmap.mapsdk.maps.model.MarkerOptions;
import com.tencent.tencentmap.mapsdk.maps.model.MyLocationStyle;
import com.tencent.tencentmap.mapsdk.maps.model.Polygon;
import com.tencent.tencentmap.mapsdk.maps.model.PolygonOptions;
import com.tencent.tencentmap.mapsdk.maps.model.Polyline;
import com.tencent.tencentmap.mapsdk.maps.model.PolylineOptions;
import com.vividsolutions.jts.geom.Geometry;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 寻宝的Fragment
 * 2021-5-25
 */
public class TreasureFragment extends BaseFragment implements View.OnClickListener {
    private MapView treasureMap;
    private TencentMap tencentMap;
    private CheckBox cbMapType;
    private ImageView ivZoomAdd;
    private ImageView ivZoomDel;
    private MyLocationStyle locationStyle;
    private ImageView ivLocation;
    private ImageView ivSubmit;
    private ImageView ivRefish;
    private SlidingUpPanelLayout sliding_layout;
    private FragmentTransaction fragmentTransaction;
    private Marker markerPoi;

    private ImageView ivFilter;
    private Point screenPosition; //marker的屏幕坐标
    private FrameLayout frameLayout;
    private GatherGetFragment gatherGetFragment;
    private LinearLayout dragView;
    public ImageView ivMessage;
    private PoiDao poiDao;
    private String userEncode;
    private String centerEncode;
    private List<Removable> removables;
    private List<Removable> removableScreenMarker;
    private List<Removable> removablesLocality;
    private int treasurePage=1;
    /**
     * bitmapDescriptor1
     */

    //   private BitmapDescriptor bitmapDescriptor1, bitmapDescriptor2, bitmapDescriptor3, bitmapDescriptor4, bitmapDescriptor5;
    private Marker bigMarker;
    private List<Integer> upload;
    private final int MARKER_DOT = 3;
    private final int MARKER_LINE = 2;
    private final int MARKER_FACE = 1;
    private final int MARKER_BIG = 4;

    public static TreasureFragment newInstance(Bundle bundle) {
        TreasureFragment fragment = new TreasureFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.treasure_fragment;
    }

    /**
     * 刷新筛选界面数据
     */
    private void refreshFilterData() {
        Message msg = Message.obtain();
        msg.what = Constant.FILTER_DATA_CLEAR;
        EventBus.getDefault().post(msg);
        dismissLoadingDialog();
        initThread(); // 刷新筛选的本地数据
        initList(Constant.currentLocation); // 刷新筛选的网络数据
    }

    @Override
    protected void initView() {
        super.initView();
       /* bitmapDescriptor1 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
        bitmapDescriptor2 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
        bitmapDescriptor3 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
        bitmapDescriptor4 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);
        bitmapDescriptor5 = BitmapDescriptorFactory.fromResource(R.mipmap.datouzhen);*/
        EventBus.getDefault().register(this);
        //fragment 管理器
        supportFragmentManager = getActivity().getSupportFragmentManager();
        PoiDatabase poiDatabase = PoiDatabase.getInstance(getContext());
        poiDao = poiDatabase.getPoiDao();
        sliding_layout = findViewById(R.id.sliding_layout);
        dragView = findViewById(R.id.dragView);
        frameLayout = findViewById(R.id.frame_layout);
        ivRefish = findViewById(R.id.iv_refrish);
        ivRefish.setOnClickListener(this::onClick);
        ivFilter = findViewById(R.id.iv_filter);
        ivFilter.setOnClickListener(this::onClick);
        ivSubmit = findViewById(R.id.iv_submit);
        ivSubmit.setOnClickListener(this::onClick);
        ivMessage = findViewById(R.id.iv_message);
        ivMessage.setOnClickListener(this::onClick);
        treasureMap = (MapView) findViewById(R.id.treasure_map);
        tencentMap = treasureMap.getMap();
        MapManager.getInstance().init(getActivity(), tencentMap);
//        if (getClass().getCanonicalName().equals("PioFragment")){
//            ivMessage.setVisibility(View.VISIBLE);
//        }else {
//            ivMessage.setVisibility(View.GONE);
//        }
        cbMapType = (CheckBox) findViewById(R.id.cb_map_type);
        sliding_layout.setScrollableViewHelper(new NestedScrollableViewHelper());
        //地图转换
        cbMapType.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    tencentMap.setMapType(TencentMap.MAP_TYPE_SATELLITE);
                } else {
                    tencentMap.setMapType(TencentMap.MAP_TYPE_NORMAL);
                }
            }
        });
        //地图放大
        ivZoomAdd = (ImageView) findViewById(R.id.iv_zoom_add);
        ivZoomAdd.setOnClickListener(this::onClick);
        //地图缩小
        ivZoomDel = (ImageView) findViewById(R.id.iv_zoom_del);
        ivZoomDel.setOnClickListener(this::onClick);
        //回到定位位置
        ivLocation = findViewById(R.id.iv_location);
        ivLocation.setOnClickListener(this::onClick);
        //样式
        tencentMap.setMapStyle(2);
        //启用3d视图
        tencentMap.setBuilding3dEffectEnable(true);
        //获取地图UI 设置对象
        UiSettings uiSettings = tencentMap.getUiSettings();
        //设置logo的大小
        uiSettings.setLogoScale(0.7f);
        uiSettings.setRotateGesturesEnabled(false);//禁止地图旋转手势.
        uiSettings.setTiltGesturesEnabled(false);//禁止倾斜手势.
        showLoadingDialog();
        //开启定位权限
        checkNetWork();
        //上传用户位置金纬度
        iniUserLocation();
        //检查是否有没有填完的页面
        initSharePre();
        removables = new ArrayList<>();//存储网络数据的marker数据（线，面，点）
        removablesLocality = new ArrayList<>();  //存储本地的marker数据（线，面，点）
        removableScreenMarker = new ArrayList<>();//存储点击屏幕上的marker的marker数据（线，面，点）
        tencentMap.addOnMapLoadedCallback(new TencentMap.OnMapLoadedCallback() {
            @Override
            public void onMapLoaded() {
                if (Constant.currentLocation != null) {
                    // 地图中心点位置设置为当前用户所在位置
                    CameraUpdate cameraSigma =
                            CameraUpdateFactory.newCameraPosition(new CameraPosition(
                                    new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), //中心点坐标，地图目标经纬度
                                    tencentMap.getCameraPosition().zoom,  //目标缩放级别
                                    0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                                    0)); //目标旋转角 0~360° (正北方为0)
                    tencentMap.animateCamera(cameraSigma, new TencentMap.CancelableCallback() {
                        @Override
                        public void onFinish() {
                            dismissLoadingDialog();
                            refreshFilterData();
                        }

                        @Override
                        public void onCancel() {
                        }
                    });
                } else {
                    dismissLoadingDialog();
                }
                Constant.markerClickListener=markerClickListener;
                tencentMap.setOnMarkerClickListener(Constant.markerClickListener);
            }
        });
        // 设置地图宽高为屏幕的宽高
        int[] widtHeight = DensityUtil.getDeviceInfo(getActivity());
        treasureMap.getLayoutParams().width = widtHeight[0];
        treasureMap.getLayoutParams().height = widtHeight[1];

    }


    private class NestedScrollableViewHelper extends ScrollableViewHelper {
        public int getScrollableViewScrollPosition(View mScrollableView, boolean isSlidingUp) {
            if (mScrollableView instanceof NestedScrollView) {
                if (isSlidingUp) {
                    return mScrollableView.getScrollY();
                } else {
                    NestedScrollView nsv = ((NestedScrollView) mScrollableView);
                    View child = nsv.getChildAt(0);
                    return (child.getBottom() - (nsv.getHeight() + nsv.getScrollY()));
                }
            } else if (mScrollableView instanceof XRecyclerView) {
                if (isSlidingUp) {
                    return ((XRecyclerView) mScrollableView).getScrollDyCounter();
                } else {
                    XRecyclerView nsv = ((XRecyclerView) mScrollableView);
                    View child = nsv.getChildAt(0);
                    return (child.getBottom() - (nsv.getHeight() + nsv.getScrollY()));
                }
            } else {
                return 0;
            }
        }
    }

    private void iniUserLocation() {
        Geometry geometry = GeometryTools.createGeometry(new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()));
        try {
            String encode = Base64.desEncrypt(geometry.toString());
            HttpParams httpParams = new HttpParams();
            httpParams.put("geom", encode);
            long time = System.currentTimeMillis();
            httpParams.put("datetime", time);
            OkGoBuilder.getInstance().Builder(getActivity())
                    .url(HttpInterface.USER_LOCATION)
                    .cls(UserBean.class)
                    .params(httpParams)
                    .token(Constant.ACCESS_TOKEN)
                    .postRequest(new Callback<UserBean>() {
                        @Override
                        public void onSuccess(UserBean response, int id) {
                            dismissLoadingDialog();
                            if (response.getCode() == 200) {
                                Toast.makeText(getActivity(), "成功", Toast.LENGTH_SHORT).show();
                                Log.d("TAG", "onSuccess: ssssssssssssssssssssssssss 成功");
                                showLoadingDialog();
                            } else {
                                Toast.makeText(getActivity(), response.getMessage() + "", Toast.LENGTH_SHORT).show();
                                Log.d("TAG", "onSuccess:  " + response.getCode() + response.getMessage() + "" + response.getBody());
                            }
                        }

                        @Override
                        public void onError(Throwable e, int id) {
                            dismissLoadingDialog();
                            Log.d("TAG", "onSuccess: sss********sssssssssssss 成功" + e.getMessage() + "");
                        }
                    });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initList(TencentLocation tencentLocation) {
        int task_type = Constant.TASK_TYPE;
        int limit_type = Constant.LIMIT_TTPE;
        int taskStatus = Constant.TASK_STASTUS;
        if (taskStatus == 1 || taskStatus == 2 || taskStatus == 3) {
            Message obtain = Message.obtain();
            obtain.what = Constant.JOB_SEARCH_WORD;
            obtain.obj = null;
            EventBus.getDefault().post(obtain);
            return;
        }
        //获取中心点位置
        LatLng mapCenterPoint = getMapCenterPoint();
        if (mapCenterPoint != null) {
            centerEncode = Geohash.getInstance().encode(mapCenterPoint.latitude, mapCenterPoint.longitude);
        }
        userEncode = Geohash.getInstance().encode(tencentLocation.getLatitude(), tencentLocation.getLongitude());
        OkGo.getInstance().cancelTag(this);
        showLoadingDialog();
        // 请求方式和请求url
        HttpParams httpParams = new HttpParams();
        httpParams.put("userGeo", userEncode);
        httpParams.put("centerGeo", centerEncode);
        httpParams.put("pageSize", Constant.NUMBER);
        httpParams.put("pageNum", treasurePage);
        httpParams.put("type", task_type);
        httpParams.put("isExclusive", limit_type);
        OkGoBuilder.getInstance()
                .Builder(getActivity())
                .url(HttpInterface.TASK_LIST)
                .cls(JobSearchBean.class)
                .params(httpParams)
                .token(Constant.ACCESS_TOKEN)
                .getRequest(new Callback<JobSearchBean>() {
                    @Override
                    public void onSuccess(JobSearchBean response, int id) {
                        dismissLoadingDialog();
                        if (response.getCode()==200){
                            JobSearchBean.BodyBean body = response.getBody();
                            upload = response.getBody().getUpload();

                            if (body != null) {
                                if (upload != null) {
                                    ivSubmit.setEnabled(true);
                                } else {
                                    ivSubmit.setEnabled(false);
                                }
                                Log.d("TAG", "onSuccess: " + response.getBody().toString() + "sssssssssssss");
                                for (int i = 0; i < removables.size(); i++) {
                                    removables.get(i).remove();
                                }
                                removables.clear();
                                List<JobSearchBean.BodyBean.ListBean> list = response.getBody().getList();
                                for (int i = 0; i < list.size(); i++) {
                                    JobSearchBean.BodyBean.ListBean listBean = list.get(i);
                                    String encodeStr = list.get(i).getGeo();
                                    // 解密geo
                                    String geo = Geohash.getInstance().decode(encodeStr);
                                    listBean.setGeo(geo);
                                    Log.d("TAG", "onSuccess: " + geo);
                                    Geometry geometry = GeometryTools.createGeometry(geo);
                                    LatLng latLng = null;
                                    if (geometry.getGeometryType().equals("Point")) {//点
                                        latLng = GeometryTools.createLatLng(geo);
                                    } else if (geometry.getGeometryType().equals("LineString")) {//线
                                        BitmapDescriptor bitmapLine = null;
                                        if (Integer.valueOf(listBean.getType()) == 3) {//poi录像
                                            bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
                                        } else if (Integer.valueOf(listBean.getType()) == 4) {//道路录像
                                            bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
                                        }
                                        List<LatLng> latLineString = GeometryTools.getLatLngs(geo);
                                        // 构造 PolylineOpitons
                                        PolylineOptions polylineOptions = new PolylineOptions()
                                                .addAll(latLineString)
                                                // 折线设置圆形线头
                                                .lineCap(true)
                                                // 折线的颜色为绿色
                                                .color(0xff00ff00)
                                                // 折线宽度为5像素
                                                .width(10)
                                                .arrow(true)
                                                .arrowSpacing(100)
                                                .arrowTexture(bitmapLine);
                                        // 还可以添加描边颜色
                                        //.borderColor(0xffff0000)
                                        // 描边颜色的宽度，线宽还是 25 像素，不过填充的部分宽度为 `width` - 2 * `borderWidth`
                                        //.borderWidth(1);
                                        // 绘制折线
                                        Polyline polyline = tencentMap.addPolyline(polylineOptions);
                                        polyline.setZIndex(MARKER_LINE);
                                        removables.add(polyline);
                                        if (latLineString != null && latLineString.size() > 0) {
                                            latLng = latLineString.get(0);
                                        }
                                    } else if (geometry.getGeometryType().equals("Polygon")) {//面
                                        List<LatLng> latPolygon = GeometryTools.getLatLngs(geo);
                                        Polygon polygon = tencentMap.addPolygon(new PolygonOptions().
                                                //连接封闭图形的点
                                                        addAll(latPolygon).
                                                //填充颜色为红色
                                                        fillColor(Color.parseColor("#97E0E7EC")).
                                                //边线颜色为黑色
                                                        strokeColor(0xff000000).
                                                //边线宽度15像素
                                                        strokeWidth(5));
                                        polygon.setZIndex(MARKER_FACE);
                                        removables.add(polygon);
                                        com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid();
                                        double x = centroid.getX();
                                        double y = centroid.getY();
                                        if (centroid != null) {
                                            latLng = new LatLng();
                                            latLng.setLatitude(y);
                                            latLng.setLongitude(x);
                                        }
                             /*   if (latPolygon != null && latPolygon.size() > 0) {
                                        latLng = latPolygon.get(0);
                                    }*/
                                    }
                                    switch (Integer.valueOf(list.get(i).getType())) {
                                        case 1://poi
                                            BitmapDescriptor poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bg1);
                                            poiDescriptor.getFormater().setScale(50);
                                            Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiDescriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            poiMarker.setZIndex(MARKER_DOT);
                                            poiMarker.setTag(listBean);
                                            removables.add(poiMarker);
                                            poiMarker.setClickable(true);
                                            break;
                                        case 2://充电站
                                            BitmapDescriptor chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bg1);
                                            Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(chargeDescriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            stationMarker.setZIndex(MARKER_DOT);
                                            stationMarker.setTag(listBean);
                                            removables.add(stationMarker);
                                            stationMarker.setClickable(true);

                                            break;
                                        case 3://poi录像
                                            BitmapDescriptor poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_bg1);
                                            Marker poiVideoMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            poiVideoMarker.setTag(listBean);
                                            poiVideoMarker.setZIndex(MARKER_DOT);
                                            removables.add(poiVideoMarker);
                                            poiVideoMarker.setClickable(true);
                                            break;
                                        case 4://道路录像
                                            BitmapDescriptor roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bg);
                                            Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(roadDescriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            roadMarker.setZIndex(MARKER_DOT);
                                            roadMarker.setTag(listBean);
                                            removables.add(roadMarker);
                                            roadMarker.setClickable(true);

                                            break;
                                        case 5://其他
                                            BitmapDescriptor otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bg1);
                                            Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            otherMarker.setZIndex(MARKER_DOT);
                                            otherMarker.setTag(listBean);
                                            removables.add(otherMarker);
                                            otherMarker.setClickable(true);
                                            break;
                                        case 6://面状任务
                                            BitmapDescriptor Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_facet_bg1);
                                            Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Descriptor).alpha(0.9f)
                                                    .anchor(0.5f,1.0f)
                                                    .flat(true)
                                                    .clockwise(false));
                                            planarMarker.setZIndex(MARKER_DOT);
                                            planarMarker.setTag(listBean);
                                            removables.add(planarMarker);
                                            planarMarker.setClickable(true);
                                            break;
                                    }
                                }
                                treasurePage++;
                            }
                            Message obtain = Message.obtain();
                            obtain.what = Constant.JOB_SEARCH_WORD;
                            obtain.obj = response;
                            EventBus.getDefault().post(obtain);
                        }else {
                            Toast.makeText(getActivity(), response.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }

                    @Override
                    public void onError(Throwable e, int id) {
                        dismissLoadingDialog();
                        Log.d("TAG", "onError: " + e.getMessage() + "");
                    }
                });
        dismissDialog();
    }

    public void initMarker(PoiEntity poiEntity, boolean aBoolean) {
        String geo = poiEntity.getGeoWkt();
        Log.d("TAG", "onSuccess: " + geo);
        Geometry geometry = GeometryTools.createGeometry(geo);
        if (geometry == null) {
            return;
        }

        for (int i = 0; i < removableScreenMarker.size(); i++) {
            removableScreenMarker.get(i).remove();
        }
        removableScreenMarker.clear();

        LatLng latLng = null;
        if (geometry.getGeometryType().equals("Point")) {//点
            latLng = GeometryTools.createLatLng(geo);
        } else if (geometry.getGeometryType().equals("LineString")) {//线
            BitmapDescriptor bitmapLine = null;
            if (poiEntity.getType() == 3) {//poi录像
                bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
            } else if (poiEntity.getType() == 4) {//道路录像
                bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
            }
            List<LatLng> latLineString = GeometryTools.getLatLngs(geo);
            // 构造 PolylineOpitons
            PolylineOptions polylineOptions = new PolylineOptions()
                    .addAll(latLineString)
                    // 折线设置圆形线头
                    .lineCap(true)
                    // 折线的颜色为绿色
                    .color(0xff00ff00)
                    // 折线宽度为5像素
                    .width(20)
                    .arrow(true)
                    .arrowSpacing(150)
                    .arrowTexture(bitmapLine);
                 /*   // 还可以添加描边颜色
                    .borderColor(0xffff0000)
                    // 描边颜色的宽度，线宽还是 25 像素，不过填充的部分宽度为 `width` - 2 * `borderWidth`
                    .borderWidth(1);*/
            // 绘制折线
            Polyline polyline = tencentMap.addPolyline(polylineOptions);
            polyline.setZIndex(MARKER_LINE);
            removableScreenMarker.add(polyline);
            if (latLineString != null && latLineString.size() > 0) {
                latLng = latLineString.get(0);
            }
        } else if (geometry.getGeometryType().equals("Polygon")) {//面
            List<LatLng> latPolygon = GeometryTools.getLatLngs(geo);
            Polygon polygon = tencentMap.addPolygon(new PolygonOptions().
                    //连接封闭图形的点
                            addAll(latPolygon).
                    //填充颜色为浅蓝色
                            fillColor(Color.parseColor("#97E0E7EC")).
                    //边线颜色为黑色
                            strokeColor(0xff000000).
                    //边线宽度15像素
                            strokeWidth(25));

            polygon.setZIndex(MARKER_FACE);
            removableScreenMarker.add(polygon);
            com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid();
            double x = centroid.getX();
            double y = centroid.getY();
            if (centroid != null) {
                latLng = new LatLng();
                latLng.setLatitude(y);
                latLng.setLongitude(x);
            }
      /* if (latPolygon != null && latPolygon.size() > 0) {
             latLng = latPolygon.get(0);
         }*/
        }
        BitmapDescriptor descriptor = null;
        if (poiEntity.getType() == 1) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bags);
        } else if (poiEntity.getType() == 2) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bags);
        } else if (poiEntity.getType() == 3) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bag);
        } else if (poiEntity.getType() == 4) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bag);
        } else if (poiEntity.getType() == 5) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bag);
        } else if (poiEntity.getType() == 6) {
            descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_facet_bag);
        }
        MapManager.getInstance().moveLatlng(latLng,null);
        if (bigMarker == null) {
            bigMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(descriptor)
                    .anchor(0.5f,1f)
                    .flat(true)
                    .clockwise(false));
        } else {
            bigMarker.setPosition(latLng);
            bigMarker.setIcon(descriptor);
        }
        bigMarker.setVisible(true);
        bigMarker.setZIndex(MARKER_BIG);
        bigMarker.setClickable(false);
        if (aBoolean) {
            sliding_layout.setPanelHeight(0);
            sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            frameLayout.setVisibility(View.VISIBLE);
            setMainButtonVisiable(View.GONE);
            fragmentTransaction = supportFragmentManager.beginTransaction();
            Bundle bundle = new Bundle();
            bundle.putSerializable("poiEntity", poiEntity);
            gatherGetFragment = GatherGetFragment.newInstance(bundle);
            fragmentTransaction.replace(R.id.frame_layout, gatherGetFragment);
            fragmentTransaction.commit();
        }

    }

    private void initThread() {
        int taskStatus = Constant.TASK_STASTUS;
        int type = Constant.TASK_TYPE;
        int limit = Constant.LIMIT_TTPE;
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<PoiEntity> allTaskStatus = poiDao.getAllTaskStatus(taskStatus, taskStatus, type, type, limit, limit);
                //List<PoiEntity> allTaskStatus = poiDao.getAllPoi();
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < removablesLocality.size(); i++) {
                            removablesLocality.get(i).remove();
                        }
                        removablesLocality.clear();
                        for (int i = 0; i < allTaskStatus.size(); i++) {
                            PoiEntity poiEntity = allTaskStatus.get(i);
                            String geo = allTaskStatus.get(i).getGeoWkt();
                            LatLng latLng = null;
                            Log.d("TAG", "onSuccess: " + geo);
                            Geometry geometry = GeometryTools.createGeometry(geo);
                            if (geometry != null) {
                                if (geometry.getGeometryType().equals("Point")) {//点
                                    latLng = GeometryTools.createLatLng(geo);
                                } else if (geometry.getGeometryType().equals("LineString")) {//线
                                    BitmapDescriptor bitmapLine = null;
                                    if (type == 3) {//poi录像
                                        bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_arrows);
                                    } else if (type == 4) {//道路录像
                                        bitmapLine = BitmapDescriptorFactory.fromResource(R.drawable.road_arrows);
                                    }
                                    List<LatLng> latLineString = GeometryTools.getLatLngs(geo);
                                    // 构造 PolylineOpitons
                                    PolylineOptions polylineOptions = new PolylineOptions()
                                            .alpha(0.5f)
                                            .addAll(latLineString)
                                            // 折线设置圆形线头
                                            .lineCap(true)
                                            .color(Color.parseColor("#AFDBD8"))
                                            // 折线宽度为5像素
                                            .width(10)
                                            .arrow(true)
                                            .arrowSpacing(100)
                                            .arrowTexture(bitmapLine);
                                          /*  // 还可以添加描边颜色
                                            .borderColor(0xffff0000)
                                            // 描边颜色的宽度，线宽还是 25 像素，不过填充的部分宽度为 `width` - 2 * `borderWidth`
                                            .borderWidth(1);*/
                                    // 绘制折线
                                    Polyline polyline = tencentMap.addPolyline(polylineOptions);
                                    polyline.setZIndex(MARKER_LINE);
                                    removablesLocality.add(polyline);
                                    if (latLineString != null && latLineString.size() > 0) {
                                        latLng = latLineString.get(0);
                                    }
                                } else if (geometry.getGeometryType().equals("Polygon")) {//面
                                    List<LatLng> latPolygon = GeometryTools.getLatLngs(geo);
                                    Polygon polygon = tencentMap.addPolygon(new PolygonOptions().
                                            //连接封闭图形的点
                                                    addAll(latPolygon).
                                            //填充颜色为浅蓝色
                                                    fillColor(Color.parseColor("#97E0E7EC")).
                                            //边线颜色为黑色
                                                    strokeColor(0xff00ff00).
                                            //边线宽度15像素
                                                    strokeWidth(5));
                                    polygon.setZIndex(MARKER_FACE);
                                    removablesLocality.add(polygon);
                                    com.vividsolutions.jts.geom.Point centroid = geometry.getCentroid();
                                    double x = centroid.getX();
                                    double y = centroid.getY();
                                    if (centroid != null) {
                                        latLng = new LatLng();
                                        latLng.setLatitude(y);
                                        latLng.setLongitude(x);
                                    }
                                 /*if (latPolygon != null && latPolygon.size() > 0) {
                                        latLng = latPolygon.get(0);
                                    }*/
                                }
                            } else {
                                if (allTaskStatus.get(i).getX() != null && allTaskStatus.get(i).getY() != null) {
                                    latLng = new LatLng(Double.valueOf(allTaskStatus.get(i).getY()), Double.valueOf(allTaskStatus.get(i).getX()));
                                }
                            }
                            switch (Integer.valueOf(poiEntity.getType())) {
                                case 1://poi
                                    BitmapDescriptor poiDescriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bg1);
                                    } else {
                                        poiDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graypoi);
                                    }
                                    Marker poiMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiDescriptor)
                                            .flat(true)
                                            .anchor(0.5f,1f)
                                            .clockwise(false));
                                    poiMarker.setClickable(true);
                                    poiMarker.setZIndex(MARKER_DOT);
                                    poiMarker.setTitle(poiEntity.getName() + "");
                                    poiMarker.setTag(poiEntity);

                                    removablesLocality.add(poiMarker);
                                    break;
                                case 2://充电站
                                    BitmapDescriptor chargeDescriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bg1);
                                    } else {
                                        chargeDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.graycharge);
                                    }
                                    Marker stationMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(chargeDescriptor)
                                            .flat(true)
                                            .anchor(0.5f,1f)
                                            .clockwise(false));
                                    stationMarker.setClickable(true);
                                    stationMarker.setZIndex(MARKER_DOT);
                                    stationMarker.setTitle(poiEntity.getName() + "");
                                    stationMarker.setTag(poiEntity);
                                    removablesLocality.add(stationMarker);
                                    break;
                                case 3://poi录像
                                    BitmapDescriptor poiVideoDescriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_video_bg1);
                                    } else {
                                        poiVideoDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_have_bg1);
                                    }
                                    Marker poiVideoMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(poiVideoDescriptor)
                                            .anchor(0.5f,1f)
                                            .flat(true)
                                            .clockwise(false));
                                    poiVideoMarker.setClickable(true);
                                    poiVideoMarker.setZIndex(MARKER_DOT);
                                    poiVideoMarker.setTitle(poiEntity.getName() + "");
                                    poiVideoMarker.setTag(poiEntity);
                                    removablesLocality.add(poiVideoMarker);
                                    break;
                                case 4://道路录像
                                    BitmapDescriptor roadDescriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bg);
                                    } else {
                                        roadDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayroad);
                                    }
                                    Marker roadMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(roadDescriptor)
                                            .anchor(0.5f,1f)
                                            .flat(true)
                                            .clockwise(false));
                                    roadMarker.setClickable(true);
                                    roadMarker.setZIndex(MARKER_DOT);
                                    roadMarker.setTitle(poiEntity.getName() + "");
                                    roadMarker.setTag(poiEntity);
                                    removablesLocality.add(roadMarker);
                                    break;
                                case 5://其他
                                    BitmapDescriptor otherDescriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bg1);
                                    } else {
                                        otherDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayother);
                                    }
                                    Marker otherMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(otherDescriptor)
                                            .anchor(0.5f,1f)
                                            .flat(true)
                                            .clockwise(false));
                                    otherMarker.setClickable(true);
                                    otherMarker.setZIndex(MARKER_DOT);
                                    otherMarker.setTitle(poiEntity.getName() + "");
                                    otherMarker.setTag(poiEntity);
                                    removablesLocality.add(otherMarker);
                                    break;
                                case 6://面状任务
                                    BitmapDescriptor Descriptor = null;
                                    if (poiEntity.getTaskStatus() == 1) {
                                        Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_facet_bg1);
                                    } else {
                                        Descriptor = BitmapDescriptorFactory.fromResource(R.drawable.grayfacet);
                                    }
                                    Marker planarMarker = tencentMap.addMarker(new MarkerOptions(latLng).icon(Descriptor)
                                            .anchor(0.5f,1f)
                                            .clockwise(false)
                                            .flat(true));
                                    planarMarker.setClickable(true);
                                    planarMarker.setZIndex(MARKER_DOT);
                                    planarMarker.setTitle(poiEntity.getName() + "");
                                    planarMarker.setTag(poiEntity);
                                    removablesLocality.add(planarMarker);
                                    break;
                            }
                        }
                        Message obtain = Message.obtain();
                        obtain.what = Constant.JOB_SEARCH_POI_WORD;
                        obtain.obj = allTaskStatus;
                        EventBus.getDefault().post(obtain);
                    }
                });
            }
        }).start();
    }

    private void initSharePre() {
        //根据保存时所用的name属性，获取SharedPreferences对象
        SharedPreferences dataFile = getActivity().getSharedPreferences(Constant.DATA_FILE, 0);
        //根据数据类型，调用对应的get方法，通过键取得对应的值。
        String dataFileString = dataFile.getString("poiEntity", null);
        if (dataFileString != null) {
            PoiEntity poiEntity = new Gson().fromJson(dataFileString, PoiEntity.class);
            switch (poiEntity.getType()) {
                case 1:
                    DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                    MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi页面还有未提交完的数据，之前的成果已保存，点击确定可继续作业", "确定").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("poiEntity", poiEntity);
                            PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                            LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX()));
                            //  showPoiMarkerByType(1, newPoiLatLng);
                            showSlidingFragment(poiFragment);
                            initRemovePoiSharePre();
                            return false;
                        }
                    });
                    break;
                case 2:
                    DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                    MessageDialog.show((AppCompatActivity) getContext(), "提示", "你充电站页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("poiEntity", poiEntity);
                            ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                            LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX()));
                            // showPoiMarkerByType(4, newPoiLatLng);
                            showSlidingFragment(chargingStationFragment);
                            initRemovePoiSharePre();
                            return false;
                        }
                    });
                    break;
                case 3:
                    DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                    MessageDialog.show((AppCompatActivity) getContext(), "提示", "你poi录像页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("poiEntity", poiEntity);
                            PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                            LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX()));
                            // showPoiMarkerByType(2, newPoiLatLng);
                            showSlidingFragment(poiVideoFragment);
                            initRemovePoiSharePre();
                            return false;
                        }
                    });
                    break;
                case 4:
                    DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                    MessageDialog.show((AppCompatActivity) getContext(), "提示", "你道路页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("poiEntity", poiEntity);
                            RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                            LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX()));
                            //  showPoiMarkerByType(3, newPoiLatLng);
                            showSlidingFragment(roadFragment);
                            initRemovePoiSharePre();
                            return false;
                        }
                    });
                    break;
                case 5:
                    DialogSettings.style = DialogSettings.STYLE.STYLE_KONGZUE;
                    MessageDialog.show((AppCompatActivity) getContext(), "提示", "你其他页面还有未提交完的数据", "确定").setOkButton(new OnDialogButtonClickListener() {
                        @Override
                        public boolean onClick(BaseDialog baseDialog, View v) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("poiEntity", poiEntity);
                            OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                            LatLng newPoiLatLng = new LatLng(Double.valueOf(poiEntity.getY()), Double.valueOf(poiEntity.getX()));
                            //  showPoiMarkerByType(5, newPoiLatLng);
                            showSlidingFragment(otherFragment);
                            initRemovePoiSharePre();
                            return false;
                        }
                    });
                    break;
            }
        }
    }

    public void initRemovePoiSharePre() {
        //获取SharedPreferences对象，方法中两个参数的意思为：第一个name
        //表示文件名，系统将会在/dada/dada/包名/shared_prefs目录下生成
        //一个以该参数命名的.xml文件。第二个mode表示创建的模式，通过查看
        //方法注释得知，建议以0或者MODE_PRIVATE为默认值。
        SharedPreferences poi = getActivity().getSharedPreferences(Constant.DATA_FILE, 0);
        //获取Editor对象
        SharedPreferences.Editor edit = poi.edit();
        //根据要保存的数据的类型，调用对应的put方法,
        //以键值对的形式添加新值。
        edit.putString("poiEntity", null);
        //提交新值。必须执行，否则前面的操作都无效。
        edit.commit();
    }

    @Subscribe
    public void onEvent(Message data) {
        if (data.what == Constant.FILTER_LIST_ITEM) { // 点击筛选的item
            PoiEntity poiEntity = (PoiEntity) data.obj;
            initMarker(poiEntity,true);
            // 如果当前fragment是筛选，则移除该fragment
            FilterFragment filterFragment = (FilterFragment) supportFragmentManager.findFragmentByTag(FilterFragment.class.getName());
            if (filterFragment != null) {
                fragmentTransaction.remove(filterFragment);
            }
        } else if (data.what == Constant.GATHER_GET) { //筛选item 点击开始采集
            PoiEntity poiEntity = (PoiEntity) data.obj;
            Bundle bundle = new Bundle();
            bundle.putBoolean("isSliding", false); // 通知抽屉不收回
            bundle.putSerializable("poiEntity", poiEntity);
            switch (poiEntity.getType()) {
                case 1:
                    PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                    showSlidingFragment(poiFragment);
                    break;
                case 2:
                    ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                    showSlidingFragment(chargingStationFragment);
                    break;
                case 3:
                    PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                    showSlidingFragment(poiVideoFragment);
                    break;
                case 4:
                    RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                    showSlidingFragment(roadFragment);
                    break;
                case 5:
                    OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                    showSlidingFragment(otherFragment);
                    break;
            }
            frameLayout.setVisibility(View.GONE);
            if (gatherGetFragment != null) {
                fragmentTransaction.remove(gatherGetFragment);
            }
        } else if (data.what == Constant.GATHER_GET_MAP) { //地图界面点击采集 点击开始采集
            PoiEntity poiEntity = (PoiEntity) data.obj;
            Bundle bundle = new Bundle();
            bundle.putSerializable("poiEntity", poiEntity);
            bundle.putBoolean("isSliding", true); // 通知抽屉不收回
            switch (poiEntity.getType()) {
                case 1:
                    PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                    showSlidingFragment(poiFragment);
                    break;
                case 2:
                    ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                    showSlidingFragment(chargingStationFragment);
                    break;
                case 3:
                    PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                    showSlidingFragment(poiVideoFragment);
                    break;
                case 4:
                    RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                    showSlidingFragment(roadFragment);
                    break;
                case 5:
                    OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                    showSlidingFragment(otherFragment);
                    break;
            }
            frameLayout.setVisibility(View.GONE);
            if (gatherGetFragment != null) {
                fragmentTransaction.remove(gatherGetFragment);
            }
        }/* else if (data.what == Constant.TREASURE_WORD) { // POI采集-移动位置
            initPoiMarker((LatLng) data.obj);
        } else if (data.what == Constant.TREASURE_CHECKED_WORD) {//poi采集 -确定位置
            if ((boolean) data.obj) {
                initCheckedMarker(Constant.POI_WORD);
            }
        } else if (data.what == Constant.MAIN_CHARGING_STATION) {//充电站采集-移动位置
            initPoiMarker((LatLng) data.obj);
        } else if (data.what == Constant.MAIN_CHARGING_CHECKED_STATION) {//充电站采集 -确定位置
            if ((boolean) data.obj) {
                initCheckedMarker(Constant.CHARGING_STATION_WORD);
            }
        }*//* else if (data.what == Constant.MAIN_CHARGING_PILE) {//充电桩采集-移动位置
            initPileMarker((LatLng) data.obj);
        } else if (data.what == Constant.MAIN_CHARGING_CHECKED_PILE) {//充电桩采集-确定位置
            if ((boolean) data.obj) {
                initCheckedPileMarker(Constant.CHARGING_PILE_WORD);
            }
        }*//* else if (data.what == Constant.MAIN_OTHER) {//其他采集-移动位置
            initPoiMarker((LatLng) data.obj);
        } else if (data.what == Constant.MAIN_CHECKED_OTHER) {//其他采集-确定位置
            if ((boolean) data.obj) {
                initCheckedMarker(Constant.OTHER_WORD);
            }
        }*/ else if (data.what == Constant.TREASURE_FRAGMENT) {//抽屉界面的展示和隐藏
            if ((boolean) data.obj == true) {
                frameLayout.setVisibility(View.GONE);
                sliding_layout.setPanelHeight(0);
                setMainButtonVisiable(View.VISIBLE);
                sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
                if (bigMarker != null) {
                    bigMarker.setVisible(false);
                }
                for (int i = 0; i < removableScreenMarker.size(); i++) {
                    removableScreenMarker.get(i).remove();
                }
                removableScreenMarker.clear();

            }
        } else if (data.what == Constant.MAIN_BUTTON_VISIABLE) {//控制主界面各个按钮显隐状态的what值
            setMainButtonVisiable((Integer) data.obj);
        } else if (data.what == Constant.GATHER_GET_RETURN) {//item 点击页面的返回事件的处理
            if ((boolean) data.obj) {
                frameLayout.setVisibility(View.GONE);
                sliding_layout.setPanelHeight(1000);
                sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
            } else {
                frameLayout.setVisibility(View.GONE);
                setMainButtonVisiable(View.VISIBLE);
                fragmentTransaction.remove(gatherGetFragment);
            }
            if (bigMarker != null) {
                bigMarker.setVisible(false);
            }
            for (int i = 0; i < removableScreenMarker.size(); i++) {
                removableScreenMarker.get(i).remove();
            }
            removableScreenMarker.clear();

        } else if (data.what == Constant.CHARGING_STATION) {//充电站的充电桩-新增
            if ((HashMap<String, Object>) data.obj != null) {
                HashMap<String, Object> stationHashMap = (HashMap<String, Object>) data.obj;
                String showStation = (String) stationHashMap.get("showStation");
                ChargingPileEntity chargingPileEntity = (ChargingPileEntity) stationHashMap.get("chargingPileEntity");
                Bundle bundle = new Bundle();
                bundle.putBoolean("isSliding", false); // 通知抽屉不收回
                bundle.putString("station", showStation);
                bundle.putSerializable("chargingPileEntity", chargingPileEntity);
                ChargingPileFragment chargingPileFragment = ChargingPileFragment.newInstance(bundle);
                showSlidingFragment(chargingPileFragment);
            }
        } else if (data.what == Constant.CHARGING_STATION_ITEM) {//充电站的item 跳转到充电桩
            Bundle bundle = new Bundle();
            bundle.putBoolean("isSliding", false); // 通知抽屉不收回
            ChargingPileEntity chargingPileEntity = (ChargingPileEntity) data.obj;
            bundle.putSerializable("chargingPileEntity", chargingPileEntity);
            ChargingPileFragment chargingPileFragment = ChargingPileFragment.newInstance(bundle);
            showSlidingFragment(chargingPileFragment);
        } else if (data.what == Constant.JOB_WORD_MONITOR) {//筛选条件界面的刷新
            if ((boolean) data.obj) {
                for (int i = 0; i < removables.size(); i++) {
                    removables.get(i).remove();
                }
                removables.clear();
                for (int i = 0; i < removablesLocality.size(); i++) {
                    removablesLocality.get(i).remove();
                }
                removablesLocality.clear();
                refreshFilterData();
            }
        } /*else if (data.what == Constant.EVENT_WHAT_CURRENT_MARKER) {
            LatLng latLng = (LatLng) data.obj;
            int type = data.arg1;
            BitmapDescriptor descriptor = null;
            switch (type){
                case 1:
                    descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_poi_bags);
                    break;
                case 2:
                    descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_charge_bags);
                    break;
                case 3:
                    descriptor = BitmapDescriptorFactory.fromResource(R.drawable.poi_video_bag);
                    break;
                case 4:
                    descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_road_bag);
                    break;
                case 5:
                    descriptor = BitmapDescriptorFactory.fromResource(R.drawable.marker_other_bag);
                    break;
            }
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(descriptor).zIndex(MARKER_BIG));
        } */ else if (data.what == Constant.EVENT_WHAT_COMPLETE_TASK) {
            PoiEntity poiEntity = (PoiEntity) data.obj;
            Bundle bundle = new Bundle();
            bundle.putBoolean("isSliding", true); // 通知抽屉不收回
            bundle.putSerializable("poiEntity", poiEntity);
            switch (poiEntity.getType()) {
                case 1:
                    PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                    showSlidingFragment(poiFragment);
                    break;
                case 2:
                    ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                    showSlidingFragment(chargingStationFragment);
                    break;
                case 3:
                    PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                    showSlidingFragment(poiVideoFragment);
                    break;
                case 4:
                    RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                    showSlidingFragment(roadFragment);
                    break;
                case 5:
                    OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                    showSlidingFragment(otherFragment);
                    break;
            }
            frameLayout.setVisibility(View.GONE);
            if (gatherGetFragment != null) {
                fragmentTransaction.remove(gatherGetFragment);
            }
        } else if (data.what == Constant.POI_DRAWER) {//设置每个点的中心位置
            LatLng latLng = (LatLng) data.obj;
            if (latLng != null) {
                MapManager.getInstance().animateMapLocation2TopCenter(latLng, 0.5f, 0.25f);
            }

        } else if (data.what == Constant.UN_POLY_GEN_TASK) {//面妆任务立即采集 领取
            if ((boolean) data.obj) {

                frameLayout.setVisibility(View.GONE);
                sliding_layout.setPanelHeight(0);
                setMainButtonVisiable(View.VISIBLE);
                sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
            }
            if (bigMarker != null) {
                bigMarker.setVisible(false);
            }
            for (int i = 0; i < removableScreenMarker.size(); i++) {
                removableScreenMarker.get(i).remove();
            }
            removableScreenMarker.clear();
        }
    }


    /**
     * 控制主界面各个按钮的显示状态
     */
    private void setMainButtonVisiable(int visiable) {
        ivZoomAdd.setVisibility(visiable);
        ivZoomDel.setVisibility(visiable);
        ivLocation.setVisibility(visiable);
        ivRefish.setVisibility(visiable);
        cbMapType.setVisibility(visiable);
        ivSubmit.setVisibility(visiable);
        ivFilter.setVisibility(visiable);
        ivMessage.setVisibility(visiable);
    }

/*    private void initPoiMarker(LatLng latLng) {
        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, new TencentMap.CancelableCallback() {
            @Override
            public void onFinish() {
                screenPosition = tencentMap.getProjection().toScreenLocation(latLng);
                sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                //创建Marker对象之前，设置属性
                if (markerPoi != null) {
                    markerPoi.setFixingPoint(screenPosition.x, screenPosition.y);
                }
            }

            @Override
            public void onCancel() {
            }
        });
    }

    private void initCheckedMarker(int poiWord) {
        if (screenPosition != null) {
            sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
            LatLng latLng = tencentMap.getProjection().fromScreenLocation(screenPosition);
            markerPoi.setPosition(latLng);
            markerPoi.setFixingPointEnable(false);
            Constant.markerLatlng = latLng;
            Message obtain = Message.obtain();
            obtain.what = poiWord;
            obtain.obj = latLng;
            EventBus.getDefault().post(obtain);
        }
    }*/

    /**
     * 设置定位图标样式
     */
    private void setLocMarkerStyle() {
        locationStyle = new MyLocationStyle();
        locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER);
        //创建图标
        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(getBitMap(R.drawable.location));
        locationStyle.icon(bitmapDescriptor);
        //设置定位圆形区域的边框宽度;
        locationStyle.strokeWidth(1);
        //设置圆区域的颜色
        // locationStyle.fillColor(R.color.colormap);
        // locationStyle.anchor(1000,2000);
        tencentMap.setMyLocationStyle(locationStyle);
    }

    /**
     * 定位的一些初始化设置
     */
    private void initLocation() {
        //设置定位周期（位置监听器回调周期）为3s
        //locationRequest.setInterval(3000);
        //地图上设置定位数据源
        tencentMap.setLocationSource(new MyTecentLocationSource(getActivity()));
        //设置当前位置可见
        tencentMap.setMyLocationEnabled(true);
        //设置定位图标样式
        setLocMarkerStyle();
        tencentMap.setMyLocationStyle(locationStyle);
    }

    private Bitmap getBitMap(int resourceId) {
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int newWidth = 55;
        int newHeight = 55;
        float widthScale = ((float) newWidth) / width;
        float heightScale = ((float) newHeight) / height;
        Matrix matrix = new Matrix();
        matrix.postScale(widthScale, heightScale);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
        return bitmap;
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void onStart() {
        super.onStart();
        treasureMap.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        ivMessage.setVisibility(View.VISIBLE);
        treasureMap.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        ivMessage.setVisibility(View.GONE);
        treasureMap.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
        treasureMap.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        treasureMap.onDestroy();
        if (markerPoi != null) {
            markerPoi.remove();
        }
        if (bigMarker != null) {
            bigMarker.remove();
        }
        for (int i = 0; i < removableScreenMarker.size(); i++) {
            removableScreenMarker.get(i).remove();
        }
        removableScreenMarker.clear();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_zoom_add://放大
                CameraUpdate cameraUpdateIn = CameraUpdateFactory.zoomIn();
                tencentMap.animateCamera(cameraUpdateIn);
                break;
            case R.id.iv_zoom_del://缩小
                CameraUpdate cameraUpdateOut = CameraUpdateFactory.zoomOut();
                tencentMap.animateCamera(cameraUpdateOut);
                break;
            case R.id.iv_refrish://刷新
                refreshFilterData();
                break;
            case R.id.iv_location://定位:
                if (Constant.currentLocation != null) {
                    CameraUpdate cameraSigma =
                            CameraUpdateFactory.newCameraPosition(new CameraPosition(
                                    new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude()), //中心点坐标，地图目标经纬度
                                    tencentMap.getCameraPosition().zoom,  //目标缩放级别
                                    0, //目标倾斜角[0.0 ~ 45.0] (垂直地图时为0)
                                    0)); //目标旋转角 0~360° (正北方为0)
                    tencentMap.animateCamera(cameraSigma);
                } else {
                    Toast.makeText(getActivity(), "无定位", Toast.LENGTH_SHORT).show();
                    checkNetWork();
                }
                break;
            case R.id.iv_submit://弹窗
                if (upload == null) {
                    Toast.makeText(getActivity(), "网络请求失败", Toast.LENGTH_SHORT).show();
                    return;
                }

                //分享
                CharSequence title = "请选择上报类型";
                // 如果当前fragment是筛选，则移除该fragment
                FilterFragment filterFragments = (FilterFragment) supportFragmentManager.findFragmentByTag(FilterFragment.class.getName());
                if (filterFragments != null) {
                    fragmentTransaction.remove(filterFragments);
                }
                DialogSettings.style = DialogSettings.STYLE.STYLE_MIUI;
                List<ShareDialog.Item> itemList = new ArrayList<>();
                if (upload.contains(1)) {
                    itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_poi, "POI"));
                } else {

                }
                if (upload.contains(2)) {
                    itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_chongdianzhuang, "充电站"));
                } else {

                }
                if (upload.contains(3)) {
                    itemList.add(new ShareDialog.Item(getContext(), R.drawable.poi_video, "POI录像"));
                } else {

                }
                if (upload.contains(4)) {
                    itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_road, "道路"));
                } else {

                }
                if (upload.contains(5)) {
                    itemList.add(new ShareDialog.Item(getContext(), R.drawable.push_qingbao, "其他"));
                } else {

                }
                Bundle bundle = new Bundle();
                PoiEntity poiEntity = new PoiEntity();
                // 上报时以当前用户位置为准
                if (Constant.currentLocation == null) {
                    ToastUtil.showShort(getContext(), "无法获取当前位置，请检查GPS是否打开！");
                    return;
                }
//              LatLng mapCenterPoint = getMapCenterPoint();
                LatLng newPoiLatLng = new LatLng(Constant.currentLocation.getLatitude(), Constant.currentLocation.getLongitude());
                poiEntity.setX(newPoiLatLng.getLongitude() + "");
                poiEntity.setY(newPoiLatLng.getLatitude() + "");
                bundle.putSerializable("poiEntity", poiEntity);
                ShareDialog.show((AppCompatActivity) getActivity(), itemList, new ShareDialog.OnItemClickListener() {
                    @Override
                    public boolean onClick(ShareDialog shareDialog, int index, ShareDialog.Item item) {
                        if (item.getText().equals("POI")) {
                            //showPoiMarkerByType(1, newPoiLatLng);
                            PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                            showSlidingFragment(poiFragment);
                        } else if (item.getText().equals("充电站")) {
                            // showPoiMarkerByType(4, newPoiLatLng);
                            ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                            showSlidingFragment(chargingStationFragment);
                        } else if (item.getText().equals("POI录像")) {
                            // showPoiMarkerByType(2, newPoiLatLng);
                            poiEntity.setWork_type(1);
                            bundle.putSerializable("poiEntity", poiEntity);
                            PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                            showSlidingFragment(poiVideoFragment);
                        } else if (item.getText().equals("道路")) {
                            //showPoiMarkerByType(3, newPoiLatLng);
                            RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                            showSlidingFragment(roadFragment);
                        } else if (item.getText().equals("其他")) {
                            // showPoiMarkerByType(5, newPoiLatLng);
                            OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                            showSlidingFragment(otherFragment);
                        }
                        return false;
                    }
                }).setTitle(title);
                break;
            case R.id.iv_filter:
                FilterFragment filterFragment = FilterFragment.newInstance(new Bundle());
                showSlidingFragment(filterFragment);
                refreshFilterData();
                break;
            case R.id.iv_message:
                Intent messageIntent = new Intent(getContext(), FragmentManagement.class);
                messageIntent.putExtra("tag", 35);
                startActivity(messageIntent);
                break;
        }
    }

   /* private void showPoiMarkerByType(int type, LatLng latLng) {
        if (type == 1) {
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(bitmapDescriptor1).zIndex(MARKER_BIG));
        } else if (type == 2) {
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(bitmapDescriptor2).zIndex(MARKER_BIG));
        } else if (type == 3) {
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(bitmapDescriptor3).zIndex(MARKER_BIG));
        } else if (type == 4) {
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(bitmapDescriptor4).zIndex(MARKER_BIG));
        } else if (type == 5) {
            markerPoi = tencentMap.addMarker(new MarkerOptions(latLng).icon(bitmapDescriptor5).zIndex(MARKER_BIG));
        }
    }*/

    /**
     * 将fragment显示到抽屉内
     */
    private void showSlidingFragment(BaseDrawerFragment fragment) {
        fragmentTransaction = supportFragmentManager.beginTransaction();
        int[] deviceInfo = DensityUtil.getDeviceInfo(getActivity());
        sliding_layout.setPanelHeight(deviceInfo[1] / 2);
        sliding_layout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
        Constant.SLIDING_LAYOUT = sliding_layout;
        fragmentTransaction.add(R.id.scroll_view, fragment, fragment.getClass().getName());
        if (!(fragment instanceof FilterFragment)) {
            FilterFragment filterFragment = (FilterFragment) supportFragmentManager.findFragmentByTag(FilterFragment.class.getName());
            if (filterFragment != null) {
                fragmentTransaction.hide(filterFragment);
            }
        }
        if (!(fragment instanceof ChargingStationFragment)) {
            ChargingStationFragment chargingStationFragment = (ChargingStationFragment) supportFragmentManager.findFragmentByTag(ChargingStationFragment.class.getName());
            if (chargingStationFragment != null) {
                fragmentTransaction.hide(chargingStationFragment);
            }
        }
        if (!(fragment instanceof PoiFragment)) {
            PoiFragment poiFragment = (PoiFragment) supportFragmentManager.findFragmentByTag(PoiFragment.class.getName());
            if (poiFragment != null) {
                fragmentTransaction.hide(poiFragment);
            }
        }
        if (!(fragment instanceof RoadFragment)) {
            RoadFragment roadFragment = (RoadFragment) supportFragmentManager.findFragmentByTag(RoadFragment.class.getName());
            if (roadFragment != null) {
                fragmentTransaction.hide(roadFragment);
            }
        }
        if (!(fragment instanceof PoiVideoFragment)) {
            PoiVideoFragment poiVideoFragment = (PoiVideoFragment) supportFragmentManager.findFragmentByTag(PoiVideoFragment.class.getName());
            if (poiVideoFragment != null) {
                fragmentTransaction.hide(poiVideoFragment);
            }
        }
        fragmentTransaction.show(fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }

    /**
     * 检查网络状态
     */
    private void checkNetWork() {
        if (NetWorkUtils.iConnected(getContext())) { // 当前网络可用
            checkMyLocation();
        } else { // 当前网络不可用
            dismissLoadingDialog();
            ToastUtil.showShort(getContext(), Constant.NETWORK_UNAVAILABLE);
        }
    }

    /**
     * 检查所需权限
     */
    private void checkMyLocation() {
        // 1.判断是否拥有定位的权限
        // 1.1 拥有权限进行相应操作
        // 1.2 没有权限申请权限
        // 1.2.1 Android 6.0 动态申请权限
        // 1.2.1.1 用户给予权限进行相应操作
        // 1.2.1.2 用户没有给予权限 作出相应提示
        // 1.2.2 某些5.0权限的手机执行相应操作
        XXPermissions.with(this)
                .permission(Permission.ACCESS_COARSE_LOCATION)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        if (all) {
                            //建立定位
                            initLocation();
                        } else {
                            dismissLoadingDialog();
                            Toast.makeText(getActivity(), "申请权限失败", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        if (never) {
                            dismissLoadingDialog();
                            Toast.makeText(getActivity(), "被永久拒绝授权，请手动授予定位权限", Toast.LENGTH_SHORT).show();
                            // 如果是被永久拒绝就跳转到应用权限系统设置页面
                            XXPermissions.startPermissionActivity(getActivity(), permissions);
                        }
                    }
                });
    }

    TencentMap.OnMarkerClickListener markerClickListener=new TencentMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            if (marker.getTitle() != null && !marker.getTitle().equals("")) {//是本地数据直接跳转到采集页面
                PoiEntity poiEntity = (PoiEntity) marker.getTag();
                frameLayout.setVisibility(View.GONE);
                if (gatherGetFragment != null) {
                    fragmentTransaction.remove(gatherGetFragment);
                }
                if (markerPoi != null) {
                    markerPoi.remove();
                }
                if (bigMarker != null) {
                    bigMarker.setVisible(false);
                }
                for (int i = 0; i < removableScreenMarker.size(); i++) {
                    removableScreenMarker.get(i).remove();
                }
                removableScreenMarker.clear();
                if (poiEntity.getTaskStatus()==1){//已领取
                    initMarker(poiEntity, true);
                }else {
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("poiEntity", poiEntity);
                    switch (poiEntity.getType()) {
                        case 1:
                            initMarker(poiEntity,false);
                            PoiFragment poiFragment = PoiFragment.newInstance(bundle);
                            showSlidingFragment(poiFragment);
                            break;
                        case 2:
                            initMarker(poiEntity,false);
                            ChargingStationFragment chargingStationFragment = ChargingStationFragment.newInstance(bundle);
                            showSlidingFragment(chargingStationFragment);
                            break;
                        case 3:
                            initMarker(poiEntity,false);
                            PoiVideoFragment poiVideoFragment = PoiVideoFragment.newInstance(bundle);
                            showSlidingFragment(poiVideoFragment);
                            break;
                        case 4:
                            initMarker(poiEntity,false);
                            RoadFragment roadFragment = RoadFragment.newInstance(bundle);
                            showSlidingFragment(roadFragment);
                            break;
                        case 5:
                            initMarker(poiEntity,false);
                            OtherFragment otherFragment = OtherFragment.newInstance(bundle);
                            showSlidingFragment(otherFragment);
                            break;
                        case 6:
                            initMarker(poiEntity, true);
                            break;
                    }
                }



            } else {
                JobSearchBean.BodyBean.ListBean listBean = (JobSearchBean.BodyBean.ListBean) marker.getTag();
                if (listBean != null) {
                    PoiEntity poiListEntity = new PoiEntity();
                    poiListEntity.setTaskId(listBean.getId());
                    poiListEntity.setGeoWkt(listBean.getGeo());
                    poiListEntity.setName(listBean.getName());
                    poiListEntity.setAddress(listBean.getAddress());
                    poiListEntity.setTelPhone(listBean.getTelephone() + "");
                    poiListEntity.setPrecision(listBean.getPrice() + "");
                    poiListEntity.setDist(listBean.getDist() + "");
                    poiListEntity.setDescribe(listBean.getMemo());
                    poiListEntity.setCreateTime(listBean.getEndDate());
                    poiListEntity.setType(Integer.valueOf(listBean.getType()));
                    String geo = listBean.getGeo();
                    poiListEntity.setGeoWkt(geo);
                    Geometry geometry = GeometryTools.createGeometry(geo);
                    if (geometry.getGeometryType().equals("Point")) {//点
                        LatLng latLng = GeometryTools.createLatLng(geo);
                        poiListEntity.setX(latLng.longitude + "");
                        poiListEntity.setY(latLng.latitude + "");
                    } else if (geometry.getGeometryType().equals("LineString")) {//线
                        List<LatLng> latLineString = GeometryTools.getLatLngs(geo);
                        poiListEntity.setX(latLineString.get(0).longitude + "");
                        poiListEntity.setY(latLineString.get(0).latitude + "");
                    } else if (geometry.getGeometryType().equals("Polygon")) {//面
                        List<LatLng> latPolygon = GeometryTools.getLatLngs(geo);
                        poiListEntity.setX(latPolygon.get(0).longitude + "");
                        poiListEntity.setY(latPolygon.get(0).latitude + "");
                    }
                    initMarker(poiListEntity, true);
                } else {
                    Toast.makeText(getActivity(), "数据为空", Toast.LENGTH_SHORT).show();
                }
            }
            return false;
        }
    };


    @Override
    public boolean onBackPressed() {
        getActivity().finish();
        return true;
    }

    /**
     * 获取屏幕中心点位置
     *
     * @return
     */
    public LatLng getMapCenterPoint() {
//        int left = treasureMap.getLeft();
//        int top = treasureMap.getTop();
//        int right = treasureMap.getRight();
//        int bottom = treasureMap.getBottom();
//        // 获得屏幕点击的位置
//        int x = (int) (treasureMap.getX() + (right - left) / 2);
//        int y = (int) (treasureMap.getY() + (bottom - top) / 2);
//        Projection projection = tencentMap.getProjection();
//        LatLng pt = projection.fromScreenLocation(new Point(x, y));
        return tencentMap.getCameraPosition().target;
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        int measuredWidth = treasureMap.getWidth();
        int measuredHeight = treasureMap.getHeight();
        if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
            treasureMap.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight);
        } else if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
            treasureMap.onSizeChanged(measuredHeight, measuredWidth, measuredWidth, measuredHeight);
        }
    }
}