|
@@ -11,6 +11,7 @@ import android.graphics.PointF
|
|
|
import android.util.Pair
|
|
import android.util.Pair
|
|
|
import android.view.MotionEvent
|
|
import android.view.MotionEvent
|
|
|
import com.grkj.iscs.R
|
|
import com.grkj.iscs.R
|
|
|
|
|
+import com.grkj.iscs.util.BitmapUtil
|
|
|
import com.onlylemi.mapview.library.MapView
|
|
import com.onlylemi.mapview.library.MapView
|
|
|
import com.onlylemi.mapview.library.layer.MapBaseLayer
|
|
import com.onlylemi.mapview.library.layer.MapBaseLayer
|
|
|
import kotlin.math.cos
|
|
import kotlin.math.cos
|
|
@@ -30,6 +31,7 @@ class CustomStationLayer @JvmOverloads constructor(
|
|
|
private var currentZoom = 0f
|
|
private var currentZoom = 0f
|
|
|
private var currentDegree = 0f
|
|
private var currentDegree = 0f
|
|
|
private lateinit var bgBitmap: Bitmap
|
|
private lateinit var bgBitmap: Bitmap
|
|
|
|
|
+ private lateinit var coverBitmap: Bitmap
|
|
|
|
|
|
|
|
|
|
|
|
|
init {
|
|
init {
|
|
@@ -40,58 +42,15 @@ class CustomStationLayer @JvmOverloads constructor(
|
|
|
|
|
|
|
|
private fun initLayer() {
|
|
private fun initLayer() {
|
|
|
radiusMark = setValue(4.0f)
|
|
radiusMark = setValue(4.0f)
|
|
|
- bgBitmap = getResizedBitmapFromMipmap(mapView.context, R.mipmap.red_stroke_bg, 24, 32)
|
|
|
|
|
|
|
+ bgBitmap = BitmapUtil.getResizedBitmapFromMipmap(mapView.context, R.mipmap.red_stroke_bg, 24, 32)
|
|
|
|
|
+ coverBitmap = BitmapUtil.getResizedBitmapFromDrawable(mapView.context, R.drawable.map_item_cover_bg, 24, 32)!!
|
|
|
|
|
|
|
|
paint = Paint()
|
|
paint = Paint()
|
|
|
paint.isAntiAlias = true
|
|
paint.isAntiAlias = true
|
|
|
paint.style = Paint.Style.FILL_AND_STROKE
|
|
paint.style = Paint.Style.FILL_AND_STROKE
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private fun getResizedBitmapFromMipmap(
|
|
|
|
|
- context: Context,
|
|
|
|
|
- resId: Int,
|
|
|
|
|
- reqWidth: Int,
|
|
|
|
|
- reqHeight: Int
|
|
|
|
|
- ): Bitmap {
|
|
|
|
|
- // First decode with inJustDecodeBounds=true to check dimensions
|
|
|
|
|
- val options = BitmapFactory.Options()
|
|
|
|
|
- options.inJustDecodeBounds = true
|
|
|
|
|
- BitmapFactory.decodeResource(context.resources, resId, options)
|
|
|
|
|
-
|
|
|
|
|
- // Calculate inSampleSize
|
|
|
|
|
- options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight)
|
|
|
|
|
-
|
|
|
|
|
- // Decode bitmap with inSampleSize set
|
|
|
|
|
- options.inJustDecodeBounds = false
|
|
|
|
|
- val scaledBitmap = BitmapFactory.decodeResource(context.resources, resId, options)
|
|
|
|
|
-
|
|
|
|
|
- // Resize the bitmap if necessary
|
|
|
|
|
- return Bitmap.createScaledBitmap(scaledBitmap, reqWidth, reqHeight, false)
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private fun calculateInSampleSize(
|
|
|
|
|
- options: BitmapFactory.Options,
|
|
|
|
|
- reqWidth: Int,
|
|
|
|
|
- reqHeight: Int
|
|
|
|
|
- ): Int {
|
|
|
|
|
- // Raw height and width of image
|
|
|
|
|
- val height = options.outHeight
|
|
|
|
|
- val width = options.outWidth
|
|
|
|
|
- var inSampleSize = 1
|
|
|
|
|
-
|
|
|
|
|
- if (height > reqHeight || width > reqWidth) {
|
|
|
|
|
- val halfHeight = height / 2
|
|
|
|
|
- val halfWidth = width / 2
|
|
|
|
|
-
|
|
|
|
|
- // Calculate the largest inSampleSize value that is a power of 2 and keeps both
|
|
|
|
|
- // height and width larger than the requested height and width.
|
|
|
|
|
- while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
|
|
|
|
|
- inSampleSize *= 2
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return inSampleSize
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
override fun onTouch(event: MotionEvent) {
|
|
override fun onTouch(event: MotionEvent) {
|
|
|
if (pointList.isNotEmpty()) {
|
|
if (pointList.isNotEmpty()) {
|
|
@@ -146,7 +105,7 @@ class CustomStationLayer @JvmOverloads constructor(
|
|
|
paint.color = Color.parseColor("#CCFF0000")
|
|
paint.color = Color.parseColor("#CCFF0000")
|
|
|
paint.textSize = radiusMark
|
|
paint.textSize = radiusMark
|
|
|
// 先画背景再画文字防止文字被盖住
|
|
// 先画背景再画文字防止文字被盖住
|
|
|
- canvas.drawBitmap(bgBitmap, goal[0] - width / 2, goal[1] - 2 * radiusMark, paint)
|
|
|
|
|
|
|
+ canvas.drawBitmap(bgBitmap, goal[0] - bgBitmap.width / 2, goal[1] - 2 * radiusMark, paint)
|
|
|
// 一直显示文字
|
|
// 一直显示文字
|
|
|
canvas.drawText(
|
|
canvas.drawText(
|
|
|
point.entityName,
|
|
point.entityName,
|
|
@@ -154,6 +113,12 @@ class CustomStationLayer @JvmOverloads constructor(
|
|
|
goal[1] + radiusMark / 3.0f,
|
|
goal[1] + radiusMark / 3.0f,
|
|
|
paint
|
|
paint
|
|
|
)
|
|
)
|
|
|
|
|
+ if (point.isSelected) {
|
|
|
|
|
+ canvas.drawBitmap(coverBitmap, goal[0] - bgBitmap.width / 2, goal[1] - 2 * radiusMark, paint)
|
|
|
|
|
+ val selectTextWidth = paint.measureText("√")
|
|
|
|
|
+ paint.color = Color.parseColor("#FFFFFF")
|
|
|
|
|
+ canvas.drawText("√", goal[0] - selectTextWidth / 2, goal[1] - radiusMark / 2, paint)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 定位点,仅调试用,不要显示
|
|
// 定位点,仅调试用,不要显示
|
|
|
// canvas.drawCircle(goal[0], goal[1], 2f, paint)
|
|
// canvas.drawCircle(goal[0], goal[1], 2f, paint)
|