|
@@ -1,28 +1,26 @@
|
|
|
package com.cr.pages
|
|
|
|
|
|
+import android.graphics.Bitmap
|
|
|
import android.graphics.Color
|
|
|
import android.graphics.drawable.BitmapDrawable
|
|
|
import android.os.Bundle
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
+import com.cr.common.CrFileManager
|
|
|
import com.cr.common.CrUnitManager
|
|
|
import com.cr.common.DataManager
|
|
|
-import com.cr.common.CrFileManager
|
|
|
import com.cr.cruav.CrApplication
|
|
|
import com.cr.cruav.R
|
|
|
import com.cr.data.CrUtil
|
|
|
import com.cr.dialog.DialogInput
|
|
|
import com.cr.dialog.DialogNormal
|
|
|
+import com.cr.event.EventMapCapture
|
|
|
import com.cr.map.*
|
|
|
import com.cr.models.CompletionModel
|
|
|
import com.cr.models.ICompletion
|
|
|
import com.esri.arcgisruntime.arcgisservices.LabelDefinition
|
|
|
-import com.esri.arcgisruntime.data.Feature
|
|
|
-import com.esri.arcgisruntime.data.FeatureTable
|
|
|
-import com.esri.arcgisruntime.data.Geodatabase
|
|
|
-import com.esri.arcgisruntime.data.QueryParameters
|
|
|
-import com.esri.arcgisruntime.data.ServiceFeatureTable
|
|
|
+import com.esri.arcgisruntime.data.*
|
|
|
import com.esri.arcgisruntime.geometry.*
|
|
|
import com.esri.arcgisruntime.layers.ArcGISMapImageLayer
|
|
|
import com.esri.arcgisruntime.layers.ArcGISTiledLayer
|
|
@@ -36,6 +34,11 @@ import com.google.gson.JsonParser
|
|
|
import com.google.gson.JsonPrimitive
|
|
|
import com.squareup.otto.Subscribe
|
|
|
import kotlinx.android.synthetic.main.frag_map.*
|
|
|
+import kotlinx.coroutines.*
|
|
|
+import java.io.File
|
|
|
+import java.io.FileOutputStream
|
|
|
+import java.lang.Runnable
|
|
|
+import java.util.*
|
|
|
import java.util.concurrent.ExecutionException
|
|
|
import kotlin.math.abs
|
|
|
|
|
@@ -171,6 +174,10 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
// todo: 2023/6/15 内部监听 自行设置
|
|
|
private var eventListener: EventListener? = null
|
|
|
|
|
|
+ // todo: 2023/8/8 截屏相关
|
|
|
+ private var mapStateList = mutableListOf<MapStateModel>() // define: 2023/8/14 地图状态
|
|
|
+ private var captureNames = mutableListOf<String>() // define: 2023/8/14 截屏图片名称
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 重写创建View方法
|
|
@@ -1196,7 +1203,12 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
asyncUpdate?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
if (asyncUpdate.isDone) {
|
|
|
- if (callback != null) callback.onCompletion(CompletionModel(true, ""))
|
|
|
+ if (callback != null) callback.onCompletion(
|
|
|
+ CompletionModel(
|
|
|
+ true,
|
|
|
+ ""
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
} catch (ex: java.lang.IllegalArgumentException) {
|
|
|
if (callback != null) callback.onCompletion(
|
|
@@ -1289,7 +1301,7 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
*/
|
|
|
private fun caseRemoveCaseWaypoing(screenPoint: android.graphics.Point) {
|
|
|
// todo: 2023/6/14 开始查询
|
|
|
- var identifyAsync = map_mapView?.identifyLayerAsync(fLayerMedia,screenPoint,6.0,false)
|
|
|
+ var identifyAsync = map_mapView?.identifyLayerAsync(fLayerMedia, screenPoint, 6.0, false)
|
|
|
identifyAsync?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
if (identifyAsync.isDone) {
|
|
@@ -1305,15 +1317,16 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
dig.setListener(object : DialogNormal.DialogNormalListener {
|
|
|
// todo: 2023/6/14 确认删除
|
|
|
override fun completion() {
|
|
|
- caseRemoveWaypointAndUpdateCasePolygon(features,object:ICompletion<String>{
|
|
|
- override fun onCompletion(completion: CompletionModel<String>) {
|
|
|
- if(completion.isSuccess == true){
|
|
|
- CrUtil.showToast("删除成功!")
|
|
|
- }else{
|
|
|
- showError(completion.result!!)
|
|
|
+ caseRemoveWaypointAndUpdateCasePolygon(features,
|
|
|
+ object : ICompletion<String> {
|
|
|
+ override fun onCompletion(completion: CompletionModel<String>) {
|
|
|
+ if (completion.isSuccess == true) {
|
|
|
+ CrUtil.showToast("删除成功!")
|
|
|
+ } else {
|
|
|
+ showError(completion.result!!)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// todo: 2023/6/14 关闭
|
|
@@ -1337,20 +1350,23 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
* @param features List<Feature> 案件点集合
|
|
|
* @param callback iCompletion 完成回调
|
|
|
*/
|
|
|
- private fun caseRemoveWaypointAndUpdateCasePolygon(features:List<Feature>,callback: ICompletion<String>){
|
|
|
+ private fun caseRemoveWaypointAndUpdateCasePolygon(
|
|
|
+ features: List<Feature>,
|
|
|
+ callback: ICompletion<String>
|
|
|
+ ) {
|
|
|
var deleteAsync = fTableMedia?.deleteFeaturesAsync(features)
|
|
|
deleteAsync?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
if (deleteAsync.isDone) {
|
|
|
// todo: 2023/6/16 更新
|
|
|
var wheres = mutableListOf<String>()
|
|
|
- for(fea in features){
|
|
|
+ for (fea in features) {
|
|
|
wheres.add(fea.attributes[FIELD_CASE_NAME].toString())
|
|
|
}
|
|
|
- caseUpdateCasePolygonByWhere(wheres,callback)
|
|
|
+ caseUpdateCasePolygonByWhere(wheres, callback)
|
|
|
}
|
|
|
} catch (ex: java.lang.IllegalArgumentException) {
|
|
|
- if (callback != null) callback.onCompletion(CompletionModel(false,"案件点删除失败!"))
|
|
|
+ if (callback != null) callback.onCompletion(CompletionModel(false, "案件点删除失败!"))
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -1360,25 +1376,25 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
* @param wheres List<String> 案件Id的集合
|
|
|
* @param callback iCompletion 完成回调
|
|
|
*/
|
|
|
- private fun caseUpdateCasePolygonByWhere(wheres:List<String>,callback:ICompletion<String>){
|
|
|
+ private fun caseUpdateCasePolygonByWhere(wheres: List<String>, callback: ICompletion<String>) {
|
|
|
var updateWhere = ""
|
|
|
// todo: 2023/6/16 组合条件
|
|
|
- for(where in wheres){
|
|
|
- updateWhere += if(updateWhere == ""){
|
|
|
- String.format("'%s'",where)
|
|
|
- }else{
|
|
|
- String.format(",'%s'",where)
|
|
|
+ for (where in wheres) {
|
|
|
+ updateWhere += if (updateWhere == "") {
|
|
|
+ String.format("'%s'", where)
|
|
|
+ } else {
|
|
|
+ String.format(",'%s'", where)
|
|
|
}
|
|
|
}
|
|
|
// todo: 2023/6/16 开始查询
|
|
|
var queryParameters = QueryParameters()
|
|
|
queryParameters.whereClause = updateWhere
|
|
|
var asyncQuery = fTableCasePolygon?.queryFeaturesAsync(queryParameters)
|
|
|
- asyncQuery?.addDoneListener(Runnable{
|
|
|
+ asyncQuery?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
- if(asyncQuery.isDone){
|
|
|
+ if (asyncQuery.isDone) {
|
|
|
var features = mutableListOf<Feature>()
|
|
|
- for(fea in asyncQuery.get()){
|
|
|
+ for (fea in asyncQuery.get()) {
|
|
|
fea.attributes[FIELD_CASE_POLYGON_ANJID] = ""
|
|
|
fea.attributes[FIELD_CASE_POLYGON_BZ] = FIELD_CASE_POLYGON_BZ_VALUE_NO
|
|
|
features.add(fea)
|
|
@@ -1387,16 +1403,26 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
var asyncUpdate = fTableCasePolygon?.updateFeaturesAsync(features)
|
|
|
asyncUpdate?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
- if(asyncUpdate.isDone){
|
|
|
- if(callback != null) callback.onCompletion(CompletionModel(true,""))
|
|
|
+ if (asyncUpdate.isDone) {
|
|
|
+ if (callback != null) callback.onCompletion(
|
|
|
+ CompletionModel(
|
|
|
+ true,
|
|
|
+ ""
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
- }catch (ex:java.lang.IllegalArgumentException){
|
|
|
- if(callback != null) callback.onCompletion(CompletionModel(false,"关联案件更新失败!"))
|
|
|
+ } catch (ex: java.lang.IllegalArgumentException) {
|
|
|
+ if (callback != null) callback.onCompletion(
|
|
|
+ CompletionModel(
|
|
|
+ false,
|
|
|
+ "关联案件更新失败!"
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- }catch(ex:java.lang.IllegalArgumentException) {
|
|
|
- if(callback != null) callback.onCompletion(CompletionModel(false,"关联案件查询失败!"))
|
|
|
+ } catch (ex: java.lang.IllegalArgumentException) {
|
|
|
+ if (callback != null) callback.onCompletion(CompletionModel(false, "关联案件查询失败!"))
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -1469,20 +1495,22 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
asyncUpdate?.addDoneListener(Runnable {
|
|
|
try {
|
|
|
if (asyncUpdate.isDone) {
|
|
|
- caseUpdatePolygonByFeature(features[0], object : ICompletion<String> {
|
|
|
- override fun onCompletion(completion: CompletionModel<String>) {
|
|
|
- if (completion.isSuccess == true) {
|
|
|
- CrUtil.showToast("移动完成!")
|
|
|
- sketchEditor?.removeGeometryChangedListener(
|
|
|
- sketchGeometryChangeListener
|
|
|
- )
|
|
|
- sketchEditor?.stop()
|
|
|
- fLayerMedia?.clearSelection()
|
|
|
- } else {
|
|
|
- showError(completion.result!!)
|
|
|
+ caseUpdatePolygonByFeature(
|
|
|
+ features[0],
|
|
|
+ object : ICompletion<String> {
|
|
|
+ override fun onCompletion(completion: CompletionModel<String>) {
|
|
|
+ if (completion.isSuccess == true) {
|
|
|
+ CrUtil.showToast("移动完成!")
|
|
|
+ sketchEditor?.removeGeometryChangedListener(
|
|
|
+ sketchGeometryChangeListener
|
|
|
+ )
|
|
|
+ sketchEditor?.stop()
|
|
|
+ fLayerMedia?.clearSelection()
|
|
|
+ } else {
|
|
|
+ showError(completion.result!!)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
+ })
|
|
|
}
|
|
|
} catch (ex: java.lang.IllegalArgumentException) {
|
|
|
showError("移动错误,无法完成移动操作!")
|
|
@@ -1511,7 +1539,7 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
CrUtil.showToast("未选择上传案件!")
|
|
|
} else {
|
|
|
fLayerMedia?.selectFeature(elements.last() as Feature)
|
|
|
- if(eventListener != null) eventListener?.onCaseUpdate(CaseModel(elements.last().attributes))
|
|
|
+ if (eventListener != null) eventListener?.onCaseUpdate(CaseModel(elements.last().attributes))
|
|
|
}
|
|
|
}
|
|
|
} catch (ex: java.lang.IllegalArgumentException) {
|
|
@@ -1520,6 +1548,164 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存截图
|
|
|
+ * @param joinCaseName String 关联的案件名称
|
|
|
+ */
|
|
|
+ private fun captures(joinCaseName:String) {
|
|
|
+ // todo: 2023/8/14 显示等待框
|
|
|
+ showLoading("初始化...")
|
|
|
+ // todo: 2023/8/14 初始化图片信息
|
|
|
+ captureNames.clear()
|
|
|
+ captureNames.add("${joinCaseName}_yx.jpg")
|
|
|
+ captureNames.add("${joinCaseName}_xz.jpg")
|
|
|
+ captureNames.add("${joinCaseName}_gh.jpg")
|
|
|
+ // todo: 2023/8/14 初始化信息
|
|
|
+ var opNameList = mutableListOf<MutableList<String>>()
|
|
|
+ var ovLayerList = mutableListOf<MutableList<GraphicsOverlay>>()
|
|
|
+ // todo: 2023/8/14 截图-影像图
|
|
|
+ val opNamesYX = mutableListOf<String>(
|
|
|
+ LAYER_NAME_YX,
|
|
|
+ LAYER_NAME_CONFIG_VILLAGE,
|
|
|
+ LAYER_NAME_CONFIG_TOWNS,
|
|
|
+ LAYER_NAME_CASE
|
|
|
+ )
|
|
|
+ val ovLayersYX = mutableListOf<GraphicsOverlay>(gLayerIco!!)
|
|
|
+ opNameList.add(opNamesYX)
|
|
|
+ ovLayerList.add(ovLayersYX)
|
|
|
+ // todo: 2023/8/14 截图-现状图
|
|
|
+ var opNamesXZ = mutableListOf<String>(
|
|
|
+ LAYER_NAME_XZ, LAYER_NAME_CONFIG_VILLAGE, LAYER_NAME_CONFIG_TOWNS, LAYER_NAME_CASE
|
|
|
+ )
|
|
|
+ var ovLayersXZ = mutableListOf<GraphicsOverlay>(gLayerIco!!)
|
|
|
+ opNameList.add(opNamesXZ)
|
|
|
+ ovLayerList.add(ovLayersXZ)
|
|
|
+ // todo: 2023/8/14 截图-规划图
|
|
|
+ var opNamesGH = mutableListOf<String>(
|
|
|
+ LAYER_NAME_GH,LAYER_NAME_CONFIG_VILLAGE,LAYER_NAME_CONFIG_TOWNS,LAYER_NAME_CASE
|
|
|
+ )
|
|
|
+ var ovLayersGH = mutableListOf<GraphicsOverlay>(gLayerIco!!)
|
|
|
+ opNameList.add(opNamesGH)
|
|
|
+ ovLayerList.add(ovLayersGH)
|
|
|
+ // todo: 2023/8/14 执行协程
|
|
|
+ GlobalScope.launch {
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+ updateLoading("保存地图状态...")
|
|
|
+ saveMapLayerState()
|
|
|
+ updateLoading("截取影像图...")
|
|
|
+ capturesByName(opNameList[0],ovLayerList[0],captureNames[0])
|
|
|
+ updateLoading("截取现状图...")
|
|
|
+ capturesByName(opNameList[1],ovLayerList[1],captureNames[1])
|
|
|
+ updateLoading("截取规划图...")
|
|
|
+ capturesByName(opNameList[2],ovLayerList[2],captureNames[2])
|
|
|
+ updateLoading("恢复地图状态...")
|
|
|
+ restoreMapLayerState()
|
|
|
+ // todo: 2023/8/14 发送截图完成事件
|
|
|
+ CrApplication.getEventBus().post(EventMapCapture(EventMapCapture.CaptureAction.CAPTURE_ACTION_COMPLETE,null,captureNames))
|
|
|
+ // todo: 2023/8/14 关闭等待框
|
|
|
+ closeLoading()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 协程函数 可挂起
|
|
|
+ * 保存地图图层当前可视状态
|
|
|
+ */
|
|
|
+ private suspend fun saveMapLayerState() {
|
|
|
+ // todo: 2023/8/8 清除数据
|
|
|
+ mapStateList.clear()
|
|
|
+ // todo: 2023/8/8 循环操作类型图层
|
|
|
+ for (i in 0 until mMap?.operationalLayers!!.size) {
|
|
|
+ var visible = mMap?.operationalLayers!![i].isVisible
|
|
|
+ mapStateList.add(MapStateModel(i, visible, MapType.MAP_TYPE_O_LAYER))
|
|
|
+ }
|
|
|
+ // todo: 2023/8/8 循环绘制类型图层
|
|
|
+ for (i in 0 until map_mapView.graphicsOverlays.size) {
|
|
|
+ var visible = map_mapView.graphicsOverlays[i].isVisible
|
|
|
+ mapStateList.add(MapStateModel(i, visible, MapType.MAP_TYPE_D_LAYER))
|
|
|
+ }
|
|
|
+ delay(1000)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 协程函数 可挂起
|
|
|
+ * 恢复地图图层状态
|
|
|
+ */
|
|
|
+ private suspend fun restoreMapLayerState() {
|
|
|
+ for (model in mapStateList) {
|
|
|
+ if (model.mapType == MapType.MAP_TYPE_O_LAYER) {
|
|
|
+ mMap?.operationalLayers!![model.index].isVisible = model.visible
|
|
|
+ } else if (model.mapType == MapType.MAP_TYPE_D_LAYER) {
|
|
|
+ map_mapView.graphicsOverlays[model.index].isVisible = model.visible
|
|
|
+ }
|
|
|
+ }
|
|
|
+ delay(1000)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 地图截图
|
|
|
+ * @param opLayerNames List<String> 显示的操作图层名称
|
|
|
+ * @param ovLayerNames List<GraphicsOverlay> 显示的绘制图层名称
|
|
|
+ * @param saveName String 保存截图名称
|
|
|
+ */
|
|
|
+ private suspend fun capturesByName(
|
|
|
+ opLayerNames: List<String>,
|
|
|
+ ovLayerNames: List<GraphicsOverlay>,
|
|
|
+ saveName: String
|
|
|
+ ) {
|
|
|
+ // todo: 2023/8/14 控制操作图层
|
|
|
+ for (layer in mMap?.operationalLayers!!) {
|
|
|
+ layer.isVisible = opLayerNames.indexOf(layer.name) != -1
|
|
|
+ }
|
|
|
+ // todo: 2023/8/14 操作绘制图层
|
|
|
+ for (overlay in map_mapView.graphicsOverlays) {
|
|
|
+ overlay.isVisible = ovLayerNames.indexOf(overlay) != -1
|
|
|
+ }
|
|
|
+ // todo: 2023/8/14 延迟1.5秒 为了图层能正确加载
|
|
|
+ delay(1500)
|
|
|
+ toBitmapAndSave("${CrUtil.IMAGE_PATH}${saveName}")
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存地图截图到指定路径文件
|
|
|
+ * @param filePath String 文件全路径
|
|
|
+ */
|
|
|
+ private suspend fun toBitmapAndSave(filePath: String) {
|
|
|
+ map_mapView.clearFocus()
|
|
|
+ map_mapView.isPressed = false
|
|
|
+ // todo: 2023/8/14 能绘制缓存就返回false
|
|
|
+ var willNotCache = map_mapView.willNotCacheDrawing()
|
|
|
+ map_mapView.setWillNotCacheDrawing(false)
|
|
|
+ var color: Int = map_mapView.drawingCacheBackgroundColor
|
|
|
+ map_mapView.drawingCacheBackgroundColor = 0
|
|
|
+ if (color != 0) {
|
|
|
+ map_mapView.destroyDrawingCache()
|
|
|
+ }
|
|
|
+ map_mapView.buildDrawingCache()
|
|
|
+ var cacheBitmap: Bitmap? = null
|
|
|
+ while (cacheBitmap == null) {
|
|
|
+ var export = map_mapView.exportImageAsync()
|
|
|
+ try {
|
|
|
+ cacheBitmap = export.get()
|
|
|
+ } catch (e: InterruptedException) {
|
|
|
+ e.message?.let { CrUtil.showToast(it) }
|
|
|
+ } catch (e: ExecutionException) {
|
|
|
+ e.message?.let { CrUtil.showToast(it) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // todo: 2023/8/14 创建位图
|
|
|
+ var bitmap = Bitmap.createBitmap(cacheBitmap)
|
|
|
+ // todo: 2023/8/14 重置地图
|
|
|
+ map_mapView.destroyDrawingCache()
|
|
|
+ map_mapView.setWillNotCacheDrawing(willNotCache)
|
|
|
+ map_mapView.drawingCacheBackgroundColor = color
|
|
|
+ // todo: 2023/8/14 保存截图
|
|
|
+ var saveFile = File(filePath)
|
|
|
+ var stream = FileOutputStream(saveFile)
|
|
|
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 订阅地图事件执行动作
|
|
@@ -1673,6 +1859,18 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 订阅截屏事件
|
|
|
+ */
|
|
|
+ @Subscribe
|
|
|
+ fun onCapture(event:EventMapCapture){
|
|
|
+ event?.let {
|
|
|
+ if(it.action == EventMapCapture.CaptureAction.CAPTURE_ACTION_START){
|
|
|
+ captures(it.joinCaseName!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 设置事件监听
|
|
|
* @param listener EventListener 事件监听
|
|
|
*/
|