fix: 删除flutter和ocr的依赖
This commit is contained in:
@@ -70,10 +70,10 @@ dependencies {
|
|||||||
implementation "org.mapsforge:vtm:$vtmVersion"
|
implementation "org.mapsforge:vtm:$vtmVersion"
|
||||||
implementation "org.mapsforge:vtm-themes:$vtmVersion"
|
implementation "org.mapsforge:vtm-themes:$vtmVersion"
|
||||||
implementation "org.mapsforge:vtm-android:$vtmVersion"
|
implementation "org.mapsforge:vtm-android:$vtmVersion"
|
||||||
implementation "org.mapsforge:vtm-android:$vtmVersion:natives-armeabi-v7a"
|
runtimeOnly "org.mapsforge:vtm-android:$vtmVersion:natives-armeabi-v7a"
|
||||||
implementation "org.mapsforge:vtm-android:$vtmVersion:natives-arm64-v8a"
|
runtimeOnly "org.mapsforge:vtm-android:$vtmVersion:natives-arm64-v8a"
|
||||||
implementation "org.mapsforge:vtm-android:$vtmVersion:natives-x86"
|
runtimeOnly "org.mapsforge:vtm-android:$vtmVersion:natives-x86"
|
||||||
implementation "org.mapsforge:vtm-android:$vtmVersion:natives-x86_64"
|
runtimeOnly "org.mapsforge:vtm-android:$vtmVersion:natives-x86_64"
|
||||||
implementation "org.mapsforge:vtm-http:$vtmVersion"
|
implementation "org.mapsforge:vtm-http:$vtmVersion"
|
||||||
|
|
||||||
implementation "org.mapsforge:vtm-json:$vtmVersion"
|
implementation "org.mapsforge:vtm-json:$vtmVersion"
|
||||||
@@ -81,10 +81,10 @@ dependencies {
|
|||||||
implementation "org.mapsforge:vtm-android-mvt:$vtmVersion"
|
implementation "org.mapsforge:vtm-android-mvt:$vtmVersion"
|
||||||
implementation "org.mapsforge:vtm-mvt:$vtmVersion"
|
implementation "org.mapsforge:vtm-mvt:$vtmVersion"
|
||||||
|
|
||||||
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-armeabi-v7a"
|
runtimeOnly "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-armeabi-v7a"
|
||||||
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-arm64-v8a"
|
runtimeOnly "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-arm64-v8a"
|
||||||
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-x86"
|
runtimeOnly "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-x86"
|
||||||
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-x86_64"
|
runtimeOnly "org.mapsforge:vtm-android-gdx:$vtmVersion:natives-x86_64"
|
||||||
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion"
|
implementation "org.mapsforge:vtm-android-gdx:$vtmVersion"
|
||||||
|
|
||||||
implementation "com.google.protobuf:protobuf-java:3.6.1"
|
implementation "com.google.protobuf:protobuf-java:3.6.1"
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.PermissionChecker;
|
import androidx.core.content.PermissionChecker;
|
||||||
|
|
||||||
import com.baidu.ai.edge.core.base.Consts;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by linyiran on 6/16/22.
|
* Created by linyiran on 6/16/22.
|
||||||
*/
|
*/
|
||||||
@@ -87,9 +84,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
* Android 11 跳转到设置获取SD卡根目录写入权限
|
* Android 11 跳转到设置获取SD卡根目录写入权限
|
||||||
*/
|
*/
|
||||||
private void requestAllFilesAccess() {
|
private void requestAllFilesAccess() {
|
||||||
if (!Consts.AUTH_REQUIRE_SDCARD) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
|
||||||
allPermissionsGranted = false;
|
allPermissionsGranted = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,223 +0,0 @@
|
|||||||
package com.navinfo.collect.library.data.handler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import android.media.ExifInterface
|
|
||||||
import android.util.Log
|
|
||||||
import com.baidu.ai.edge.ui.util.ImageUtil
|
|
||||||
import com.baidu.ai.edge.ui.view.model.OcrViewResultModel
|
|
||||||
import com.navinfo.collect.FlutterBaseActivity
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.ocr.OCRManager
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import java.io.*
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
interface OnOCRBatchListener {
|
|
||||||
fun onProgress(total: Int, current: Int)
|
|
||||||
suspend fun onResult(list: List<Map<String, Any>>)
|
|
||||||
}
|
|
||||||
|
|
||||||
open class DataCameraHandler(
|
|
||||||
context: Context,
|
|
||||||
activity: FlutterBaseActivity,
|
|
||||||
dataBase: MapLifeDataBase
|
|
||||||
) :
|
|
||||||
BaseDataHandler(context, dataBase) {
|
|
||||||
|
|
||||||
private val mActivity: FlutterBaseActivity = activity
|
|
||||||
|
|
||||||
init {
|
|
||||||
OCRManager.instance.init(activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun openCamera() {
|
|
||||||
OCRManager.instance.openCamera(mActivity)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量OCR识别
|
|
||||||
*/
|
|
||||||
fun ocrBatch(filePath: String, listener: OnOCRBatchListener) {
|
|
||||||
mActivity.launch(Dispatchers.IO) {
|
|
||||||
Log.e("jingo", "OCRManager 线程开始 ${Thread.currentThread().name}")
|
|
||||||
val file = File(filePath)
|
|
||||||
val resultList = mutableListOf<Map<String, Any>>()
|
|
||||||
if (file.isDirectory) {
|
|
||||||
val fileList = file.listFiles()
|
|
||||||
val bitmapList = mutableListOf<String>()
|
|
||||||
for (item in fileList!!) {
|
|
||||||
if (item.isFile) {
|
|
||||||
if (checkIsImageFile(item.name)) {
|
|
||||||
bitmapList.add(item.path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val bfw: BufferedWriter
|
|
||||||
val csvFile = File("$filePath/ocr.csv")
|
|
||||||
val out: FileOutputStream
|
|
||||||
val osw: OutputStreamWriter
|
|
||||||
try {
|
|
||||||
out = FileOutputStream(csvFile)
|
|
||||||
//用excel打开,中文会乱码,所以用GBK编译
|
|
||||||
osw = OutputStreamWriter(out, "GBK")
|
|
||||||
bfw = BufferedWriter(osw)
|
|
||||||
//第一行表头数据
|
|
||||||
bfw.write("图片路径和名称,")
|
|
||||||
bfw.write("识别结果序号,")
|
|
||||||
bfw.write("识别结果内容,")
|
|
||||||
bfw.write("置信度,")
|
|
||||||
bfw.write("识别面积,")
|
|
||||||
bfw.write("图片大小,")
|
|
||||||
bfw.write("识别区域,")
|
|
||||||
//写好表头后换行
|
|
||||||
bfw.newLine()
|
|
||||||
for (i in 0 until bitmapList.size) {
|
|
||||||
val path = bitmapList[i]
|
|
||||||
|
|
||||||
val bitmap: Bitmap? = readFile(path)
|
|
||||||
var exif = ExifInterface(path)
|
|
||||||
val exifRotation = exif.getAttributeInt(
|
|
||||||
ExifInterface.TAG_ORIENTATION,
|
|
||||||
ExifInterface.ORIENTATION_NORMAL
|
|
||||||
)
|
|
||||||
val rotation = ImageUtil.exifToDegrees(exifRotation)
|
|
||||||
val rotateBitmap = ImageUtil.createRotateBitmap(bitmap, rotation)
|
|
||||||
val list = OCRManager.instance.ocr(rotateBitmap)
|
|
||||||
|
|
||||||
|
|
||||||
// val list = ocrBitmap(path)
|
|
||||||
if (list != null) {
|
|
||||||
for (o in list) {
|
|
||||||
bfw.write("$path,")
|
|
||||||
bfw.write("${o.index},")
|
|
||||||
bfw.write("${o.name},")
|
|
||||||
bfw.write("${o.confidence.toString()},")
|
|
||||||
val pointList = o.bounds
|
|
||||||
bfw.write("${(pointList[3].y - pointList[0].y) * (pointList[2].x - pointList[0].x)},")
|
|
||||||
bfw.write("${rotateBitmap.width} ${rotateBitmap.height},")
|
|
||||||
bfw.write("${o.bounds[0].x} ${o.bounds[0].y};${o.bounds[1].x} ${o.bounds[1].y};${o.bounds[2].x} ${o.bounds[2].y};${o.bounds[3].x} ${o.bounds[3].y},")
|
|
||||||
bfw.newLine()
|
|
||||||
}
|
|
||||||
bfw.newLine()
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
listener.onProgress(bitmapList.size, i)
|
|
||||||
}
|
|
||||||
val m1 = mutableMapOf<String, Any>();
|
|
||||||
m1["data"] = list;
|
|
||||||
m1["width"] = rotateBitmap.width
|
|
||||||
m1["height"] = rotateBitmap.height
|
|
||||||
m1["path"] = path
|
|
||||||
resultList.add(m1)
|
|
||||||
}
|
|
||||||
rotateBitmap.recycle()
|
|
||||||
}
|
|
||||||
|
|
||||||
//将缓存数据写入文件
|
|
||||||
bfw.flush()
|
|
||||||
//释放缓存
|
|
||||||
bfw.close()
|
|
||||||
osw.close()
|
|
||||||
out.close()
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
//将缓存数据写入文件
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
Log.e("jingo", "OCRManager 线程名称2 ${Thread.currentThread().name}")
|
|
||||||
listener.onResult(resultList)
|
|
||||||
}
|
|
||||||
} else if (file.isFile && checkIsImageFile(file.name)) {
|
|
||||||
val list = ocrBitmap(filePath)
|
|
||||||
if (list != null) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
Log.e("jingo", "OCRManager 线程名称2 ${Thread.currentThread().name}")
|
|
||||||
listener.onProgress(1, 1)
|
|
||||||
}
|
|
||||||
val m = mutableMapOf<String, List<OcrViewResultModel>>()
|
|
||||||
m[file.name] = list
|
|
||||||
resultList.add(m)
|
|
||||||
}
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
Log.e("jingo", "OCRManager 线程名称2 ${Thread.currentThread().name}")
|
|
||||||
listener.onResult(resultList)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun ocrBitmap(path: String): List<OcrViewResultModel>? {
|
|
||||||
try {
|
|
||||||
val bitmap: Bitmap? = readFile(path)
|
|
||||||
var exif = ExifInterface(path)
|
|
||||||
val exifRotation = exif.getAttributeInt(
|
|
||||||
ExifInterface.TAG_ORIENTATION,
|
|
||||||
ExifInterface.ORIENTATION_NORMAL
|
|
||||||
)
|
|
||||||
val rotation = ImageUtil.exifToDegrees(exifRotation)
|
|
||||||
val rotateBitmap = ImageUtil.createRotateBitmap(bitmap, rotation)
|
|
||||||
val res = OCRManager.instance.ocr(rotateBitmap)
|
|
||||||
rotateBitmap.recycle()
|
|
||||||
return res
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Log.e("jingo", "图像识别,获取图像信息失败 ${e.printStackTrace()}")
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查是不是bitmap文件
|
|
||||||
*/
|
|
||||||
private fun checkIsImageFile(fName: String): Boolean {
|
|
||||||
val isImageFile: Boolean
|
|
||||||
// 获取扩展名
|
|
||||||
val fileEnd = fName.substring(
|
|
||||||
fName.lastIndexOf(".") + 1,
|
|
||||||
fName.length
|
|
||||||
).lowercase(Locale.getDefault())
|
|
||||||
isImageFile =
|
|
||||||
fileEnd == "jpg" || fileEnd == "png" || fileEnd == "webp" || fileEnd == "jpeg" || fileEnd == "bmp"
|
|
||||||
return isImageFile
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取bitmap文件
|
|
||||||
*/
|
|
||||||
private fun readFile(path: String): Bitmap? {
|
|
||||||
var stream: FileInputStream? = null
|
|
||||||
try {
|
|
||||||
stream = FileInputStream(path)
|
|
||||||
return BitmapFactory.decodeStream(stream)
|
|
||||||
} catch (e: FileNotFoundException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
} finally {
|
|
||||||
if (stream != null) {
|
|
||||||
try {
|
|
||||||
stream.close()
|
|
||||||
} catch (e: IOException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// private fun onOcrBitmap(
|
|
||||||
// bitmap, confidence,
|
|
||||||
// object: OcrListener {
|
|
||||||
// override fun onResult(models: List<BasePolygonResultModel>) {
|
|
||||||
// if (models == null) {
|
|
||||||
// listener.onResult(null)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// ocrResultModelCache = models
|
|
||||||
// listener.onResult(models)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,584 +0,0 @@
|
|||||||
package com.navinfo.collect.library.data.handler
|
|
||||||
|
|
||||||
import android.content.ContentValues
|
|
||||||
import android.content.Context
|
|
||||||
import android.database.Cursor
|
|
||||||
import android.database.sqlite.SQLiteDatabase.CONFLICT_NONE
|
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
|
||||||
import com.navinfo.collect.library.data.DataConversion
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.data.entity.*
|
|
||||||
import com.navinfo.collect.library.data.entity.DataLayerItemType.*
|
|
||||||
import com.navinfo.collect.library.data.search.OnGetSearchDataResultListener
|
|
||||||
import com.navinfo.collect.library.data.search.SearchDataOption
|
|
||||||
import com.navinfo.collect.library.utils.GeometryTools
|
|
||||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
|
||||||
import io.realm.RealmSet
|
|
||||||
import org.oscim.core.MercatorProjection
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
import kotlin.concurrent.fixedRateTimer
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库操作
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
open class
|
|
||||||
DataElementHandler(context: Context, dataBase: MapLifeDataBase) :
|
|
||||||
BaseDataHandler(context, dataBase) {
|
|
||||||
private var mListener: OnGetSearchDataResultListener? = null
|
|
||||||
|
|
||||||
private var lastSearchTime = 0
|
|
||||||
private var timer: Timer? = null
|
|
||||||
|
|
||||||
fun setListener(listener: OnGetSearchDataResultListener) {
|
|
||||||
this.mListener = listener
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存数据
|
|
||||||
*/
|
|
||||||
fun saveData(
|
|
||||||
element: Element,
|
|
||||||
map: Map<String, Any>?,
|
|
||||||
callback: (res: Boolean, errorString: String) -> Unit
|
|
||||||
) {
|
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
if (map != null) {
|
|
||||||
val cursor =
|
|
||||||
mDataBase.openHelper.writableDatabase.query(
|
|
||||||
"Select * from \"${element.layerId}\" where uuid=?",
|
|
||||||
arrayOf(element.id)
|
|
||||||
)
|
|
||||||
|
|
||||||
val contentValues = ContentValues() //存储信息
|
|
||||||
for ((key, value) in map) {
|
|
||||||
when (value) {
|
|
||||||
is String -> contentValues.put(key, value)
|
|
||||||
is Long -> contentValues.put(key, value)
|
|
||||||
is Int -> contentValues.put(key, value)
|
|
||||||
is Double -> contentValues.put(key, value)
|
|
||||||
is ByteArray -> contentValues.put(key, value)
|
|
||||||
is Boolean -> contentValues.put(key, value)
|
|
||||||
is Float -> contentValues.put(key, value)
|
|
||||||
is Short -> contentValues.put(key, value)
|
|
||||||
is Byte -> contentValues.put(key, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contentValues.put("uuid", element.id);
|
|
||||||
cursor.moveToFirst()
|
|
||||||
if (cursor.count > 0) {
|
|
||||||
mDataBase.openHelper.writableDatabase.update(
|
|
||||||
"'${element.layerId}'",
|
|
||||||
CONFLICT_NONE,
|
|
||||||
contentValues,
|
|
||||||
"uuid = ? ",
|
|
||||||
arrayOf(element.id)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
mDataBase.openHelper.writableDatabase.insert(
|
|
||||||
"'${element.layerId}'",//element.layerId,
|
|
||||||
CONFLICT_NONE,
|
|
||||||
contentValues
|
|
||||||
).toInt()
|
|
||||||
}
|
|
||||||
cursor.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
//resetCoordinate(element)
|
|
||||||
element.tLifecycle = 2
|
|
||||||
|
|
||||||
//优先删除已有数据,下面会重新计算最新的tile
|
|
||||||
mDataBase.tileElementDao.deleteElementId(element.id)
|
|
||||||
|
|
||||||
val list = ArrayList<TileElement>()
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (element.geometry != null) {
|
|
||||||
val tileX = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileXByGeometry(element.geometry, tileX)
|
|
||||||
val tileY = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileYByGeometry(element.geometry, tileY)
|
|
||||||
|
|
||||||
//遍历存储tile对应的x与y的值
|
|
||||||
tileX.forEach { x ->
|
|
||||||
|
|
||||||
tileY.forEach { y ->
|
|
||||||
val tile = TileElement()
|
|
||||||
tile.elementId = element.id
|
|
||||||
tile.tilex = x
|
|
||||||
tile.tiley = y
|
|
||||||
list.add(tile)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
mDataBase.tileElementDao.insertList(list)
|
|
||||||
|
|
||||||
mDataBase.elementDao.insert(element)
|
|
||||||
|
|
||||||
} catch (e: java.lang.Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
e.message?.let { Log.e("jingo", it) }
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除数据
|
|
||||||
*/
|
|
||||||
|
|
||||||
fun deleteData(element: Element, callback: (res: Boolean, errorString: String) -> Unit) {
|
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
mDataBase.openHelper.writableDatabase.delete(
|
|
||||||
"'${element.layerId}'",
|
|
||||||
"uuid=?",
|
|
||||||
arrayOf("'${element.id}'")
|
|
||||||
)
|
|
||||||
mDataBase.elementDao.delete(element);
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Log.e("jingo", "删除数据报错 ${e.message}");
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 根据给定的geometry计算其横跨的20级瓦片Y值
|
|
||||||
// */
|
|
||||||
// private fun getTileYByGeometry(geometry: Geometry, tileYSet: MutableSet<Int?>): Set<Int?>? {
|
|
||||||
// var tileYSet: MutableSet<Int?>? = tileYSet
|
|
||||||
// val startTime = System.currentTimeMillis()
|
|
||||||
// if (tileYSet == null) {
|
|
||||||
// tileYSet = RealmSet()
|
|
||||||
// }
|
|
||||||
// val envelope = geometry.envelope
|
|
||||||
// if (envelope != null) {
|
|
||||||
// val coordinates = envelope.coordinates
|
|
||||||
// // 最小最大x轴坐标,索引0位最小x值,索引1位最大y值
|
|
||||||
// if (coordinates != null && coordinates.isNotEmpty()) {
|
|
||||||
// val minMaxY = doubleArrayOf(coordinates[0].y, coordinates[0].y)
|
|
||||||
// for (coordinate in coordinates) {
|
|
||||||
// // 获取最大和最小y的值
|
|
||||||
// if (coordinate.y < minMaxY[0]) {
|
|
||||||
// minMaxY[0] = coordinate.y
|
|
||||||
// }
|
|
||||||
// if (coordinate.y > minMaxY[1]) {
|
|
||||||
// minMaxY[1] = coordinate.y
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// // 分别计算最大和最小x值对应的tile号
|
|
||||||
// val tileY0 = MercatorProjection.latitudeToTileY(minMaxY[0], 20.toByte())
|
|
||||||
// val tileY1 = MercatorProjection.latitudeToTileY(minMaxY[1], 20.toByte())
|
|
||||||
// val minTileY = if (tileY0 <= tileY1) tileY0 else tileY1
|
|
||||||
// val maxTileY = if (tileY0 <= tileY1) tileY1 else tileY0
|
|
||||||
// println("getTileYByGeometry$envelope===$minTileY===$maxTileY")
|
|
||||||
//
|
|
||||||
// for (i in minTileY..maxTileY) {
|
|
||||||
// tileYSet.add(i)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// println("YGeometry-time:" + (System.currentTimeMillis() - startTime))
|
|
||||||
// return tileYSet
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算数据最大最小坐标
|
|
||||||
*/
|
|
||||||
private fun resetCoordinate(element: Element) {
|
|
||||||
when {
|
|
||||||
element.geometry.startsWith("POINT") -> {
|
|
||||||
var geoPoint = GeometryTools.createGeoPoint(element.geometry)
|
|
||||||
val tile = TileElement()
|
|
||||||
tile.elementId = element.id
|
|
||||||
val minLatitude = Math.max(
|
|
||||||
MercatorProjection.LATITUDE_MIN,
|
|
||||||
MercatorProjection.tileYToLatitude(
|
|
||||||
(geoPoint.latitude.toLong() + 1).toLong(),
|
|
||||||
20
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val minLongitude = Math.max(
|
|
||||||
-180.0,
|
|
||||||
MercatorProjection.tileXToLongitude(geoPoint.longitude.toLong(), 20)
|
|
||||||
)
|
|
||||||
/* element.maxx = (geoPoint.longitude * Constant.CONVERSION_FACTOR).toFloat()
|
|
||||||
element.minx = element.maxx
|
|
||||||
element.maxy = (geoPoint.latitude * Constant.CONVERSION_FACTOR).toFloat()
|
|
||||||
element.miny = element.maxy*/
|
|
||||||
}
|
|
||||||
element.geometry.startsWith("LINESTRING") -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
element.geometry.startsWith("POLYGON") -> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 捕捉数据
|
|
||||||
*/
|
|
||||||
fun snapElementDataList(
|
|
||||||
polygon: String,
|
|
||||||
callback: (list: List<Element>) -> Unit
|
|
||||||
) {
|
|
||||||
thread(start = true) {
|
|
||||||
|
|
||||||
val geometry = GeometryTools.createGeometry(polygon)
|
|
||||||
|
|
||||||
if (geometry != null) {
|
|
||||||
//计算tileX号
|
|
||||||
val tileX = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileXByGeometry(polygon, tileX)
|
|
||||||
|
|
||||||
//计算tileY号
|
|
||||||
val tileY = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileYByGeometry(polygon, tileY)
|
|
||||||
|
|
||||||
//读取数据库获取数据
|
|
||||||
val list = mDataBase.elementDao.findList(tileX, tileY)
|
|
||||||
val elements = java.util.ArrayList<Element>()
|
|
||||||
|
|
||||||
//几何遍历判断数据包括或者相交
|
|
||||||
list.forEach { element ->
|
|
||||||
if (element != null && element.geometry != null) {
|
|
||||||
val geometryTemp = GeometryTools.createGeometry(element.geometry)
|
|
||||||
if (geometryTemp != null && geometry.contains(geometryTemp) || geometry.intersects(
|
|
||||||
geometryTemp
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
elements.add(element)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
for (e in elements) {
|
|
||||||
// val layer: LayerManager =
|
|
||||||
// mDataBase.layerManagerDao.findLayerManager(e.layerId)
|
|
||||||
e.values = mutableMapOf<String, String>()
|
|
||||||
// MoshiUtil.fromJson<List<CustomLayerItem>>(layer.bundle)
|
|
||||||
cursor =
|
|
||||||
mDataBase.openHelper.readableDatabase.query("select * from \"${e.layerId}\" where uuid = \"${e.id}\"")
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (index in 0 until cursor.columnNames.size) {
|
|
||||||
val key = cursor.getColumnName(index)
|
|
||||||
val value = cursor.getString(index)
|
|
||||||
e.values[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
e.message?.let { Log.e("jingo", it) }
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(elements)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(listOfNotNull())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询数据深度信息模板
|
|
||||||
*/
|
|
||||||
fun queryElementDeepInfo(
|
|
||||||
id: String,
|
|
||||||
layerId: String,
|
|
||||||
callback: (layer: LayerManager?, itemList: List<CustomLayerItem>?) -> Unit
|
|
||||||
) {
|
|
||||||
thread(start = true) {
|
|
||||||
val layerManager = mDataBase.layerManagerDao.findLayerManager(layerId)
|
|
||||||
var layerItems = listOf<CustomLayerItem>()
|
|
||||||
if (layerManager != null) {
|
|
||||||
layerItems = DataConversion.jsonToLayerItemsList(layerManager.bundle)
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
cursor =
|
|
||||||
mDataBase.openHelper.readableDatabase.query("select * from \"$layerId\" where uuid = \"$id\"")
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (layerItem in layerItems) {
|
|
||||||
val index = cursor.getColumnIndex(layerItem.key)
|
|
||||||
when (layerItem.type) {
|
|
||||||
DataLayerItemTypeInput -> {
|
|
||||||
// layerItem.value = cursor.getString(index)
|
|
||||||
}
|
|
||||||
DataLayerItemTypeInputArray -> TODO()
|
|
||||||
DataLayerItemTypeText -> TODO()
|
|
||||||
DataLayerItemTypeSingleSelection -> {
|
|
||||||
// layerItem.value = cursor.getString(index)
|
|
||||||
}
|
|
||||||
DataLayerItemTypeMultipleSelection -> TODO()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
e.message?.let { Log.e("jingo", it) }
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(layerManager, layerItems)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fun queryElementByName(
|
|
||||||
// name: String,
|
|
||||||
// start: Int,
|
|
||||||
// total: Int,
|
|
||||||
// callback: (list: List<Element>) -> Unit
|
|
||||||
// ) {
|
|
||||||
// thread(start = true) {
|
|
||||||
// if (name.isNotEmpty()) {
|
|
||||||
// //读取数据库获取数据
|
|
||||||
// val elements = mDataBase.elementDao.findListByKeyword(name, start, total)
|
|
||||||
// var cursor: Cursor? = null
|
|
||||||
// try {
|
|
||||||
// for (e in elements) {
|
|
||||||
//// val layer: LayerManager =
|
|
||||||
//// mDataBase.layerManagerDao.findLayerManager(e.layerId)
|
|
||||||
// e.values = mutableMapOf<String, String>()
|
|
||||||
//// MoshiUtil.fromJson<List<CustomLayerItem>>(layer.bundle)
|
|
||||||
// cursor =
|
|
||||||
// mDataBase.openHelper.readableDatabase.query("select * from \"${e.layerId}\" where uuid = \"${e.id}\"")
|
|
||||||
// while (cursor.moveToNext()) {
|
|
||||||
// for (index in 0 until cursor.columnNames.size) {
|
|
||||||
// val key = cursor.getColumnName(index)
|
|
||||||
// val value = cursor.getString(index)
|
|
||||||
// e.values[key] = value
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (e: Throwable) {
|
|
||||||
// Log.e("jingo", e.message)
|
|
||||||
// } finally {
|
|
||||||
// cursor?.close()
|
|
||||||
// }
|
|
||||||
// Handler(Looper.getMainLooper()).post {
|
|
||||||
// callback.invoke(elements)
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// Handler(Looper.getMainLooper()).post {
|
|
||||||
// callback.invoke(listOfNotNull())
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun searchData(option: SearchDataOption, callback: (list: List<Element>) -> Unit) {
|
|
||||||
val nowTime = System.currentTimeMillis()
|
|
||||||
if (nowTime - lastSearchTime < 1500 && timer != null) {
|
|
||||||
timer?.cancel()
|
|
||||||
timer = null
|
|
||||||
}
|
|
||||||
timer = fixedRateTimer("", false, 1500, 10000) {
|
|
||||||
thread(start = true) {
|
|
||||||
var cursor: Cursor? = null
|
|
||||||
try {
|
|
||||||
val db = mDataBase.openHelper.readableDatabase;
|
|
||||||
|
|
||||||
val elementList = mutableListOf<Element>()
|
|
||||||
if (option.layerItemList.isEmpty() && option.projectItemList.isEmpty() && option.fieldItemList.isEmpty()) {
|
|
||||||
elementList.addAll(
|
|
||||||
mDataBase.elementDao.findListByKeyword(
|
|
||||||
option.keyword,
|
|
||||||
option.pageNum * option.pageCapacity,
|
|
||||||
option.pageCapacity
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for (e in elementList) {
|
|
||||||
e.values = mutableMapOf<String, String>()
|
|
||||||
if (cursor != null && !cursor.isClosed) {
|
|
||||||
cursor.close()
|
|
||||||
}
|
|
||||||
cursor =
|
|
||||||
db.query("select * from \"${e.layerId}\" where uuid = \"${e.id}\"")
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (index in 0 until cursor.columnNames.size) {
|
|
||||||
val key = cursor.getColumnName(index)
|
|
||||||
val value = cursor.getString(index)
|
|
||||||
e.values[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (option.fieldItemList.isNotEmpty()) {
|
|
||||||
for (item in option.fieldItemList) {
|
|
||||||
val valuesMap = mutableMapOf<String, String>()
|
|
||||||
if (cursor != null && !cursor.isClosed) {
|
|
||||||
cursor.close()
|
|
||||||
}
|
|
||||||
val sql =
|
|
||||||
"select * from \"${item.layerId}\" where ${item.fieldName} like '%${option.keyword}%' limit ${option.pageNum * option.pageCapacity},${option.pageCapacity} "
|
|
||||||
cursor = db.query(sql)
|
|
||||||
var uuid = ""
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (index in 0 until cursor.columnNames.size) {
|
|
||||||
val key = cursor.getColumnName(index)
|
|
||||||
val value = cursor.getString(index)
|
|
||||||
if (key == "uuid") {
|
|
||||||
uuid = value;
|
|
||||||
}
|
|
||||||
valuesMap[key] = value
|
|
||||||
}
|
|
||||||
val e = mDataBase.elementDao.findById(uuid);
|
|
||||||
e.values = valuesMap
|
|
||||||
elementList.add(e)
|
|
||||||
for (layer in option.layerItemList) {
|
|
||||||
if (layer.layerId == item.layerId) {
|
|
||||||
option.layerItemList.remove(layer)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (project in option.projectItemList) {
|
|
||||||
if (project.projectId == item.projectId) {
|
|
||||||
var his = false;
|
|
||||||
for (layer in option.layerItemList) {
|
|
||||||
if (layer.projectId == project.projectId) {
|
|
||||||
his = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!his) {
|
|
||||||
option.projectItemList.remove(project)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option.layerItemList.isNotEmpty()) {
|
|
||||||
val layerSet = RealmSet<String>();
|
|
||||||
for (layer in option.layerItemList) {
|
|
||||||
layerSet.add(layer.layerId)
|
|
||||||
for (project in option.projectItemList) {
|
|
||||||
if (project.projectId == layer.projectId) {
|
|
||||||
option.projectItemList.remove(project)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val elements = mDataBase.elementDao.findListByKeywordLimitLayer(
|
|
||||||
option.keyword,
|
|
||||||
layerSet,
|
|
||||||
option.pageNum * option.pageCapacity,
|
|
||||||
option.pageCapacity
|
|
||||||
)
|
|
||||||
for (e in elements) {
|
|
||||||
e.values = mutableMapOf<String, String>()
|
|
||||||
if (cursor != null && !cursor.isClosed) {
|
|
||||||
cursor.close()
|
|
||||||
}
|
|
||||||
cursor =
|
|
||||||
db.query("select * from \"${e.layerId}\" where uuid = \"${e.id}\"")
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (index in 0 until cursor.columnNames.size) {
|
|
||||||
val key = cursor.getColumnName(index)
|
|
||||||
val value = cursor.getString(index)
|
|
||||||
e.values[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elementList.addAll(elements)
|
|
||||||
}
|
|
||||||
if (option.projectItemList.isNotEmpty()) {
|
|
||||||
val projectSet = RealmSet<String>();
|
|
||||||
for (project in option.projectItemList) {
|
|
||||||
projectSet.add(project.projectId)
|
|
||||||
}
|
|
||||||
val elements = mDataBase.elementDao.findListByKeywordLimitProject(
|
|
||||||
option.keyword,
|
|
||||||
projectSet,
|
|
||||||
option.pageNum * option.pageCapacity,
|
|
||||||
option.pageCapacity
|
|
||||||
)
|
|
||||||
elementList.addAll(elements)
|
|
||||||
for (e in elementList) {
|
|
||||||
e.values = mutableMapOf<String, String>()
|
|
||||||
if (cursor != null && !cursor.isClosed) {
|
|
||||||
cursor.close()
|
|
||||||
}
|
|
||||||
cursor =
|
|
||||||
db.query("select * from \"${e.layerId}\" where uuid = \"${e.id}\"")
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
for (index in 0 until cursor.columnNames.size) {
|
|
||||||
val key = cursor.getColumnName(index)
|
|
||||||
val value = cursor.getString(index)
|
|
||||||
e.values[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
mListener?.onGetElementResult(elementList)
|
|
||||||
// callback.invoke(elementList)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
println(e)
|
|
||||||
} finally {
|
|
||||||
cursor?.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
timer?.cancel();
|
|
||||||
timer = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有检查项标签
|
|
||||||
*/
|
|
||||||
fun queryCheckManagerList(callback: (list: List<CheckManager>) -> Unit) {
|
|
||||||
thread(start = true) {
|
|
||||||
val list = mDataBase.checkManagerDao.findList()
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,268 +0,0 @@
|
|||||||
package com.navinfo.collect.library.data.handler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
import com.navinfo.collect.library.data.DataConversion
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.data.entity.CheckManager
|
|
||||||
import com.navinfo.collect.library.data.entity.CustomLayerItem
|
|
||||||
import com.navinfo.collect.library.data.entity.DataLayerItemType
|
|
||||||
import com.navinfo.collect.library.data.entity.LayerManager
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库操作
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
open class DataLayerHandler(context: Context, dataBase: MapLifeDataBase) :
|
|
||||||
BaseDataHandler(context, dataBase) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据json创建数据库
|
|
||||||
* [
|
|
||||||
* {"key":"name","type":"TEXT","nullable":true},
|
|
||||||
* {"key":"address","type":"TEXT","nullable":true},
|
|
||||||
* {"key":"type","type":"INTEGER","nullable":false},
|
|
||||||
* {"key":"longitude","type":"REAL","nullable":false},
|
|
||||||
* {"key":"latitude","type":"REAL","nullable":false},
|
|
||||||
* {"key":"id","type":"INTEGER","nullable":false,"primaryKey":true}
|
|
||||||
* ]
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* _db.execSQL("CREATE TABLE IF NOT EXISTS `edit_pois` (`rowId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `postCode` TEXT, `address` TEXT, `kindCode` TEXT, `uuid` TEXT, `geometry` TEXT, `maxx` REAL NOT NULL, `minx` REAL NOT NULL, `maxy` REAL NOT NULL, `miny` REAL NOT NULL)");
|
|
||||||
_db.execSQL("CREATE TABLE IF NOT EXISTS `element` (`rowId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `display_style` TEXT, `display_text` TEXT, `start_level` INTEGER NOT NULL, `end_level` INTEGER NOT NULL, `zindex` INTEGER NOT NULL, `visibility` INTEGER NOT NULL, `operation_time` TEXT, `export_time` TEXT, `t_lifecycle` INTEGER NOT NULL, `t_status` INTEGER NOT NULL, `bundle` TEXT, `uuid` TEXT, `geometry` TEXT, `maxx` REAL NOT NULL, `minx` REAL NOT NULL, `maxy` REAL NOT NULL, `miny` REAL NOT NULL)");
|
|
||||||
_db.execSQL("CREATE TABLE IF NOT EXISTS `layerElement` (`rowId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `uuid` TEXT, `layer_uuid` TEXT, `element_uuid` TEXT)");
|
|
||||||
_db.execSQL("CREATE TABLE IF NOT EXISTS `layerManager` (`rowId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `uuid` TEXT, `layer_name` TEXT, `zindex` INTEGER NOT NULL, `visibility` INTEGER NOT NULL, `export_time` TEXT, `import_time` TEXT, `bundle` TEXT)");
|
|
||||||
_db.execSQL("CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)");
|
|
||||||
_db.execSQL("INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7a041262c922535fc32b56d4dd16ea92')");
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
fun createTable(
|
|
||||||
layer: LayerManager,
|
|
||||||
list: List<CustomLayerItem>,
|
|
||||||
callback: (res: Boolean, errorString: String) -> Unit
|
|
||||||
) {
|
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
val sql = StringBuffer();
|
|
||||||
val database: SupportSQLiteDatabase = mDataBase.openHelper.writableDatabase
|
|
||||||
val locLayer = mDataBase.layerManagerDao.findLayerManager(layer.id);
|
|
||||||
if (locLayer != null) {
|
|
||||||
sql.append("CREATE TABLE IF NOT EXISTS '${layer.id}temp' ( uuid TEXT NOT NULL, ")
|
|
||||||
val columnBuffer = StringBuffer()
|
|
||||||
columnBuffer.append("uuid")
|
|
||||||
var count = 0;
|
|
||||||
//比对旧的数据库表,看看哪些字段需要更改
|
|
||||||
val items = DataConversion.jsonToLayerItemsList(locLayer.bundle)
|
|
||||||
for (i in list.indices) {
|
|
||||||
if (i > 0) {
|
|
||||||
sql.append(", ")
|
|
||||||
}
|
|
||||||
sql.append("'${list[i].key}' ")
|
|
||||||
sql.append(layerItemTypeToDBType(list[i].type))
|
|
||||||
for (j in items.indices) {
|
|
||||||
//这里只根据id是否相同进行了判断,如果类型变换了话会有风险,需要应用层做限制
|
|
||||||
if (items[j].key == list[i].key) {
|
|
||||||
columnBuffer.append(",")
|
|
||||||
columnBuffer.append(items[j].key)
|
|
||||||
count++
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql.append(")")
|
|
||||||
|
|
||||||
if (count == items.size && count == list.size) {
|
|
||||||
mDataBase.layerManagerDao.update(layer)
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var b = true
|
|
||||||
val sql2 =
|
|
||||||
"insert into \"${layer.id}temp\"($columnBuffer) select $columnBuffer from \"${layer.id}\""
|
|
||||||
try {
|
|
||||||
database.beginTransaction()
|
|
||||||
database.execSQL(sql.toString())
|
|
||||||
database.execSQL(sql2)
|
|
||||||
database.execSQL("drop TABLE \"${layer.id}\"")
|
|
||||||
database.execSQL("ALTER TABLE \"${layer.id}temp\" RENAME TO \"${layer.id}\"")
|
|
||||||
database.setTransactionSuccessful()
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "${e.message}")
|
|
||||||
}
|
|
||||||
b = false
|
|
||||||
} finally {
|
|
||||||
database.endTransaction()
|
|
||||||
}
|
|
||||||
if (b) {
|
|
||||||
mDataBase.layerManagerDao.update(layer)
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sql.append("CREATE TABLE IF NOT EXISTS '${layer.id}' ( uuid TEXT NOT NULL, ")
|
|
||||||
for (i in list.indices) {
|
|
||||||
if (i > 0) {
|
|
||||||
sql.append(", ")
|
|
||||||
}
|
|
||||||
sql.append("'${list[i].key}' ")
|
|
||||||
sql.append(layerItemTypeToDBType(list[i].type))
|
|
||||||
}
|
|
||||||
sql.append(")")
|
|
||||||
mDataBase.layerManagerDao.insert(layer)
|
|
||||||
mDataBase.openHelper.writableDatabase.execSQL(sql.toString())
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将数据图层自定义子表所有配置转成JSON形式
|
|
||||||
* (现在用在向数据库插入数据图层表时,主要用于原生层)
|
|
||||||
*/
|
|
||||||
private fun customLayerItemListToBundle(list: List<CustomLayerItem>): String {
|
|
||||||
val jsonArray = JSONArray()
|
|
||||||
for (item in list) {
|
|
||||||
val jsonObject = JSONObject()
|
|
||||||
jsonObject.put("key", item.key)
|
|
||||||
jsonObject.put("title", item.title)
|
|
||||||
jsonObject.put("type", item.type.ordinal)
|
|
||||||
// jsonObject.put("nullable", item.nullable)
|
|
||||||
// jsonObject.put("primaryKey", item.primaryKey)
|
|
||||||
// jsonObject.put("value", item.value)
|
|
||||||
// jsonObject.put("selectOptions", item.selectOptions)
|
|
||||||
// jsonObject.put("isMainName", item.isMainName)
|
|
||||||
jsonObject.put("describe", item.describe)
|
|
||||||
val checkIdsArray = JSONArray()
|
|
||||||
// for (c in item.checkManagerList) {
|
|
||||||
// checkIdsArray.put(c.id)
|
|
||||||
// }
|
|
||||||
jsonObject.put(
|
|
||||||
"checkManagerIds", checkIdsArray
|
|
||||||
)
|
|
||||||
jsonArray.put(jsonObject)
|
|
||||||
}
|
|
||||||
return jsonArray.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将字段的控件类型,转换成数据库字段类型
|
|
||||||
*
|
|
||||||
* enum LayerItemType {
|
|
||||||
///输入框
|
|
||||||
layerItemTypeInput,
|
|
||||||
|
|
||||||
///输入框集合
|
|
||||||
layerItemTypeInputArray,
|
|
||||||
|
|
||||||
///纯展示文本
|
|
||||||
layerItemTypeText,
|
|
||||||
|
|
||||||
///单选框
|
|
||||||
layerItemTypeSingleSelection,
|
|
||||||
|
|
||||||
///多选框
|
|
||||||
layerItemTypeMultipleSelection,
|
|
||||||
|
|
||||||
///菜单
|
|
||||||
layerItemTypeMultiLevelMenu
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
private fun layerItemTypeToDBType(type: DataLayerItemType): String {
|
|
||||||
when (type) {
|
|
||||||
DataLayerItemType.DataLayerItemTypeInput -> return "TEXT"
|
|
||||||
}
|
|
||||||
return "TEXT";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询获取图层列表
|
|
||||||
*/
|
|
||||||
fun getDataLayerList(callback: (list: List<LayerManager>) -> Unit) {
|
|
||||||
thread(start = true) {
|
|
||||||
val list = mDataBase.layerManagerDao.findList();
|
|
||||||
// ///获取拓展部分
|
|
||||||
// for (l in list) {
|
|
||||||
// l.itemList = getItemList(l.bundle);
|
|
||||||
// }
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(list)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析dataLayer的bundle部分
|
|
||||||
*/
|
|
||||||
private fun getItemList(bundle: String): List<CustomLayerItem>? {
|
|
||||||
val itemList: MutableList<CustomLayerItem> = ArrayList()
|
|
||||||
if (bundle != null) {
|
|
||||||
try {
|
|
||||||
val jsonArray = JSONArray(bundle)
|
|
||||||
for (i in 0 until jsonArray.length()) {
|
|
||||||
val itemObject = jsonArray.getJSONObject(i)
|
|
||||||
val checkManagerList = mutableListOf<CheckManager>()
|
|
||||||
val idArray = itemObject.optJSONArray("checkManagerIds")
|
|
||||||
if (idArray != null) {
|
|
||||||
for (j in 0 until idArray.length()) {
|
|
||||||
val id = idArray[j] as Int
|
|
||||||
val check = mDataBase.checkManagerDao.findCheckManagerById(id.toLong())
|
|
||||||
if (check != null)
|
|
||||||
checkManagerList.add(check)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val item = CustomLayerItem(
|
|
||||||
key = itemObject.optString("key"),
|
|
||||||
title = itemObject.optString("title"),
|
|
||||||
type = DataLayerItemType.values()[itemObject.optInt("type")],
|
|
||||||
// nullable = itemObject.optBoolean("nullable", true),
|
|
||||||
// primaryKey = itemObject.optBoolean("primaryKey", false),
|
|
||||||
// value = itemObject.opt("value"),
|
|
||||||
// selectOptions = itemObject.optString("selectOptions"),
|
|
||||||
// isMainName = itemObject.optBoolean("isMainName"),
|
|
||||||
describe = itemObject.optString("describe"),
|
|
||||||
// checkManagerList =
|
|
||||||
itemBean = ""
|
|
||||||
)
|
|
||||||
itemList.add(item)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("jingo", "CustomLayerItem 列表创建失败 " + e.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return itemList
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询某个获取图层
|
|
||||||
*/
|
|
||||||
fun getDataLayer(layerId: String, callback: (layer: LayerManager) -> Unit) {
|
|
||||||
thread(start = true) {
|
|
||||||
val layer = mDataBase.layerManagerDao.findLayerManager(layerId);
|
|
||||||
layer.itemList = getItemList(layer.bundle);
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(layer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import android.database.sqlite.SQLiteDatabase.CONFLICT_NONE
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.navinfo.collect.library.data.DataConversion
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
||||||
import com.navinfo.collect.library.data.entity.*
|
import com.navinfo.collect.library.data.entity.*
|
||||||
import com.navinfo.collect.library.data.entity.DataLayerItemType.*
|
import com.navinfo.collect.library.data.entity.DataLayerItemType.*
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
|
|
||||||
open class ImportExportController(context: Context, dataBase: MapLifeDataBase) {
|
|
||||||
protected val mContext: Context = context;
|
|
||||||
protected val mDataBase: MapLifeDataBase = dataBase;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.flutter
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.importExport.ImportExportController
|
|
||||||
import com.navinfo.collect.library.importExport.flutter.flutterhandler.FlutterImportFileHandler
|
|
||||||
import com.navinfo.collect.library.importExport.flutter.flutterhandler.FlutterShpFileHandler
|
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class FlutterImportExportController(
|
|
||||||
id: Int,
|
|
||||||
context: Context,
|
|
||||||
binaryMessenger: BinaryMessenger,
|
|
||||||
dataBase: MapLifeDataBase,
|
|
||||||
) : ImportExportController(context, dataBase), MethodChannel.MethodCallHandler {
|
|
||||||
|
|
||||||
private val mMethodChannel: MethodChannel = MethodChannel(
|
|
||||||
binaryMessenger,
|
|
||||||
"com.navinfo.collect/importOrExport_$id"
|
|
||||||
)
|
|
||||||
|
|
||||||
private val flutterShpFileHandler: FlutterShpFileHandler =
|
|
||||||
FlutterShpFileHandler(context, mMethodChannel, mDataBase)
|
|
||||||
|
|
||||||
private val flutterImportFileHandler: FlutterImportFileHandler =
|
|
||||||
FlutterImportFileHandler(context, mMethodChannel, mDataBase)
|
|
||||||
|
|
||||||
init {
|
|
||||||
mMethodChannel.setMethodCallHandler(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
when (call.method) {
|
|
||||||
/**
|
|
||||||
* shp文件操作
|
|
||||||
*/
|
|
||||||
//获取shp文件信息
|
|
||||||
FlutterImportExportProtocolKeys.ShpFileProtocol.kGetImportShpFileInfo -> {
|
|
||||||
flutterShpFileHandler.getImportShpFileInfo(call, result)
|
|
||||||
}
|
|
||||||
//导入shp数据
|
|
||||||
FlutterImportExportProtocolKeys.ShpFileProtocol.kImportShpData -> {
|
|
||||||
flutterShpFileHandler.importShpData(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//导入检查项数据
|
|
||||||
FlutterImportExportProtocolKeys.MainProtocol.kGetImportCheckFileInfo ->{
|
|
||||||
flutterImportFileHandler.importCheckData(call,result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.flutter
|
|
||||||
|
|
||||||
class FlutterImportExportProtocolKeys {
|
|
||||||
/**
|
|
||||||
* SHP文件操作
|
|
||||||
*/
|
|
||||||
object ShpFileProtocol {
|
|
||||||
/**
|
|
||||||
* 获取SHP文件信息
|
|
||||||
*/
|
|
||||||
const val kGetImportShpFileInfo = "flutter_nimap/ShpFile/getImportShpFileInfo";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入SHP数据
|
|
||||||
*/
|
|
||||||
const val kImportShpData = "flutter_nimap/ShpFile/ImportShpData";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
object MainProtocol{
|
|
||||||
/**
|
|
||||||
* 导入检查项数据
|
|
||||||
*/
|
|
||||||
const val kGetImportCheckFileInfo =
|
|
||||||
"flutter_nimap/ShpFile/getImportCheckFileInfo";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.importExport.handler.ImportFileHandler
|
|
||||||
import com.navinfo.collect.library.system.Constant
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class FlutterImportFileHandler(
|
|
||||||
context: Context,
|
|
||||||
methodChannel: MethodChannel,
|
|
||||||
dataBase: MapLifeDataBase,
|
|
||||||
) : ImportFileHandler(context, dataBase) {
|
|
||||||
/**
|
|
||||||
* 获取shp文件属性信息
|
|
||||||
*/
|
|
||||||
fun importCheckData(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is String) {
|
|
||||||
importCheckFileInfo("${call.arguments}") { bSuccess, message ->
|
|
||||||
if (bSuccess) {
|
|
||||||
result.success(message)
|
|
||||||
} else {
|
|
||||||
result.error("1", message, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Environment
|
|
||||||
import com.navinfo.collect.library.data.DataConversion
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.importExport.handler.ShpFileHandler
|
|
||||||
import com.navinfo.collect.library.system.Constant
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class FlutterShpFileHandler(
|
|
||||||
context: Context,
|
|
||||||
methodChannel: MethodChannel,
|
|
||||||
dataBase: MapLifeDataBase,
|
|
||||||
) : ShpFileHandler(context, dataBase) {
|
|
||||||
/**
|
|
||||||
* 获取shp文件属性信息
|
|
||||||
*/
|
|
||||||
fun getImportShpFileInfo(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is String) {
|
|
||||||
// .path + "/yongfeng/yongfengpolygon.shp"
|
|
||||||
// val path = call.arguments["path"];
|
|
||||||
getImportShpFileInfo("${call.arguments}") { bSuccess, message ->
|
|
||||||
if (bSuccess) {
|
|
||||||
result.success(message)
|
|
||||||
} else {
|
|
||||||
result.error("1", message, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导入shp文件数据
|
|
||||||
*/
|
|
||||||
fun importShpData(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is Map<*, *>) {
|
|
||||||
var path = "";
|
|
||||||
var layerId = "";
|
|
||||||
if (call.hasArgument("path")) {
|
|
||||||
path = call.argument<String>("path").toString()
|
|
||||||
// path = Environment.getExternalStorageDirectory()
|
|
||||||
// .path + "/yongfeng/yongfengpolygon.shp"
|
|
||||||
}
|
|
||||||
if (call.hasArgument("layerId")) {
|
|
||||||
layerId = call.argument<String>("layerId").toString()
|
|
||||||
}
|
|
||||||
if (path.isNotEmpty() && layerId.isNotEmpty()) {
|
|
||||||
importShpData("$path", layerId) { bSuccess, message ->
|
|
||||||
if (bSuccess) {
|
|
||||||
result.success(true)
|
|
||||||
} else {
|
|
||||||
result.error("-1", message, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.handler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
|
|
||||||
open class ImportExportBaseHandler(context: Context, dataBase: MapLifeDataBase) {
|
|
||||||
protected val mContext: Context = context
|
|
||||||
protected val mDataBase: MapLifeDataBase = dataBase
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.handler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.data.entity.CheckManager
|
|
||||||
import org.json.JSONObject
|
|
||||||
import java.io.File
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
open class ImportFileHandler(context: Context, dataBase: MapLifeDataBase) :
|
|
||||||
ImportExportBaseHandler(context, dataBase) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
}
|
|
||||||
|
|
||||||
fun importCheckFileInfo(path: String, callback: (bSuccess: Boolean, message: String) -> Unit) {
|
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
val file = File(path)
|
|
||||||
if (file.exists()) {
|
|
||||||
val inputStream = file.inputStream()
|
|
||||||
inputStream.bufferedReader().useLines { lines ->
|
|
||||||
try {
|
|
||||||
val iterator = lines.iterator()
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
var json = iterator.next();
|
|
||||||
val jsonObject = JSONObject(json)
|
|
||||||
val type = jsonObject.optInt("type", 0)
|
|
||||||
val tag = jsonObject.optString("tag", "未命名")
|
|
||||||
var regex = jsonObject.optString("regexStr")
|
|
||||||
if (regex.startsWith("/") && regex.endsWith("/")) {
|
|
||||||
regex = regex.substring(1, regex.length - 1)
|
|
||||||
}
|
|
||||||
val check = CheckManager(type = type, tag = tag, regexStr = regex)
|
|
||||||
mDataBase.checkManagerDao.insert(check)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.message?.let { Log.e("jingo", it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// inputStream.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.message?.let { Log.e("jingo", it) }
|
|
||||||
}
|
|
||||||
android.os.Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
package com.navinfo.collect.library.importExport.handler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Environment
|
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
|
||||||
import com.navinfo.collect.library.data.DataConversion
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.data.entity.TileElement
|
|
||||||
import com.navinfo.collect.library.utils.GeometryToolsKt
|
|
||||||
import com.navinfo.collect.library.utils.StringUtil
|
|
||||||
import io.realm.RealmSet
|
|
||||||
import org.gdal.gdal.gdal
|
|
||||||
import org.gdal.ogr.*
|
|
||||||
import org.gdal.osr.SpatialReference
|
|
||||||
import org.json.JSONObject
|
|
||||||
import java.io.File
|
|
||||||
import kotlin.concurrent.thread
|
|
||||||
|
|
||||||
open class ShpFileHandler(context: Context, dataBase: MapLifeDataBase) :
|
|
||||||
ImportExportBaseHandler(context, dataBase) {
|
|
||||||
val strDriverName = "ESRI Shapefile"
|
|
||||||
|
|
||||||
init {
|
|
||||||
Log.e("jingo", "ShpFileHandler 初始化!!!!!")
|
|
||||||
ogr.RegisterAll()
|
|
||||||
gdal.AllRegister()
|
|
||||||
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
|
|
||||||
// 为了使属性表字段支持中文,请添加下面这句
|
|
||||||
gdal.SetConfigOption("SHAPE_ENCODING", "CP936")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getImportShpFileInfo(path: String, callback: (bSuccess: Boolean, message: String) -> Unit) {
|
|
||||||
try {
|
|
||||||
val file: File = File(path);
|
|
||||||
if (file.exists()) {
|
|
||||||
//创建一个文件,根据strDriverName扩展名自动判断驱动类型
|
|
||||||
val oDriver: org.gdal.ogr.Driver = ogr.GetDriverByName(strDriverName)
|
|
||||||
if (oDriver == null) {
|
|
||||||
Log.e("jingo", "$strDriverName 驱动不可用!");
|
|
||||||
callback(false, "$strDriverName 驱动不可用!")
|
|
||||||
}
|
|
||||||
val dataSource: DataSource = oDriver.Open(path)
|
|
||||||
val layer: Layer = dataSource.GetLayer(0)
|
|
||||||
// for (i in 0 until dataSource.GetLayerCount()) {
|
|
||||||
val layerItem = dataSource.GetLayer(0);
|
|
||||||
// Log.e("jingo", "图层名称:${layerItem.GetName()}")
|
|
||||||
//空间参考坐标系
|
|
||||||
// val spatialReference:SpatialReference = layerItem.GetSpatialRef()
|
|
||||||
//图层范围
|
|
||||||
// val layerExtent: DoubleArray = layerItem.GetExtent()
|
|
||||||
// }
|
|
||||||
val geomType = getGeomType(layerItem.GetGeomType())
|
|
||||||
Log.e("jingo", "图层数据类型:${layerItem.GetGeomType()}")
|
|
||||||
//获取图层信息
|
|
||||||
val featureDefn: FeatureDefn = layer.GetLayerDefn()
|
|
||||||
val fieldCount = featureDefn.GetFieldCount()
|
|
||||||
val stringBuffer = StringBuffer()
|
|
||||||
for (i in 0 until fieldCount) {
|
|
||||||
val fieldDefn: FieldDefn = featureDefn.GetFieldDefn(i)
|
|
||||||
//得到属性字段类型
|
|
||||||
// val fieldType = fieldDefn.GetFieldType()
|
|
||||||
// val fieldTypeName = fieldDefn.GetFieldTypeName(fieldType)
|
|
||||||
//得到属性字段名称
|
|
||||||
val fieldName = fieldDefn.GetName()
|
|
||||||
if (stringBuffer.isNotEmpty()) {
|
|
||||||
stringBuffer.append(";")
|
|
||||||
}
|
|
||||||
stringBuffer.append(fieldName)
|
|
||||||
}
|
|
||||||
|
|
||||||
val jsonString =
|
|
||||||
"{\"layerName\":\"${layerItem.GetName()}\",\"geomType\":$geomType,\"keys\":\"$stringBuffer\"}"
|
|
||||||
callback(true, jsonString)
|
|
||||||
// //读取空间信息及属性列表
|
|
||||||
// for (i in 0 until fieldCount) {
|
|
||||||
// val feature: Feature = layer.GetFeature(i.toLong())
|
|
||||||
// for ((key, value) in map) {
|
|
||||||
// val fvalue = feature.GetFieldAsString(value)
|
|
||||||
// Log.e("jingo", "属性名称:$value 属性值:$fvalue")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
callback(false, "${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getGeomType(type: Int): Int {
|
|
||||||
when (type) {
|
|
||||||
ogr.wkbPoint -> return 0
|
|
||||||
ogr.wkbPolygon -> return 2
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
fun importShpData(
|
|
||||||
path: String,
|
|
||||||
mapLayerId: String,
|
|
||||||
callback: (bSuccess: Boolean, message: String) -> Unit
|
|
||||||
) {
|
|
||||||
thread(start = true) {
|
|
||||||
try {
|
|
||||||
val mapLayer = mDataBase.layerManagerDao.findLayerManager(mapLayerId)
|
|
||||||
if (mapLayer != null) {
|
|
||||||
|
|
||||||
val mapLayerItemList = DataConversion.jsonToLayerItemsList(mapLayer.bundle)
|
|
||||||
var mainName = ""
|
|
||||||
// for (item in mapLayerItemList) {
|
|
||||||
// if (item.isMainName) {
|
|
||||||
// mainName = item.key
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
val file = File(path);
|
|
||||||
if (file.exists()) {
|
|
||||||
val oDriver: org.gdal.ogr.Driver = ogr.GetDriverByName(strDriverName)
|
|
||||||
if (oDriver == null) {
|
|
||||||
Log.e("jingo", "$strDriverName 驱动不可用!");
|
|
||||||
callback(false, "$strDriverName 驱动不可用!")
|
|
||||||
}
|
|
||||||
val dataSource: DataSource = oDriver.Open(path)
|
|
||||||
val layer: Layer = dataSource.GetLayer(0)
|
|
||||||
val layerItem = dataSource.GetLayer(0)
|
|
||||||
//获取图层信息
|
|
||||||
val featureDefn: FeatureDefn = layer.GetLayerDefn()
|
|
||||||
val fieldCount = featureDefn.GetFieldCount()
|
|
||||||
val db = mDataBase.openHelper.readableDatabase
|
|
||||||
db.beginTransaction()
|
|
||||||
for (i in 0 until layer.GetFeatureCount()) {
|
|
||||||
val feature = layer.GetFeature(i)
|
|
||||||
val geometry = feature.GetGeometryRef()
|
|
||||||
val stringNameBuffer = StringBuffer()
|
|
||||||
val stringValueBuffer = StringBuffer()
|
|
||||||
var displayText = ""
|
|
||||||
for (i in 0 until fieldCount) {
|
|
||||||
val fieldDefn: FieldDefn = featureDefn.GetFieldDefn(i)
|
|
||||||
//得到属性字段名称
|
|
||||||
val fieldName = fieldDefn.GetName()
|
|
||||||
val fieldValue = feature.GetFieldAsString(fieldName)
|
|
||||||
stringNameBuffer.append(",'")
|
|
||||||
stringNameBuffer.append(fieldName)
|
|
||||||
stringNameBuffer.append("'")
|
|
||||||
|
|
||||||
stringValueBuffer.append(",'")
|
|
||||||
stringValueBuffer.append(fieldValue)
|
|
||||||
stringValueBuffer.append("'")
|
|
||||||
if (mainName == fieldName) {
|
|
||||||
displayText = fieldValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val uuid = StringUtil.createUUID()
|
|
||||||
val wkt = geometry.ExportToWkt()
|
|
||||||
val nowTime = StringUtil.getYYYYMMDDHHMMSSS();
|
|
||||||
val masterPoint = GeometryToolsKt.getMasterPoint(wkt)
|
|
||||||
var jsonObject = JSONObject(mapLayer.style)
|
|
||||||
jsonObject.put(
|
|
||||||
"masterPoint",
|
|
||||||
masterPoint
|
|
||||||
)
|
|
||||||
val style = jsonObject.toString()
|
|
||||||
val sql =
|
|
||||||
"insert into '$mapLayerId' ('uuid'${stringNameBuffer}) values ('$uuid'${stringValueBuffer})"
|
|
||||||
val sql2 =
|
|
||||||
"insert into 'element' ('layer_id','display_style','display_text','visibility','export_time','t_lifecycle','t_status','geometry','uuid','start_level','end_level','zindex','operation_time') values ('$mapLayerId','$style','$displayText','0','$nowTime','2','1','${wkt}','$uuid',0,0,0,'$nowTime')"
|
|
||||||
Log.e("jingo",sql)
|
|
||||||
Log.e("jingo",sql2)
|
|
||||||
db.execSQL(sql)
|
|
||||||
db.execSQL(sql2)
|
|
||||||
if (geometry != null) {
|
|
||||||
val tileX = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileXByGeometry(wkt, tileX)
|
|
||||||
val tileY = RealmSet<Int>()
|
|
||||||
GeometryToolsKt.getTileYByGeometry(wkt, tileY)
|
|
||||||
|
|
||||||
//遍历存储tile对应的x与y的值
|
|
||||||
tileX.forEach { x ->
|
|
||||||
|
|
||||||
tileY.forEach { y ->
|
|
||||||
val sql3 =
|
|
||||||
"insert into 'tileElement' ('tilex','tiley','element_uuid','uuid') values ('$x','$y','$uuid','${StringUtil.createUUID()}')"
|
|
||||||
db.execSQL(sql3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.setTransactionSuccessful()
|
|
||||||
db.endTransaction()
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(true, "SHP导入成功")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "没有对应的图层")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("导入数据出错", e.toString());
|
|
||||||
Handler(Looper.getMainLooper()).post {
|
|
||||||
callback.invoke(false, "SHP导入失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.FlutterBaseActivity
|
|
||||||
import com.navinfo.collect.library.map.NIMapController
|
|
||||||
import com.navinfo.collect.library.map.NIMapOptions
|
|
||||||
import com.navinfo.collect.library.map.flutter.flutterhandler.*
|
|
||||||
import com.navinfo.collect.library.map.flutter.maphandler.FlutterMeasureLayerHandler
|
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class FlutterMapController(
|
|
||||||
id: Int,
|
|
||||||
context: Context,
|
|
||||||
binaryMessenger: BinaryMessenger,
|
|
||||||
options: NIMapOptions,
|
|
||||||
) : NIMapController(context, options), MethodChannel.MethodCallHandler {
|
|
||||||
private val mMethodChannel: MethodChannel = MethodChannel(
|
|
||||||
binaryMessenger,
|
|
||||||
"com.navinfo.collect/mapView_$id"
|
|
||||||
)
|
|
||||||
|
|
||||||
private val flutterMapBaseControlHandler: FlutterMapBaseControlHandler =
|
|
||||||
FlutterMapBaseControlHandler(context, mMethodChannel, mMapView)
|
|
||||||
|
|
||||||
private val flutterAnimationHandler: FlutterAnimationHandler by lazy {
|
|
||||||
FlutterAnimationHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
private val flutterMarkerHandler: FlutterMarkerHandler by lazy {
|
|
||||||
FlutterMarkerHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterLocationHandler: FlutterLocationLayerHandler by lazy {
|
|
||||||
FlutterLocationLayerHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterLineHandler: FlutterLineHandler by lazy {
|
|
||||||
FlutterLineHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterPolygonHandler: FlutterPolygonHandler by lazy {
|
|
||||||
FlutterPolygonHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterViewportHandler: FlutterViewportHandler by lazy {
|
|
||||||
FlutterViewportHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterLayerManagerHandler: FlutterLayerManagerHandler =
|
|
||||||
FlutterLayerManagerHandler(context, mMapView)
|
|
||||||
|
|
||||||
init {
|
|
||||||
mMethodChannel.setMethodCallHandler(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val flutterMeasureLayerHandler: FlutterMeasureLayerHandler by lazy {
|
|
||||||
FlutterMeasureLayerHandler(context, mMapView)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
when (call.method) {
|
|
||||||
/**
|
|
||||||
* 地图基础操作部分
|
|
||||||
*/
|
|
||||||
//刷新地图
|
|
||||||
FlutterMapProtocolKeys.kMapUpdateMap -> {
|
|
||||||
flutterMapBaseControlHandler.updateMap(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图动画效果控制协议
|
|
||||||
*/
|
|
||||||
//根据屏幕像素移动地图
|
|
||||||
FlutterMapProtocolKeys.AnimationProtocol.kMapAnimationByPixel -> {
|
|
||||||
flutterAnimationHandler.animation(call, result)
|
|
||||||
}
|
|
||||||
//地图缩小
|
|
||||||
FlutterMapProtocolKeys.AnimationProtocol.kMapAnimationZoomOut -> {
|
|
||||||
flutterAnimationHandler.zoomOut(call, result)
|
|
||||||
}
|
|
||||||
//地图放大
|
|
||||||
FlutterMapProtocolKeys.AnimationProtocol.kMapAnimationZoomIn -> {
|
|
||||||
flutterAnimationHandler.zoomIn(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图Marker控制协议
|
|
||||||
*/
|
|
||||||
//增加或更新marker
|
|
||||||
FlutterMapProtocolKeys.MarkerProtocol.kMapAddMarkerMethod -> {
|
|
||||||
flutterMarkerHandler.addMarker(call, result)
|
|
||||||
}
|
|
||||||
//删除marker
|
|
||||||
FlutterMapProtocolKeys.MarkerProtocol.kMapRemoveMarkerMethod -> {
|
|
||||||
flutterMarkerHandler.removeMarker(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图定位信息控制协议
|
|
||||||
*/
|
|
||||||
//更新定位信息
|
|
||||||
FlutterMapProtocolKeys.LocationProtocol.kMapUpdateLocationDataMethod -> {
|
|
||||||
flutterLocationHandler.updateCurrentLocation(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线数据协议
|
|
||||||
*/
|
|
||||||
//绘制线时的打点
|
|
||||||
FlutterMapProtocolKeys.LineProtocol.kMapAddDrawLinePointMethod -> {
|
|
||||||
flutterLineHandler.addDrawLinePoint(call, result)
|
|
||||||
}
|
|
||||||
//清除正在绘制的线
|
|
||||||
FlutterMapProtocolKeys.LineProtocol.kMapCleanDrawLineMethod -> {
|
|
||||||
flutterLineHandler.clean(call, result)
|
|
||||||
}
|
|
||||||
//添加线数据
|
|
||||||
FlutterMapProtocolKeys.LineProtocol.kMapAddDrawLineMethod -> {
|
|
||||||
flutterLineHandler.addDrawLine(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 面数据协议
|
|
||||||
*/
|
|
||||||
//绘制面时的打点
|
|
||||||
FlutterMapProtocolKeys.PolygonProtocol.kMapAddDrawPolygonPointMethod -> {
|
|
||||||
flutterPolygonHandler.addDrawPolygonPoint(call, result)
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 面数据协议
|
|
||||||
*/
|
|
||||||
//绘制面时的打点
|
|
||||||
FlutterMapProtocolKeys.PolygonProtocol.kMapAddDrawPolygonNiPointMethod -> {
|
|
||||||
flutterPolygonHandler.addDrawPolygonNiPoint(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//绘制面
|
|
||||||
FlutterMapProtocolKeys.PolygonProtocol.kMapAddDrawPolygonMethod -> {
|
|
||||||
flutterPolygonHandler.addDrawPolygon(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//清除正在绘制的面
|
|
||||||
FlutterMapProtocolKeys.PolygonProtocol.kMapCleanDrawPolygonMethod -> {
|
|
||||||
flutterPolygonHandler.clean(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 视窗操作
|
|
||||||
*/
|
|
||||||
//设置地图中心点的偏移量
|
|
||||||
FlutterMapProtocolKeys.ViewportProtocol.kMapViewportSetViewCenterMethod -> {
|
|
||||||
flutterViewportHandler.setMapViewCenter(call, result)
|
|
||||||
}
|
|
||||||
//获取几何扩展后的外接矩形
|
|
||||||
FlutterMapProtocolKeys.ViewportProtocol.kMapViewportGetBoundingBoxMethod -> {
|
|
||||||
flutterViewportHandler.getBoundingBoxWkt(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//坐标转屏幕点
|
|
||||||
FlutterMapProtocolKeys.ViewportProtocol.kMapViewportToScreenPointMethod -> {
|
|
||||||
flutterViewportHandler.toScreenPoint(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//屏幕点转坐标
|
|
||||||
FlutterMapProtocolKeys.ViewportProtocol.kMapViewportFromScreenPointMethod -> {
|
|
||||||
flutterViewportHandler.fromScreenPoint(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 底图切换控制协议
|
|
||||||
*/
|
|
||||||
//切换底图
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapSwitchRasterTileLayerMethod -> {
|
|
||||||
flutterLayerManagerHandler.switchRasterTileLayer(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取支持的底图
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapGetRasterTileLayerListMethod -> {
|
|
||||||
flutterLayerManagerHandler.getBaseRasterTileLayerList(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 底图切换控制协议
|
|
||||||
*/
|
|
||||||
//切换底图
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapSwitchRasterTileLayerMethod -> {
|
|
||||||
flutterLayerManagerHandler.switchRasterTileLayer(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取支持的底图
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapGetRasterTileLayerListMethod -> {
|
|
||||||
flutterLayerManagerHandler.getBaseRasterTileLayerList(call, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
//绘制线或者面
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapDrawLineOrPolygonMethod -> {
|
|
||||||
flutterMeasureLayerHandler.drawLineOrPolygon(call, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//清理绘制线或者面
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapCleanDrawLineOrPolygonMethod -> {
|
|
||||||
flutterMeasureLayerHandler.clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
//绘制线或者面
|
|
||||||
FlutterMapProtocolKeys.LayerManagerProtocol.kMapEditLineOrPolygonMethod -> {
|
|
||||||
flutterLayerManagerHandler.editLineOrPolygon(call, result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun release() {
|
|
||||||
super.release()
|
|
||||||
|
|
||||||
mMethodChannel.setMethodCallHandler(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter
|
|
||||||
|
|
||||||
import com.navinfo.collect.library.map.NIMapOptions
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
import org.oscim.layers.marker.MarkerItem
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 和flutter层进行数据传递时的数据格式转换
|
|
||||||
*/
|
|
||||||
class FlutterMapConversion {
|
|
||||||
companion object {
|
|
||||||
// flutter json 转成原生对象
|
|
||||||
/**
|
|
||||||
* 地图初始配置信息转换
|
|
||||||
*/
|
|
||||||
fun flutterToNIMapOptions(args: String): NIMapOptions {
|
|
||||||
|
|
||||||
return NIMapOptions.fromJson(args)
|
|
||||||
// return MoshiUtil.fromJson<NIMapOptions>(args)!!;
|
|
||||||
// val moshi = Moshi.Builder().build()
|
|
||||||
// val jsonAdapter: JsonAdapter<NIMapOptions> = moshi.adapter(NIMapOptions::class.java)
|
|
||||||
// return jsonAdapter.fromJson(args)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//原生转给flutter
|
|
||||||
/**
|
|
||||||
* marker 转json
|
|
||||||
*/
|
|
||||||
fun markerToJson(marker: MarkerItem): String {
|
|
||||||
return "{\"id\":\"${marker.title}\",\"description\":\"${marker.description}\",\"geoPoint\":{\"longitude\":${marker.geoPoint.longitude},\"latitude\":${marker.geoPoint.latitude}}}"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* line转json
|
|
||||||
*/
|
|
||||||
fun lineToJson(list: List<GeoPoint>): String {
|
|
||||||
var jsonArray = JSONArray();
|
|
||||||
for (point in list) {
|
|
||||||
val jsonObject = JSONObject();
|
|
||||||
jsonObject.put("latitude", point.latitude)
|
|
||||||
jsonObject.put("longitude", point.longitude)
|
|
||||||
jsonObject.put("latitudeE6", point.latitudeE6)
|
|
||||||
jsonObject.put("longitudeE6", point.longitudeE6)
|
|
||||||
jsonArray.put(jsonObject)
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonArray.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图转json
|
|
||||||
*/
|
|
||||||
fun baseMapTypeToJson(list: Array<NIMapView.BASE_MAP_TYPE>): String {
|
|
||||||
var jsonArray = JSONArray();
|
|
||||||
//循环输出 值
|
|
||||||
for (baseMapType in list) {
|
|
||||||
val jsonObject = JSONObject();
|
|
||||||
jsonObject.put("title", baseMapType.title)
|
|
||||||
jsonObject.put("url", baseMapType.url)
|
|
||||||
jsonObject.put("tilePath", baseMapType.tilePath)
|
|
||||||
jsonArray.put(jsonObject)
|
|
||||||
}
|
|
||||||
return jsonArray.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun toGeoPointMapList(list: List<GeoPoint>): List<*> {
|
|
||||||
val newList = mutableListOf<Map<*, *>>()
|
|
||||||
for (item in list) {
|
|
||||||
newList.add(
|
|
||||||
mapOf(
|
|
||||||
"latitude" to item.latitude,
|
|
||||||
"longitude" to item.longitude,
|
|
||||||
"latitudeE6" to item.latitudeE6,
|
|
||||||
"longitudeE6" to item.longitudeE6,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return newList
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter
|
|
||||||
|
|
||||||
object FlutterMapProtocolKeys {
|
|
||||||
|
|
||||||
///刷新地图
|
|
||||||
const val kMapUpdateMap = "flutter_nimap/base/UpdateMap";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图动画控制协议
|
|
||||||
*/
|
|
||||||
object AnimationProtocol {
|
|
||||||
// 按像素移动地图中心点
|
|
||||||
const val kMapAnimationByPixel = "flutter_nimap/animation/AnimationByPixel"
|
|
||||||
|
|
||||||
///地图缩小
|
|
||||||
const val kMapAnimationZoomOut = "flutter_nimap/animation/AnimationZoomOut";
|
|
||||||
|
|
||||||
///地图放大
|
|
||||||
const val kMapAnimationZoomIn = "flutter_nimap/animation/AnimationZoomIn";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* marker控制协议
|
|
||||||
*/
|
|
||||||
object MarkerProtocol {
|
|
||||||
// 添加marker
|
|
||||||
const val kMapAddMarkerMethod = "flutter_nimap/marker/addMarker"
|
|
||||||
|
|
||||||
// 删除marker
|
|
||||||
const val kMapRemoveMarkerMethod = "flutter_nimap/marker/removeMarker";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定位信息控制协议
|
|
||||||
*/
|
|
||||||
object LocationProtocol {
|
|
||||||
// 动态更新我的位置数据
|
|
||||||
const val kMapUpdateLocationDataMethod = "flutter_nimap/location/updateLocationData"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线数据控制协议
|
|
||||||
*/
|
|
||||||
object LineProtocol {
|
|
||||||
// 线数据打点
|
|
||||||
const val kMapAddDrawLinePointMethod = "flutter_nimap/line/addDrawLinePoint";
|
|
||||||
|
|
||||||
// 清除画线功能
|
|
||||||
const val kMapCleanDrawLineMethod = "flutter_nimap/line/cleanDrawLine"
|
|
||||||
|
|
||||||
// 添加线数据
|
|
||||||
const val kMapAddDrawLineMethod = "flutter_nimap/line/addDrawLine"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线数据控制协议
|
|
||||||
*/
|
|
||||||
object PolygonProtocol {
|
|
||||||
// 线数据打点
|
|
||||||
const val kMapAddDrawPolygonPointMethod = "flutter_nimap/Polygon/addDrawPolygonPoint";
|
|
||||||
// 线数据打点
|
|
||||||
const val kMapAddDrawPolygonNiPointMethod = "flutter_nimap/Polygon/addDrawPolygonNiPoint";
|
|
||||||
// 添加面数据
|
|
||||||
const val kMapAddDrawPolygonMethod = "flutter_nimap/Polygon/addDrawPolygon"
|
|
||||||
// 清除画线功能
|
|
||||||
const val kMapCleanDrawPolygonMethod = "flutter_nimap/Polygon/cleanDrawPolygon"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图view操作
|
|
||||||
*/
|
|
||||||
object ViewportProtocol {
|
|
||||||
// 设置地图中心点
|
|
||||||
const val kMapViewportSetViewCenterMethod = "flutter_nimap/Viewport/SetViewCenter";
|
|
||||||
//获取几何扩展后的外接矩形
|
|
||||||
const val kMapViewportGetBoundingBoxMethod = "flutter_nimap/Viewport/GetBoundingBox";
|
|
||||||
//坐标转屏幕点
|
|
||||||
const val kMapViewportToScreenPointMethod = "flutter_nimap/Viewport/ToScreenPoint";
|
|
||||||
//屏幕点转坐标
|
|
||||||
const val kMapViewportFromScreenPointMethod = "flutter_nimap/Viewport/FromScreenPoint";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 原生地图通知flutter命令
|
|
||||||
*/
|
|
||||||
object MapCallBackProtocol {
|
|
||||||
// 用户操作地图,状态回调
|
|
||||||
const val kMapEventCallback = "flutter_nimap/mapCallBack/kMapEventCallback";
|
|
||||||
|
|
||||||
// 用户单击地图,回调点击坐标
|
|
||||||
const val kMapOnClickCallback = "flutter_nimap/mapCallBack/kMapOnClickCallback";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LayerManager控制协议
|
|
||||||
*/
|
|
||||||
object LayerManagerProtocol {
|
|
||||||
// 切换RasterTileLayer
|
|
||||||
const val kMapSwitchRasterTileLayerMethod = "flutter_nimap/LayerManager/switchRasterTileLayer";
|
|
||||||
|
|
||||||
// 移除RasterTileLayer
|
|
||||||
const val kMapRemoveRasterTileLayerMethod = "flutter_nimap/LayerManager/removeRasterTileLayer"
|
|
||||||
|
|
||||||
// 获取RasterTileLayer
|
|
||||||
const val kMapGetRasterTileLayerListMethod = "flutter_nimap/LayerManager/getRasterTileLayerList"
|
|
||||||
|
|
||||||
// 绘制线或者面
|
|
||||||
const val kMapDrawLineOrPolygonMethod = "flutter_nimap/LayerManager/drawLineOrPolygon"
|
|
||||||
|
|
||||||
// 清理绘制线或者面
|
|
||||||
const val kMapCleanDrawLineOrPolygonMethod = "flutter_nimap/LayerManager/cleanDrawLineOrPolygon"
|
|
||||||
|
|
||||||
// 编辑线或者面
|
|
||||||
const val kMapEditLineOrPolygonMethod = "flutter_nimap/LayerManager/editLineOrPolygon"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.handler.AnimationHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
class FlutterAnimationHandler(
|
|
||||||
context: Context,
|
|
||||||
mapView: NIMapView
|
|
||||||
) :
|
|
||||||
AnimationHandler(context, mapView) {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用像素移动地图
|
|
||||||
*/
|
|
||||||
fun animation(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.hasArgument("xPixel") && call.hasArgument("yPixel")) {
|
|
||||||
val x = call.argument<Double>("xPixel")
|
|
||||||
val y = call.argument<Double>("yPixel")
|
|
||||||
var time = 200;
|
|
||||||
if (call.hasArgument("animateDurationMs")) {
|
|
||||||
time = call.argument<Int>("animateDurationMs")!!;
|
|
||||||
}
|
|
||||||
super.animationByPixel(x!!.toInt(), y!!.toInt(), time.toLong())
|
|
||||||
result.success(true)
|
|
||||||
} else if (call.hasArgument("latitude") && call.hasArgument("longitude")) {
|
|
||||||
var time = 200;
|
|
||||||
if (call.hasArgument("animateDurationMs")) {
|
|
||||||
time = call.argument<Int>("animateDurationMs")!!;
|
|
||||||
}
|
|
||||||
animationByLonLat(
|
|
||||||
call.argument<Double>("latitude") as Double,
|
|
||||||
call.argument<Double>("longitude") as Double,
|
|
||||||
time.toLong()
|
|
||||||
)
|
|
||||||
result.success(true)
|
|
||||||
} else {
|
|
||||||
result.error("-1", "像素坐标错误", "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图缩小
|
|
||||||
*/
|
|
||||||
fun zoomOut(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
super.zoomOut()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 地图放大
|
|
||||||
*/
|
|
||||||
fun zoomIn(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
super.zoomIn()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.handler.LayerManagerHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 图层操作控制
|
|
||||||
*/
|
|
||||||
class FlutterLayerManagerHandler(context: Context, mapView: NIMapView) :
|
|
||||||
LayerManagerHandler(context, mapView) {
|
|
||||||
|
|
||||||
//切换底图
|
|
||||||
fun switchRasterTileLayer(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.hasArgument("url") && call.hasArgument("tilePath")) {
|
|
||||||
|
|
||||||
}
|
|
||||||
val url = call.argument<String>("url")
|
|
||||||
val tilePath = call.argument<String>("tilePath")
|
|
||||||
val cache = call.argument<Boolean>("cache")
|
|
||||||
switchRasterTileLayer(url, tilePath, cache)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeRasterTileLayer(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.hasArgument("url")) {
|
|
||||||
val url = call.argument<String>("url")
|
|
||||||
removeRasterTileLayer(url!!);
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取支持底图内容
|
|
||||||
fun getBaseRasterTileLayerList(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
getBaseRasterTileLayerList { baseMapJson ->
|
|
||||||
result.success(baseMapJson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//编辑线或者面
|
|
||||||
fun editLineOrPolygon(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.hasArgument("type")&&call.hasArgument("geometry")) {
|
|
||||||
val type = call.argument<Int>("type")
|
|
||||||
val geometry = call.argument<String>("geometry")
|
|
||||||
if (type != null) {
|
|
||||||
editLineOrPolygon(geometry!!,type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import com.navinfo.collect.library.map.handler.LineHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线数据操作控制
|
|
||||||
*/
|
|
||||||
class FlutterLineHandler(context: Context, mapView: NIMapView) :
|
|
||||||
LineHandler(context, mapView) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给线数据增加一个点,如果是经纬度就用经纬度,如果是屏幕坐标就转换成经纬度
|
|
||||||
*/
|
|
||||||
fun addDrawLinePoint(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
val list = addDrawLinePoint(
|
|
||||||
GeoPoint(
|
|
||||||
mMapView.vtmMap.mapPosition.latitude,
|
|
||||||
mMapView.vtmMap.mapPosition.longitude
|
|
||||||
)
|
|
||||||
)
|
|
||||||
result.success(FlutterMapConversion.lineToJson(list))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clean(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
clean()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addDrawLine(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
clean()
|
|
||||||
val pointList = mutableListOf<GeoPoint>();
|
|
||||||
if (call.arguments is List<*>) {
|
|
||||||
for (item in call.arguments as List<*>) {
|
|
||||||
if (item is Map<*, *>) {
|
|
||||||
pointList.add(GeoPoint(item["latitude"] as Double, item["longitude"] as Double))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addDrawLine(pointList);
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NILocation
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.handler.LocationLayerHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
|
|
||||||
class FlutterLocationLayerHandler(context: Context, mapView: NIMapView) :
|
|
||||||
LocationLayerHandler(context, mapView) {
|
|
||||||
|
|
||||||
var bFirst = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置当前定位信息
|
|
||||||
*/
|
|
||||||
fun updateCurrentLocation(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
var bTracking = true;
|
|
||||||
if (call.hasArgument("tracking")) {
|
|
||||||
bTracking = call.argument<Boolean>("tracking") == true
|
|
||||||
}
|
|
||||||
var locationMap = call.argument<Map<*, *>>("location");
|
|
||||||
if (locationMap != null) {
|
|
||||||
if (locationMap.containsKey("latitude") && locationMap.containsKey("longitude")) {
|
|
||||||
val longitude = locationMap["longitude"]
|
|
||||||
val latitude = locationMap["latitude"]
|
|
||||||
val location = NILocation("GPS");
|
|
||||||
if (latitude is Double && longitude is Double) {
|
|
||||||
location.latitude = latitude
|
|
||||||
location.longitude = longitude
|
|
||||||
} else {
|
|
||||||
return result.success(false)
|
|
||||||
}
|
|
||||||
if (locationMap.containsKey("direction")) {
|
|
||||||
val direction = locationMap["direction"]
|
|
||||||
if (direction is Float)
|
|
||||||
location.bearing = direction
|
|
||||||
}
|
|
||||||
if (locationMap.containsKey("altitude")) {
|
|
||||||
val altitude = locationMap["altitude"]
|
|
||||||
if (altitude is Double)
|
|
||||||
location.altitude = altitude
|
|
||||||
}
|
|
||||||
if (locationMap.containsKey("radius")) {
|
|
||||||
val radius = locationMap["radius"]
|
|
||||||
if (radius is Float)
|
|
||||||
location.radius = radius
|
|
||||||
}
|
|
||||||
setCurrentLocation(location)
|
|
||||||
if (bFirst || bTracking) {
|
|
||||||
mMapView.vtmMap.animator().animateTo(GeoPoint(latitude, longitude))
|
|
||||||
bFirst = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapProtocolKeys
|
|
||||||
import com.navinfo.collect.library.map.handler.MapBaseControlHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.event.Gesture
|
|
||||||
import org.oscim.event.GestureListener
|
|
||||||
import org.oscim.event.MotionEvent
|
|
||||||
import org.oscim.layers.Layer
|
|
||||||
import org.oscim.map.Map
|
|
||||||
|
|
||||||
class FlutterMapBaseControlHandler(
|
|
||||||
context: Context,
|
|
||||||
methodChannel: MethodChannel,
|
|
||||||
mapView: NIMapView
|
|
||||||
) :
|
|
||||||
MapBaseControlHandler(context, mapView) {
|
|
||||||
init {
|
|
||||||
mMapView.vtmMap.events.bind(Map.UpdateListener { e, _ ->
|
|
||||||
when (e) {
|
|
||||||
Map.MOVE_EVENT -> methodChannel.invokeMethod(
|
|
||||||
FlutterMapProtocolKeys.MapCallBackProtocol.kMapEventCallback,
|
|
||||||
mapOf("MapEvent" to 0)
|
|
||||||
);
|
|
||||||
Map.SCALE_EVENT -> methodChannel.invokeMethod(
|
|
||||||
FlutterMapProtocolKeys.MapCallBackProtocol.kMapEventCallback,
|
|
||||||
mapOf("MapEvent" to 1)
|
|
||||||
);
|
|
||||||
Map.ROTATE_EVENT -> methodChannel.invokeMethod(
|
|
||||||
FlutterMapProtocolKeys.MapCallBackProtocol.kMapEventCallback,
|
|
||||||
mapOf("MapEvent" to 2)
|
|
||||||
);
|
|
||||||
Map.TILT_EVENT -> methodChannel.invokeMethod(
|
|
||||||
FlutterMapProtocolKeys.MapCallBackProtocol.kMapEventCallback,
|
|
||||||
mapOf("MapEvent" to 3)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
mMapView.layerManager.addLayer(
|
|
||||||
"pointSnapLayer",
|
|
||||||
MapEventsReceiver(methodChannel, mMapView.vtmMap)
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private class MapEventsReceiver(methodChannel: MethodChannel, map: Map?) : Layer(map),
|
|
||||||
GestureListener {
|
|
||||||
private val _methodChannel = methodChannel;
|
|
||||||
override fun onGesture(g: Gesture, e: MotionEvent): Boolean {
|
|
||||||
if (g is Gesture.Tap) {
|
|
||||||
val p = mMap.viewport().fromScreenPoint(e.x, e.y)
|
|
||||||
_methodChannel.invokeMethod(
|
|
||||||
FlutterMapProtocolKeys.MapCallBackProtocol.kMapOnClickCallback,
|
|
||||||
mapOf(
|
|
||||||
"latitude" to p.latitude,
|
|
||||||
"longitude" to p.longitude,
|
|
||||||
"longitudeE6" to p.longitudeE6,
|
|
||||||
"latitudeE6" to p.latitudeE6,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新地图
|
|
||||||
*/
|
|
||||||
fun updateMap(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
var redraw = call.argument<Boolean>("redraw") ?: true
|
|
||||||
upDateMap(redraw);
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import com.navinfo.collect.library.map.handler.MarkHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
import org.oscim.layers.marker.MarkerItem
|
|
||||||
|
|
||||||
class FlutterMarkerHandler(context: Context, mapView: NIMapView) :
|
|
||||||
MarkHandler(context, mapView) {
|
|
||||||
|
|
||||||
fun addMarker(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
val marker: MarkerItem;
|
|
||||||
val description = call.argument<String>("description")
|
|
||||||
val title = call.argument<String>("title")
|
|
||||||
if (call.hasArgument("xPixel") && call.hasArgument("yPixel")) {
|
|
||||||
val x = call.argument<Double>("xPixel")
|
|
||||||
val y = call.argument<Double>("yPixel")
|
|
||||||
val description = call.argument<String>("description")
|
|
||||||
val geoPoint =
|
|
||||||
mMapView.vtmMap.viewport().fromScreenPoint(x!!.toFloat(), y!!.toFloat())
|
|
||||||
marker = addMarker(geoPoint, title, description)
|
|
||||||
} else if (call.hasArgument("longitude") && call.hasArgument("latitude")) {
|
|
||||||
val lon = call.argument<Double>("longitude")
|
|
||||||
val lat = call.argument<Double>("latitude")
|
|
||||||
|
|
||||||
marker = addMarker(GeoPoint(lat!!, lon!!), title, description)
|
|
||||||
} else {
|
|
||||||
marker = addMarker(
|
|
||||||
GeoPoint(
|
|
||||||
mMapView.vtmMap.mapPosition.latitude,
|
|
||||||
mMapView.vtmMap.mapPosition.longitude
|
|
||||||
), title, description
|
|
||||||
)
|
|
||||||
}
|
|
||||||
result.success(FlutterMapConversion.markerToJson(marker));
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeMarker(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.hasArgument("title")) {
|
|
||||||
val title = call.argument<String>("title")
|
|
||||||
removeMarker(title!!);
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.maphandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.maphandler.MeasureLayerHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 测距操作控制
|
|
||||||
*/
|
|
||||||
class FlutterMeasureLayerHandler(context: Context, mapView: NIMapView) :
|
|
||||||
MeasureLayerHandler(context, mapView) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给面数据增加一个点,如果是经纬度就用经纬度,如果是屏幕坐标就转换成经纬度
|
|
||||||
*/
|
|
||||||
fun drawLineOrPolygon(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
|
|
||||||
if (call.hasArgument("type")) {
|
|
||||||
val type = call.argument<Int>("type")
|
|
||||||
if (type != null) {
|
|
||||||
drawLineOrPolygon(type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun clean(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
clean()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import com.navinfo.collect.library.map.handler.PolygonHandler
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 面据操作控制
|
|
||||||
*/
|
|
||||||
class FlutterPolygonHandler(context: Context, mapView: NIMapView) :
|
|
||||||
PolygonHandler(context, mapView) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 给面数据增加一个点,如果是经纬度就用经纬度,如果是屏幕坐标就转换成经纬度
|
|
||||||
*/
|
|
||||||
fun addDrawPolygonPoint(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
val list = addDrawPolygonPoint(
|
|
||||||
GeoPoint(
|
|
||||||
mMapView.vtmMap.mapPosition.latitude,
|
|
||||||
mMapView.vtmMap.mapPosition.longitude
|
|
||||||
)
|
|
||||||
)
|
|
||||||
result.success(FlutterMapConversion.lineToJson(list));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 给面数据增加一个点,如果是经纬度就用经纬度,如果是屏幕坐标就转换成经纬度
|
|
||||||
*/
|
|
||||||
fun addDrawPolygonNiPoint(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
|
|
||||||
if (call.hasArgument("longitude")&&call.hasArgument("latitude")) {
|
|
||||||
|
|
||||||
val x = call.argument<Double>("longitude")
|
|
||||||
val y = call.argument<Double>("latitude")
|
|
||||||
|
|
||||||
val list = addDrawPolygonPoint(GeoPoint(y!!, x!!))
|
|
||||||
|
|
||||||
result.success(FlutterMapConversion.lineToJson(list))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addDrawPolygon(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
clean()
|
|
||||||
val pointList = mutableListOf<GeoPoint>();
|
|
||||||
if (call.arguments is List<*>) {
|
|
||||||
for (item in call.arguments as List<*>) {
|
|
||||||
if (item is Map<*, *>) {
|
|
||||||
pointList.add(GeoPoint(item["latitude"] as Double, item["longitude"] as Double))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addDrawPolygon(pointList);
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clean(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
clean()
|
|
||||||
result.success(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.flutterhandler
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.handler.ViewportHandler
|
|
||||||
import com.navinfo.collect.library.utils.GeometryTools
|
|
||||||
import io.flutter.plugin.common.MethodCall
|
|
||||||
import io.flutter.plugin.common.MethodChannel
|
|
||||||
import org.oscim.core.GeoPoint
|
|
||||||
|
|
||||||
class FlutterViewportHandler(context: Context, mapView: NIMapView) :
|
|
||||||
ViewportHandler(context, mapView) {
|
|
||||||
/**
|
|
||||||
* 设置地图中心偏移量 [-1,1]之间
|
|
||||||
*/
|
|
||||||
fun setMapViewCenter(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is Map<*, *>) {
|
|
||||||
val x = call.argument<Double>("xPivot")
|
|
||||||
val y = call.argument<Double>("yPivot")
|
|
||||||
val mapPosition = mMapView.vtmMap.mapPosition;
|
|
||||||
setMapViewCenter(x!!.toFloat(), y!!.toFloat())
|
|
||||||
mMapView.vtmMap.animator().animateTo(mapPosition)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取几何的外接矩形,返回矩形的左上,右下两个坐标
|
|
||||||
*/
|
|
||||||
fun getBoundingBoxWkt(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is Map<*, *>) {
|
|
||||||
val lat = call.argument<Double>("latitude")
|
|
||||||
val lon = call.argument<Double>("longitude")
|
|
||||||
val snapType = call.argument<Int>("snapType")
|
|
||||||
val distance = call.argument<Int>("distance")
|
|
||||||
val geoPoint = GeoPoint(lat!!, lon!!);
|
|
||||||
|
|
||||||
val map = getBoundingBoxWkt(geoPoint, GeometryTools.SNAP_TYPE.values()[snapType!!], distance!!)
|
|
||||||
|
|
||||||
result.success(map)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 坐标转屏幕点
|
|
||||||
*/
|
|
||||||
fun toScreenPoint(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
if (call.arguments is Map<*, *>) {
|
|
||||||
val lat = call.argument<Double>("latitude")
|
|
||||||
val lon = call.argument<Double>("longitude")
|
|
||||||
val geoPoint = GeoPoint(lat!!, lon!!);
|
|
||||||
|
|
||||||
val map = toScreenPoint(geoPoint)
|
|
||||||
|
|
||||||
result.success(map)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 屏幕点转坐标
|
|
||||||
*/
|
|
||||||
fun fromScreenPoint(call: MethodCall, result: MethodChannel.Result) {
|
|
||||||
|
|
||||||
print("qj===fromScreenPoint")
|
|
||||||
|
|
||||||
if (call.arguments is Map<*, *>) {
|
|
||||||
val px = call.argument<Double>("px")
|
|
||||||
val py = call.argument<Double>("py")
|
|
||||||
|
|
||||||
print("qj===px:$px==py:$py")
|
|
||||||
|
|
||||||
if(px!=null&&py!=null){
|
|
||||||
val map = fromScreenPoint(px.toFloat(),py.toFloat())
|
|
||||||
|
|
||||||
result.success(map)
|
|
||||||
}else{
|
|
||||||
result.success("")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
|
||||||
import io.flutter.embedding.engine.plugins.lifecycle.HiddenLifecycleReference
|
|
||||||
|
|
||||||
|
|
||||||
class FlutterLifecycleAdapter {
|
|
||||||
private val TAG = "FlutterLifecycleAdapter"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the lifecycle object for the activity a plugin is bound to.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Returns null if the Flutter engine version does not include the lifecycle extraction code.
|
|
||||||
* (this probably means the Flutter engine version is too old).
|
|
||||||
*/
|
|
||||||
companion object {
|
|
||||||
@NonNull
|
|
||||||
fun getActivityLifecycle(
|
|
||||||
@NonNull activityPluginBinding: ActivityPluginBinding
|
|
||||||
): Lifecycle {
|
|
||||||
val reference = activityPluginBinding.lifecycle as HiddenLifecycleReference
|
|
||||||
return reference.lifecycle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import com.navinfo.collect.library.data.flutter.FlutterDataController
|
|
||||||
import com.navinfo.collect.library.importExport.flutter.FlutterImportExportController
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapController
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import io.flutter.plugin.platform.PlatformView
|
|
||||||
|
|
||||||
|
|
||||||
class FlutterMapView(
|
|
||||||
mapController: FlutterMapController,
|
|
||||||
dataController: FlutterDataController,
|
|
||||||
importExportController: FlutterImportExportController,
|
|
||||||
lifecycleProxy: LifecycleProxy
|
|
||||||
) :
|
|
||||||
PlatformView, DefaultLifecycleObserver {
|
|
||||||
private val mMapController: FlutterMapController = mapController
|
|
||||||
private val mDataController: FlutterDataController = dataController
|
|
||||||
private val mImportExportController: FlutterImportExportController = importExportController
|
|
||||||
private val mapView: NIMapView = mMapController.mMapView
|
|
||||||
private var mIsDisposed = false
|
|
||||||
private val mLifecycleProxy: LifecycleProxy = lifecycleProxy;
|
|
||||||
|
|
||||||
init {
|
|
||||||
var lifecycle: Lifecycle? = mLifecycleProxy.getLifecycle()
|
|
||||||
lifecycle?.addObserver(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getView(): View {
|
|
||||||
return mapView
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dispose() {
|
|
||||||
|
|
||||||
if (mIsDisposed) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsDisposed = true
|
|
||||||
|
|
||||||
mMapController.release()
|
|
||||||
mDataController.release()
|
|
||||||
|
|
||||||
val lifecycle: Lifecycle? = mLifecycleProxy.getLifecycle()
|
|
||||||
lifecycle?.removeObserver(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause(owner: LifecycleOwner) {
|
|
||||||
if (!mIsDisposed) {
|
|
||||||
mapView.onPause()
|
|
||||||
}
|
|
||||||
super.onPause(owner)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume(owner: LifecycleOwner) {
|
|
||||||
if (!mIsDisposed) {
|
|
||||||
mapView.onResume()
|
|
||||||
}
|
|
||||||
super.onResume(owner)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStop(owner: LifecycleOwner) {}
|
|
||||||
|
|
||||||
override fun onDestroy(owner: LifecycleOwner) {
|
|
||||||
if (!mIsDisposed) {
|
|
||||||
mMapController.release()
|
|
||||||
mDataController.release()
|
|
||||||
// mapView = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.FlutterBaseActivity
|
|
||||||
import com.navinfo.collect.library.data.dao.impl.MapLifeDataBase
|
|
||||||
import com.navinfo.collect.library.data.flutter.FlutterDataController
|
|
||||||
import com.navinfo.collect.library.importExport.flutter.FlutterImportExportController
|
|
||||||
import com.navinfo.collect.library.map.NIMapOptions
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapController
|
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
import io.flutter.plugin.common.StandardMessageCodec
|
|
||||||
import io.flutter.plugin.platform.PlatformView
|
|
||||||
import io.flutter.plugin.platform.PlatformViewFactory
|
|
||||||
|
|
||||||
class FlutterMapViewFactory(
|
|
||||||
messenger: BinaryMessenger,
|
|
||||||
lifecycleProxy: LifecycleProxy,
|
|
||||||
activity: FlutterBaseActivity,
|
|
||||||
) :
|
|
||||||
PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
|
||||||
private val binaryMessenger: BinaryMessenger = messenger
|
|
||||||
|
|
||||||
private var mLifecycleProxy: LifecycleProxy = lifecycleProxy
|
|
||||||
|
|
||||||
lateinit var mapController: FlutterMapController
|
|
||||||
lateinit var dataController: FlutterDataController
|
|
||||||
private val activity: FlutterBaseActivity = activity
|
|
||||||
|
|
||||||
override fun create(context: Context?, id: Int, args: Any?): PlatformView {
|
|
||||||
mapController = buildMapController(context!!, id, args!!)
|
|
||||||
dataController = buildDataController(context, id, activity)
|
|
||||||
val importExportController =
|
|
||||||
buildImportExportController(context, id, dataController.mDateBase)
|
|
||||||
return FlutterMapView(
|
|
||||||
mapController,
|
|
||||||
dataController,
|
|
||||||
importExportController,
|
|
||||||
mLifecycleProxy
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建地图控制器
|
|
||||||
*/
|
|
||||||
private fun buildMapController(
|
|
||||||
context: Context,
|
|
||||||
viewId: Int,
|
|
||||||
args: Any,
|
|
||||||
): FlutterMapController {
|
|
||||||
|
|
||||||
val options: NIMapOptions = FlutterMapConversion.flutterToNIMapOptions(args.toString())
|
|
||||||
return FlutterMapController(viewId, context, binaryMessenger, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建数据控制器
|
|
||||||
*/
|
|
||||||
private fun buildDataController(
|
|
||||||
context: Context,
|
|
||||||
viewId: Int,
|
|
||||||
activity: FlutterBaseActivity
|
|
||||||
): FlutterDataController {
|
|
||||||
return FlutterDataController(viewId, context, binaryMessenger, activity)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建文件导入导出
|
|
||||||
*/
|
|
||||||
private fun buildImportExportController(
|
|
||||||
context: Context,
|
|
||||||
viewId: Int,
|
|
||||||
dataBase: MapLifeDataBase
|
|
||||||
): FlutterImportExportController {
|
|
||||||
return FlutterImportExportController(viewId, context, binaryMessenger, dataBase)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.lifecycle.LifecycleRegistry
|
|
||||||
import com.navinfo.collect.FlutterBaseActivity
|
|
||||||
import com.navinfo.collect.library.system.Constant
|
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
|
||||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
||||||
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
|
|
||||||
object FlutterMapViewFlutterPlugin : ActivityAware, FlutterPlugin {
|
|
||||||
private const val NATIVE_VIEW_TYPE_ID = "com.navinfo.collect/mapView"
|
|
||||||
private var mLifecycle: Lifecycle? = null
|
|
||||||
private lateinit var mActivity:FlutterBaseActivity
|
|
||||||
// //旧方法
|
|
||||||
// fun registerWith(registry: PluginRegistry) {
|
|
||||||
// val key = FlutterMapViewFlutterPlugin::class.java.canonicalName
|
|
||||||
// if (registry.hasPlugin(key)) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// val registrar = registry.registrarFor(key)
|
|
||||||
// registrar.platformViewRegistry()
|
|
||||||
// .registerViewFactory(NATIVE_VIEW_TYPE_ID, FlutterMapViewFactory(registrar.messenger()))
|
|
||||||
// }
|
|
||||||
|
|
||||||
//新方法
|
|
||||||
fun registerWith(
|
|
||||||
flutterEngine: FlutterEngine,
|
|
||||||
activity: FlutterBaseActivity,
|
|
||||||
rootPath: String = ""
|
|
||||||
): FlutterMapViewFactory {
|
|
||||||
mActivity = activity
|
|
||||||
var lifecycleProxy: LifecycleProxy = if (activity is LifecycleOwner) {
|
|
||||||
object : LifecycleProxy {
|
|
||||||
override fun getLifecycle(): Lifecycle {
|
|
||||||
return (activity as LifecycleOwner).lifecycle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ActivityLifecycleProxy(activity)
|
|
||||||
}
|
|
||||||
if (rootPath != "") {
|
|
||||||
Constant.ROOT_PATH = rootPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
val factory =
|
|
||||||
FlutterMapViewFactory(flutterEngine.dartExecutor.binaryMessenger, lifecycleProxy,activity)
|
|
||||||
flutterEngine.platformViewsController.registry.registerViewFactory(
|
|
||||||
NATIVE_VIEW_TYPE_ID,
|
|
||||||
factory
|
|
||||||
)
|
|
||||||
return factory
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ActivityLifecycleProxy(activity: Activity) :
|
|
||||||
LifecycleProxy, Application.ActivityLifecycleCallbacks, LifecycleOwner {
|
|
||||||
private val mLifecycle = LifecycleRegistry(this)
|
|
||||||
private var mRegistrarActivityHashCode: Int = activity.hashCode()
|
|
||||||
override fun getLifecycle(): Lifecycle {
|
|
||||||
return mLifecycle
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityPaused(activity: Activity) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
|
||||||
if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
|
||||||
activity.application.registerActivityLifecycleCallbacks(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//首次绑定到Activity
|
|
||||||
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
|
||||||
mLifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding)
|
|
||||||
}
|
|
||||||
|
|
||||||
//由于某些原因导致暂时解绑
|
|
||||||
override fun onDetachedFromActivityForConfigChanges() {
|
|
||||||
onDetachedFromActivity()
|
|
||||||
}
|
|
||||||
|
|
||||||
//恢复绑定
|
|
||||||
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
|
||||||
onAttachedToActivity(binding)
|
|
||||||
}
|
|
||||||
|
|
||||||
//解绑
|
|
||||||
override fun onDetachedFromActivity() {
|
|
||||||
mLifecycle = null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
// val mMessenger: BinaryMessenger = binding.binaryMessenger
|
|
||||||
|
|
||||||
binding.platformViewRegistry.registerViewFactory(
|
|
||||||
NATIVE_VIEW_TYPE_ID,
|
|
||||||
FlutterMapViewFactory(binding.binaryMessenger, object : LifecycleProxy {
|
|
||||||
override fun getLifecycle(): Lifecycle? {
|
|
||||||
return mLifecycle
|
|
||||||
}
|
|
||||||
}, mActivity)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// // 单独配置获取版本的消息通道,和地图实例的消息通道无关
|
|
||||||
// val methodChannel = MethodChannel(
|
|
||||||
// mMessenger,
|
|
||||||
// Constants.NATIVE_SDK_VERSION_CHANNEL
|
|
||||||
// )
|
|
||||||
// methodChannel.setMethodCallHandler(this)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
// val binaryMessenger = binding.binaryMessenger
|
|
||||||
|
|
||||||
// mOfflineHandler.unInit(binaryMessenger)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.view.View
|
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import com.navinfo.collect.library.map.NIMapCopyView
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import io.flutter.plugin.platform.PlatformView
|
|
||||||
|
|
||||||
|
|
||||||
class FlutterNiMapCopyView(context:Context,niMapView: NIMapView,
|
|
||||||
lifecycleProxy: LifecycleProxy
|
|
||||||
) :
|
|
||||||
PlatformView, DefaultLifecycleObserver {
|
|
||||||
private val copyView: NIMapCopyView = NIMapCopyView(context,niMapView);
|
|
||||||
private var mIsDisposed = false
|
|
||||||
private val mLifecycleProxy: LifecycleProxy = lifecycleProxy;
|
|
||||||
|
|
||||||
init {
|
|
||||||
var lifecycle: Lifecycle? = mLifecycleProxy.getLifecycle()
|
|
||||||
lifecycle?.addObserver(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getView(): View {
|
|
||||||
return copyView
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun dispose() {
|
|
||||||
|
|
||||||
if (mIsDisposed) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsDisposed = true
|
|
||||||
val lifecycle: Lifecycle? = mLifecycleProxy.getLifecycle()
|
|
||||||
lifecycle?.removeObserver(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.navinfo.collect.library.data.flutter.FlutterDataController
|
|
||||||
import com.navinfo.collect.library.map.NIMapOptions
|
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapController
|
|
||||||
import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
import io.flutter.plugin.common.StandardMessageCodec
|
|
||||||
import io.flutter.plugin.platform.PlatformView
|
|
||||||
import io.flutter.plugin.platform.PlatformViewFactory
|
|
||||||
|
|
||||||
class FlutterNiMapCopyViewFactory(
|
|
||||||
private val messenger: BinaryMessenger,
|
|
||||||
lifecycleProxy: LifecycleProxy
|
|
||||||
) :
|
|
||||||
PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
|
||||||
private val binaryMessenger: BinaryMessenger = messenger
|
|
||||||
|
|
||||||
private var mLifecycleProxy: LifecycleProxy = lifecycleProxy
|
|
||||||
|
|
||||||
override fun create(context: Context, id: Int, args: Any?): PlatformView {
|
|
||||||
return FlutterNiMapCopyView(context,args as NIMapView, mLifecycleProxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
//package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
//
|
|
||||||
//import android.app.Activity
|
|
||||||
//import android.app.Application
|
|
||||||
//import android.os.Bundle
|
|
||||||
//import androidx.lifecycle.Lifecycle
|
|
||||||
//import androidx.lifecycle.LifecycleOwner
|
|
||||||
//import androidx.lifecycle.LifecycleRegistry
|
|
||||||
//import com.navinfo.collect.library.system.Constant
|
|
||||||
//import io.flutter.embedding.engine.FlutterEngine
|
|
||||||
//import io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
||||||
//import io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
||||||
//import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
|
|
||||||
//import io.flutter.plugin.common.BinaryMessenger
|
|
||||||
//
|
|
||||||
//object FlutterNiMapCopyViewFlutterPlugin : ActivityAware, FlutterPlugin {
|
|
||||||
// private const val NATIVE_VIEW_TYPE_ID = "com.navinfo.collect/copyView"
|
|
||||||
// private var mLifecycle: Lifecycle? = null
|
|
||||||
//
|
|
||||||
// //新方法
|
|
||||||
// fun registerWith(flutterEngine: FlutterEngine, activity: Activity, rootPath: String = "") {
|
|
||||||
// var lifecycleProxy: LifecycleProxy = if (activity is LifecycleOwner) {
|
|
||||||
// object : LifecycleProxy {
|
|
||||||
// override fun getLifecycle(): Lifecycle {
|
|
||||||
// return (activity as LifecycleOwner).lifecycle
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// ActivityLifecycleProxy(activity)
|
|
||||||
// }
|
|
||||||
// if (rootPath != "") {
|
|
||||||
// Constant.ROOT_PATH = rootPath;
|
|
||||||
// }
|
|
||||||
// flutterEngine.platformViewsController.registry.registerViewFactory(
|
|
||||||
// NATIVE_VIEW_TYPE_ID,
|
|
||||||
// FlutterMapViewFactory(flutterEngine.dartExecutor.binaryMessenger, lifecycleProxy)
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private class ActivityLifecycleProxy(activity: Activity) :
|
|
||||||
// LifecycleProxy, Application.ActivityLifecycleCallbacks, LifecycleOwner {
|
|
||||||
// private val mLifecycle = LifecycleRegistry(this)
|
|
||||||
// private var mRegistrarActivityHashCode: Int = activity.hashCode()
|
|
||||||
// override fun getLifecycle(): Lifecycle {
|
|
||||||
// return mLifecycle
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// override fun onActivityStarted(activity: Activity) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onActivityResumed(activity: Activity) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onActivityPaused(activity: Activity) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onActivityStopped(activity: Activity) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
|
|
||||||
// override fun onActivityDestroyed(activity: Activity) {
|
|
||||||
// if (activity.hashCode() != mRegistrarActivityHashCode) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// mLifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// init {
|
|
||||||
// activity.application.registerActivityLifecycleCallbacks(this)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onAttachedToActivity(binding: ActivityPluginBinding) {
|
|
||||||
// mLifecycle = FlutterLifecycleAdapter.getActivityLifecycle(binding)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onDetachedFromActivityForConfigChanges() {
|
|
||||||
// onDetachedFromActivity()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
|
|
||||||
// onAttachedToActivity(binding)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onDetachedFromActivity() {
|
|
||||||
// mLifecycle = null
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
// binding.platformViewRegistry.registerViewFactory(
|
|
||||||
// NATIVE_VIEW_TYPE_ID,
|
|
||||||
// FlutterMapViewFactory(binding.binaryMessenger, object : LifecycleProxy {
|
|
||||||
// override fun getLifecycle(): Lifecycle? {
|
|
||||||
// return mLifecycle
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.navinfo.collect.library.map.flutter.plugin
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
|
|
||||||
interface LifecycleProxy {
|
|
||||||
fun getLifecycle(): Lifecycle?
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ package com.navinfo.collect.library.map.handler
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.navinfo.collect.library.map.NIMapView
|
import com.navinfo.collect.library.map.NIMapView
|
||||||
import com.navinfo.collect.library.map.NIMapView.LAYER_GROUPS
|
import com.navinfo.collect.library.map.NIMapView.LAYER_GROUPS
|
||||||
import com.navinfo.collect.library.map.flutter.FlutterMapConversion
|
|
||||||
import org.oscim.layers.Layer
|
import org.oscim.layers.Layer
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,14 +32,4 @@ open class LayerManagerHandler(context: Context, mapView: NIMapView) :
|
|||||||
fun removeRasterTileLayer(url: String) {
|
fun removeRasterTileLayer(url: String) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getBaseRasterTileLayerList(callback: (baseMapJson: String) -> Unit) {
|
|
||||||
val strJson = FlutterMapConversion.baseMapTypeToJson(NIMapView.BASE_MAP_TYPE.values())
|
|
||||||
callback.invoke(strJson)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun editLineOrPolygon(geometry: String,type: Int){
|
|
||||||
mMapView.layerManager.showEditMapGraphical(geometry,type)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,29 +6,12 @@ import android.os.Environment;
|
|||||||
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource;
|
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource;
|
||||||
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource;
|
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource;
|
||||||
|
|
||||||
import org.oscim.android.MapPreferences;
|
|
||||||
import org.oscim.android.cache.TileCache;
|
import org.oscim.android.cache.TileCache;
|
||||||
import org.oscim.android.canvas.AndroidGraphics;
|
|
||||||
import org.oscim.backend.CanvasAdapter;
|
|
||||||
import org.oscim.backend.DateTime;
|
|
||||||
import org.oscim.backend.DateTimeAdapter;
|
|
||||||
import org.oscim.backend.GLAdapter;
|
|
||||||
import org.oscim.core.Tile;
|
|
||||||
import org.oscim.gdx.AndroidGL;
|
|
||||||
import org.oscim.gdx.AndroidGL30;
|
|
||||||
import org.oscim.gdx.GdxAssets;
|
|
||||||
import org.oscim.gdx.GdxMap;
|
|
||||||
import org.oscim.gdx.poi3d.Poi3DLayer;
|
|
||||||
import org.oscim.layers.Layer;
|
import org.oscim.layers.Layer;
|
||||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
|
||||||
import org.oscim.layers.tile.buildings.S3DBLayer;
|
|
||||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
|
||||||
import org.oscim.map.Map;
|
import org.oscim.map.Map;
|
||||||
import org.oscim.theme.VtmThemes;
|
|
||||||
import org.oscim.tiling.source.OkHttpEngine;
|
import org.oscim.tiling.source.OkHttpEngine;
|
||||||
import org.oscim.tiling.source.mapfile.MapFileTileSource;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|||||||
Reference in New Issue
Block a user