diff --git a/app/src/main/java/com/navinfo/omqs/OMQSApplication.kt b/app/src/main/java/com/navinfo/omqs/OMQSApplication.kt index 9d0ea133..cfaf898c 100644 --- a/app/src/main/java/com/navinfo/omqs/OMQSApplication.kt +++ b/app/src/main/java/com/navinfo/omqs/OMQSApplication.kt @@ -12,9 +12,7 @@ import dagger.hilt.android.HiltAndroidApp import org.videolan.vlc.Util import io.realm.Realm import io.realm.RealmConfiguration -import kotlinx.coroutines.launch import java.io.File -import java.math.BigInteger import java.security.MessageDigest @HiltAndroidApp diff --git a/app/src/main/java/com/navinfo/omqs/db/RealmOperateHelper.kt b/app/src/main/java/com/navinfo/omqs/db/RealmOperateHelper.kt index e4b1d608..ced6dcb2 100644 --- a/app/src/main/java/com/navinfo/omqs/db/RealmOperateHelper.kt +++ b/app/src/main/java/com/navinfo/omqs/db/RealmOperateHelper.kt @@ -15,6 +15,7 @@ import org.locationtech.spatial4j.distance.DistanceUtils import org.oscim.core.GeoPoint import org.oscim.core.MercatorProjection import javax.inject.Inject +import kotlin.streams.toList class RealmOperateHelper() { @@ -25,29 +26,126 @@ class RealmOperateHelper() { * @param point 点位经纬度信息 * @param buffer 点位的外扩距离 * @param bufferType 点位外扩距离的单位: 米-Meter,像素-PIXEL - * @param order 是否需要排序 + * @param sort 是否需要排序 * */ - suspend fun queryLink(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE, order: Boolean = false): MutableList<RenderEntity> { + suspend fun queryLink(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE, sort: Boolean = false): MutableList<RenderEntity> { + val result = mutableListOf<RenderEntity>() withContext(Dispatchers.IO) { val polygon = getPolygonFromPoint(point, buffer, bufferType) // 根据polygon查询相交的tile号 val tileXSet = mutableSetOf<Int>() + tileXSet.toString() GeometryToolsKt.getTileXByGeometry(polygon.toString(), tileXSet) val tileYSet = mutableSetOf<Int>() GeometryToolsKt.getTileYByGeometry(polygon.toString(), tileYSet) + // 对tileXSet和tileYSet查询最大最小值 + val xStart = tileXSet.stream().min(Comparator.naturalOrder()).orElse(null) + val xEnd = tileXSet.stream().max(Comparator.naturalOrder()).orElse(null) + val yStart = tileYSet.stream().min(Comparator.naturalOrder()).orElse(null) + val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null) // 查询realm中对应tile号的数据 - Realm.getDefaultInstance().where(RenderEntity::class.java).equalTo("table", "HAD_LINK") + val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java) + .equalTo("table", "HAD_LINK") + .and() + .rawPredicate("tileX>=$xStart and tileX<=$xEnd and tileY>=$yStart and tileY<=$yEnd") + .findAll() + // 将获取到的数据和查询的polygon做相交,只返回相交的数据 + val queryResult = realmList?.stream()?.filter { + polygon.intersects(it.wkt) + }?.toList() + queryResult?.let { + result.addAll(queryResult) + } + if (sort) { + result.clear() + result.addAll(sortRenderEntity(point, result)) + } } - return mutableListOf() + return result + } + /** + * 根据当前点位查询匹配的除Link外的其他要素数据 + * @param point 点位经纬度信息 + * @param buffer 点位的外扩距离 + * @param bufferType 点位外扩距离的单位: 米-Meter,像素-PIXEL + * @param sort 是否需要排序 + * */ + suspend fun queryElement(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE, sort: Boolean = false): MutableList<RenderEntity> { + val result = mutableListOf<RenderEntity>() + withContext(Dispatchers.IO) { + val polygon = getPolygonFromPoint(point, buffer, bufferType) + // 根据polygon查询相交的tile号 + val tileXSet = mutableSetOf<Int>() + tileXSet.toString() + GeometryToolsKt.getTileXByGeometry(polygon.toString(), tileXSet) + val tileYSet = mutableSetOf<Int>() + GeometryToolsKt.getTileYByGeometry(polygon.toString(), tileYSet) + + // 对tileXSet和tileYSet查询最大最小值 + val xStart = tileXSet.stream().min(Comparator.naturalOrder()).orElse(null) + val xEnd = tileXSet.stream().max(Comparator.naturalOrder()).orElse(null) + val yStart = tileYSet.stream().min(Comparator.naturalOrder()).orElse(null) + val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null) + // 查询realm中对应tile号的数据 + val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java) + .notEqualTo("table", "HAD_LINK") + .and() + .rawPredicate("tileX>=$xStart and tileX<=$xEnd and tileY>=$yStart and tileY<=$yEnd") + .findAll() + // 将获取到的数据和查询的polygon做相交,只返回相交的数据 + val queryResult = realmList?.stream()?.filter { + polygon.intersects(it.wkt) + }?.toList() + queryResult?.let { + result.addAll(queryResult) + } + if (sort) { + result.clear() + result.addAll(sortRenderEntity(point, result)) + } + } + return result + } + + /** + * 根据linkPid查询关联的要素(除去Link数据) + * @param point 点位经纬度信息 + * @param buffer 点位的外扩距离 + * @param bufferType 点位外扩距离的单位: 米-Meter,像素-PIXEL + * @param sort 是否需要排序 + * */ + suspend fun queryLinkByLinkPid(linkPid: String): MutableList<RenderEntity> { + val result = mutableListOf<RenderEntity>() + withContext(Dispatchers.IO) { + val realmList = Realm.getDefaultInstance().where(RenderEntity::class.java) + .notEqualTo("table", "HAD_LINK") + .and() + .equalTo("properties['LINK_PID']", linkPid) + .findAll() + result.addAll(realmList) + } + return result + } + + /** + * 根据给定的点位对数据排序 + * @param point 点位经纬度信息 + * @param unSortList 未排序的数据 + * @return 排序后的数据 + * */ + fun sortRenderEntity(point: Point, unSortList: MutableList<RenderEntity>): List<RenderEntity> { + val sortList = unSortList.stream().sorted { renderEntity, renderEntity2 -> + val near = point.distance(renderEntity.wkt) - point.distance(renderEntity2.wkt) + if (near<0) -1 else 1 + }.toList() + return sortList } private fun getPolygonFromPoint(point: Point, buffer: Double = DEFAULT_BUFFER, bufferType: BUFFER_TYPE = DEFAULT_BUFFER_TYPE): Polygon { // 首先计算当前点位的buffer组成的geometry val wkt: Polygon = if (bufferType == BUFFER_TYPE.METER) { // 如果单位是米 - // 计算米和地球角度之间的关系,在Spatial4J中,经度和纬度的单位是度,而不是米。因此,将距离从米转换为度需要使用一个转换因子,这个转换因子是由地球的周长和360度之间的比例计算得出的。 - // 在这个例子中,使用的转换因子是111000.0,这是因为地球的周长约为40075公里,而每个经度的距离大约是地球周长的1/360,因此每个经度的距离约为111.32公里 - val distanceDegrees = DistanceUtils.dist2Degrees(buffer, DistanceUtils.EARTH_MEAN_RADIUS_KM) * 111000.0 + val distanceDegrees = GeometryTools.convertDistanceToDegree(buffer, point.y) // 计算外扩矩形 BufferOp.bufferOp(point, distanceDegrees) as Polygon } else { // 如果单位是像素,需要根据当前屏幕像素计算出经纬度变化 diff --git a/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt b/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt index 503705cf..37e6b7f5 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainActivity.kt @@ -1,21 +1,18 @@ package com.navinfo.omqs.ui.activity.map import android.os.Bundle -import android.util.Log import androidx.activity.viewModels import androidx.core.view.WindowCompat import androidx.databinding.DataBindingUtil import androidx.lifecycle.ViewModelProvider import com.blankj.utilcode.util.ToastUtils import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.viewModelScope import androidx.navigation.findNavController import com.navinfo.collect.library.map.NIMapController import com.navinfo.collect.library.map.handler.NiLocationListener import com.navinfo.omqs.Constant import com.navinfo.omqs.R import com.navinfo.omqs.databinding.ActivityMainBinding -import com.navinfo.omqs.db.TraceDataBase import com.navinfo.omqs.http.offlinemapdownload.OfflineMapDownloadManager import com.navinfo.omqs.system.SystemConstant import com.navinfo.omqs.ui.activity.BaseActivity @@ -50,7 +47,8 @@ class MainActivity : BaseActivity() { this, binding.mainActivityMap, null, - Constant.MAP_PATH + Constant.MAP_PATH, + Constant.DATA_PATH+ SystemConstant.USER_ID+"/trace.sqlite" ) //关联生命周期 binding.lifecycleOwner = this @@ -78,6 +76,7 @@ class MainActivity : BaseActivity() { }) //显示轨迹图层 // mapController.layerManagerHandler.showNiLocationLayer(Constant.DATA_PATH+ SystemConstant.USER_ID+"/trace.sqlite") + mapController.layerManagerHandler.showNiLocationLayer() } override fun onPause() { @@ -108,6 +107,8 @@ class MainActivity : BaseActivity() { */ fun openCamera() { binding.viewModel!!.onClickCameraButton(this) + //显示轨迹图层 + //binding!!.viewModel!!.onClickCameraButton(this) } /** diff --git a/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt b/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt index d5f357e0..76aba0e5 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/activity/map/MainViewModel.kt @@ -8,6 +8,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.navigation.findNavController import com.blankj.utilcode.util.ToastUtils +import com.navinfo.collect.library.data.dao.impl.TraceDataBase import com.navinfo.collect.library.data.entity.NiLocation import com.navinfo.collect.library.map.NIMapController import com.navinfo.collect.library.map.handler.OnQsRecordItemClickListener @@ -15,12 +16,12 @@ import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryToolsKt import com.navinfo.omqs.Constant import com.navinfo.omqs.R -import com.navinfo.omqs.db.TraceDataBase import com.navinfo.omqs.system.SystemConstant import com.navinfo.omqs.ui.dialog.CommonDialog import com.navinfo.omqs.ui.manager.TakePhotoManager import dagger.hilt.android.lifecycle.HiltViewModel import io.realm.RealmSet +import org.oscim.core.GeoPoint import org.videolan.libvlc.LibVlcUtil import javax.inject.Inject @@ -105,10 +106,7 @@ class MainViewModel @Inject constructor( if (niLocationList != null && niLocationList.size > 0) { var niLocation = niLocationList[0] - var doubleArray = doubleArrayOf() - doubleArray[0] = niLocation.longitude - doubleArray[1] = niLocation.latitude - val geometry = GeometryTools.createGeometry(doubleArray) + val geometry = GeometryTools.createGeometry(GeoPoint(niLocation.latitude,niLocation.longitude)) val tileX = RealmSet<Int>() GeometryToolsKt.getTileXByGeometry(geometry.toString(), tileX) val tileY = RealmSet<Int>() diff --git a/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterViewModel.kt b/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterViewModel.kt index 6c91bf36..24a5bdb2 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterViewModel.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterViewModel.kt @@ -225,7 +225,9 @@ class PersonalCenterViewModel @Inject constructor( fun readRealmData() { viewModelScope.launch(Dispatchers.IO) { - realmOperateHelper.queryLink(GeometryTools.createPoint(115.685817,28.62759)) +// val result = realmOperateHelper.queryLink(GeometryTools.createPoint(115.685817,28.62759)) + val result = realmOperateHelper.queryLinkByLinkPid("84206617008217069") + Log.d("xiaoyan", result.toString()) } } } \ No newline at end of file diff --git a/collect-library/src/main/assets/editormarker.xml b/collect-library/src/main/assets/editormarker.xml index 1cbff96f..7ca48369 100644 --- a/collect-library/src/main/assets/editormarker.xml +++ b/collect-library/src/main/assets/editormarker.xml @@ -1530,4 +1530,23 @@ <symbol src="assets:symbols/traffic_signal.svg" /> </m> </m> + + <m k="nav_style"> + <m v="symbol_object_line"> + <m k="rule" zoom-min="15" zoom-max="22"> + <!-- 蓝色黑色间隔线 --> + <m v="blue_link"> + <line stroke="#00000000" stipple-stroke="#00000000" dasharray="20,20" fix="true" width="0.1" /> + </m> + <!-- 黄色线 --> + <m v="yellow_link"> + <line stroke="#f4ea2a" width="0.1" stipple-width="0.1"/> + </m> + </m> + <line stroke="#33aaaa" width="0.3" stipple-width="0.5"/> + </m> + <m v="symbol_track_point" zoom-min="10" zoom-max="25"> + <symbol src="assets:symbols/dot_blue.svg" /> + </m> + </m> </rendertheme> \ No newline at end of file diff --git a/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/MapLifeDataBase.java b/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/MapLifeDataBase.java index bb98e07a..382f7ea1 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/MapLifeDataBase.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/MapLifeDataBase.java @@ -10,7 +10,6 @@ import androidx.sqlite.db.SupportSQLiteDatabase; import com.navinfo.collect.library.data.entity.CheckManager; import com.navinfo.collect.library.data.entity.Element; import com.navinfo.collect.library.data.entity.LayerManager; -import com.navinfo.collect.library.data.entity.NiLocation; import com.navinfo.collect.library.data.entity.Project; import com.navinfo.collect.library.data.entity.TileElement; import com.tencent.wcdb.database.SQLiteCipherSpec; @@ -25,7 +24,7 @@ import com.tencent.wcdb.room.db.WCDBDatabase; import java.util.ArrayList; import java.util.List; -@Database(entities = {Element.class, TileElement.class, LayerManager.class, Project.class, NiLocation.class, CheckManager.class},version = 1, exportSchema = false) +@Database(entities = {Element.class, TileElement.class, LayerManager.class, Project.class, CheckManager.class},version = 1, exportSchema = false) public abstract class MapLifeDataBase extends RoomDatabase { // marking the instance as volatile to ensure atomic access to the variable /** @@ -38,11 +37,6 @@ public abstract class MapLifeDataBase extends RoomDatabase { */ public abstract IElementDao getElementDao(); - /** - * 地图坐标库类 - */ - public abstract INiLocationDao getNiLocationDao(); - /** * 图层要素数据库类 */ diff --git a/app/src/main/java/com/navinfo/omqs/db/TraceDataBase.java b/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/TraceDataBase.java similarity index 98% rename from app/src/main/java/com/navinfo/omqs/db/TraceDataBase.java rename to collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/TraceDataBase.java index 99d2ae2c..99e861bd 100644 --- a/app/src/main/java/com/navinfo/omqs/db/TraceDataBase.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/dao/impl/TraceDataBase.java @@ -1,14 +1,15 @@ -package com.navinfo.omqs.db; +package com.navinfo.collect.library.data.dao.impl; import android.content.Context; import android.os.AsyncTask; import android.util.Log; + import androidx.annotation.NonNull; import androidx.room.Database; import androidx.room.Room; import androidx.room.RoomDatabase; import androidx.sqlite.db.SupportSQLiteDatabase; -import com.navinfo.collect.library.data.dao.impl.INiLocationDao; + import com.navinfo.collect.library.data.entity.NiLocation; import com.tencent.wcdb.database.SQLiteCipherSpec; import com.tencent.wcdb.database.SQLiteDatabase; diff --git a/collect-library/src/main/java/com/navinfo/collect/library/data/entity/RenderEntity.kt b/collect-library/src/main/java/com/navinfo/collect/library/data/entity/RenderEntity.kt index 2627658d..b4842cb2 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/data/entity/RenderEntity.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/entity/RenderEntity.kt @@ -6,6 +6,7 @@ import com.navinfo.collect.library.utils.GeometryToolsKt import io.realm.RealmDictionary import io.realm.RealmObject import io.realm.RealmSet +import io.realm.annotations.Ignore import io.realm.annotations.PrimaryKey import org.locationtech.jts.geom.Coordinate import org.locationtech.jts.geom.Geometry @@ -28,7 +29,15 @@ open class RenderEntity(): RealmObject() { // 根据geometry自动计算当前要素的x-tile和y-tile GeometryToolsKt.getTileXByGeometry(value, tileX) GeometryToolsKt.getTileYByGeometry(value, tileY) + // 根据传入的geometry文本,自动转换为Geometry对象 + try { + wkt = GeometryTools.createGeometry(value) + } catch (e: Exception) { + + } } + @Ignore + var wkt: Geometry? = null var properties: RealmDictionary<String?> = RealmDictionary() val tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 val tileY: RealmSet<Int> = RealmSet() // y方向的tile编码 diff --git a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/BaseDataHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/BaseDataHandler.kt index e6064283..35a47e72 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/BaseDataHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/BaseDataHandler.kt @@ -1,9 +1,9 @@ package com.navinfo.collect.library.data.handler import android.content.Context -import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase +import androidx.room.RoomDatabase -open class BaseDataHandler(context: Context, dataBase: MapLifeDataBase) { +open class BaseDataHandler(context: Context, dataBase: RoomDatabase) { protected val mContext: Context = context; - protected val mDataBase: MapLifeDataBase = dataBase; + protected val mDataBase: RoomDatabase = dataBase; } \ No newline at end of file diff --git a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataNiLocationHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataNiLocationHandler.kt index 5415baee..d5e82ce4 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataNiLocationHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataNiLocationHandler.kt @@ -8,6 +8,7 @@ import android.os.Handler import android.os.Looper import android.util.Log import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase +import com.navinfo.collect.library.data.dao.impl.TraceDataBase import com.navinfo.collect.library.data.entity.* import com.navinfo.collect.library.data.entity.DataLayerItemType.* import com.navinfo.collect.library.utils.GeometryTools @@ -25,7 +26,7 @@ import kotlin.concurrent.thread open class -DataNiLocationHandler(context: Context, dataBase: MapLifeDataBase) : +DataNiLocationHandler(context: Context, dataBase: TraceDataBase) : BaseDataHandler(context, dataBase) { /** @@ -58,11 +59,11 @@ DataNiLocationHandler(context: Context, dataBase: MapLifeDataBase) : } } - val niLocationLoad = mDataBase.niLocationDao.find(niLocation.id); + val niLocationLoad = (mDataBase as TraceDataBase).niLocationDao.find(niLocation.id); if(niLocationLoad!=null){ - mDataBase.niLocationDao.update(niLocation) + (mDataBase as TraceDataBase).niLocationDao.update(niLocation) }else{ - mDataBase.niLocationDao.insert(niLocation) + (mDataBase as TraceDataBase).niLocationDao.insert(niLocation) } Handler(Looper.getMainLooper()).post { callback.invoke(true, "") @@ -89,7 +90,7 @@ DataNiLocationHandler(context: Context, dataBase: MapLifeDataBase) : "uuid=?", arrayOf("'${niLocation.id}'") ) - mDataBase.niLocationDao.delete(niLocation); + (mDataBase as TraceDataBase).niLocationDao.delete(niLocation); } catch (e: Throwable) { Handler(Looper.getMainLooper()).post { callback.invoke(false, "${e.message}") diff --git a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataProjectHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataProjectHandler.kt index e1bf43c5..72f12d81 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataProjectHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/data/handler/DataProjectHandler.kt @@ -4,6 +4,7 @@ import android.content.Context import android.os.Handler import android.os.Looper import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase +import com.navinfo.collect.library.data.dao.impl.TraceDataBase import com.navinfo.collect.library.data.entity.Project import kotlin.concurrent.thread @@ -22,7 +23,7 @@ open class DataProjectHandler(context: Context, dataBase: MapLifeDataBase) : ) { thread(start = true) { try { - mDataBase.projectManagerDao.insert(project) + (mDataBase as MapLifeDataBase).projectManagerDao.insert(project) Handler(Looper.getMainLooper()).post { callback.invoke(true, "") } @@ -41,7 +42,7 @@ open class DataProjectHandler(context: Context, dataBase: MapLifeDataBase) : */ fun getProjectList(callback: (list: List<Project>) -> Unit) { thread(start = true) { - val list = mDataBase.projectManagerDao.findList(); + val list = (mDataBase as MapLifeDataBase).projectManagerDao.findList(); Handler(Looper.getMainLooper()).post { callback.invoke(list) } diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/NIMapController.kt b/collect-library/src/main/java/com/navinfo/collect/library/map/NIMapController.kt index 74c6bc92..8a172a47 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/NIMapController.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/NIMapController.kt @@ -25,9 +25,9 @@ class NIMapController { lateinit var viewportHandler: ViewportHandler lateinit var measureLayerHandler: MeasureLayerHandler - fun init(context: AppCompatActivity, mapView: NIMapView, options: NIMapOptions? = null, mapPath: String) { + fun init(context: AppCompatActivity, mapView: NIMapView, options: NIMapOptions? = null, mapPath: String, tracePath: String) { Constant.MAP_PATH = mapPath - layerManagerHandler = LayerManagerHandler(context, mapView) + layerManagerHandler = LayerManagerHandler(context, mapView, tracePath) locationLayerHandler = LocationLayerHandler(context, mapView) animationHandler = AnimationHandler(context, mapView) markerHandle = MarkHandler(context, mapView) diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt index bf3395ad..0c589f39 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt @@ -49,11 +49,10 @@ import java.util.* /** * Layer 操作 */ -open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView) : - BaseHandler(context, mapView) { +open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView,tracePath: String) : BaseHandler(context, mapView) { private var baseGroupLayer // 用于盛放所有基础底图的图层组,便于统一管理 : GroupLayer? = null - + protected val mTracePath:String = tracePath /** * 默认文字颜色 */ @@ -104,6 +103,26 @@ open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView) : loadBaseMap() //初始化之间数据图层 initQsRecordDataLayer() + + mapLifeNiLocationTileSource = MapLifeNiLocationTileSource(mContext, mTracePath) + + vectorNiLocationTileLayer = VectorTileLayer(mMapView.vtmMap, mapLifeNiLocationTileSource) + + labelNiLocationLayer = LabelLayer(mMapView.vtmMap, vectorNiLocationTileLayer, LabelTileLoaderHook(), 15) + + if(vectorNiLocationTileLayer!=null){ + addLayer(vectorNiLocationTileLayer,NIMapView.LAYER_GROUPS.BASE) + } + if(labelNiLocationLayer!=null){ + addLayer(labelNiLocationLayer, NIMapView.LAYER_GROUPS.BASE) + } + + vectorNiLocationTileLayer.isEnabled = false + labelNiLocationLayer.isEnabled = false + + mMapView.switchTileVectorLayerTheme(NIMapView.MAP_THEME.DEFAULT) + + mMapView.updateMap() // initMapLifeSource() // 设置矢量图层均在12级以上才显示 @@ -579,24 +598,15 @@ open class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView) : } //显示轨迹图层 - fun showNiLocationLayer(dbName: String?) { - if (mapLifeNiLocationTileSource == null) { - mapLifeNiLocationTileSource = MapLifeNiLocationTileSource(mContext, dbName) - } - if (vectorNiLocationTileLayer == null) { - vectorNiLocationTileLayer = - VectorTileLayer(mMapView.vtmMap, mapLifeNiLocationTileSource) - } - if (labelNiLocationLayer == null) { - labelNiLocationLayer = - LabelLayer(mMapView.vtmMap, vectorNiLocationTileLayer, LabelTileLoaderHook(), 15) - } - addLayer(labelNiLocationLayer, NIMapView.LAYER_GROUPS.VECTOR) + fun showNiLocationLayer() { + vectorNiLocationTileLayer.isEnabled = true + labelNiLocationLayer.isEnabled = true } //隐藏轨迹图层 fun hideNiLocationLayer() { - removeLayer(labelNiLocationLayer) + vectorNiLocationTileLayer.isEnabled = false + labelNiLocationLayer.isEnabled = false } } diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LocationLayerHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LocationLayerHandler.kt index c23a35f8..5c65013b 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LocationLayerHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LocationLayerHandler.kt @@ -57,9 +57,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) : Bas //获取定位类型、定位错误返回码,具体信息可参照类参考中BDLocation类中的说明 val errorCode = it.locType mCurrentLocation = it - mLocationLayer.setPosition( - it.latitude, it.longitude, it.radius - ) + mLocationLayer.setPosition(it.latitude, it.longitude, it.radius) Log.e("qj","location==${it.longitude}==errorCode===$errorCode===${it.locTypeDescription}") if(niLocationListener!=null){ getCurrentNiLocation()?.let { it1 -> niLocationListener.call(it1) } diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationDecoder.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationDecoder.java index 631f9259..abb33510 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationDecoder.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationDecoder.java @@ -90,7 +90,7 @@ public class MapLifeNiLocationDecoder extends TileDecoder { } if(count==0){ properties.put("nav_style","symbol_object_line"); - parseGeometry(layerName, GeometryTools.createGeometry("LINESTRING (116.245567 40.073475, 116.245855 40.072811, 116.24706 40.073034)"), properties); + parseGeometry(layerName, GeometryTools.createGeometry("LINESTRING (116.245859 40.073475, 116.245855 40.073477)"), properties); } // if(count%55==0){ // Log.e("qj","decode==geometry==symbol_track_point"+geometry.toString()+String.valueOf(anyNum)); diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileDataSource.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileDataSource.java index 7bad0cfe..52909ec7 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileDataSource.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileDataSource.java @@ -6,6 +6,7 @@ import android.util.Log; import androidx.annotation.RequiresApi; import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase; +import com.navinfo.collect.library.data.dao.impl.TraceDataBase; import com.navinfo.collect.library.data.entity.Element; import com.navinfo.collect.library.data.entity.NiLocation; import org.oscim.core.MapElement; @@ -43,16 +44,16 @@ public class MapLifeNiLocationTileDataSource implements ITileDataSource { // 获取tile对应的坐标范围 if (tile.zoomLevel >= 10 && tile.zoomLevel <= 20) { - int m = 20 - tile.zoomLevel; + int m = 21 - tile.zoomLevel; int xStart = (int) tile.tileX << m; int xEnd = (int) ((tile.tileX + 1) << m); int yStart = (int) tile.tileY << m; int yEnd = (int) ((tile.tileY + 1) << m); List<NiLocation> list = null; if(mEndTime!=0){ - list = MapLifeDataBase.getDatabase(mCon, dbName).getNiLocationDao().timeTofindList(xStart, xEnd, yStart, yEnd,mStartTime,mEndTime); + list = TraceDataBase.getDatabase(mCon, dbName).getNiLocationDao().timeTofindList(xStart, xEnd, yStart, yEnd,mStartTime,mEndTime); }else{ - list = MapLifeDataBase.getDatabase(mCon, dbName).getNiLocationDao().findList(xStart, xEnd, yStart, yEnd); + list = TraceDataBase.getDatabase(mCon, dbName).getNiLocationDao().findList(xStart, xEnd, yStart, yEnd); } Log.e("qj","query"+(list==null?0:list.size())+"==="+xStart+"==="+xEnd+"==="+yStart+"==="+yEnd); diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileSource.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileSource.java index 2b1f4be4..d169bb12 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileSource.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/MapLifeNiLocationTileSource.java @@ -5,6 +5,8 @@ import android.content.Context; import org.oscim.tiling.ITileDataSource; import org.oscim.tiling.TileSource; +import java.util.Date; + public class MapLifeNiLocationTileSource extends TileSource { private Context mCon; private String dbName; diff --git a/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java b/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java index 8f4c3411..e9cd2426 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java @@ -1566,4 +1566,19 @@ public class GeometryTools { return earthRadiusMeters * acos; // 最终结果 } + + /** + * 将平面坐标系中的距离(以米为单位)转换为地理坐标系中的角度(以度为单位) + * + * @param distance 平面坐标系中的距离(单位:米) + * @param latitude 点的纬度(单位:度) + * @return 对应的地理坐标系中的距离(单位:度) + */ + private static final double EARTH_RADIUS = 6371000.0; + public static double convertDistanceToDegree(double distance, double latitude) { + double radianDistance = distance / EARTH_RADIUS; + double radianLatitude = Math.toRadians(latitude); + double radianDegree = 2 * Math.asin(Math.sin(radianDistance / 2) / Math.cos(radianLatitude)); + return Math.toDegrees(radianDegree); + } } diff --git a/navinfo.jks b/navinfo.jks index 28de488b..5be224fe 100644 Binary files a/navinfo.jks and b/navinfo.jks differ