增加数据渲染

This commit is contained in:
squallzhjch
2023-04-19 15:40:00 +08:00
parent 88326d3247
commit a9def220ce
43 changed files with 1760 additions and 482 deletions

View File

@@ -0,0 +1,102 @@
package com.navinfo.collect.library.data.entity
import com.navinfo.collect.library.utils.GeometryToolsKt
import io.realm.RealmObject
import io.realm.RealmSet
import io.realm.annotations.PrimaryKey
import io.realm.annotations.RealmClass
/**
* @author zhjch
* @version V1.0
* @ClassName: Rd_qcRecord
* @Date 2016/1/12
* @Description: ${TODO}(质检对象)
*/
@RealmClass
open class QsRecordBean @JvmOverloads constructor(
/**
* id 主键
*
*/
@PrimaryKey
var id: String = "",
/**
* 关联要素id
*/
var elementId: String = "",
/**
* linkPid 绑定的道路ID
*/
var linkId: String = "",
/**
*问题分类
*/
var classType: String = "",
/**
* 问题类型
*/
var type: String = "",
/**
* 问题现象
*/
var phenomenon: String = "",
/**
* 描述信息
*/
var description: String = "",
/**
* 问题环节
*/
var problemLink: String = "",
/**
* 问题原因
* 根本原因RCA
*/
var cause: String = "",
/**
* 质检员ID
*/
var checkUserId: String = "",
/**
* 质检日期
*/
var checkTime: String = "",
/**
* 确认人
*/
var confirmUserId: String = "",
/**
* 状态 0 无; 1 删除2 更新3 新增;
*/
var t_lifecycle: Int = 3,
/**
* 问题记录提交状态 0 未提交1 已提交;
*/
var t_status: Int = 0,
/**
* 显示坐标
*/
// var geometry: String = "",
/**
* 显示坐标
*/
var guideGeometry: String = "",
) : RealmObject() {
private val tileX = RealmSet<Int>() // x方向的tile编码
private val tileY = RealmSet<Int>() // y方向的tile编码
var geometry: String = ""
set(value) {
field = value
// 根据geometry自动计算当前要素的x-tile和y-tile
GeometryToolsKt.getTileXByGeometry(value, tileX)
GeometryToolsKt.getTileYByGeometry(value, tileY)
}
}

View File

@@ -0,0 +1,14 @@
package com.navinfo.collect.library.map
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@Parcelize
data class GeoPoint(
var latitude: Double = 0.0,
var longitude: Double = 0.0
) : Parcelable {
fun toGeometry(): String {
return "POINT($longitude $latitude)"
}
}

View File

