package com.shoyoo.react.anavi.maps import android.content.Context import android.graphics.Color import com.shoyoo.react.anavi.toLatLngList import com.amap.api.maps.AMap import com.amap.api.maps.model.* import com.facebook.react.bridge.ReadableArray import com.facebook.react.views.view.ReactViewGroup import com.shoyoo.react.anavi.R class AMapTexturePolyline(context: Context) : ReactViewGroup(context), AMapOverlay { var polyline: Polyline? = null private set private var texture: BitmapDescriptor? private var coordinates: ArrayList = ArrayList() init { texture = BitmapDescriptorFactory.fromResource(R.drawable.amap_alr) } var width: Float = 1f set(value) { field = value polyline?.width = value } var zIndex: Float = 0f set(value) { field = value polyline?.zIndex = value } fun setCoordinates(coordinates: ReadableArray) { this.coordinates = coordinates.toLatLngList() polyline?.points = this.coordinates } fun setTexture(textureName: String) { val resId = context.resources.getIdentifier("amap_alr", "drawable", context.packageName) texture = BitmapDescriptorFactory.fromResource(resId) polyline?.setCustomTexture(texture) } override fun add(map: AMap) { polyline = map.addPolyline(PolylineOptions() .addAll(coordinates) .width(width) .setCustomTexture(texture ?: BitmapDescriptorFactory.fromResource(R.drawable.amap_alr)) .zIndex(zIndex)) } override fun remove() { polyline?.remove() } }