This commit is contained in:
qiji4215
2023-07-21 15:40:32 +08:00
25 changed files with 1096 additions and 751 deletions

View File

@@ -15,6 +15,7 @@ import io.realm.annotations.PrimaryKey
*/
//@RealmClass
open class QsRecordBean @JvmOverloads constructor(
var taskId: Int = -1,
/**
* id 主键
*
@@ -97,6 +98,7 @@ open class QsRecordBean @JvmOverloads constructor(
fun copy(): QsRecordBean {
val qs = QsRecordBean(
taskId = taskId,
id = id,
elementId = elementId,
linkId = linkId,

View File

@@ -0,0 +1,3 @@
package com.navinfo.collect.library.map
interface BaseClickListener

View File

@@ -1,12 +1,8 @@
package com.navinfo.collect.library.map
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.map.handler.*
import com.navinfo.collect.library.system.Constant
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import org.oscim.core.GeoPoint
/**
* 地图控制器
@@ -23,7 +19,7 @@ class NIMapController {
lateinit var viewportHandler: ViewportHandler
lateinit var measureLayerHandler: MeasureLayerHandler
val onMapClickFlow = MutableSharedFlow<GeoPoint>()
// val onMapClickFlow = MutableSharedFlow<GeoPoint>()
fun init(
context: AppCompatActivity,
@@ -43,13 +39,26 @@ class NIMapController {
measureLayerHandler = MeasureLayerHandler(context, mapView)
mMapView = mapView
mMapView.setOnMapClickListener {
context.lifecycleScope.launch {
onMapClickFlow.emit(it)
if (mapView.listenerTagList.isNotEmpty()) {
val tag = mapView.listenerTagList.last()
val listenerList = mapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
if (listener is OnGeoPointClickListener) {
listener.onMapClick(tag, it)
return@setOnMapClickListener
}
}
}
}
// context.lifecycleScope.launch {
// onMapClickFlow.emit(it)
// }
}
mapView.setOptions(options)
}
}

View File

@@ -3,8 +3,8 @@ package com.navinfo.collect.library.map;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -12,12 +12,12 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.navinfo.collect.library.R;
import com.navinfo.collect.library.data.entity.NiLocation;
import com.navinfo.collect.library.map.layers.NaviMapScaleBar;
import com.navinfo.collect.library.map.source.MapLifeNiLocationTileSource;
import org.oscim.android.MapPreferences;
import org.oscim.android.MapView;
@@ -29,22 +29,14 @@ import org.oscim.event.Gesture;
import org.oscim.event.GestureListener;
import org.oscim.layers.GroupLayer;
import org.oscim.layers.Layer;
import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.OsmTileLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.layers.tile.vector.labeling.LabelTileLoaderHook;
import org.oscim.map.Map;
import org.oscim.renderer.GLViewport;
import org.oscim.scalebar.MapScaleBarLayer;
import org.oscim.theme.IRenderTheme;
import org.oscim.theme.ThemeLoader;
import org.oscim.theme.VtmThemes;
import org.oscim.tiling.source.mapfile.MapFileTileSource;
import org.oscim.tiling.source.mapfile.MultiMapFileTileSource;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -91,11 +83,6 @@ public final class NIMapView extends RelativeLayout {
* 地图状态设置
*/
private NIMapOptions options;
/**
* 地图图层管理器
*/
// private NILayerManager mLayerManager;
// private Layer baseRasterLayer, defaultVectorTileLayer, defaultVectorLabelLayer, gridLayer;
/**
* 地图网格图层
*/
@@ -109,6 +96,23 @@ public final class NIMapView extends RelativeLayout {
protected String mapFilePath = "/map";
protected GroupLayer baseGroupLayer; // 用于盛放所有基础底图的图层组,便于统一管理
private HashMap<String, BaseClickListener[]> listenerList = new HashMap();
private List<String> listenerTagList = new ArrayList();
public HashMap<String, BaseClickListener[]> getListenerList() {
return listenerList;
}
/**
* 获取所有tag
*
* @return
*/
public List<String> getListenerTagList() {
return listenerTagList;
}
public void setOptions(NIMapOptions option) {
this.options = option;
initOptions();
@@ -812,8 +816,6 @@ public final class NIMapView extends RelativeLayout {
/**
* 设置logo显隐
*
* @param position 按钮位置
*/
public void setLogoVisable(int visable) {
if (logoImage != null) {
@@ -886,12 +888,13 @@ public final class NIMapView extends RelativeLayout {
/**
* 设置比例尺位置
*
* @param position
* @param xOffset
* @param yOffset
*/
public void setScaleBarLayer(GLViewport.Position position, int xOffset, int yOffset){
if(mapScaleBarLayer!=null&&mapView.map().layers().contains(mapScaleBarLayer)){
public void setScaleBarLayer(GLViewport.Position position, int xOffset, int yOffset) {
if (mapScaleBarLayer != null && mapView.map().layers().contains(mapScaleBarLayer)) {
mapView.map().layers().remove(mapScaleBarLayer);
mapScaleBarLayer = null;
}
@@ -1029,4 +1032,39 @@ public final class NIMapView extends RelativeLayout {
mapView.map().updateMap(redraw);
}
/**
* 增加地图点击监听
*/
public boolean addOnNIMapClickListener(@NonNull String tag, @NonNull BaseClickListener... listeners) {
if (TextUtils.equals(tag, "")) {
return false;
}
for (Object s : listenerTagList) {
if (s == tag) {
return false;
}
}
listenerTagList.add(tag);
listenerList.put(tag, listeners);
return true;
}
/**
* 移除点击监听
*
* @param tag
*/
public void removeOnNIMapClickListener(@NonNull String tag) {
listenerList.remove(tag);
for (String t : listenerTagList) {
if (t.equals(tag)) {
listenerTagList.remove(t);
return;
}
}
}
}

View File

@@ -0,0 +1,7 @@
package com.navinfo.collect.library.map
import org.oscim.core.GeoPoint
interface OnGeoPointClickListener : BaseClickListener {
fun onMapClick(tag: String, point: GeoPoint)
}

View File

@@ -4,6 +4,7 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.R
import com.navinfo.collect.library.data.entity.HadLinkDvoBean
import com.navinfo.collect.library.map.BaseClickListener
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.layers.MultiLinesLayer
import com.navinfo.collect.library.map.layers.OmdbTaskLinkLayer
@@ -19,21 +20,23 @@ import org.oscim.layers.vector.geometries.Style
class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(context, mapView) {
//绘制线 样式
private val lineStyle: Style
//高亮线绘制线 样式
private val defaultLineStyle: Style
/**
* 高亮线图层,同时只高亮一条线,如线选择
*/
private val mDefaultPathLayer: PathLayer
private val mDefaultPathLayer: PathLayer by lazy {
//高亮线绘制线 样式
val defaultLineStyle = Style.builder()
.stippleColor(context.resources.getColor(R.color.draw_line_blue2_color))
.strokeWidth(10f)
.fillColor(context.resources.getColor(R.color.teal_200))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.teal_200))
.fixed(true).build()
private var onTaskLinkItemClickListener: OnTaskLinkItemClickListener? = null
fun setOnTaskLinkItemClickListener(listener: OnTaskLinkItemClickListener) {
onTaskLinkItemClickListener = listener
val layer = PathLayer(mMapView.vtmMap, defaultLineStyle)
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_LINE)
layer
}
@@ -84,12 +87,18 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
markerSymbol,
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
onTaskLinkItemClickListener?.let {
if (item is MarkerItem) {
it.onTaskLink(item.title)
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
if (listener is OnTaskLinkItemClickListener) {
if (item is MarkerItem) {
listener.onTaskLink(tag, item.title)
}
break
}
}
}
return false
}
@@ -103,30 +112,6 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
layer
}
init {
//新增线数据图层和线样式
lineStyle = Style.builder()
.stippleColor(context.resources.getColor(R.color.draw_line_blue1_color))
.strokeWidth(4f)
.fillColor(context.resources.getColor(R.color.draw_line_blue2_color))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.draw_line_blue2_color))
.fixed(true).build()
defaultLineStyle = Style.builder()
.stippleColor(context.resources.getColor(R.color.draw_line_blue2_color))
.strokeWidth(10f)
.fillColor(context.resources.getColor(R.color.teal_200))
.fillAlpha(0.5f)
.strokeColor(context.resources.getColor(R.color.teal_200))
.fixed(true).build()
mDefaultPathLayer = PathLayer(mMapView.vtmMap, defaultLineStyle)
addLayer(mDefaultPathLayer, NIMapView.LAYER_GROUPS.OPERATE_LINE)
}
/**
* 高亮一条线
@@ -226,6 +211,6 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
}
}
interface OnTaskLinkItemClickListener {
fun onTaskLink(taskLinkId: String)
interface OnTaskLinkItemClickListener : BaseClickListener {
fun onTaskLink(tag: String, taskLinkId: String)
}

View File

@@ -10,6 +10,7 @@ import com.navinfo.collect.library.R
import com.navinfo.collect.library.data.entity.NiLocation
import com.navinfo.collect.library.data.entity.NoteBean
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.map.BaseClickListener
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.cluster.ClusterMarkerItem
import com.navinfo.collect.library.map.cluster.ClusterMarkerRenderer
@@ -144,18 +145,22 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
list: MutableList<Int>,
nearest: Int
): Boolean {
itemListener?.let {
val idList = mutableListOf<String>()
if (list.size == 0) {
} else {
for (i in list) {
val markerInterface: MarkerInterface =
qsRecordItemizedLayer.itemList[i]
if (markerInterface is MarkerItem) {
idList.add(markerInterface.title)
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
if (listener is OnQsRecordItemClickListener) {
val idList = mutableListOf<String>()
for (i in list) {
val markerInterface: MarkerInterface =
qsRecordItemizedLayer.itemList[i]
if (markerInterface is MarkerItem) {
idList.add(markerInterface.title)
}
}
listener.onQsRecordList(tag, idList.distinct().toMutableList())
break
}
it.onQsRecordList(idList.distinct().toMutableList())
}
}
return true
@@ -184,17 +189,28 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
)
layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let {
it.onNiLocation(index,(niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation)
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
if (listener is OnNiLocationItemListener) {
listener.onNiLocation(
tag,
index,
(niLocationItemizedLayer.itemList[index] as MarkerItem).uid as NiLocation
)
break
}
}
}
return true
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
})
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
@@ -222,10 +238,17 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
)
layer.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
itemListener?.let {
val marker = layer.itemList[index]
if (marker is MarkerItem)
it.onNote(marker.title)
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
if (listener is ONNoteItemClickListener) {
val marker = layer.itemList[index]
if (marker is MarkerItem)
listener.onNote(tag, marker.title)
break
}
}
}
return true
}
@@ -241,7 +264,6 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
private val resId = R.mipmap.map_icon_report
private val noteResId = R.drawable.icon_note_marker
private var itemListener: OnQsRecordItemClickListener? = null
/**
* 文字大小
@@ -259,22 +281,15 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
})
}
/**
* 设置marker 点击回调
*/
fun setOnQsRecordItemClickListener(listener: OnQsRecordItemClickListener?) {
itemListener = listener
}
/**
* 增加marker
*/
fun addMarker(
geoPoint: GeoPoint,
title: String?,
description: String? = "",
uid: java.lang.Object?=null,
uid: java.lang.Object? = null,
) {
var marker: MarkerItem? = null
for (e in mDefaultMarkerLayer.itemList) {
@@ -307,8 +322,8 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
fun getCurrentMark(): MarkerInterface? {
if(mDefaultMarkerLayer!=null){
return mDefaultMarkerLayer.itemList[mDefaultMarkerLayer.itemList.size-1]
if (mDefaultMarkerLayer != null) {
return mDefaultMarkerLayer.itemList[mDefaultMarkerLayer.itemList.size - 1]
}
return null
}
@@ -488,7 +503,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
}
private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem{
private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem {
val direction: Double = niLocation.direction
@@ -754,31 +769,39 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
niLocationItemizedLayer.update()
}
fun getNILocationItemizedLayerSize():Int{
/**
* 移除所有质检数据
*/
fun removeAllQsMarker() {
qsRecordItemizedLayer.removeAllItems()
mMapView.updateMap(true)
}
fun getNILocationItemizedLayerSize(): Int {
return niLocationItemizedLayer.itemList.size
}
fun getNILocation(index:Int):NiLocation?{
return if(index>-1&&index<getNILocationItemizedLayerSize()){
((niLocationItemizedLayer.itemList[index])as MarkerItem).uid as NiLocation
}else{
fun getNILocation(index: Int): NiLocation? {
return if (index > -1 && index < getNILocationItemizedLayerSize()) {
((niLocationItemizedLayer.itemList[index]) as MarkerItem).uid as NiLocation
} else {
null
}
}
fun getNILocationIndex(niLocation: NiLocation):Int?{
fun getNILocationIndex(niLocation: NiLocation): Int? {
var list = niLocationItemizedLayer.itemList
if(niLocation!=null&&list.isNotEmpty()){
if (niLocation != null && list.isNotEmpty()) {
var index = -1
list.forEach{
list.forEach {
index += 1
if(((it as MarkerItem).uid as NiLocation).id.equals(niLocation.id)){
if (((it as MarkerItem).uid as NiLocation).id.equals(niLocation.id)) {
return index
}
}
@@ -786,11 +809,16 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
return -1
}
}
interface OnQsRecordItemClickListener {
fun onQsRecordList(list: MutableList<String>)
fun onNote(noteId: String)
fun onNiLocation(index:Int,it: NiLocation)
interface OnQsRecordItemClickListener : BaseClickListener {
fun onQsRecordList(tag: String, list: MutableList<String>)
}
interface ONNoteItemClickListener : BaseClickListener {
fun onNote(tag: String, noteId: String)
}
interface OnNiLocationItemListener : BaseClickListener {
fun onNiLocation(tag: String, index: Int, it: NiLocation)
}