[3.4.0-map-sdk] code style

This commit is contained in:
zhongchao
2023-09-12 17:51:27 +08:00
parent b0355d967d
commit e368a0fda4
71 changed files with 1053 additions and 1193 deletions

View File

@@ -7,6 +7,7 @@ import android.opengl.GLException
import android.opengl.GLSurfaceView
import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.text.TextUtils
import android.util.Log
@@ -49,7 +50,10 @@ import java.util.concurrent.atomic.AtomicBoolean
import javax.microedition.khronos.egl.EGL10
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10
import kotlin.math.abs
import kotlin.math.absoluteValue
import kotlin.math.acos
import kotlin.math.sqrt
class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, private val mILockLocation: ILockLocation) :
GLSurfaceView(context), GLSurfaceView.Renderer, IMapView {
@@ -156,7 +160,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
lateinit var mDemaningScope: CoroutineScope
private val mHandler: Handler = object : Handler() {
private val mHandler: Handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
when (msg.what) {
ZOOM_CHANGE -> mMapController?.dispatchZoomChanged()
@@ -234,7 +238,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
override fun destory() {
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(TAG, "mapop-destory")
}
isFirst = true
@@ -337,7 +341,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
val animationListener = mMarkerCall?.getAnimationListener(markerId)
animationListener?.let {
mAnimJob?.cancel()
mAnimJob = mScope?.launch(Dispatchers.IO){
mAnimJob = mScope.launch(Dispatchers.IO){
it.onAnimationFinish(markerId, type)
}
}
@@ -377,7 +381,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
isTouchingFlag = true
if (!(mEventController?.isMapTouchListenerListEmpty()?:true)) {
if (mEventController?.isMapTouchListenerListEmpty() == false) {
val flag = mEventController?.dispatchMapTouchListener(ev)
if (flag != null && flag) {
return flag
@@ -406,7 +410,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mILockLocation.setLockCar(false)
if(isAutoLockCar) {
mLockCarJob?.cancel()
mLockCarJob = mDemaningScope?.launch(Dispatchers.IO) {
mLockCarJob = mDemaningScope.launch(Dispatchers.IO) {
if (DEBUG) {
Log.i(TAG, "lockop--onTouchEvent:mLockCarJob start: ${mMapStyleParams.getVrAngleMode()}")
}
@@ -438,7 +442,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
//跳到3d效果
val dy0 = m_iLastY0 - ev.getY(0)
val dy1 = m_iLastY1 - ev.getY(1)
if (Math.abs(dy0) > 1 || Math.abs(dy1) > 1) {
if (abs(dy0) > 1 || abs(dy1) > 1) {
if (dy1 * dy0 > 1 && dy1 / dy0 < 3 && dy0 / dy1 < 3) {
if (isFling) {
@@ -456,15 +460,15 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
if (!m_bBending) {
val dx = ev.getX(1) - ev.getX(0)
val dy = ev.getY(1) - ev.getY(0)
val dist = Math.sqrt(dx * dx + dy * dy.toDouble()).toFloat()
val dist = sqrt(dx * dx + dy * dy.toDouble()).toFloat()
//角度
angle = (Math.acos(dx / dist.toDouble()) * 180.0 / Math.PI).toInt()
angle = (acos(dx / dist.toDouble()) * 180.0 / Math.PI).toInt()
if (dy < 0) {
angle = 360 - angle
}
}
if (m_bLastMultiple
&& (Math.abs(angle - m_iLastAngle) > 10 || m_bRotating)
&& (abs(angle - m_iLastAngle) > 10 || m_bRotating)
&& !m_bBending
) {
val dx0 = m_iLastX0 - ev.getX(0)
@@ -473,7 +477,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
val dy1 = m_iLastY1 - ev.getY(1)
if (dx0 * dx1 < -10 || dy0 * dy1 < -10) {
m_bRotating = true
//m_MapCtrl.stopAnimation(MapAnimator.ANITYPE_NANGLE, false);
//m_MapCtrl.stopAnimation(MapAnimator.ANITYPE_NANGLE, false)
if (isRotate && m_bRotating) {
if (DEBUG && mShowTouchInfo) {
Log.i(TAG, "touchop--rotateBy")
@@ -496,7 +500,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mMapEngine.setScaleMapCenter(it.lon, it.lat)
mScaleCenterLonLat = null
}
val interValue = Math.abs(m_fCurAverageDistanceFromCenter - m_fLastAverageDistanceFromCenter)
val interValue = abs(m_fCurAverageDistanceFromCenter - m_fLastAverageDistanceFromCenter)
if (m_iMultiTouchCnt > 5 && m_fLastAverageDistanceFromCenter != -1f && interValue > SCALE_SMALL_DISTANCE && ev.action and MotionEvent.ACTION_MASK == MotionEvent.ACTION_MOVE) {
val zoomFactor = m_fCurAverageDistanceFromCenter / m_fLastAverageDistanceFromCenter
if (isCanZoom) {
@@ -511,7 +515,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
// lastScaleByTime = SystemClock.uptimeMillis()
if(isVr && (mMapStyleParams.getStyleMode() == MapAutoApi.MAP_STYLE_NIGHT_VR || mMapStyleParams.getStyleMode() == MapAutoApi.MAP_STYLE_DAY_VR)){
if(DEBUG) {
Log.d(TAG, "getZoomVal(): ${mMapEngine.getZoomValue()}, ${zoomFactor}")
Log.d(TAG, "getZoomVal(): ${mMapEngine.getZoomValue()}, $zoomFactor")
}
//zoomFactor 缩放比例 > 1 放大 < 1 缩小 getZoomVal() / zoomFactor 缩放到的值
if(mMapEngine.getZoomValue() / zoomFactor < 3.0) {
@@ -542,7 +546,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
m_iLastY1 = ev.getY(1)
if (ev.action == MotionEvent.ACTION_UP || ev.action == MotionEvent.ACTION_CANCEL) {
m_iLastAngle = NOT_A_ANGLE
//m_bLastMultiple = false;
//m_bLastMultiple = false
m_bBending = false
m_bRotating = false
}
@@ -557,7 +561,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mGestureDetector.onTouchEvent(ev)
}
m_iLastAngle = NOT_A_ANGLE
//m_bLastMultiple = false;
//m_bLastMultiple = false
m_bBending = false
m_bRotating = false
m_iMultiTouchCnt = 0
@@ -643,7 +647,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
}
if(enableSync){
// 2ms是每次耗时补充
var sTime = renderTimePer-(System.currentTimeMillis()-time)-2
val sTime = renderTimePer-(System.currentTimeMillis()-time)-2
if(sTime > 0 && sTime < 100){
try {
Thread.sleep(sTime)
@@ -732,8 +736,8 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mLockCar?.cancel()
mScope.cancel()
mDemaningScope.cancel()
mHandler?.removeCallbacksAndMessages(null)
if (CompileConfig.DEBUG) {
mHandler.removeCallbacksAndMessages(null)
if (DEBUG) {
Log.i(TAG, "destroyop--MapEngine.unload-start")
}
mMapEngine.unload()
@@ -748,8 +752,8 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
if (DEBUG) {
Log.i(TAG, "mapop-surfaceop----onSurfaceCreated,threadop:${Thread.currentThread().id}")
}
// setStyleDir("sdcard/shmdata/style");
var styleMode = mMapStyleParams.getStyleMode()
// setStyleDir("sdcard/shmdata/style")
val styleMode = mMapStyleParams.getStyleMode()
val dir = Constant.nDSDataPath
mMapEngine.setIsEnableShadow(mMapStyleParams.isShadowEnable())
if(!loadP(dir)){
@@ -854,15 +858,15 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
// return false
// }
// var y = e.getY()
// val sxy = M3DEsngine.glToPixel(0, getHeight() * 2, 0);
// val miny = Math.max(0, (short)(sxy & 0xFFFF));
// val sxy = M3DEsngine.glToPixel(0, getHeight() * 2, 0)
// val miny = Math.max(0, (short)(sxy & 0xFFFF))
// if(y < miny){
// y = miny;
// return true;
// y = miny
// return true
// }
// var lonLat = pixelsToLonlat(e.getX().toInt(), y.toInt());
// var lonLat = pixelsToLonlat(e.getX().toInt(), y.toInt())
// lonLat?.let {
// animateTo(lonLat.lon.toFloat(), lonLat.lat.toFloat(),-1f,-1f,-1f);
// animateTo(lonLat.lon.toFloat(), lonLat.lat.toFloat(),-1f,-1f,-1f)
// }
// return true
return false
@@ -881,15 +885,15 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
val x = e.x.toInt()
val y = e.y.toInt()
mMarkerJob?.cancel()
mMarkerJob = mDemaningScope?.launch(Dispatchers.IO) {
if (CompileConfig.DEBUG) {
mMarkerJob = mDemaningScope.launch(Dispatchers.IO) {
if (DEBUG) {
Log.i(TAG, "markerop--findAnchorAtScreenPoint:start")
}
if(!mSurfaceCreated.get()){
return@launch
}
val resultInfo = mMapEngine.findAnchorAtScreen(x, y)
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(TAG, "markerop--findAnchorAtScreenPoint:${resultInfo}")
}
if (TextUtils.isEmpty(resultInfo) || resultInfo == "unableBeTouch") {
@@ -897,7 +901,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
val markerInfo = jsonToObj(resultInfo)
if (markerInfo != null) {
var marker: Marker = Marker(MarkerOptions(markerInfo.id,null).setGps(true).position(
val marker: Marker = Marker(MarkerOptions(markerInfo.id,null).setGps(true).position(
LonLatPoint(markerInfo.lon, markerInfo.lat)
).setAssInfo(markerInfo.assInfo),mMapController,mMarkerCall)
lastClickMarker?.let {
@@ -908,7 +912,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
lastClickMarker = marker
if (markerInfo.type == "1") {
if (!(mEventController?.isMarkClickListenerListEmpty()?:true)) {
if (mEventController?.isMarkClickListenerListEmpty() == false) {
withContext(Dispatchers.Main) { mEventController?.dispatchMarkClickListener(marker) }
}
val onMarkClickListener = mMarkerCall?.getMarkClickListener(markerInfo.id)
@@ -917,7 +921,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mILockLocation.setLockCar(false)
it.onMarkClick(marker)
mLockCarJob?.cancel()
mLockCarJob = mDemaningScope?.launch(Dispatchers.IO) {
mLockCarJob = mDemaningScope.launch(Dispatchers.IO) {
delay(waitTime)
mILockLocation.setLockCar(true)
}
@@ -960,12 +964,12 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
return
}
mLongPressJob?.cancel()
mLongPressJob = mScope?.launch(Dispatchers.IO) {
mLongPressJob = mScope.launch(Dispatchers.IO) {
if(!mSurfaceCreated.get()){
return@launch
}
val resultInfo = mMapEngine.findAnchorAtScreen(x.toInt(), y.toInt())
if (CompileConfig.DEBUG) {
if (DEBUG) {
Log.i(TAG, "markerop--touch--findAnchorAtScreenPoint:${resultInfo}")
}
if (TextUtils.isEmpty(resultInfo) || resultInfo == "unableBeTouch") {
@@ -1013,10 +1017,10 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
//Marker Event
markerEvent(e)
if (!(mEventController?.isMarkClickListenerListEmpty()?:true)) {
if (mEventController?.isMarkClickListenerListEmpty() == false) {
val x = e.x.toInt()
val y = e.y.toInt()
var latLonPoint = MapTools.fromScreenLocation(Point(x, y),mMapController)
val latLonPoint = MapTools.fromScreenLocation(Point(x, y),mMapController)
mEventController?.dispatchMapClickListener(latLonPoint)
return true
}
@@ -1049,14 +1053,14 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
return false
}
if (velocityX.absoluteValue > 200 || velocityY.absoluteValue > 200) {
var x1 = e1.x
var y1 = e1.y
var x2 = e2.x
var y2 = e2.y
var distanceX = x2 - x1
var distanceY = y2 - y1
var inertiaX = 1 + velocityX.absoluteValue / VELOCITY_MEASURE
var inertiaY = 1 + velocityY.absoluteValue / VELOCITY_MEASURE
val x1 = e1.x
val y1 = e1.y
val x2 = e2.x
val y2 = e2.y
val distanceX = x2 - x1
val distanceY = y2 - y1
val inertiaX = 1 + velocityX.absoluteValue / VELOCITY_MEASURE
val inertiaY = 1 + velocityY.absoluteValue / VELOCITY_MEASURE
if (DEBUG && mShowTouchInfo) {
Log.i(TAG, "touchop--mGestureDetector--onFling--inertia:${inertiaX},${inertiaY},distance${distanceX},${distanceY},scrollby:${inertiaX * distanceX},${-inertiaY * distanceY}")
}
@@ -1070,10 +1074,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
mMapEngine.scrollByAnim(scrollX, scrollY)
}
}
return if (!isFling) {
false
} else true
return isFling
}
// 参数:
@@ -1230,7 +1231,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
Log.i(TAG, "loadop--${mMapParams.getStyleDir()}")
}
if (!TextUtils.isEmpty(mMapParams.getStyleDir())) {
mMapEngine.setStyleDir(mMapParams.getStyleDir()!!)
mMapEngine.setStyleDir(mMapParams.getStyleDir())
} else if (!TextUtils.isEmpty(mStylePath)) {
mMapEngine.setStyleDir(mStylePath!!)
}
@@ -1312,18 +1313,18 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
}
private fun renderDataCallback(data: String) {
if(CompileConfig.DEBUG){
if(DEBUG){
Log.d("renderDataCallback", "renderDataCallback:$data")
}
renderDataCall?.renderDataResult(data)
}
override fun getScope():CoroutineScope?{
override fun getScope(): CoroutineScope {
return mScope
}
override fun getDemaningScope():CoroutineScope?{
override fun getDemaningScope(): CoroutineScope {
return mDemaningScope
}
@@ -1345,7 +1346,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
Log.i(TAG, "mapop---renderop-init:${this} ")
}
isFirst = true
getHolder().setType(SurfaceHolder.SURFACE_TYPE_HARDWARE);
holder.setType(SurfaceHolder.SURFACE_TYPE_HARDWARE)
//setEGLContextClientVersion(3)
setEGLConfigChooser { egl, display ->
@@ -1367,7 +1368,7 @@ class MapView(context: Context, private val mMapStyleParams: IMapStyleParams, pr
egl.eglChooseConfig(display, attributes, configs, 1, result)
configs[0]
}
setEGLContextClientVersion(3);
setEGLContextClientVersion(3)
setRenderer(this)
//getHolder().setFormat(PixelFormat.TRANSLUCENT)
mGestureDetector = GestureDetector(context, TouchGestureDetecter())