fix: 合并代码

This commit is contained in:
2023-11-03 15:31:34 +08:00
49 changed files with 3588 additions and 1981 deletions

View File

@@ -120,6 +120,7 @@ dependencies {
api 'org.locationtech.jts:jts-core:1.19.0'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'
implementation 'com.squareup.okio:okio:3.3.0'
implementation 'com.alibaba:fastjson:1.2.73'
implementation "com.fasterxml.jackson.core:jackson-annotations:2.9.9"
implementation "com.fasterxml.jackson.core:jackson-core:2.9.9"

View File

@@ -1558,7 +1558,6 @@
<symbol repeat="false" repeat-start="0" repeat-gap="2000"
src="@symbol" symbol-height="24" degree="90"></symbol>
</m>
<!-- 杆状物 -->
<m v="OMDB_POLE">
<symbol src="assets:omdb/icon_pole_3006.svg" symbol-height="56" symbol-width="56"></symbol>
@@ -1720,22 +1719,22 @@
<m k="markType" v="6">
<!--其他|实线-->
<m k="markColor" v="1">
<symbol repeat="true" repeat-start="0" repeat-gap="24" src="assets:omdb/icon_2013_1.svg"/>
<symbol repeat="true" repeat-start="0" repeat-gap="32" symbol-height="8" symbol-width="8" src="assets:omdb/icon_2013_1.svg"/>
</m>
<m k="markColor" v="2">
<symbol repeat="true" repeat-start="0" repeat-gap="24" src="assets:omdb/icon_2013_2.svg"></symbol>
<symbol repeat="true" repeat-start="0" repeat-gap="32" symbol-height="8" symbol-width="8" src="assets:omdb/icon_2013_2.svg"></symbol>
</m>
<m k="markColor" v="6">
<symbol repeat="true" repeat-start="0" repeat-gap="24" src="assets:omdb/icon_2013_6.svg"></symbol>
<symbol repeat="true" repeat-start="0" repeat-gap="32" symbol-height="8" symbol-width="8" src="assets:omdb/icon_2013_6.svg"></symbol>
</m>
<m k="markColor" v="7">
<symbol repeat="true" repeat-start="0" repeat-gap="24" src="assets:omdb/icon_2013_7.svg"></symbol>
<symbol repeat="true" repeat-start="0" repeat-gap="32" symbol-height="8" symbol-width="8" src="assets:omdb/icon_2013_7.svg"></symbol>
</m>
<m k="markColor" v="0|9">
<symbol repeat="true" repeat-start="0" repeat-gap="24" src="assets:omdb/icon_2013_0.svg"></symbol>
<symbol repeat="true" repeat-start="0" repeat-gap="32" symbol-height="8" symbol-width="8" src="assets:omdb/icon_2013_0.svg"></symbol>
</m>
</m>
</m>

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1695622778812" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="8830" xmlns:xlink="http://www.w3.org/1999/xlink"
width="48" height="48">
<path
d="M284.444444 227.555556h739.555556L739.555556 796.444444H0L284.444444 227.555556z m26.368 42.666666l-241.777777 483.555556h644.152889l241.777777-483.555556H310.812444z"
fill="#8e44ad" p-id="8831"></path>
<path d="M310.812444 270.222222l-241.777777 483.555556h644.152889l241.777777-483.555556z"
fill="#8e44ad" fill-opacity=".99" p-id="8832"></path>
<?xml version="1.0" encoding="UTF-8"?>
<svg id="b" xmlns="http://www.w3.org/2000/svg" width="136.1" height="113.4"
viewBox="0 0 136.1 113.4">
<g id="c">
<g>
<rect width="136.1" height="113.4" style="fill:none;" />
<polygon points="109.7 56.7 0 56.7 26.4 0 136.1 0 109.7 56.7" style="fill:#8e44ad;" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 369 B

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1695622778812" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="8830" xmlns:xlink="http://www.w3.org/1999/xlink"
width="48" height="48">
<path
d="M284.444444 227.555556h739.555556L739.555556 796.444444H0L284.444444 227.555556z m26.368 42.666666l-241.777777 483.555556h644.152889l241.777777-483.555556H310.812444z"
fill="#ffffff" p-id="8831"></path>
<path d="M310.812444 270.222222l-241.777777 483.555556h644.152889l241.777777-483.555556z"
fill="#ffffff" fill-opacity=".99" p-id="8832"></path>
<?xml version="1.0" encoding="UTF-8"?>
<svg id="b" xmlns="http://www.w3.org/2000/svg" width="136.1" height="113.4"
viewBox="0 0 136.1 113.4">
<g id="c">
<g>
<rect width="136.1" height="113.4" style="fill:none;" />
<polygon points="109.7 56.7 0 56.7 26.4 0 136.1 0 109.7 56.7" style="fill:#fff;" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 366 B

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1695622778812" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="8830" xmlns:xlink="http://www.w3.org/1999/xlink"
width="48" height="48">
<path
d="M284.444444 227.555556h739.555556L739.555556 796.444444H0L284.444444 227.555556z m26.368 42.666666l-241.777777 483.555556h644.152889l241.777777-483.555556H310.812444z"
fill="#eccc68" p-id="8831"></path>
<path d="M310.812444 270.222222l-241.777777 483.555556h644.152889l241.777777-483.555556z"
fill="#eccc68" fill-opacity=".99" p-id="8832"></path>
<?xml version="1.0" encoding="UTF-8"?>
<svg id="b" xmlns="http://www.w3.org/2000/svg" width="136.1" height="113.4"
viewBox="0 0 136.1 113.4">
<g id="c">
<g>
<rect width="136.1" height="113.4" style="fill:none;" />
<polygon points="109.7 56.7 0 56.7 26.4 0 136.1 0 109.7 56.7" style="fill:#eccc68;" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 369 B

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1695622778812" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="8830" xmlns:xlink="http://www.w3.org/1999/xlink"
width="48" height="48">
<path
d="M284.444444 227.555556h739.555556L739.555556 796.444444H0L284.444444 227.555556z m26.368 42.666666l-241.777777 483.555556h644.152889l241.777777-483.555556H310.812444z"
fill="#0000ff" p-id="8831"></path>
<path d="M310.812444 270.222222l-241.777777 483.555556h644.152889l241.777777-483.555556z"
fill="#0000ff" fill-opacity=".99" p-id="8832"></path>
<?xml version="1.0" encoding="UTF-8"?>
<svg id="b" xmlns="http://www.w3.org/2000/svg" width="136.1" height="113.4"
viewBox="0 0 136.1 113.4">
<g id="c">
<g>
<rect width="136.1" height="113.4" style="fill:none;" />
<polygon points="109.7 56.7 0 56.7 26.4 0 136.1 0 109.7 56.7" style="fill:#0000ff;" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 369 B

View File

@@ -1,11 +1,10 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg t="1695622778812" class="icon" viewBox="0 0 1024 1024" version="1.1"
xmlns="http://www.w3.org/2000/svg" p-id="8830" xmlns:xlink="http://www.w3.org/1999/xlink"
width="48" height="48">
<path
d="M284.444444 227.555556h739.555556L739.555556 796.444444H0L284.444444 227.555556z m26.368 42.666666l-241.777777 483.555556h644.152889l241.777777-483.555556H310.812444z"
fill="#00ff00" p-id="8831"></path>
<path d="M310.812444 270.222222l-241.777777 483.555556h644.152889l241.777777-483.555556z"
fill="#00ff00" fill-opacity=".99" p-id="8832"></path>
<?xml version="1.0" encoding="UTF-8"?>
<svg id="b" xmlns="http://www.w3.org/2000/svg" width="136.1" height="113.4"
viewBox="0 0 136.1 113.4">
<g id="c">
<g>
<rect width="136.1" height="113.4" style="fill:none;" />
<polygon points="109.7 56.7 0 56.7 26.4 0 136.1 0 109.7 56.7" style="fill:#00ff00;" />
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 730 B

After

Width:  |  Height:  |  Size: 369 B

View File

@@ -1,5 +1,7 @@
package com.navinfo.collect.library.data.entity
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
@@ -12,11 +14,13 @@ open class HadLinkDvoBean @JvmOverloads constructor(
* 图幅号
*/
var mesh: String = "",
/**
* linkPid
*/
@PrimaryKey
var linkPid: String = "",
/**
* (几何)加偏后
*/
@@ -31,10 +35,12 @@ open class HadLinkDvoBean @JvmOverloads constructor(
* 1:源库link2选择link 3现场新增
*/
var linkStatus: Int = 1,
/**
* 详细属性
*/
var linkInfo: LinkInfoBean? = null,
/**
* 长度(米)
*/

View File

@@ -0,0 +1,30 @@
package com.navinfo.collect.library.data.entity
import android.os.Parcelable
import com.navinfo.collect.library.system.Constant
import com.navinfo.collect.library.utils.GeometryTools
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.Index
import io.realm.annotations.PrimaryKey
import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
import org.oscim.core.MercatorProjection
import java.util.*
/**
* 渲染要素对应的实体
* */
@Parcelize
open class LinkRelation() : RealmObject(), Parcelable {
@Index
var linkPid:String = ""
@Index
var sNodeId: String? = null
@Index
var eNodeId: String? = null
}

View File

@@ -1,7 +1,12 @@
package com.navinfo.collect.library.data.entity
import android.util.Log
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.utils.DeflaterUtil
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import com.navinfo.collect.library.utils.StrZipUtil
import io.realm.RealmDictionary
import io.realm.RealmObject
import io.realm.RealmSet
@@ -14,18 +19,28 @@ import java.util.*
* 渲染要素对应的实体
* */
open class ReferenceEntity() : RealmObject() {
@PrimaryKey
var id: String = UUID.randomUUID().toString() // id
var renderEntityId: String = "" // 参考的renderEntity的Id
// @PrimaryKey
// var id: Int = 0 // id
// var renderEntityId: Int = 0 // 参考的renderEntity的Id
@Ignore
lateinit var name: String //要素名
lateinit var table: String //要素表名
var propertiesDb: String = ""
var code: String = "0" // 要素编码
@Ignore
var zoomMin: Int = 18 //显示最小级别
@Ignore
var zoomMax: Int = 23 //显示最大级别
var taskId: Int = 0 //任务ID
var enable:Int = 0 // 默认0不是显示 1为渲染显示
var geometry: String = "" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
var enable: Int = 0 // 默认0不是显示 1为渲染显示
var tileXMin: Int = 0
var tileXMax: Int = 0
var tileYMin: Int = 0
var tileYMax: Int = 0
var geometry: String =
"" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
get() {
wkt = GeometryTools.createGeometry(field)
return field
@@ -34,7 +49,13 @@ open class ReferenceEntity() : RealmObject() {
field = value
// 根据geometry自动计算当前要素的x-tile和y-tile
GeometryToolsKt.getTileXByGeometry(value, tileX)
tileXMin = tileX.min()
tileXMax = tileX.max()
GeometryToolsKt.getTileYByGeometry(value, tileY)
tileYMin = tileY.min()
tileYMax = tileY.max()
// 根据传入的geometry文本自动转换为Geometry对象
try {
wkt = GeometryTools.createGeometry(value)
@@ -55,11 +76,29 @@ open class ReferenceEntity() : RealmObject() {
}
return field
}
@Ignore
var properties: RealmDictionary<String> = RealmDictionary()
get() {
if (propertiesDb != null && propertiesDb!!.isNotEmpty() && field.isEmpty()) {
try {
val gson = Gson()
val type = object : TypeToken<RealmDictionary<String>>() {}.type
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
} catch (e: Exception) {
Log.e("jingo","ReferenceEntity 转 properties $e")
}
}
return field
}
@Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@Ignore
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
constructor(name: String): this() {
constructor(name: String) : this() {
this.name = name
}
}

View File

@@ -1,40 +1,59 @@
package com.navinfo.collect.library.data.entity
import android.os.Parcelable
import com.navinfo.collect.library.system.Constant
import android.util.Log
import com.alibaba.fastjson.JSON
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.utils.DeflaterUtil
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import com.navinfo.collect.library.utils.StrZipUtil
import io.realm.RealmDictionary
import io.realm.RealmObject
import io.realm.RealmSet
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import io.realm.annotations.Index
import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
import org.oscim.core.MercatorProjection
import java.util.*
/**
* 渲染要素对应的实体
* */
@Parcelize
open class RenderEntity() : RealmObject(), Parcelable {
@PrimaryKey
var id: String = UUID.randomUUID().toString() // id
// @PrimaryKey
// var id: String = UUID.randomUUID().toString() // id
lateinit var name: String //要素名
lateinit var table: String //要素表名
var code: String = "0" // 要素编码
var geometry: String = "" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
var propertiesDb: String = ""
var geometry: String =
"" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
get() {
wkt = GeometryTools.createGeometry(field)
return field
}
// get() {
// if (geometryDb != null && geometryDb.isNotEmpty() && field.isEmpty()) {
// field = StrZipUtil.uncompress(geometryDb)
// }
// return field
// }
set(value) {
field = value
// geometryDb = StrZipUtil.compress(value)
// 根据geometry自动计算当前要素的x-tile和y-tile
GeometryToolsKt.getTileXByGeometry(value, tileX)
tileXMin = tileX.min()
tileXMax = tileX.max()
GeometryToolsKt.getTileYByGeometry(value, tileY)
tileYMin = tileY.min()
tileYMax = tileY.max()
// 根据传入的geometry文本自动转换为Geometry对象
try {
wkt = GeometryTools.createGeometry(value)
@@ -50,36 +69,47 @@ open class RenderEntity() : RealmObject(), Parcelable {
try {
field = GeometryTools.createGeometry(geometry)
} catch (e: Exception) {
Log.e("jingo","RenderEntity 转 wkt失败 $e")
}
}
return field
}
@Ignore
var properties: RealmDictionary<String> = RealmDictionary()
get() {
if (propertiesDb != null && propertiesDb!!.isNotEmpty()&& field.isEmpty()) {
try {
val gson = Gson()
val type = object : TypeToken<RealmDictionary<String>>() {}.type
field = gson.fromJson(DeflaterUtil.unzipString(propertiesDb), type)
} catch (e: Exception) {
Log.e("jingo","RenderEntity 转 properties $e")
}
}
return field
}
@Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@Ignore
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
var tileXMin: Int = 0
var tileXMax: Int = 0
var tileYMin: Int = 0
var tileYMax: Int = 0
var taskId: Int = 0 //任务ID
var zoomMin: Int = 18 //显示最小级别
var zoomMax: Int = 23 //显示最大级别
var enable:Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable:Int = 0 // 0不捕捉 1捕捉
var enable: Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable: Int = 0 // 0不捕捉 1捕捉
@Index
var linkPid: String = "" // RenderEntity关联的linkPid集合(可能会关联多个)
var linkRelation: LinkRelation? = null
constructor(name: String) : this() {
this.name = name
}
companion object {
object LinkTable {
//道路linkId
const val linkPid = "linkPid"
}
object LimitTable {
const val linkPid = "linkPid"
}
object KindCodeTable {
const val linkPid = "linkPid"
}
}
}

View File

@@ -81,6 +81,7 @@ enum class DataCodeEnum(var tableName: String, var code: String) {
OMDB_TRAFFICLIGHT("交通灯", "4022"),
OMDB_TOLLGATE("收费站", "4023"),
OMDB_LANEINFO("车信", "4601"),
OMDB_CLM_LANEINFO("车信CLM", "4602"),
OMDB_LANE_LINK_LG("车道中心线", "5001");
companion object {

View File

@@ -608,6 +608,7 @@ public final class NIMapView extends RelativeLayout {
LABEL(4)/*图标,文字图层*/,
OPERATE_LINE(5)/*操作图层组*/,
OPERATE_MARKER(6)/*操作图层组*/;
int groupIndex;
LAYER_GROUPS(int groupIndex) {

View File

@@ -171,7 +171,7 @@ class LocationLayerHandler(context: AppCompatActivity, mapView: NIMapView) :
mCurrentLocation?.run {
val mapPosition = mMapView.vtmMap.mapPosition
mapPosition.setPosition(this.latitude, this.longitude)
mMapView.vtmMap.animator().animateTo(300, mapPosition)
mMapView.vtmMap.animator().animateTo(800, mapPosition)
}
}
@@ -224,7 +224,6 @@ private class MyLocationListener(callback: (BDLocation) -> Unit) : BDAbstractLoc
val call = callback;
override fun onReceiveLocation(location: BDLocation) {
call(location)
Log.e("jingo", "定位结果:速度=" + location.speed + " 方向=" + location.direction)
}
}

View File

@@ -28,6 +28,8 @@ import org.oscim.backend.canvas.Paint
import org.oscim.core.GeoPoint
import org.oscim.layers.marker.*
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.tile.vector.VectorTileLayer
import org.oscim.layers.vector.VectorLayer
import org.oscim.layers.vector.geometries.*
import org.oscim.map.Map
import java.util.*
@@ -43,8 +45,17 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
*/
private val mDefaultTextColor = "#4E55AF"
/**
* 默认Marker可用状态
*/
private var markerEnable = true
/**
* 默认轨迹可用状态
*/
private var traceMarkerEnable = true
/**
* 文字画笔
*/
@@ -179,6 +190,68 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
layer
}
/**
* 评测精简数据marker 图层
*/
private val niLocationItemizedLayerRough: ItemizedLayer by lazy {
val symbol = MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER)
val layerRough = ItemizedLayer(
mapView.vtmMap,
symbol,
)
layerRough.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
}
}
return true
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
layerRough.isEnabled = false
addLayer(layerRough, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layerRough
}
/**
* 评测精简数据marker 图层
*/
private val niLocationItemizedLayerSimple: ItemizedLayer by lazy {
val symbol = MarkerSymbol(niLocationBitmap, MarkerSymbol.HotspotPlace.CENTER)
val layerSimple = ItemizedLayer(
mapView.vtmMap,
symbol,
)
layerSimple.setOnItemGestureListener(object : OnItemGestureListener<MarkerInterface> {
override fun onItemSingleTapUp(index: Int, item: MarkerInterface?): Boolean {
val tag = mMapView.listenerTagList.last()
val listenerList = mMapView.listenerList[tag]
if (listenerList != null) {
for (listener in listenerList) {
}
}
return true
}
override fun onItemLongPress(index: Int, item: MarkerInterface?): Boolean {
return true
}
})
addLayer(layerSimple, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layerSimple
}
/**
* 评测数据marker 图层
*/
@@ -213,7 +286,7 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
}
})
layer.isEnabled = false
addLayer(layer, NIMapView.LAYER_GROUPS.OPERATE_MARKER)
layer
}
@@ -277,13 +350,20 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
// 设置矢量图层均在12级以上才显示
mMapView.vtmMap.events.bind(Map.UpdateListener { e, mapPosition ->
if (e == Map.SCALE_EVENT) {
if(markerEnable){
if (markerEnable) {
qsRecordItemizedLayer.isEnabled = mapPosition.getZoomLevel() >= 12
}else{
} else {
qsRecordItemizedLayer.isEnabled = false
}
niLocationItemizedLayer.isEnabled = mapPosition.getZoomLevel() >= 12
if (traceMarkerEnable) {
niLocationItemizedLayer.isEnabled = mapPosition.getZoomLevel() in 18..20
niLocationItemizedLayerSimple.isEnabled = mapPosition.getZoomLevel() in 14..17
niLocationItemizedLayerRough.isEnabled = mapPosition.getZoomLevel() in 12..13
} else {
niLocationItemizedLayer.isEnabled = false
niLocationItemizedLayerSimple.isEnabled = false
niLocationItemizedLayerRough.isEnabled = false
}
}
})
}
@@ -379,13 +459,30 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
mMapView.updateMap(true)
}
fun setQsRecordMarkEnable(enable:Boolean){
/**
* Marker是否显示
*/
fun setQsRecordMarkEnable(enable: Boolean) {
qsRecordItemizedLayer.isEnabled = enable
markerEnable = enable
qsRecordItemizedLayer.populate()
mMapView.updateMap(true)
}
/**
* 轨迹是否显示
*/
fun setTraceMarkEnable(enable: Boolean) {
niLocationItemizedLayer.isEnabled = enable
niLocationItemizedLayerSimple.isEnabled = enable
niLocationItemizedLayerRough.isEnabled = enable
traceMarkerEnable = enable
niLocationItemizedLayer.populate()
niLocationItemizedLayerSimple.populate()
niLocationItemizedLayerRough.populate()
mMapView.updateMap(true)
}
/**
* 增加或更新便签
@@ -520,11 +617,27 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
* 添加质检数据marker
*/
fun addNiLocationMarkerItem(niLocation: NiLocation) {
synchronized(this) {
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayer.addItem(geoMarkerItem)
niLocationItemizedLayer.update()
}
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayer.addItem(geoMarkerItem)
niLocationItemizedLayer.update()
}
/**
* 添加质检数据marker
*/
fun addNiLocationMarkerItemSimple(niLocation: NiLocation) {
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayerSimple.addItem(geoMarkerItem)
niLocationItemizedLayerSimple.update()
}
/**
* 添加质检数据marker
*/
fun addNiLocationMarkerItemRough(niLocation: NiLocation) {
var geoMarkerItem = createNILocationBitmap(niLocation)
niLocationItemizedLayerRough.addItem(geoMarkerItem)
niLocationItemizedLayerRough.update()
}
private fun createNILocationBitmap(niLocation: NiLocation): MarkerItem {
@@ -791,6 +904,10 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
fun clearNiLocationLayer() {
niLocationItemizedLayer.removeAllItems()
niLocationItemizedLayer.update()
niLocationItemizedLayerSimple.removeAllItems()
niLocationItemizedLayerSimple.update()
niLocationItemizedLayerRough.removeAllItems()
niLocationItemizedLayerRough.update()
}
/**
@@ -805,6 +922,30 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
return niLocationItemizedLayer.itemList.size
}
fun getNILocationItemizedLayerSimpleSize(): Int {
return niLocationItemizedLayerSimple.itemList.size
}
fun getNILocationSimple(index: Int): NiLocation? {
return if (index > -1 && index < getNILocationItemizedLayerSimpleSize()) {
((niLocationItemizedLayerSimple.itemList[index]) as MarkerItem).uid as NiLocation
} else {
null
}
}
fun getNILocationItemizedLayerRoughSize(): Int {
return niLocationItemizedLayerRough.itemList.size
}
fun getNILocationRough(index: Int): NiLocation? {
return if (index > -1 && index < getNILocationItemizedLayerRoughSize()) {
((niLocationItemizedLayerRough.itemList[index]) as MarkerItem).uid as NiLocation
} else {
null
}
}
fun getNILocation(index: Int): NiLocation? {
return if (index > -1 && index < getNILocationItemizedLayerSize()) {
((niLocationItemizedLayer.itemList[index]) as MarkerItem).uid as NiLocation
@@ -833,6 +974,27 @@ class MarkHandler(context: AppCompatActivity, mapView: NIMapView) :
return -1
}
fun getNILocationSimpleIndex(niLocation: NiLocation): Int? {
var list = niLocationItemizedLayerSimple.itemList
if (niLocation != null && list.isNotEmpty()) {
var index = -1
list.forEach {
index += 1
if (((it as MarkerItem).uid as NiLocation).id.equals(niLocation.id)) {
return index
}
}
}
return -1
}
}
interface OnQsRecordItemClickListener : BaseClickListener {

View File

@@ -6,6 +6,7 @@ import android.util.Log;
import androidx.annotation.RequiresApi;
import com.navinfo.collect.library.data.entity.ReferenceEntity;
import com.navinfo.collect.library.data.entity.RenderEntity;
import com.navinfo.collect.library.system.Constant;
import com.navinfo.collect.library.utils.GeometryTools;
import com.navinfo.collect.library.utils.MapParamUtils;
@@ -17,6 +18,7 @@ import org.oscim.tiling.ITileDataSink;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.QueryResult;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -41,14 +43,18 @@ public class OMDBReferenceDataSource implements ITileDataSource {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void query(MapTile tile, ITileDataSink mapDataSink) {
if(MapParamUtils.getTaskConfig() == null)
return;
// 获取tile对应的坐标范围
if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) {
Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig());
RealmQuery<ReferenceEntity> realmQuery = realm.where(ReferenceEntity.class);
int m = Constant.DATA_ZOOM - tile.zoomLevel;
int xStart = tile.tileX;
int xEnd = tile.tileX + 1;
int yStart = tile.tileY;
int yEnd = tile.tileY + 1;
if (m>0) {
if (m > 0) {
xStart = (int) (xStart << m);
xEnd = (int) (xEnd << m);
yStart = (int) (yStart << m);
@@ -56,21 +62,22 @@ public class OMDBReferenceDataSource implements ITileDataSource {
}
final int currentTileX = xStart;
if(isUpdate){
Realm.getInstance(MapParamUtils.getTaskConfig()).refresh();
if (isUpdate) {
realm.refresh();
isUpdate = false;
}
String sql = " tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
String sql = " ((tileXMin <= " + xStart + " and tileXMax >= " + xStart + ") or (tileXMin <=" + xEnd + " and tileXMax >=" + xStart + ")) and ((tileYMin <= " + yStart + " and tileYMax >= " + yStart + ") or (tileYMin <=" + yEnd + " and tileYMin >=" + yStart + "))";
if(MapParamUtils.getDataLayerEnum()!=null){
// String sql = " tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
if (MapParamUtils.getDataLayerEnum() != null) {
sql += " and enable" + MapParamUtils.getDataLayerEnum().getSql();
}else{
} else {
sql += " and enable>=0";
}
RealmQuery<ReferenceEntity> realmQuery = Realm.getInstance(MapParamUtils.getTaskConfig()).where(ReferenceEntity.class)
.rawPredicate(sql);
realmQuery.rawPredicate(sql);
// 筛选不显示的数据
if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) {
realmQuery.beginGroup();
@@ -91,10 +98,11 @@ public class OMDBReferenceDataSource implements ITileDataSource {
} else {
mapDataSink.completed(QueryResult.SUCCESS);
}
Realm.getInstance(MapParamUtils.getTaskConfig()).close();
realm.close();
} else {
mapDataSink.completed(QueryResult.SUCCESS);
}
}
@Override
@@ -104,13 +112,12 @@ public class OMDBReferenceDataSource implements ITileDataSource {
@Override
public void cancel() {
if (Realm.getDefaultInstance().isInTransaction()) {
Realm.getDefaultInstance().cancelTransaction();
}
// if (Realm.getDefaultInstance().isInTransaction()) {
// Realm.getDefaultInstance().cancelTransaction();
// }
}
public void update(){
public void update() {
isUpdate = true;
Log.e("qj",Thread.currentThread().getName());
}
}

View File

@@ -4,10 +4,13 @@ import static org.oscim.core.MercatorProjection.latitudeToY;
import static org.oscim.core.MercatorProjection.longitudeToX;
import android.os.Build;
import android.util.Log;
import androidx.annotation.RequiresApi;
import com.navinfo.collect.library.data.entity.ReferenceEntity;
import com.navinfo.collect.library.enums.DataCodeEnum;
import com.navinfo.collect.library.utils.GeometryTools;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
@@ -100,7 +103,14 @@ public class OMDBReferenceDecoder extends TileDecoder {
processCoordinateArray(multiPoint.getGeometryN(i).getCoordinates(), false);
}
} else if (geometry instanceof LineString) {
processLineString((LineString) geometry);
//将车道中心进行转化面渲染
if(layerName!=null&&layerName.equals(DataCodeEnum.OMDB_LANE_LINK_LG.name())){
Log.e("qj","车道中心线转化开始");
processPolygon((Polygon)GeometryTools.createGeometry(GeometryTools.computeLine(0.000035,0.000035,geometry.toString())));
Log.e("qj","车道中心线转化结束");
}else{
processLineString((LineString) geometry);
}
} else if (geometry instanceof MultiLineString) {
MultiLineString multiLineString = (MultiLineString) geometry;
for (int i = 0; i < multiLineString.getNumGeometries(); i++) {

View File

@@ -11,21 +11,45 @@ import com.navinfo.collect.library.utils.GeometryTools;
import com.navinfo.collect.library.utils.MapParamUtils;
import org.locationtech.jts.geom.Polygon;
import org.oscim.core.MapPosition;
import org.oscim.layers.tile.MapTile;
import org.oscim.map.Map;
import org.oscim.map.Viewport;
import org.oscim.tiling.ITileDataSink;
import org.oscim.tiling.ITileDataSource;
import org.oscim.tiling.QueryResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmQuery;
public class OMDBTileDataSource implements ITileDataSource {
class RealmObject {
int threadCode;
int realmConfigCode;
Realm realm;
}
// class DataObject {
// int threadCode = 0;
// byte zoom = 0;
// String lonLat = "";
// List<String> listIds = new ArrayList<>();
// }
private boolean isUpdate;
private Viewport viewport;
private List<RealmObject> realmObjectList = new ArrayList<>();
// private List<DataObject> dataObjectList = new ArrayList<>();
private final ThreadLocal<OMDBDataDecoder> mThreadLocalDecoders = new ThreadLocal<OMDBDataDecoder>() {
@Override
protected OMDBDataDecoder initialValue() {
@@ -40,36 +64,63 @@ public class OMDBTileDataSource implements ITileDataSource {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void query(MapTile tile, ITileDataSink mapDataSink) {
if(MapParamUtils.getTaskConfig() == null)
return;
// 获取tile对应的坐标范围
if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.DATA_ZOOM) {
Realm realm = null;
int threadCode = Thread.currentThread().hashCode();
synchronized (realmObjectList) {
int configCode = MapParamUtils.getTaskConfig().hashCode();
for (RealmObject object : realmObjectList) {
if (object.threadCode == threadCode) {
if (object.realmConfigCode == configCode) {
realm = object.realm;
} else {
object.realm.close();
realmObjectList.remove(object);
}
break;
}
}
if (realm == null) {
realm = Realm.getInstance(MapParamUtils.getTaskConfig());
RealmObject o = new RealmObject();
o.threadCode = threadCode;
o.realmConfigCode = configCode;
o.realm = realm;
realmObjectList.add(o);
}
}
// Realm realm = Realm.getInstance(MapParamUtils.getTaskConfig());
RealmQuery<RenderEntity> realmQuery = realm.where(RenderEntity.class);
int m = Constant.DATA_ZOOM - tile.zoomLevel;
int xStart = tile.tileX;
int xEnd = tile.tileX + 1;
int yStart = tile.tileY;
int yEnd = tile.tileY + 1;
if (m>0) {
if (m > 0) {
xStart = (int) (xStart << m);
xEnd = (int) (xEnd << m);
yStart = (int) (yStart << m);
yEnd = (int) (yEnd << m);
}
final int currentTileX = xStart;
if(isUpdate){
Realm.getInstance(MapParamUtils.getTaskConfig()).refresh();
if (isUpdate) {
realm.refresh();
isUpdate = false;
}
String sql =" tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
if(MapParamUtils.getDataLayerEnum()!=null){
String sql = " ((tileXMin <= " + xStart + " and tileXMax >= " + xStart + ") or (tileXMin <=" + xEnd + " and tileXMax >=" + xStart + ")) and ((tileYMin <= " + yStart + " and tileYMax >= " + yStart + ") or (tileYMin <=" + yEnd + " and tileYMin >=" + yStart + "))";
if (MapParamUtils.getDataLayerEnum() != null) {
sql += " and enable" + MapParamUtils.getDataLayerEnum().getSql();
}else{
} else {
sql += " and enable>=0";
}
realmQuery.rawPredicate(sql);
RealmQuery<RenderEntity> realmQuery = Realm.getInstance(MapParamUtils.getTaskConfig()).where(RenderEntity.class).rawPredicate(sql);
// 筛选不显示的数据
// 筛选不显示的数据
if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) {
realmQuery.beginGroup();
for (String type : Constant.HAD_LAYER_INVISIABLE_ARRAY) {
@@ -77,13 +128,17 @@ public class OMDBTileDataSource implements ITileDataSource {
}
realmQuery.endGroup();
}
List<RenderEntity> listResult = realmQuery/*.distinct("id")*/.findAll();
long time = System.currentTimeMillis();
List<RenderEntity> listResult = realmQuery.findAll();
long newTime = System.currentTimeMillis() - time;
Log.e("jingo", "当前OMDBTileDataSource " + Thread.currentThread().hashCode() + " 当前realm " + realm.hashCode() + " 查询耗时" + newTime + " 条数" + listResult.size());
// 数据记录的tile号是以正外接tile号列表此处过滤并未与当前tile相交的数据
if (!listResult.isEmpty()) {
Polygon tilePolygon = GeometryTools.getTilePolygon(tile);
// System.out.println("第一条数据的最小x值:" + listResult.get(0).getTileX().stream().min(Integer::compare).get());
// System.out.println("当前tile的:" + listResult.get(0).getTileX().stream().min(Integer::compare).get());
listResult = listResult.stream().filter((RenderEntity renderEntity) -> renderEntity.getWkt().intersects(tilePolygon))
listResult = listResult.stream().filter((RenderEntity renderEntity) ->
renderEntity.getWkt().intersects(tilePolygon)
)
/*过滤数据只有最小x屏幕的最小x或数据的最小x会被渲染跨Tile的其他数据不再重复渲染*/
// .filter((RenderEntity renderEntity) -> MercatorProjection.longitudeToTileX(viewport.fromScreenPoint(0,0).getLongitude(), (byte) Constant.DATA_ZOOM) == currentTileX || renderEntity.getTileX().stream().min(Integer::compare).get() == currentTileX)
.collect(Collectors.toList());
@@ -92,7 +147,7 @@ public class OMDBTileDataSource implements ITileDataSource {
} else {
mapDataSink.completed(QueryResult.SUCCESS);
}
Realm.getInstance(MapParamUtils.getTaskConfig()).close();
// realm.close();
} else {
mapDataSink.completed(QueryResult.SUCCESS);
}
@@ -105,13 +160,12 @@ public class OMDBTileDataSource implements ITileDataSource {
@Override
public void cancel() {
if (Realm.getDefaultInstance().isInTransaction()) {
Realm.getDefaultInstance().cancelTransaction();
}
// if (Realm.getDefaultInstance().isInTransaction()) {
// Realm.getDefaultInstance().cancelTransaction();
// }
}
public void update(){
public void update() {
isUpdate = true;
Log.e("qj",Thread.currentThread().getName());
}
}

View File

@@ -27,7 +27,7 @@ public class OMDBTileSource extends RealmDBTileSource {
@Override
public OpenResult open() {
Log.d("qj", Realm.getDefaultInstance().where(RenderEntity.class).findAll().size()+"open安装数量");
// Log.d("qj", Realm.getDefaultInstance().where(RenderEntity.class).findAll().size()+"open安装数量");
return OpenResult.SUCCESS;
}

View File

@@ -35,27 +35,29 @@ public class RealmDBTileDataSource implements ITileDataSource {
public void query(MapTile tile, ITileDataSink mapDataSink) {
// 获取tile对应的坐标范围
if (tile.zoomLevel>=15&&tile.zoomLevel<=Constant.OVER_ZOOM) {
int m = Constant.OVER_ZOOM-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);
RealmQuery<GeometryFeatureEntity> realmQuery = Realm.getDefaultInstance().where(GeometryFeatureEntity.class)
.rawPredicate("tileX>="+xStart+" and tileX<="+xEnd+" and tileY>="+yStart+" and tileY<="+yEnd);
// 筛选不显示的数据
if (Constant.HAD_LAYER_INVISIABLE_ARRAY!=null&&Constant.HAD_LAYER_INVISIABLE_ARRAY.length>0) {
realmQuery.beginGroup();
for (String type: Constant.HAD_LAYER_INVISIABLE_ARRAY) {
realmQuery.notEqualTo("name", type);
}
realmQuery.endGroup();
}
List<GeometryFeatureEntity> listResult = realmQuery.distinct("id").findAll();
mThreadLocalDecoders.get().decode(tile, mapDataSink, listResult);
mapDataSink.completed(QueryResult.SUCCESS);
Realm.getDefaultInstance().close();
Log.e("jingo","RealmDBTileDataSource RealmDBTileDataSource RealmDBTileDataSource");
// int m = Constant.OVER_ZOOM-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);
//
// RealmQuery<GeometryFeatureEntity> realmQuery = Realm.getDefaultInstance().where(GeometryFeatureEntity.class)
// .rawPredicate("tileX>="+xStart+" and tileX<="+xEnd+" and tileY>="+yStart+" and tileY<="+yEnd);
// // 筛选不显示的数据
// if (Constant.HAD_LAYER_INVISIABLE_ARRAY!=null&&Constant.HAD_LAYER_INVISIABLE_ARRAY.length>0) {
// realmQuery.beginGroup();
// for (String type: Constant.HAD_LAYER_INVISIABLE_ARRAY) {
// realmQuery.notEqualTo("name", type);
// }
// realmQuery.endGroup();
// }
// List<GeometryFeatureEntity> listResult = realmQuery.distinct("id").findAll();
// mThreadLocalDecoders.get().decode(tile, mapDataSink, listResult);
// mapDataSink.completed(QueryResult.SUCCESS);
// Realm.getDefaultInstance().close();
// Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString());
mapDataSink.completed(QueryResult.SUCCESS);
} else {
mapDataSink.completed(QueryResult.SUCCESS);
}
@@ -68,8 +70,8 @@ public class RealmDBTileDataSource implements ITileDataSource {
@Override
public void cancel() {
if (Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).isInTransaction()) {
Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).cancelTransaction();
}
// if (Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).isInTransaction()) {
// Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).cancelTransaction();
// }
}
}

View File

@@ -0,0 +1,202 @@
package com.navinfo.collect.library.utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import org.apache.commons.net.util.Base64;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
/**
* DeflaterUtils 压缩字符串
*/
public class DeflaterUtil{
private DeflaterUtil() {
}
private static final int BUFFER_SIZE = 8192;
/**
* 压缩
*/
public static String zipString(String unzipString) {
/*
* https://www.yiibai.com/javazip/javazip_deflater.html#article-start
* 0 ~ 9 压缩等级 低到高
* public static final int BEST_COMPRESSION = 9; 最佳压缩的压缩级别。
* public static final int BEST_SPEED = 1; 压缩级别最快的压缩。
* public static final int DEFAULT_COMPRESSION = -1; 默认压缩级别。
* public static final int DEFAULT_STRATEGY = 0; 默认压缩策略。
* public static final int DEFLATED = 8; 压缩算法的压缩方法(目前唯一支持的压缩方法)。
* public static final int FILTERED = 1; 压缩策略最适用于大部分数值较小且数据分布随机分布的数据。
* public static final int FULL_FLUSH = 3; 压缩刷新模式,用于清除所有待处理的输出并重置拆卸器。
* public static final int HUFFMAN_ONLY = 2; 仅用于霍夫曼编码的压缩策略。
* public static final int NO_COMPRESSION = 0; 不压缩的压缩级别。
* public static final int NO_FLUSH = 0; 用于实现最佳压缩结果的压缩刷新模式。
* public static final int SYNC_FLUSH = 2; 用于清除所有未决输出的压缩刷新模式; 可能会降低某些压缩算法的压缩率。
*/
//使用指定的压缩级别创建一个新的压缩器。
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
//设置压缩输入数据。
deflater.setInput(unzipString.getBytes(StandardCharsets.UTF_8));
//当被调用时,表示压缩应该以输入缓冲区的当前内容结束。
deflater.finish();
final byte[] bytes = new byte[256];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
while (!deflater.finished()) {
//压缩输入数据并用压缩数据填充指定的缓冲区。
int length = deflater.deflate(bytes);
outputStream.write(bytes, 0, length);
}
deflater.end();
return Base64.encodeBase64String(outputStream.toByteArray());
}
/**
* 解压缩
*/
public static String unzipString(String zipString) {
byte[] decode = Base64.decodeBase64(zipString);
//创建一个新的解压缩器 https://www.yiibai.com/javazip/javazip_inflater.html
Inflater inflater = new Inflater();
//设置解压缩的输入数据。
inflater.setInput(decode);
final byte[] bytes = new byte[256];
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
try {
//finished() 如果已到达压缩数据流的末尾则返回true。
while (!inflater.finished()) {
//将字节解压缩到指定的缓冲区中。
int length = inflater.inflate(bytes);
outputStream.write(bytes, 0, length);
}
} catch (DataFormatException e) {
e.printStackTrace();
return null;
} finally {
//关闭解压缩器并丢弃任何未处理的输入。
inflater.end();
}
try {
return outputStream.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
public static byte[] compress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
int lenght = 0;
Deflater deflater = new Deflater();
deflater.setInput(bytes);
deflater.finish();
byte[] outputBytes = new byte[BUFFER_SIZE];
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
while (!deflater.finished()) {
lenght = deflater.deflate(outputBytes);
bos.write(outputBytes, 0, lenght);
}
deflater.end();
return bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Deflater compress error", e);
}
}
public static byte[] decompress(byte[] bytes) {
if (bytes == null) {
throw new NullPointerException("bytes is null");
}
int length = 0;
Inflater inflater = new Inflater();
inflater.setInput(bytes);
byte[] outputBytes = new byte[BUFFER_SIZE];
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
while (!inflater.finished()) {
length = inflater.inflate(outputBytes);
if (length == 0) {
break;
}
bos.write(outputBytes, 0, length);
}
inflater.end();
return bos.toByteArray();
} catch (Exception e) {
throw new RuntimeException("Deflater decompress error", e);
}
}
}

View File

@@ -49,7 +49,6 @@ class GeometryToolsKt {
}
}
}
println("YGeometry-time:" + (System.currentTimeMillis() - startTime))
}
/**
@@ -93,7 +92,6 @@ class GeometryToolsKt {
}
}
}
println("XGeometry-time:" + (System.currentTimeMillis() - startTime))
}
fun getMasterPoint(wkt: String): String {

View File

@@ -0,0 +1,282 @@
package com.navinfo.collect.library.utils
import sun.misc.BASE64Decoder
import sun.misc.BASE64Encoder
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.util.*
import java.util.zip.*
object StrZipUtil {
/**
* @param input 需要压缩的字符串
* @return 压缩后的字符串
* @throws IOException IO
*/
fun compress(input: String): String {
if (input.isEmpty()) {
return input
}
try {
val out = ByteArrayOutputStream()
val gzipOs = GZIPOutputStream(out)
gzipOs.write(input.toByteArray())
gzipOs.close()
return BASE64Encoder().encode(out.toByteArray())
} catch (e: Exception) {
return input
}
}
/**
* @param zippedStr 压缩后的字符串
* @return 解压缩后的
* @throws IOException IO
*/
fun uncompress(zippedStr: String): String {
if (zippedStr.isEmpty()) {
return zippedStr
}
try {
val out = ByteArrayOutputStream()
val `in` = ByteArrayInputStream(
BASE64Decoder().decodeBuffer(zippedStr)
)
val gzipIs = GZIPInputStream(`in`)
val buffer = ByteArray(256)
var n: Int
while (gzipIs.read(buffer).also { n = it } >= 0) {
out.write(buffer, 0, n)
}
// toString()使用平台默认编码也可以显式的指定如toString("GBK")
return out.toString()
} catch (e: Exception) {
return zippedStr
}
}
/***
* 压缩GZip
*
* @param data
* @return
*/
fun gZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bos = ByteArrayOutputStream()
val gzip = GZIPOutputStream(bos)
gzip.write(data)
gzip.finish()
gzip.close()
b = bos.toByteArray()
bos.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 解压GZip
*
* @param data
* @return
*/
fun unGZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bis = ByteArrayInputStream(data)
val gzip = GZIPInputStream(bis)
val buf = ByteArray(1024)
var num = -1
val baos = ByteArrayOutputStream()
while (gzip.read(buf, 0, buf.size).also { num = it } != -1) {
baos.write(buf, 0, num)
}
b = baos.toByteArray()
baos.flush()
baos.close()
gzip.close()
bis.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 压缩Zip
*
* @param data
* @return
*/
fun zip(data: ByteArray): ByteArray? {
var b: ByteArray? = null
try {
val bos = ByteArrayOutputStream()
val zip = ZipOutputStream(bos)
val entry = ZipEntry("zip")
entry.size = data.size.toLong()
zip.putNextEntry(entry)
zip.write(data)
zip.closeEntry()
zip.close()
b = bos.toByteArray()
bos.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 解压Zip
*
* @param data
* @return
*/
fun unZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bis = ByteArrayInputStream(data)
val zip = ZipInputStream(bis)
while (zip.nextEntry != null) {
val buf = ByteArray(1024)
var num = -1
val baos = ByteArrayOutputStream()
while (zip.read(buf, 0, buf.size).also { num = it } != -1) {
baos.write(buf, 0, num)
}
b = baos.toByteArray()
baos.flush()
baos.close()
}
zip.close()
bis.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
// /***
// * 压缩BZip2
// *
// * @param data
// * @return
// */
// public static byte[] bZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos);
// bzip2.write(data);
// bzip2.flush();
// bzip2.close();
// b = bos.toByteArray();
// bos.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 解压BZip2
// *
// * @param data
// * @return
// */
// public static byte[] unBZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayInputStream bis = new ByteArrayInputStream(data);
// CBZip2InputStream bzip2 = new CBZip2InputStream(bis);
// byte[] buf = new byte[1024];
// int num = -1;
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// while ((num = bzip2.read(buf, 0, buf.length)) != -1) {
// baos.write(buf, 0, num);
// }
// b = baos.toByteArray();
// baos.flush();
// baos.close();
// bzip2.close();
// bis.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 压缩BZip2
// *
// * @param data
// * @return
// */
// public static byte[] bZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos);
// bzip2.write(data);
// bzip2.flush();
// bzip2.close();
// b = bos.toByteArray();
// bos.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 解压BZip2
// *
// * @param data
// * @return
// */
// public static byte[] unBZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayInputStream bis = new ByteArrayInputStream(data);
// CBZip2InputStream bzip2 = new CBZip2InputStream(bis);
// byte[] buf = new byte[1024];
// int num = -1;
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// while ((num = bzip2.read(buf, 0, buf.length)) != -1) {
// baos.write(buf, 0, num);
// }
// b = baos.toByteArray();
// baos.flush();
// baos.close();
// bzip2.close();
// bis.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
/**
* 把字节数组转换成16进制字符串
*
* @param bArray
* @return
*/
fun bytesToHexString(bArray: ByteArray): String? {
val sb = StringBuffer(bArray.size)
var sTemp: String
for (i in bArray.indices) {
sTemp = Integer.toHexString(0xFF and bArray[i].toInt())
if (sTemp.length < 2) sb.append(0)
sb.append(sTemp.uppercase(Locale.getDefault()))
}
return sb.toString()
}
}