@@ -2,6 +2,7 @@ package com.navinfo.collect.library.map
import android.content.Context
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.map.handler.*
import com.navinfo.collect.library.map.maphandler.MeasureLayerHandler
import com.navinfo.collect.library.map.handler.ViewportHandler
@@ -23,7 +24,7 @@ class NIMapController {
lateinit var measureLayerHandler: MeasureLayerHandler
fun init(context: Context, mapView: NIMapView, options: NIMapOptions? = null, mapPath: String) {
fun init(context: AppCompatActivity, mapView: NIMapView, options: NIMapOptions? = null, mapPath: String) {
Constant.MAP_PATH = mapPath
layerManagerHandler = LayerManagerHandler(context, mapView)
locationLayerHandler = LocationLayerHandler(context, mapView)
@@ -37,5 +38,6 @@ class NIMapController {
mapView.setOptions(options)
}
}

View File

@@ -3,7 +3,6 @@ package com.navinfo.collect.library.map;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -15,37 +14,21 @@ import androidx.annotation.Nullable;
import com.navinfo.collect.library.R;
import com.navinfo.collect.library.map.layers.NaviMapScaleBar;
import com.navinfo.collect.library.map.source.MapLifeDBTileSource;
import com.navinfo.collect.library.map.source.MapLifeNiLocationTileDataSource;
import com.navinfo.collect.library.map.source.MapLifeNiLocationTileSource;
import com.navinfo.collect.library.system.Constant;
import org.oscim.android.MapPreferences;
import org.oscim.android.MapView;
import org.oscim.core.GeoPoint;
import org.oscim.android.theme.AssetsRenderTheme;
import org.oscim.core.MapPosition;
import org.oscim.core.Tile;
import org.oscim.event.Event;
import org.oscim.event.Gesture;
import org.oscim.event.GestureListener;
import org.oscim.layers.GroupLayer;
import org.oscim.layers.Layer;
import org.oscim.layers.TileGridLayer;
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.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;
/**
@@ -125,14 +108,14 @@ public final class NIMapView extends RelativeLayout {
*
* @param point
*/
void onMapClick(GeoPoint point);
void onMapClick(com.navinfo.collect.library.map.GeoPoint point);
/**
* 地图内 Poi 单击事件回调函数
*
* @param poi
*/
void onMapPoiClick(GeoPoint poi);
// void onMapPoiClick(GeoPoint poi);
}
/**
@@ -218,10 +201,8 @@ public final class NIMapView extends RelativeLayout {
this.mContext = context;
mapView = rootView.findViewById(R.id.base_map_view);
// map = new NIMap(this);
compassImage = rootView.findViewById(R.id.navinfo_map_compass);
initMapGroup(); // 初始化图层组
// mLayerManager = new NILayerManager(context, getVtmMap());
logoImage = rootView.findViewById(R.id.navinfo_map_logo);
mRotateAnimation = new NIRotateAnimation(compassImage);
@@ -251,6 +232,7 @@ public final class NIMapView extends RelativeLayout {
}
});
// 增加比例尺图层
NaviMapScaleBar naviMapScaleBar = new NaviMapScaleBar(getVtmMap());
naviMapScaleBar.initScaleBarLayer(GLViewport.Position.BOTTOM_LEFT, 25, 60);
@@ -302,6 +284,9 @@ public final class NIMapView extends RelativeLayout {
zoomLayout = rootView.findViewById(R.id.navinfo_map_zoom_layer);
switchTileVectorLayerTheme(MAP_THEME.DEFAULT);
MapEventsReceiver mapEventReceiver = new MapEventsReceiver(mapView.map());
getVtmMap().layers().add(mapEventReceiver);
}
@@ -923,7 +908,7 @@ public final class NIMapView extends RelativeLayout {
GeoPoint geoPoint = mMap.viewport().fromScreenPoint(e.getX(), e.getY());
if (g instanceof Gesture.Tap) { // 单击事件
if (mapClickListener != null) {
mapClickListener.onMapClick(geoPoint);
mapClickListener.onMapClick(new com.navinfo.collect.library.map.GeoPoint(geoPoint.getLatitude(), geoPoint.getLongitude()));
}
} else if (g instanceof Gesture.DoubleTap) { // 双击
if (mapDoubleClickListener != null) {
@@ -934,17 +919,6 @@ public final class NIMapView extends RelativeLayout {
mapLongClickListener.onMapLongClick(geoPoint);
}
}
setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(GeoPoint point) {
}
@Override
public void onMapPoiClick(GeoPoint poi) {
}
});
return false;
}
}
@@ -952,7 +926,7 @@ public final class NIMapView extends RelativeLayout {
/**
* 设置地图的点击事件
*/
public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
public void setOnMapClickListener(OnMapClickListener listener) {
this.mapClickListener = listener;
}

View File

@@ -1,11 +1,12 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.Layer
abstract class BaseHandler(context: Context, mapView: NIMapView) {
protected val mContext: Context = context
abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
protected val mContext: AppCompatActivity = context
protected val mMapView: NIMapView = mapView
fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) {
@@ -19,4 +20,11 @@ abstract class BaseHandler(context: Context, mapView: NIMapView) {
mMapView.vtmMap.layers().remove(layer)
}
fun setOnMapClickListener(listener: NIMapView.OnMapClickListener) {
mMapView.setOnMapClickListener(listener)
}
fun removeOnMapClickListener() {
mMapView.setOnMapClickListener(null)
}
}

View File

@@ -1,15 +1,21 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource
import com.navinfo.collect.library.system.Constant
import io.realm.Realm
import io.realm.kotlin.where
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.Cache
import okhttp3.OkHttpClient
import org.oscim.backend.CanvasAdapter
import org.oscim.backend.canvas.Paint
import org.oscim.layers.GroupLayer
import org.oscim.layers.Layer
import org.oscim.layers.tile.bitmap.BitmapTileLayer
import org.oscim.layers.tile.buildings.BuildingLayer
import org.oscim.layers.tile.vector.VectorTileLayer
import org.oscim.layers.tile.vector.labeling.LabelLayer
@@ -20,11 +26,22 @@ import java.io.File
/**
* Layer 操作
*/
class LayerManagerHandler(context: Context, mapView: NIMapView) :
class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView) :
BaseHandler(context, mapView) {
private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理
: GroupLayer? = null
/**
* 默认文字颜色
*/
private val mDefaultTextColor = "#4E55AF"
/**
* 文字画笔
*/
private lateinit var paint: Paint
init {
initMap()
}
@@ -36,8 +53,9 @@ class LayerManagerHandler(context: Context, mapView: NIMapView) :
loadBaseMap()
mMapView.switchTileVectorLayerTheme(NIMapView.MAP_THEME.DEFAULT)
//初始化之间数据图层
initQsRecordDataLayer()
mMapView.vtmMap.updateMap()
// initVectorTileLayer()
// initMapLifeSource()
}
@@ -46,7 +64,7 @@ class LayerManagerHandler(context: Context, mapView: NIMapView) :
* 切换基础底图样式
*/
fun loadBaseMap() {
//给地图layer分组
if (baseGroupLayer == null) {
baseGroupLayer = GroupLayer(mMapView.vtmMap)
addLayer(baseGroupLayer!!, NIMapView.LAYER_GROUPS.BASE)
@@ -90,8 +108,11 @@ class LayerManagerHandler(context: Context, mapView: NIMapView) :
}
}
baseLayer.tileSource = urlTileSource
//增加基础路网图层
it.layers.add(baseLayer)
//增加建筑图层
it.layers.add(BuildingLayer(mMapView.vtmMap, baseLayer))
//增加文字图层
it.layers.add(LabelLayer(mMapView.vtmMap, baseLayer))
for (layer in it.layers) {
addLayer(layer, NIMapView.LAYER_GROUPS.BASE)
@@ -101,26 +122,45 @@ class LayerManagerHandler(context: Context, mapView: NIMapView) :
}
}
private fun getRasterTileLayer(
url: String?,
tilePath: String?,
useCache: Boolean
): Layer {
val builder = OkHttpClient.Builder()
val mTileSource =
NavinfoMapRastorTileSource.builder(url).tilePath(tilePath)
.httpFactory(OkHttpFactory(builder)).build()
// 如果使用缓存
if (useCache) {
val cacheDirectory =
File(Constant.MAP_PATH, "cache")
val cacheSize = 300 * 1024 * 1024 // 300 MB
val cache = Cache(cacheDirectory, cacheSize.toLong())
builder.cache(cache)
}
private fun initQsRecordDataLayer() {
paint = CanvasAdapter.newPaint()
paint.setTypeface(Paint.FontFamily.DEFAULT, Paint.FontStyle.NORMAL)
paint.setTextSize(13 * CanvasAdapter.getScale())
paint.strokeWidth = 2 * CanvasAdapter.getScale()
paint.color = Color.parseColor(mDefaultTextColor)
return BitmapTileLayer(mMapView.vtmMap, mTileSource)
mContext.lifecycleScope.launch(Dispatchers.IO) {
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
val list = realm.where<QsRecordBean>().findAll()
paint.setColor(Color.parseColor(mDefaultTextColor))
}
realm.close()
}
}
// private fun getRasterTileLayer(
// url: String?,
// tilePath: String?,
// useCache: Boolean
// ): Layer {
// val builder = OkHttpClient.Builder()
// val mTileSource =
// NavinfoMapRastorTileSource.builder(url).tilePath(tilePath)
// .httpFactory(OkHttpFactory(builder)).build()
// // 如果使用缓存
// if (useCache) {
// val cacheDirectory =
// File(Constant.MAP_PATH, "cache")
// val cacheSize = 300 * 1024 * 1024 // 300 MB
// val cache = Cache(cacheDirectory, cacheSize.toLong())
// builder.cache(cache)
// }
//
// return BitmapTileLayer(mMapView.vtmMap, mTileSource)
// }
}
/**

View File

@@ -8,6 +8,7 @@ import com.baidu.location.BDLocation
import com.baidu.location.LocationClient
import com.baidu.location.LocationClientOption
import com.baidu.location.LocationClientOption.LocationMode
import com.navinfo.collect.library.map.GeoPoint
import com.navinfo.collect.library.map.NIMapView
import org.oscim.layers.LocationLayer
@@ -142,6 +143,13 @@ class LocationLayerHandler(context: Context, mapView: NIMapView) : BaseHandler(c
mMapView.vtmMap.animator().animateTo(300, mapPosition)
}
}
fun getCurrentGeoPoint(): GeoPoint? {
mCurrentLocation?.let {
return GeoPoint(it.latitude, it.longitude)
}
return null
}
}
/**

View File

@@ -1,75 +1,101 @@
package com.navinfo.collect.library.map.handler
import android.content.Context
import android.graphics.BitmapFactory
import com.navinfo.collect.library.R
import com.navinfo.collect.library.map.GeoPoint
import com.navinfo.collect.library.map.NIMapView
import com.navinfo.collect.library.utils.StringUtil
import org.oscim.core.GeoPoint
import org.oscim.android.canvas.AndroidBitmap
import org.oscim.layers.marker.ItemizedLayer
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.marker.MarkerInterface
import org.oscim.layers.marker.MarkerItem
import org.oscim.layers.marker.MarkerSymbol
/**
* marker 操作
*/
open class MarkHandler(context: Context, mapView:NIMapView) :
BaseHandler(context, mapView), OnItemGestureListener<MarkerInterface> {
class MarkHandler(context: Context, mapView: NIMapView) :
BaseHandler(context, mapView) {
// //增加marker
// fun addMarker(
// geoPoint: GeoPoint,
// title: String?,
// description: String? = ""
// ): MarkerItem {
// var marker: MarkerItem? = null
// for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
// if (e is MarkerItem && e.title == title) {
// marker = e;
// break;
// }
// }
// if (marker == null) {
// var tempTitle = title;
// if (tempTitle.isNullOrBlank()) {
// tempTitle = StringUtil.createUUID();
// }
// val marker = MarkerItem(
// tempTitle,
// description,
// geoPoint
// )
// mMapView.layerManager.defaultMarkerLayer.addItem(marker);
// mMapView.vtmMap.updateMap(true)
// return marker
// } else {
// marker.description = description
// marker.geoPoint = geoPoint
// mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
// mMapView.layerManager.defaultMarkerLayer.addItem(marker)
// mMapView.vtmMap.updateMap(true)
// return marker
// }
// }
//
// fun removeMarker(title: String) {
// var marker: MarkerItem? = null
// for (e in mMapView.layerManager.defaultMarkerLayer.itemList) {
// if (e is MarkerItem && e.title == title) {
// marker = e;
// break;
// }
// }
// if (marker != null) {
// mMapView.layerManager.defaultMarkerLayer.removeItem(marker)
// mMapView.vtmMap.updateMap(true)
// }
// }
//
override fun onItemSingleTapUp(index: Int, item: MarkerInterface): Boolean {
return false
// //默认marker图层
private var mDefaultMarkerLayer: ItemizedLayer
init {
//新增marker图标样式
val mDefaultBitmap =
AndroidBitmap(BitmapFactory.decodeResource(context.resources, R.mipmap.marker));
val markerSymbol = MarkerSymbol(
mDefaultBitmap,
MarkerSymbol.HotspotPlace.BOTTOM_CENTER
);
//新增marker图层
mDefaultMarkerLayer = ItemizedLayer(
mapView.vtmMap,
ArrayList<MarkerInterface>(),
markerSymbol,
object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
return false
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return false
}
}
)
addLayer(mDefaultMarkerLayer, NIMapView.LAYER_GROUPS.OPERATE);
}
override fun onItemLongPress(index: Int, item: MarkerInterface): Boolean {
return false
//增加marker
fun addMarker(
geoPoint: GeoPoint,
title: String?,
description: String? = ""
) {
var marker: MarkerItem? = null
for (e in mDefaultMarkerLayer.itemList) {
if (e is MarkerItem && e.title == title) {
marker = e
break
}
}
if (marker == null) {
var tempTitle = title;
if (tempTitle.isNullOrBlank()) {
tempTitle = StringUtil.createUUID();
}
val marker = MarkerItem(
tempTitle,
description,
org.oscim.core.GeoPoint(geoPoint.latitude, geoPoint.longitude)
)
mDefaultMarkerLayer.addItem(marker);
mMapView.vtmMap.updateMap(true)
} else {
marker.description = description
marker.geoPoint = org.oscim.core.GeoPoint(geoPoint.latitude, geoPoint.longitude)
mDefaultMarkerLayer.removeItem(marker)
mDefaultMarkerLayer.addItem(marker)
mMapView.vtmMap.updateMap(true)
}
}
fun removeMarker(title: String) {
var marker: MarkerItem? = null
for (e in mDefaultMarkerLayer.itemList) {
if (e is MarkerItem && e.title == title) {
marker = e
break
}
}
if (marker != null) {
mDefaultMarkerLayer.removeItem(marker)
mMapView.vtmMap.updateMap(true)
}
}
}

View File

@@ -7,7 +7,6 @@ import org.oscim.core.GeoPoint
import org.oscim.core.Point
open class ViewportHandler(context: Context, mapView: NIMapView) : BaseHandler(context, mapView) {
/**
* Set pivot horizontal / vertical relative to view center in [-1, 1].
* e.g. pivotY 0.5 is usually preferred for navigation, moving center to 25% of view height.
@@ -73,7 +72,7 @@ open class ViewportHandler(context: Context, mapView: NIMapView) : BaseHandler(c
px: Float, py: Float
): Map<String, Any> {
val geo = mMapView.vtmMap.viewport().fromScreenPoint(px,py)
val geo = mMapView.vtmMap.viewport().fromScreenPoint(px, py)
return mapOf(
"latitude" to geo.latitude,

View File

@@ -10,7 +10,7 @@ class GeometryToolsKt {
/**
* 根据给定的geometry计算其横跨的20级瓦片Y值
*/
fun getTileYByGeometry(wkt: String, tileYSet: MutableSet<Int?>): Set<Int?>? {
fun getTileYByGeometry(wkt: String, tileYSet: MutableSet<Int?>){
val reader = WKTReader()
val geometry = reader.read(wkt);
@@ -20,6 +20,7 @@ class GeometryToolsKt {
if (tileYSet == null) {
tileYSet = RealmSet()
}
tileYSet.clear()
val envelope = geometry.envelope
if (envelope != null) {
val coordinates = envelope.coordinates
@@ -48,13 +49,12 @@ class GeometryToolsKt {
}
}
println("YGeometry-time:" + (System.currentTimeMillis() - startTime))
return tileYSet
}
/**
* 根据给定的geometry计算其横跨的20级瓦片X值
*/
fun getTileXByGeometry(wkt: String, tileXSet: MutableSet<Int?>): Set<Int?>? {
fun getTileXByGeometry(wkt: String, tileXSet: MutableSet<Int?>) {
val reader = WKTReader()
val geometry = reader.read(wkt);
@@ -63,6 +63,7 @@ class GeometryToolsKt {
if (tileXSet == null) {
tileXSet = RealmSet()
}
tileXSet.clear()
if (geometry != null) {
val envelope = geometry.envelope
if (envelope != null) {
@@ -92,7 +93,6 @@ class GeometryToolsKt {
}
}
println("XGeometry-time:" + (System.currentTimeMillis() - startTime))
return tileXSet
}
fun getMasterPoint(wkt: String): String {