diff --git a/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java new file mode 100644 index 0000000..c398eed --- /dev/null +++ b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java @@ -0,0 +1,208 @@ +package com.casic.dcms.model; + +import java.util.List; + +public class MapLampBoxBean { + + private int code; + private List data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String address; + private String areaId; + private String areaName; + private String delflag; + private String deptId; + private String deptName; + private String id; + private String lampboxCode; + private String lampboxName; + private String lampboxType; + private String lampboxTypeName; + private String latitude; + private String longitude; + private String streetId; + private String streetName; + private String teleId; + private String ts; + private String version; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getDelflag() { + return delflag; + } + + public void setDelflag(String delflag) { + this.delflag = delflag; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLampboxCode() { + return lampboxCode; + } + + public void setLampboxCode(String lampboxCode) { + this.lampboxCode = lampboxCode; + } + + public String getLampboxName() { + return lampboxName; + } + + public void setLampboxName(String lampboxName) { + this.lampboxName = lampboxName; + } + + public String getLampboxType() { + return lampboxType; + } + + public void setLampboxType(String lampboxType) { + this.lampboxType = lampboxType; + } + + public String getLampboxTypeName() { + return lampboxTypeName; + } + + public void setLampboxTypeName(String lampboxTypeName) { + this.lampboxTypeName = lampboxTypeName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getStreetId() { + return streetId; + } + + public void setStreetId(String streetId) { + this.streetId = streetId; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getTeleId() { + return teleId; + } + + public void setTeleId(String teleId) { + this.teleId = teleId; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java new file mode 100644 index 0000000..c398eed --- /dev/null +++ b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java @@ -0,0 +1,208 @@ +package com.casic.dcms.model; + +import java.util.List; + +public class MapLampBoxBean { + + private int code; + private List data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String address; + private String areaId; + private String areaName; + private String delflag; + private String deptId; + private String deptName; + private String id; + private String lampboxCode; + private String lampboxName; + private String lampboxType; + private String lampboxTypeName; + private String latitude; + private String longitude; + private String streetId; + private String streetName; + private String teleId; + private String ts; + private String version; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getDelflag() { + return delflag; + } + + public void setDelflag(String delflag) { + this.delflag = delflag; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLampboxCode() { + return lampboxCode; + } + + public void setLampboxCode(String lampboxCode) { + this.lampboxCode = lampboxCode; + } + + public String getLampboxName() { + return lampboxName; + } + + public void setLampboxName(String lampboxName) { + this.lampboxName = lampboxName; + } + + public String getLampboxType() { + return lampboxType; + } + + public void setLampboxType(String lampboxType) { + this.lampboxType = lampboxType; + } + + public String getLampboxTypeName() { + return lampboxTypeName; + } + + public void setLampboxTypeName(String lampboxTypeName) { + this.lampboxTypeName = lampboxTypeName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getStreetId() { + return streetId; + } + + public void setStreetId(String streetId) { + this.streetId = streetId; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getTeleId() { + return teleId; + } + + public void setTeleId(String teleId) { + this.teleId = teleId; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java index 0930bc1..e42e6c5 100644 --- a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java @@ -340,13 +340,13 @@ caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_case); break; } + + BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); for (Point point : points) { - BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setHeight(24); pictureMarker.setWidth(24); pictureMarker.loadAsync();//异步加载Marker,防止阻塞 - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); diff --git a/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java new file mode 100644 index 0000000..c398eed --- /dev/null +++ b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java @@ -0,0 +1,208 @@ +package com.casic.dcms.model; + +import java.util.List; + +public class MapLampBoxBean { + + private int code; + private List data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String address; + private String areaId; + private String areaName; + private String delflag; + private String deptId; + private String deptName; + private String id; + private String lampboxCode; + private String lampboxName; + private String lampboxType; + private String lampboxTypeName; + private String latitude; + private String longitude; + private String streetId; + private String streetName; + private String teleId; + private String ts; + private String version; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getDelflag() { + return delflag; + } + + public void setDelflag(String delflag) { + this.delflag = delflag; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLampboxCode() { + return lampboxCode; + } + + public void setLampboxCode(String lampboxCode) { + this.lampboxCode = lampboxCode; + } + + public String getLampboxName() { + return lampboxName; + } + + public void setLampboxName(String lampboxName) { + this.lampboxName = lampboxName; + } + + public String getLampboxType() { + return lampboxType; + } + + public void setLampboxType(String lampboxType) { + this.lampboxType = lampboxType; + } + + public String getLampboxTypeName() { + return lampboxTypeName; + } + + public void setLampboxTypeName(String lampboxTypeName) { + this.lampboxTypeName = lampboxTypeName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getStreetId() { + return streetId; + } + + public void setStreetId(String streetId) { + this.streetId = streetId; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getTeleId() { + return teleId; + } + + public void setTeleId(String teleId) { + this.teleId = teleId; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java index 0930bc1..e42e6c5 100644 --- a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java @@ -340,13 +340,13 @@ caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_case); break; } + + BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); for (Point point : points) { - BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setHeight(24); pictureMarker.setWidth(24); pictureMarker.loadAsync();//异步加载Marker,防止阻塞 - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); diff --git a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java index 225a7e3..32d2abd 100644 --- a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java @@ -24,7 +24,7 @@ import com.casic.dcms.databinding.ActivityLampBoxMapBinding; import com.casic.dcms.model.ActionResultBean; import com.casic.dcms.model.LampBoxDetailBean; -import com.casic.dcms.model.LampBoxListBean; +import com.casic.dcms.model.MapLampBoxBean; import com.casic.dcms.utils.ArcGisMapCreator; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; @@ -64,7 +64,7 @@ private final Context context = this; private final WeakReferenceHandler weakReferenceHandler = new WeakReferenceHandler(this); private LampBoxViewModel lampBoxViewModel; - private List dataBeans = new ArrayList<>(); + private List dataBeans = new ArrayList<>(); private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = LocaleConstant.DELTA_LNG_75; @@ -117,16 +117,39 @@ @Override protected void initOnCreate(@Nullable Bundle savedInstanceState) { + binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 + ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); + Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); + arcGISMap.setBasemap(basemap); + Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); + binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 + binding.mapView.setMap(arcGISMap); + //Marker相关Layer + graphicsOverlays = binding.mapView.getGraphicsOverlays(); + + //数据 lampBoxViewModel = new ViewModelProvider(this).get(LampBoxViewModel.class); - lampBoxViewModel.getLampBoxes(this); - lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { + lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { @Override - public void onChanged(LampBoxListBean resultBean) { + public void onChanged(MapLampBoxBean resultBean) { if (resultBean.getCode() == 200) { - dataBeans = resultBean.getData().getRows(); + dataBeans = resultBean.getData(); + + //转为地图Point + List points = new ArrayList<>(); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + Point point = new Point(Double.parseDouble(longitude), Double.parseDouble(latitude), SpatialReferences.getWgs84()); + points.add(point); + } + } + addPictureMarker(points); } } }); + lampBoxViewModel.getLampBoxes(this); lampBoxViewModel.lampBoxDetailResult.observe(this, new Observer() { @Override @@ -191,40 +214,6 @@ } } }); - - binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 - ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); - //创建底图、并设置底图图层 - Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); - arcGISMap.setBasemap(basemap); - Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 - binding.mapView.setMap(arcGISMap); - - //Marker相关Layer - graphicsOverlays = binding.mapView.getGraphicsOverlays(); - //显示定位点附近路灯 - LocationHelper.get().getCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800); - - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); - } - } - }, true); } @SuppressLint("ClickableViewAccessibility") @@ -234,31 +223,11 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 0.5); - clearPictureMarker(); //计算比例尺 DELTA_L -= 0.0001; if (DELTA_L < 0) { DELTA_L = 0; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List minusList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - minusList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(minusList); - } - } - }, true); } }); @@ -266,64 +235,34 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 2); - clearPictureMarker(); //计算比例尺 DELTA_L += 0.0001; if (DELTA_L > 0.01) { DELTA_L = LocaleConstant.DELTA_LNG_75; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List expandList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - expandList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(expandList); - } - } - }, true); } }); binding.removeToLocalView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - clearPictureMarker(); LoadingDialog.show(LampBoxOnMapActivity.this, "定位中,请稍后"); LocationHelper.get().getCurrentLocation(context, new ILocationListener() { @Override public void onAMapLocationGet(AMapLocation aMapLocation) { if (aMapLocation != null) { + LoadingDialog.dismiss(); double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); binding.mapView.setViewpointCenterAsync(point, 3000); - LoadingDialog.dismiss(); } } }, true); } }); - binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(context, binding.mapView) { + binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, binding.mapView) { @Override public boolean onSingleTapConfirmed(MotionEvent e) { android.graphics.Point screenPoint = new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())); @@ -333,19 +272,24 @@ public void run() { try { List overlayResultList = overlaysAsync.get(); - if (!overlayResultList.isEmpty()) { + if (overlayResultList.isEmpty()) { + weakReferenceHandler.sendEmptyMessage(2021062402); + } else { IdentifyGraphicsOverlayResult identifyResult = overlayResultList.get(0); Point point = identifyResult.getGraphicsOverlay().getExtent().getCenter(); - for (LampBoxListBean.DataBean.RowsBean dataBean : dataBeans) { - if (Math.abs(dataBean.getLongitude() - point.getX()) <= LocaleConstant.DELTA_LNG_10 && Math.abs(dataBean.getLatitude() - point.getY()) <= LocaleConstant.DELTA_LAT_10) { - Message message = weakReferenceHandler.obtainMessage(); - message.what = 2021062401; - message.obj = dataBean.getId(); - weakReferenceHandler.sendMessage(message); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + if (Math.abs(Double.parseDouble(longitude) - point.getX()) <= LocaleConstant.DELTA_LNG_10 + && Math.abs(Double.parseDouble(latitude) - point.getY()) <= LocaleConstant.DELTA_LAT_10) { + Message message = weakReferenceHandler.obtainMessage(); + message.what = 2021062401; + message.obj = dataBean.getId(); + weakReferenceHandler.sendMessage(message); + } } } - } else { - weakReferenceHandler.sendEmptyMessage(2021062402); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -380,14 +324,13 @@ } private void addPictureMarker(List points) { + Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); for (Point point : points) { - Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setWidth(24); pictureMarker.setHeight(24); pictureMarker.loadAsync(); - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); @@ -401,4 +344,21 @@ graphicsOverlays.clear(); } } + + protected void onResume() { + super.onResume(); + binding.mapView.resume(); + } + + @Override + protected void onPause() { + super.onPause(); + binding.mapView.pause(); + } + + @Override + protected void onDestroy() { + binding.mapView.dispose(); + super.onDestroy(); + } } diff --git a/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java new file mode 100644 index 0000000..c398eed --- /dev/null +++ b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java @@ -0,0 +1,208 @@ +package com.casic.dcms.model; + +import java.util.List; + +public class MapLampBoxBean { + + private int code; + private List data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String address; + private String areaId; + private String areaName; + private String delflag; + private String deptId; + private String deptName; + private String id; + private String lampboxCode; + private String lampboxName; + private String lampboxType; + private String lampboxTypeName; + private String latitude; + private String longitude; + private String streetId; + private String streetName; + private String teleId; + private String ts; + private String version; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getDelflag() { + return delflag; + } + + public void setDelflag(String delflag) { + this.delflag = delflag; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLampboxCode() { + return lampboxCode; + } + + public void setLampboxCode(String lampboxCode) { + this.lampboxCode = lampboxCode; + } + + public String getLampboxName() { + return lampboxName; + } + + public void setLampboxName(String lampboxName) { + this.lampboxName = lampboxName; + } + + public String getLampboxType() { + return lampboxType; + } + + public void setLampboxType(String lampboxType) { + this.lampboxType = lampboxType; + } + + public String getLampboxTypeName() { + return lampboxTypeName; + } + + public void setLampboxTypeName(String lampboxTypeName) { + this.lampboxTypeName = lampboxTypeName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getStreetId() { + return streetId; + } + + public void setStreetId(String streetId) { + this.streetId = streetId; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getTeleId() { + return teleId; + } + + public void setTeleId(String teleId) { + this.teleId = teleId; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java index 0930bc1..e42e6c5 100644 --- a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java @@ -340,13 +340,13 @@ caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_case); break; } + + BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); for (Point point : points) { - BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setHeight(24); pictureMarker.setWidth(24); pictureMarker.loadAsync();//异步加载Marker,防止阻塞 - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); diff --git a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java index 225a7e3..32d2abd 100644 --- a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java @@ -24,7 +24,7 @@ import com.casic.dcms.databinding.ActivityLampBoxMapBinding; import com.casic.dcms.model.ActionResultBean; import com.casic.dcms.model.LampBoxDetailBean; -import com.casic.dcms.model.LampBoxListBean; +import com.casic.dcms.model.MapLampBoxBean; import com.casic.dcms.utils.ArcGisMapCreator; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; @@ -64,7 +64,7 @@ private final Context context = this; private final WeakReferenceHandler weakReferenceHandler = new WeakReferenceHandler(this); private LampBoxViewModel lampBoxViewModel; - private List dataBeans = new ArrayList<>(); + private List dataBeans = new ArrayList<>(); private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = LocaleConstant.DELTA_LNG_75; @@ -117,16 +117,39 @@ @Override protected void initOnCreate(@Nullable Bundle savedInstanceState) { + binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 + ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); + Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); + arcGISMap.setBasemap(basemap); + Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); + binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 + binding.mapView.setMap(arcGISMap); + //Marker相关Layer + graphicsOverlays = binding.mapView.getGraphicsOverlays(); + + //数据 lampBoxViewModel = new ViewModelProvider(this).get(LampBoxViewModel.class); - lampBoxViewModel.getLampBoxes(this); - lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { + lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { @Override - public void onChanged(LampBoxListBean resultBean) { + public void onChanged(MapLampBoxBean resultBean) { if (resultBean.getCode() == 200) { - dataBeans = resultBean.getData().getRows(); + dataBeans = resultBean.getData(); + + //转为地图Point + List points = new ArrayList<>(); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + Point point = new Point(Double.parseDouble(longitude), Double.parseDouble(latitude), SpatialReferences.getWgs84()); + points.add(point); + } + } + addPictureMarker(points); } } }); + lampBoxViewModel.getLampBoxes(this); lampBoxViewModel.lampBoxDetailResult.observe(this, new Observer() { @Override @@ -191,40 +214,6 @@ } } }); - - binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 - ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); - //创建底图、并设置底图图层 - Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); - arcGISMap.setBasemap(basemap); - Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 - binding.mapView.setMap(arcGISMap); - - //Marker相关Layer - graphicsOverlays = binding.mapView.getGraphicsOverlays(); - //显示定位点附近路灯 - LocationHelper.get().getCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800); - - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); - } - } - }, true); } @SuppressLint("ClickableViewAccessibility") @@ -234,31 +223,11 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 0.5); - clearPictureMarker(); //计算比例尺 DELTA_L -= 0.0001; if (DELTA_L < 0) { DELTA_L = 0; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List minusList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - minusList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(minusList); - } - } - }, true); } }); @@ -266,64 +235,34 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 2); - clearPictureMarker(); //计算比例尺 DELTA_L += 0.0001; if (DELTA_L > 0.01) { DELTA_L = LocaleConstant.DELTA_LNG_75; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List expandList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - expandList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(expandList); - } - } - }, true); } }); binding.removeToLocalView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - clearPictureMarker(); LoadingDialog.show(LampBoxOnMapActivity.this, "定位中,请稍后"); LocationHelper.get().getCurrentLocation(context, new ILocationListener() { @Override public void onAMapLocationGet(AMapLocation aMapLocation) { if (aMapLocation != null) { + LoadingDialog.dismiss(); double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); binding.mapView.setViewpointCenterAsync(point, 3000); - LoadingDialog.dismiss(); } } }, true); } }); - binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(context, binding.mapView) { + binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, binding.mapView) { @Override public boolean onSingleTapConfirmed(MotionEvent e) { android.graphics.Point screenPoint = new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())); @@ -333,19 +272,24 @@ public void run() { try { List overlayResultList = overlaysAsync.get(); - if (!overlayResultList.isEmpty()) { + if (overlayResultList.isEmpty()) { + weakReferenceHandler.sendEmptyMessage(2021062402); + } else { IdentifyGraphicsOverlayResult identifyResult = overlayResultList.get(0); Point point = identifyResult.getGraphicsOverlay().getExtent().getCenter(); - for (LampBoxListBean.DataBean.RowsBean dataBean : dataBeans) { - if (Math.abs(dataBean.getLongitude() - point.getX()) <= LocaleConstant.DELTA_LNG_10 && Math.abs(dataBean.getLatitude() - point.getY()) <= LocaleConstant.DELTA_LAT_10) { - Message message = weakReferenceHandler.obtainMessage(); - message.what = 2021062401; - message.obj = dataBean.getId(); - weakReferenceHandler.sendMessage(message); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + if (Math.abs(Double.parseDouble(longitude) - point.getX()) <= LocaleConstant.DELTA_LNG_10 + && Math.abs(Double.parseDouble(latitude) - point.getY()) <= LocaleConstant.DELTA_LAT_10) { + Message message = weakReferenceHandler.obtainMessage(); + message.what = 2021062401; + message.obj = dataBean.getId(); + weakReferenceHandler.sendMessage(message); + } } } - } else { - weakReferenceHandler.sendEmptyMessage(2021062402); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -380,14 +324,13 @@ } private void addPictureMarker(List points) { + Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); for (Point point : points) { - Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setWidth(24); pictureMarker.setHeight(24); pictureMarker.loadAsync(); - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); @@ -401,4 +344,21 @@ graphicsOverlays.clear(); } } + + protected void onResume() { + super.onResume(); + binding.mapView.resume(); + } + + @Override + protected void onPause() { + super.onPause(); + binding.mapView.pause(); + } + + @Override + protected void onDestroy() { + binding.mapView.dispose(); + super.onDestroy(); + } } diff --git a/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java b/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java index 551bb08..f4986d9 100644 --- a/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java +++ b/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java @@ -7,6 +7,7 @@ import com.casic.dcms.model.ActionResultBean; import com.casic.dcms.model.LampBoxDetailBean; import com.casic.dcms.model.LampBoxListBean; +import com.casic.dcms.model.MapLampBoxBean; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.retrofit.RetrofitServiceManager; import com.google.gson.Gson; @@ -26,7 +27,7 @@ private final Gson gson = new Gson(); public MutableLiveData lampBoxResult = new MutableLiveData<>(); //分页 public MutableLiveData controlResult = new MutableLiveData<>(); - public MutableLiveData mapLampBoxResult = new MutableLiveData<>(); //不分页 + public MutableLiveData mapLampBoxResult = new MutableLiveData<>(); //不分页 public MutableLiveData lampBoxDetailResult = new MutableLiveData<>(); public void getLampBoxesByPage(Context context, int offset) { @@ -119,7 +120,7 @@ String response = responseBody.string(); int responseCode = StringHelper.getResponseCode(response); if (responseCode == 200) { - LampBoxListBean listBean = gson.fromJson(response, new TypeToken() { + MapLampBoxBean listBean = gson.fromJson(response, new TypeToken() { }.getType()); mapLampBoxResult.setValue(listBean); loadState.setValue(LoadState.Success); diff --git a/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java new file mode 100644 index 0000000..c398eed --- /dev/null +++ b/app/src/main/java/com/casic/dcms/model/MapLampBoxBean.java @@ -0,0 +1,208 @@ +package com.casic.dcms.model; + +import java.util.List; + +public class MapLampBoxBean { + + private int code; + private List data; + private String message; + private boolean success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public static class DataBean { + private String address; + private String areaId; + private String areaName; + private String delflag; + private String deptId; + private String deptName; + private String id; + private String lampboxCode; + private String lampboxName; + private String lampboxType; + private String lampboxTypeName; + private String latitude; + private String longitude; + private String streetId; + private String streetName; + private String teleId; + private String ts; + private String version; + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getAreaId() { + return areaId; + } + + public void setAreaId(String areaId) { + this.areaId = areaId; + } + + public String getAreaName() { + return areaName; + } + + public void setAreaName(String areaName) { + this.areaName = areaName; + } + + public String getDelflag() { + return delflag; + } + + public void setDelflag(String delflag) { + this.delflag = delflag; + } + + public String getDeptId() { + return deptId; + } + + public void setDeptId(String deptId) { + this.deptId = deptId; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getLampboxCode() { + return lampboxCode; + } + + public void setLampboxCode(String lampboxCode) { + this.lampboxCode = lampboxCode; + } + + public String getLampboxName() { + return lampboxName; + } + + public void setLampboxName(String lampboxName) { + this.lampboxName = lampboxName; + } + + public String getLampboxType() { + return lampboxType; + } + + public void setLampboxType(String lampboxType) { + this.lampboxType = lampboxType; + } + + public String getLampboxTypeName() { + return lampboxTypeName; + } + + public void setLampboxTypeName(String lampboxTypeName) { + this.lampboxTypeName = lampboxTypeName; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getStreetId() { + return streetId; + } + + public void setStreetId(String streetId) { + this.streetId = streetId; + } + + public String getStreetName() { + return streetName; + } + + public void setStreetName(String streetName) { + this.streetName = streetName; + } + + public String getTeleId() { + return teleId; + } + + public void setTeleId(String teleId) { + this.teleId = teleId; + } + + public String getTs() { + return ts; + } + + public void setTs(String ts) { + this.ts = ts; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + } +} diff --git a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java index 0930bc1..e42e6c5 100644 --- a/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/map/CaseOnMapActivity.java @@ -340,13 +340,13 @@ caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_case); break; } + + BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); for (Point point : points) { - BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setHeight(24); pictureMarker.setWidth(24); pictureMarker.loadAsync();//异步加载Marker,防止阻塞 - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); diff --git a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java index 225a7e3..32d2abd 100644 --- a/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java +++ b/app/src/main/java/com/casic/dcms/view/streetlight/LampBoxOnMapActivity.java @@ -24,7 +24,7 @@ import com.casic.dcms.databinding.ActivityLampBoxMapBinding; import com.casic.dcms.model.ActionResultBean; import com.casic.dcms.model.LampBoxDetailBean; -import com.casic.dcms.model.LampBoxListBean; +import com.casic.dcms.model.MapLampBoxBean; import com.casic.dcms.utils.ArcGisMapCreator; import com.casic.dcms.utils.LocaleConstant; import com.casic.dcms.utils.LocationHelper; @@ -64,7 +64,7 @@ private final Context context = this; private final WeakReferenceHandler weakReferenceHandler = new WeakReferenceHandler(this); private LampBoxViewModel lampBoxViewModel; - private List dataBeans = new ArrayList<>(); + private List dataBeans = new ArrayList<>(); private ListenableList graphicsOverlays; private ListenableList graphics; private double DELTA_L = LocaleConstant.DELTA_LNG_75; @@ -117,16 +117,39 @@ @Override protected void initOnCreate(@Nullable Bundle savedInstanceState) { + binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 + ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); + Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); + arcGISMap.setBasemap(basemap); + Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); + binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 + binding.mapView.setMap(arcGISMap); + //Marker相关Layer + graphicsOverlays = binding.mapView.getGraphicsOverlays(); + + //数据 lampBoxViewModel = new ViewModelProvider(this).get(LampBoxViewModel.class); - lampBoxViewModel.getLampBoxes(this); - lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { + lampBoxViewModel.mapLampBoxResult.observe(this, new Observer() { @Override - public void onChanged(LampBoxListBean resultBean) { + public void onChanged(MapLampBoxBean resultBean) { if (resultBean.getCode() == 200) { - dataBeans = resultBean.getData().getRows(); + dataBeans = resultBean.getData(); + + //转为地图Point + List points = new ArrayList<>(); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + Point point = new Point(Double.parseDouble(longitude), Double.parseDouble(latitude), SpatialReferences.getWgs84()); + points.add(point); + } + } + addPictureMarker(points); } } }); + lampBoxViewModel.getLampBoxes(this); lampBoxViewModel.lampBoxDetailResult.observe(this, new Observer() { @Override @@ -191,40 +214,6 @@ } } }); - - binding.mapView.setAttributionTextVisible(false);//去掉左下角属性标识 - ArcGISMap arcGISMap = new ArcGISMap(BasemapStyle.ARCGIS_STREETS); - //创建底图、并设置底图图层 - Basemap basemap = new Basemap(ArcGisMapCreator.createBaseLayer()); - arcGISMap.setBasemap(basemap); - Point point = new Point(LocaleConstant.DEFAULT_LNG, LocaleConstant.DEFAULT_LAT, SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800);//标注到指定经纬度并放大地图显示 - binding.mapView.setMap(arcGISMap); - - //Marker相关Layer - graphicsOverlays = binding.mapView.getGraphicsOverlays(); - //显示定位点附近路灯 - LocationHelper.get().getCurrentLocation(this, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - binding.mapView.setViewpointCenterAsync(point, 2800); - - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); - } - } - }, true); } @SuppressLint("ClickableViewAccessibility") @@ -234,31 +223,11 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 0.5); - clearPictureMarker(); //计算比例尺 DELTA_L -= 0.0001; if (DELTA_L < 0) { DELTA_L = 0; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List minusList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - minusList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(minusList); - } - } - }, true); } }); @@ -266,64 +235,34 @@ @Override public void onClick(View v) { binding.mapView.setViewpointScaleAsync(binding.mapView.getMapScale() * 2); - clearPictureMarker(); //计算比例尺 DELTA_L += 0.0001; if (DELTA_L > 0.01) { DELTA_L = LocaleConstant.DELTA_LNG_75; } - LocationHelper.get().getCurrentLocation(context, new ILocationListener() { - - @Override - public void onAMapLocationGet(AMapLocation aMapLocation) { - if (aMapLocation != null) { - double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); - Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List expandList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= DELTA_L && Math.abs(latitude - gcjToWgs[1]) <= DELTA_L) { - expandList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(expandList); - } - } - }, true); } }); binding.removeToLocalView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - clearPictureMarker(); LoadingDialog.show(LampBoxOnMapActivity.this, "定位中,请稍后"); LocationHelper.get().getCurrentLocation(context, new ILocationListener() { @Override public void onAMapLocationGet(AMapLocation aMapLocation) { if (aMapLocation != null) { + LoadingDialog.dismiss(); double[] gcjToWgs = LocationHelper.get().gcjToWgs(aMapLocation.getLongitude(), aMapLocation.getLatitude()); Point point = new Point(gcjToWgs[0], gcjToWgs[1], SpatialReferences.getWgs84()); - List pointList = new ArrayList<>(); - for (LampBoxListBean.DataBean.RowsBean bean : dataBeans) { - double longitude = bean.getLongitude(); - double latitude = bean.getLatitude(); - if (Math.abs(longitude - gcjToWgs[0]) <= LocaleConstant.DELTA_LNG_75 && Math.abs(latitude - gcjToWgs[1]) <= LocaleConstant.DELTA_LAT_75) { - pointList.add(new Point(longitude, latitude, SpatialReferences.getWgs84())); - } - } - addPictureMarker(pointList); binding.mapView.setViewpointCenterAsync(point, 3000); - LoadingDialog.dismiss(); } } }, true); } }); - binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(context, binding.mapView) { + binding.mapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, binding.mapView) { @Override public boolean onSingleTapConfirmed(MotionEvent e) { android.graphics.Point screenPoint = new android.graphics.Point(Math.round(e.getX()), Math.round(e.getY())); @@ -333,19 +272,24 @@ public void run() { try { List overlayResultList = overlaysAsync.get(); - if (!overlayResultList.isEmpty()) { + if (overlayResultList.isEmpty()) { + weakReferenceHandler.sendEmptyMessage(2021062402); + } else { IdentifyGraphicsOverlayResult identifyResult = overlayResultList.get(0); Point point = identifyResult.getGraphicsOverlay().getExtent().getCenter(); - for (LampBoxListBean.DataBean.RowsBean dataBean : dataBeans) { - if (Math.abs(dataBean.getLongitude() - point.getX()) <= LocaleConstant.DELTA_LNG_10 && Math.abs(dataBean.getLatitude() - point.getY()) <= LocaleConstant.DELTA_LAT_10) { - Message message = weakReferenceHandler.obtainMessage(); - message.what = 2021062401; - message.obj = dataBean.getId(); - weakReferenceHandler.sendMessage(message); + for (MapLampBoxBean.DataBean dataBean : dataBeans) { + String longitude = dataBean.getLongitude(); + String latitude = dataBean.getLatitude(); + if (!longitude.isEmpty() && !latitude.isEmpty()) { + if (Math.abs(Double.parseDouble(longitude) - point.getX()) <= LocaleConstant.DELTA_LNG_10 + && Math.abs(Double.parseDouble(latitude) - point.getY()) <= LocaleConstant.DELTA_LAT_10) { + Message message = weakReferenceHandler.obtainMessage(); + message.what = 2021062401; + message.obj = dataBean.getId(); + weakReferenceHandler.sendMessage(message); + } } } - } else { - weakReferenceHandler.sendEmptyMessage(2021062402); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); @@ -380,14 +324,13 @@ } private void addPictureMarker(List points) { + Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); for (Point point : points) { - Bitmap caseBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.location_verify); BitmapDrawable caseDrawable = new BitmapDrawable(getResources(), caseBitmap); PictureMarkerSymbol pictureMarker = new PictureMarkerSymbol(caseDrawable); pictureMarker.setWidth(24); pictureMarker.setHeight(24); pictureMarker.loadAsync(); - GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); graphics = graphicsOverlay.getGraphics(); graphics.add(new Graphic(point, pictureMarker)); @@ -401,4 +344,21 @@ graphicsOverlays.clear(); } } + + protected void onResume() { + super.onResume(); + binding.mapView.resume(); + } + + @Override + protected void onPause() { + super.onPause(); + binding.mapView.pause(); + } + + @Override + protected void onDestroy() { + binding.mapView.dispose(); + super.onDestroy(); + } } diff --git a/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java b/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java index 551bb08..f4986d9 100644 --- a/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java +++ b/app/src/main/java/com/casic/dcms/vm/LampBoxViewModel.java @@ -7,6 +7,7 @@ import com.casic.dcms.model.ActionResultBean; import com.casic.dcms.model.LampBoxDetailBean; import com.casic.dcms.model.LampBoxListBean; +import com.casic.dcms.model.MapLampBoxBean; import com.casic.dcms.utils.StringHelper; import com.casic.dcms.utils.retrofit.RetrofitServiceManager; import com.google.gson.Gson; @@ -26,7 +27,7 @@ private final Gson gson = new Gson(); public MutableLiveData lampBoxResult = new MutableLiveData<>(); //分页 public MutableLiveData controlResult = new MutableLiveData<>(); - public MutableLiveData mapLampBoxResult = new MutableLiveData<>(); //不分页 + public MutableLiveData mapLampBoxResult = new MutableLiveData<>(); //不分页 public MutableLiveData lampBoxDetailResult = new MutableLiveData<>(); public void getLampBoxesByPage(Context context, int offset) { @@ -119,7 +120,7 @@ String response = responseBody.string(); int responseCode = StringHelper.getResponseCode(response); if (responseCode == 200) { - LampBoxListBean listBean = gson.fromJson(response, new TypeToken() { + MapLampBoxBean listBean = gson.fromJson(response, new TypeToken() { }.getType()); mapLampBoxResult.setValue(listBean); loadState.setValue(LoadState.Success); diff --git a/app/src/main/res/layout/popu_lamp_box_on_map.xml b/app/src/main/res/layout/popu_lamp_box_on_map.xml index a5567d9..3b42137 100644 --- a/app/src/main/res/layout/popu_lamp_box_on_map.xml +++ b/app/src/main/res/layout/popu_lamp_box_on_map.xml @@ -1,7 +1,7 @@