|
@@ -9,15 +9,19 @@ import android.view.ViewGroup
|
|
|
import com.cr.common.CrUnitManager
|
|
|
import com.cr.common.DataManager
|
|
|
import com.cr.common.FileManager
|
|
|
+import com.cr.cruav.CrApplication
|
|
|
import com.cr.cruav.R
|
|
|
import com.cr.data.CrUtil
|
|
|
+import com.cr.dialog.DialogNormal
|
|
|
import com.cr.map.*
|
|
|
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment
|
|
|
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.geometry.Geometry
|
|
|
import com.esri.arcgisruntime.geometry.Point
|
|
|
import com.esri.arcgisruntime.geometry.PointBuilder
|
|
|
import com.esri.arcgisruntime.geometry.PolylineBuilder
|
|
@@ -25,14 +29,14 @@ import com.esri.arcgisruntime.layers.ArcGISMapImageLayer
|
|
|
import com.esri.arcgisruntime.layers.ArcGISTiledLayer
|
|
|
import com.esri.arcgisruntime.layers.FeatureLayer
|
|
|
import com.esri.arcgisruntime.mapping.ArcGISMap
|
|
|
-import com.esri.arcgisruntime.mapping.view.Graphic
|
|
|
-import com.esri.arcgisruntime.mapping.view.GraphicsOverlay
|
|
|
-import com.esri.arcgisruntime.mapping.view.MapView
|
|
|
-import com.esri.arcgisruntime.mapping.view.SketchEditor
|
|
|
+import com.esri.arcgisruntime.mapping.GeoElement
|
|
|
+import com.esri.arcgisruntime.mapping.view.*
|
|
|
import com.esri.arcgisruntime.symbology.*
|
|
|
import com.google.gson.JsonObject
|
|
|
import com.google.gson.JsonParser
|
|
|
import com.google.gson.JsonPrimitive
|
|
|
+import com.squareup.otto.Subscribe
|
|
|
+import java.util.concurrent.ExecutionException
|
|
|
|
|
|
/**
|
|
|
* 操作系统:MAC系统
|
|
@@ -107,7 +111,7 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
private var markChange: EventMarkChange? = null
|
|
|
|
|
|
// todo: 2023/4/13 动作相关
|
|
|
- private var mapAction: EventMapAction? = null
|
|
|
+ private var mapAction: MapAction? = null
|
|
|
|
|
|
// todo: 2023/4/14 绘制图层
|
|
|
private var gLayerIco: GraphicsOverlay? = null // define: 2023/4/13 标志图层
|
|
@@ -131,6 +135,8 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
private var graAirplaneLink: Graphic? = null // define: 2023/4/13 飞行器与返航点连接线图形
|
|
|
private var graAirplaneLocation: Graphic? = null // define: 2023/4/13 飞行器位置图形
|
|
|
private var graAirplaneHomeLocation: Graphic? = null // define: 2023/4/13 返航点位置图形
|
|
|
+
|
|
|
+ // todo: 2023/4/17 草图编辑
|
|
|
private var sketchEditor: SketchEditor? = null // define: 2023/4/13 草图编辑器
|
|
|
private var feaSelectCase: Feature? = null // define: 2023/4/13 选中的案件点
|
|
|
|
|
@@ -146,6 +152,10 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
private var fTableNetCasePolygon: ServiceFeatureTable? = null // define: 2023/4/14 网路案件表
|
|
|
private var fLayerNetCasePolygon: ArcGISMapImageLayer? = null // define: 2023/4/14 网络案件图层
|
|
|
|
|
|
+ // todo: 2023/4/18 地图Touch事件
|
|
|
+ private var mapTouch: MapTouch? = null
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 重写创建View方法
|
|
|
* @param inflater LayoutInflater
|
|
@@ -159,6 +169,8 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
savedInstanceState: Bundle?
|
|
|
): View? {
|
|
|
mainView = inflater.inflate(R.layout.frag_map, container, false)
|
|
|
+ // todo: 2023/4/17 注册订阅
|
|
|
+ CrApplication.getEventBus().register(this)
|
|
|
return mainView
|
|
|
}
|
|
|
|
|
@@ -176,23 +188,48 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
* 初始化UI
|
|
|
*/
|
|
|
private fun initUI() {
|
|
|
- ArcGISRuntimeEnvironment.setLicense("runtimelite,1000,rud4449636536,none,NKMFA0PL4S0DRJE15166");
|
|
|
+ //ArcGISRuntimeEnvironment.setLicense("runtimelite,1000,rud4449636536,none,NKMFA0PL4S0DRJE15166");
|
|
|
// todo: 2023/3/14 初始化控件
|
|
|
mapView = mainView?.findViewById(R.id.map_mapView)
|
|
|
- mapView?.let {
|
|
|
+ mapView?.let { itView ->
|
|
|
// todo: 2023/4/13 设置底部标识是否显示
|
|
|
- it.isAttributionTextVisible = false
|
|
|
+ itView.isAttributionTextVisible = false
|
|
|
mMap = ArcGISMap()
|
|
|
- it.map = mMap
|
|
|
+ itView.map = mMap
|
|
|
// todo: 2023/4/13 地图控件初始化
|
|
|
- it.backgroundGrid.color = Color.argb(255, 216, 216, 216)
|
|
|
- it.backgroundGrid.gridLineColor = Color.argb(0, 255, 255, 255)
|
|
|
+ itView.backgroundGrid.color = Color.argb(255, 216, 216, 216)
|
|
|
+ itView.backgroundGrid.gridLineColor = Color.argb(0, 255, 255, 255)
|
|
|
+ // todo: 2023/4/17 设置草图编辑
|
|
|
+ sketchEditor = SketchEditor()
|
|
|
+ sketchEditor?.sketchEditConfiguration?.let {
|
|
|
+ it.isAllowPartSelection = false
|
|
|
+ }
|
|
|
+ itView.sketchEditor = sketchEditor
|
|
|
+ // todo: 2023/4/18 Touch事件初始化
|
|
|
+ mapTouch = MapTouch(context!!, itView)
|
|
|
+ mapTouch?.setListener(touchListener)
|
|
|
+ itView.onTouchListener = mapTouch
|
|
|
}
|
|
|
// todo: 2023/4/13 地图初始化
|
|
|
mapInit()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Touch监听
|
|
|
+ */
|
|
|
+ private var touchListener = object : MapTouch.TouchListener {
|
|
|
+ // todo: 2023/4/18 涂鸦选择回调
|
|
|
+ override fun onDoodleSelect(feature: Feature?) {
|
|
|
+ if (feature != null) {
|
|
|
+ // todo: 2023/4/18 高亮显示
|
|
|
+ focusFeature(fLayerDoodle!!, feature)
|
|
|
+ } else {
|
|
|
+ unfocusFeature(fLayerDoodle!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 地图初始化
|
|
|
*/
|
|
|
private fun mapInit() {
|
|
@@ -515,11 +552,212 @@ class FragmentMap : CrAnimationFragment() {
|
|
|
private fun setMapCenter(longitude: Double, latitude: Double, scale: Double) {
|
|
|
// todo: 2023/4/13 创建中心点
|
|
|
var centerPoint: Point =
|
|
|
- Point(longitude, latitude, SketchGraphicsOverlay.wgs84SpatialReference)
|
|
|
+ Point(longitude, latitude, MapTouch.wgs84SpatialReference)
|
|
|
if (scale > 0) {
|
|
|
mapView?.setViewpointCenterAsync(centerPoint, scale)
|
|
|
} else {
|
|
|
mapView?.setViewpointCenterAsync(centerPoint)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 高亮显示要素
|
|
|
+ * @param layer FeatureLayer 要素所在图层
|
|
|
+ * @param feature Feature 要素
|
|
|
+ */
|
|
|
+ private fun focusFeature(layer: FeatureLayer, feature: Feature) {
|
|
|
+ layer.selectFeature(feature)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除高亮显示
|
|
|
+ * @param layer FeatureLayer 图层
|
|
|
+ */
|
|
|
+ private fun unfocusFeature(layer: FeatureLayer) {
|
|
|
+ layer.clearSelection()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除全部选择
|
|
|
+ */
|
|
|
+ private fun unfocusAllFeature(){
|
|
|
+ for(layer in mMap!!.operationalLayers){
|
|
|
+ if(layer is FeatureLayer){
|
|
|
+ layer.clearSelection()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(overLayer in mapView!!.graphicsOverlays){
|
|
|
+ overLayer.clearSelection()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始绘制涂鸦
|
|
|
+ */
|
|
|
+ private fun doodleStartDraw() {
|
|
|
+ sketchEditor?.start(SketchCreationMode.FREEHAND_LINE)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清除草图
|
|
|
+ */
|
|
|
+ private fun clearSketch() {
|
|
|
+ sketchEditor?.clearGeometry()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存绘制的涂鸦
|
|
|
+ */
|
|
|
+ private fun doodleSave() {
|
|
|
+ var geometry: Geometry? = sketchEditor?.geometry
|
|
|
+ geometry?.let {
|
|
|
+ var feature: Feature = fTableDoodle!!.createFeature()
|
|
|
+ feature.geometry = it
|
|
|
+ var addAsync = fTableDoodle!!.addFeatureAsync(feature)
|
|
|
+ addAsync.addDoneListener(Runnable {
|
|
|
+ try {
|
|
|
+ addAsync.get()
|
|
|
+ if (addAsync.isDone) {
|
|
|
+ DialogNormal(context!!, "提示", "涂鸦保存成功!").show()
|
|
|
+ sketchEditor?.stop()
|
|
|
+ CrApplication.getEventBus()
|
|
|
+ .post(FragmentDoodle.EventAction(FragmentDoodle.EventAction.CLOSE_DRAW))
|
|
|
+ }
|
|
|
+ } catch (e: InterruptedException) {
|
|
|
+ DialogNormal(context!!, "警告", e.message!!).show()
|
|
|
+ } catch (e: ExecutionException) {
|
|
|
+ DialogNormal(context!!, "警告", e.message!!).show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除全部涂鸦
|
|
|
+ */
|
|
|
+ private fun doodleRemove() {
|
|
|
+ var dialog = DialogNormal(context!!, "警告", "删除后无法恢复,是否删除?")
|
|
|
+ dialog.setButtonsText("是", "否")
|
|
|
+ dialog.setListener(object : DialogNormal.DialogNormalListener {
|
|
|
+ // todo: 2023/4/17 删除
|
|
|
+ override fun completion() {
|
|
|
+ var params = QueryParameters()
|
|
|
+ params.whereClause = "1=1"
|
|
|
+ var queryAsync = fTableDoodle?.queryFeaturesAsync(params)
|
|
|
+ queryAsync?.addDoneListener(Runnable {
|
|
|
+ try {
|
|
|
+ if (queryAsync.isDone) {
|
|
|
+ var deleteAsync = fTableDoodle?.deleteFeaturesAsync(queryAsync.get())
|
|
|
+ deleteAsync?.addDoneListener(Runnable {
|
|
|
+ try {
|
|
|
+ if (deleteAsync.isDone) {
|
|
|
+ DialogNormal(context!!, "提示", "删除成功!").show()
|
|
|
+ }
|
|
|
+ } catch (e: java.lang.IllegalArgumentException) {
|
|
|
+ DialogNormal(context!!, "错误", "删除错误!").show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (e: java.lang.IllegalArgumentException) {
|
|
|
+ DialogNormal(context!!, "错误", "查询错误!").show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo: 2023/4/17 否
|
|
|
+ override fun close() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ dialog.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除选择涂鸦
|
|
|
+ */
|
|
|
+ private fun doodleDelete() {
|
|
|
+ var dialog = DialogNormal(context!!, "警告", "删除后无法恢复,是否删除?")
|
|
|
+ dialog.setButtonsText("是", "否")
|
|
|
+ dialog.setListener(object : DialogNormal.DialogNormalListener {
|
|
|
+ override fun completion() {
|
|
|
+ var sAsync = fLayerDoodle!!.selectedFeaturesAsync
|
|
|
+ sAsync.addDoneListener(Runnable {
|
|
|
+ if (sAsync.isDone){
|
|
|
+ var result = sAsync.get()
|
|
|
+ var dAsync = fTableDoodle!!.deleteFeaturesAsync(result)
|
|
|
+ dAsync.addDoneListener(Runnable{
|
|
|
+ try {
|
|
|
+ if(dAsync.isDone){
|
|
|
+ DialogNormal(context!!, "提示", "删除成功!").show()
|
|
|
+ }
|
|
|
+ }catch (e:java.lang.IllegalArgumentException){
|
|
|
+ DialogNormal(context!!, "错误", "删除错误!").show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun close() {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ dialog.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订阅地图事件执行动作
|
|
|
+ * @param event EventMap 事件
|
|
|
+ */
|
|
|
+ @Subscribe
|
|
|
+ fun onAction(event: EventMap) {
|
|
|
+ when (event.action) {
|
|
|
+ // todo: 2023/4/17 绘制涂鸦
|
|
|
+ MapAction.MapTapDrawDoodle -> {
|
|
|
+ CrUtil.showMessage("地图接收绘制命令")
|
|
|
+ doodleStartDraw()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/17 清除涂鸦
|
|
|
+ MapAction.EventDoodleClear -> {
|
|
|
+ clearSketch()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/17 保存涂鸦
|
|
|
+ MapAction.EventDoodleSave -> {
|
|
|
+ doodleSave()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/17 停止草图编辑
|
|
|
+ MapAction.EventStopSketch -> {
|
|
|
+ sketchEditor?.stop()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/17 全部删除保存的涂鸦
|
|
|
+ MapAction.EventDoodleRemove -> {
|
|
|
+ doodleRemove()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/18 删除选择涂鸦
|
|
|
+ MapAction.EventDoodleDelete -> {
|
|
|
+ doodleDelete()
|
|
|
+ }
|
|
|
+ // todo: 2023/4/18 选择涂鸦
|
|
|
+ MapAction.MapTapSelectDoodle -> {
|
|
|
+ CrUtil.showMessage("地图上点击需要选择的涂鸦")
|
|
|
+ mapTouch?.setQueryLayer(fLayerDoodle!!, MapAction.MapTapSelectDoodle)
|
|
|
+ }
|
|
|
+ // todo: 2023/4/18 停止Touch
|
|
|
+ MapAction.EventStopTouch->{
|
|
|
+ mapTouch?.setQueryLayer(null,null)
|
|
|
+ unfocusAllFeature()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo: 2023/4/17 生命周期
|
|
|
+ override fun onDestroy() {
|
|
|
+ // todo: 2023/4/17 移除订阅监听
|
|
|
+ CrApplication.getEventBus().unregister(this)
|
|
|
+ super.onDestroy()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|