package com.hugetower.view.activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Point;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.PopupMenu;
import android.util.Log;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.amap.api.location.AMapLocation;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMapOptions;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.maps.model.Polygon;
import com.amap.api.maps.model.PolygonOptions;
import com.amap.api.maps.model.Polyline;
import com.amap.api.maps.model.PolylineOptions;
import com.hugetower.R;
import com.hugetower.common.utils.ToastUtils;
import com.hugetower.model.MyLatLng;
import com.hugetower.view.customview.dialog.BottomDialog;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* AMapV2地图中介绍如何TextureMapView显示一个基本地图
*/
public class AreaActivity extends AppCompatActivity implements AMap.OnMyLocationChangeListener {
private TextureMapView mapView;
private AMap aMap;
//存放所有marker点标记
private List<MyLatLng> allLatLngs = new ArrayList<>();
//所有线段的点
private List<LatLng> allLatLngsWithLine = new ArrayList<>();
//所有marker点
private List<Marker> markers = new ArrayList<>();
//线的对象
private Polyline polyline;
//多边形的对象
private Polygon polygon;
//是否为封闭图形
private boolean isEnd = false;
//矩形对象的配置
private PolygonOptions polygonOptions = new PolygonOptions();
//当前触摸的marker
private Marker touchMark;
//当前选中的点下标,相对于allLatLngs的
private int checkPos;
//地图设置
UiSettings uiSettings;
float zhouchang = 0;
///周长
private TextView mPerimeterTv;
float mianji = 0;
//面积
private TextView mAreaTv;
@BindView(R.id.btnUpload)
public Button btnUpload;
private PolygonOptions polygonOptionsTest = new PolygonOptions();
// private void test() {
// List<LatLng> latLngList = new ArrayList<>();
// latLngList.add(new LatLng(34.78303557017599, 117.30981432380786));
// latLngList.add(new LatLng(34.782878609909545, 117.310191174168));
// latLngList.add(new LatLng(34.7827216496431, 117.31056802452814));
// latLngList.add(new LatLng(34.782212213083994, 117.31075913191718));
// latLngList.add(new LatLng(34.78170277652489, 117.31095023930622));
// latLngList.add(new LatLng(34.78126658368178, 117.31032729627319));
//
// latLngList.add(new LatLng(34.780830390838666, 117.30970435324015));
// latLngList.add(new LatLng(34.781445024879, 117.30956219616479));
// latLngList.add(new LatLng(34.78205965891933, 117.30942003908943));
// latLngList.add(new LatLng(34.782419292690165, 117.30933890226811));
// latLngList.add(new LatLng(34.782778926461006, 117.30925776544679));
// latLngList.add(new LatLng(34.782907248318494, 117.30953604462732));
// polygonOptionsTest.addAll(latLngList);
//
// int fillColor = Color.parseColor("#31000000");
//
// // 设置多边形的边框颜色,32位 ARGB格式,默认为黑色
//
// polygonOptionsTest.strokeWidth(4);
// polygonOptionsTest.fillColor(fillColor);
// polygonOptionsTest.strokeColor(getResources().getColor(R.color.red));
//
// //创建多边形
// aMap.addPolygon(polygonOptionsTest);
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
//透明状态栏
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);// this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
com.jaeger.library.StatusBarUtil.setColor(AreaActivity.this, ContextCompat.getColor(this, R.color.transparent), 0);
mPerimeterTv = findViewById(R.id.mPerimeterTv);
mAreaTv = findViewById(R.id.mAreaTv);
/*
* 设置离线地图存储目录,在下载离线地图或初始化地图设置;
* 使用过程中可自行设置, 若自行设置了离线地图存储的路径,
* 则需要在离线地图下载和使用地图页面都进行路径设置
* */
//Demo中为了其他界面可以使用下载的离线地图,使用默认位置存储,屏蔽了自定义设置
// MapsInitializer.sdcardDir =OffLineMapUtils.getSdCacheDir(this);
mapView = (TextureMapView) findViewById(R.id.map);
mapView.onCreate(savedInstanceState);// 此方法必须重写
init();
// test();
}
/**
* 初始化AMap对象
*/
private void init() {
if (aMap == null) {
aMap = mapView.getMap();
}
// 如果要设置定位的默认状态,可以在此处进行设置
MyLocationStyle myLocationStyle = new MyLocationStyle();
aMap.setMyLocationStyle(myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE));
aMap.setMyLocationStyle(myLocationStyle);
aMap.setMapType(AMap.MAP_TYPE_SATELLITE);
aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
//设置SDK 自带定位消息监听
aMap.setOnMyLocationChangeListener(this);
//获取地图ui设置对象
uiSettings = aMap.getUiSettings();
uiSettings.setZoomPosition(AMapOptions.ZOOM_POSITION_RIGHT_CENTER);
//地图点击监听
aMap.setOnMapClickListener(new AMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
if (!isEnd) {
addMarker(latLng);
}
}
});
//marker点击监听
aMap.setOnMarkerClickListener(new AMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (isEnd) {
} else {
if (markers.get(0).equals(marker)) {
//封闭图形
isEnd = true;
btnUpload.setVisibility(View.VISIBLE);
//初始化多边形参数