package com.ewei.demo.otherui;

import android.os.Bundle;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.ewei.demo.R;
import com.ewei.sdk.base.BaseActivity;
import com.ewei.sdk.constants.CommonValue;


/**
 * Created by Administrator on 2016/6/3.
 */
public class LocationShowActivity extends BaseActivity {

    private TextView mAddress;
    private MapView mMapView;

    private BaiduMap mBaiduMap;

    private LatLng mLatLng;
    private String mAddr = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location_show);

        mAddr = getIntent().getStringExtra(CommonValue.LOCATION_ADDRESS);
        String msgLongitude = getIntent().getStringExtra(CommonValue.LOCATION_LONGITUDE);
        String msgLatitude = getIntent().getStringExtra(CommonValue.LOCATION_LATITUDE);

        mLatLng = new LatLng(Double.parseDouble(msgLatitude), Double.parseDouble(msgLongitude));

        initControl();
        markAddress();
    }

    private void initControl() {
        initTitle("位置信息");

        mAddress = (TextView) findViewById(R.id.tv_bdmap_address);
        mAddress.setText(mAddr);

        // 地图初始化
        mMapView = (MapView) findViewById(R.id.mv_bdmap_show);
        mBaiduMap = mMapView.getMap();
    }

    private void markAddress() {
        MapStatusUpdate msu = MapStatusUpdateFactory.newLatLng(mLatLng);
        mBaiduMap.setMapStatus(msu);

        BitmapDescriptor bd = BitmapDescriptorFactory.fromResource(R.mipmap.position_search);
        OverlayOptions oo = new MarkerOptions().position(mLatLng).icon(bd).animateType(MarkerOptions.MarkerAnimateType.grow);
        mBaiduMap.addOverlay(oo);

        MapStatus.Builder builder = new MapStatus.Builder();
        builder.target(mLatLng).zoom(18.0f);
        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
    }

    @Override
    protected void onDestroy() {
        // 关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        mMapView.onDestroy();
        mMapView = null;
        super.onDestroy();
    }
}
