From 7c94d21cc08f51b15a7ab2464746f3acccb1ab1f Mon Sep 17 00:00:00 2001 From: Kurisu Date: Tue, 25 Oct 2022 17:35:13 +0800 Subject: [PATCH] 封装地图路线规划bug修复 --- lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt | 4 ++-- lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt | 276 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt | 39 ++++++++++++++++++++++----------------- lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RouteOverlay.kt | 17 +++++++++++++---- lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png | Bin 1496 -> 0 bytes lib/src/index.ts | 2 +- lib/src/polyline.tsx | 2 +- lib/src/route/driving-route.tsx | 61 +++++++------------------------------------------------------ lib/src/types.ts | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 11 files changed, 391 insertions(+), 356 deletions(-) delete mode 100644 lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt create mode 100644 lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt delete mode 100644 lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png diff --git a/lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt b/lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt index 0c98ff3..69b70b0 100644 --- a/lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt +++ b/lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt @@ -5,7 +5,7 @@ import com.facebook.react.bridge.NativeModule import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.uimanager.ViewManager import cn.feewee.amap3d.map_view.* -import cn.feewee.amap3d.map_view.route.DrivingRouteManager +import cn.feewee.amap3d.map_view.route.RoutePlanManager import cn.feewee.amap3d.modules.SdkModule import cn.feewee.amap3d.modules.AMapGeolocationModule @@ -26,7 +26,7 @@ class AMap3DPackage : ReactPackage { CircleManager(), HeatMapManager(), MultiPointManager(), - DrivingRouteManager() + RoutePlanManager() ) } } diff --git a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt deleted file mode 100644 index 3c53cdc..0000000 --- a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt +++ /dev/null @@ -1,276 +0,0 @@ -package cn.feewee.amap3d.map_view.route - -import android.content.Context -import android.graphics.Color -import android.widget.Toast -import cn.feewee.amap3d.* -import com.amap.api.maps.AMap -import com.amap.api.maps.model.LatLng -import com.amap.api.maps.model.Marker -import com.amap.api.maps.model.MarkerOptions -import com.amap.api.maps.model.PolylineOptions -import com.amap.api.services.core.AMapException -import com.amap.api.services.route.* -import com.facebook.react.bridge.ReadableArray - -class DrivingRoute(context: Context) : RouteOverlay(context), RouteSearch.OnRouteSearchListener { - private var drivePath: DrivePath? = null - private var throughPointList: List = emptyList() - private var isColorfulline = true - private var throughPointMarkerList: ArrayList = ArrayList() - private var throughPointMarkerVisible = true - private var mPolylineOptions: PolylineOptions? = null - private var mPolylineOptionsColor: PolylineOptions? = null - - init { - try { - mRouteSearch = RouteSearch(context) - mRouteSearch!!.setRouteSearchListener(this) - } catch (e: AMapException) { - e.printStackTrace() - } - } - - fun setThroughPointList(throughPoints: List) { - if (throughPoints.size > 6) { - throughPointList = throughPoints.take(6) - return - } - throughPointList = throughPoints - } - - fun setIsColorfulline(iscolorfulline: Boolean) { - isColorfulline = iscolorfulline - } - - fun setThroughPointMarkerVisible(visible: Boolean) { - try { - throughPointMarkerVisible = visible - if (this.throughPointMarkerList.isNotEmpty()) { - for (i in this.throughPointMarkerList.indices) { - this.throughPointMarkerList[i].isVisible = visible - } - } - } catch (e: Throwable) { - e.printStackTrace() - } - } - - override fun add(map: AMap) { - this.map = map - searchRouteResult() - } - - override fun remove() { - removeMarkerFromMap() - removeLineFromMap() - try { - if (throughPointMarkerList.size > 0) { - for (i in throughPointMarkerList.indices) { - throughPointMarkerList[i].remove() - } - throughPointMarkerList.clear() - } - } catch (e: Throwable) { - e.printStackTrace() - } - } - - private fun addToMap() { - initPolylineOptions() - if (getRouteWidth() == 0f || drivePath == null) { - return - } - - val mLatLngsOfPath = ArrayList() - val tmcs = ArrayList() - val drivePaths = drivePath?.steps - - for (step in drivePaths!!) { - val latlonPoints = step.polyline - val tmclist = step.tmCs - tmcs.addAll(tmclist) - addDrivingStationMarkers(step, latlonPoints[0].convertToLatLng()) - for (latlonpoint in latlonPoints) { - mPolylineOptions?.add(latlonpoint.convertToLatLng()) - mLatLngsOfPath.add(latlonpoint.convertToLatLng()) - } - } - addStartAndEndMarker() - addThroughPointMarker() - if (isColorfulline && tmcs.size > 0) { - colorWayUpdate(tmcs) - addPolyLine(mPolylineOptionsColor) - } else { - addPolyLine(mPolylineOptions) - } - } - - /** - * 初始化线段属性 - */ - private fun initPolylineOptions() { - mPolylineOptions = PolylineOptions() - .color(getRoadColor()) - .setCustomTexture(getRoadLine()) - .width(getRouteWidth()) - } - - /** - * 根据不同的路段拥堵情况展示不同的颜色 - * - * @param tmcSection - */ - private fun colorWayUpdate(tmcSection: List) { - var segmentTrafficStatus: TMC - mPolylineOptionsColor = PolylineOptions().width(getRouteWidth()) - mPolylineOptionsColor?.add(tmcSection[0].polyline[0].convertToLatLng()) - - val colorList: MutableList = ArrayList() - colorList.add(getRoadColor()) - for (i in tmcSection.indices) { - segmentTrafficStatus = tmcSection[i] - val color: Int = getColor(segmentTrafficStatus.status) - val mployline = segmentTrafficStatus.polyline - for (j in 1 until mployline.size) { - mPolylineOptionsColor?.add(mployline[j].convertToLatLng()) - colorList.add(color) - } - } - colorList.add(getRoadColor()) - mPolylineOptionsColor?.colorValues(colorList) - } - - private fun getColor(status: String): Int { - return when (status) { - "畅通" -> { - Color.GREEN - } - "缓行" -> { - Color.YELLOW - } - "拥堵" -> { - Color.RED - } - "严重拥堵" -> { - Color.parseColor("#990033") - } - else -> { - Color.parseColor("#537edc") - } - } - } - - /** - * @param driveStep - * @param latLng - */ - private fun addDrivingStationMarkers(driveStep: DriveStep, latLng: LatLng) { - addStationMarker( - MarkerOptions() - .position(latLng) - .title("\u65B9\u5411:" + driveStep.instruction + "\n\u9053\u8DEF:" + driveStep.road) - .snippet(driveStep.instruction).visible(nodeIconVisible) - .anchor(0.5f, 0.5f).icon(getDriveBit()) - ) - } - - /** - * 添加途经点marker - */ - private fun addThroughPointMarker() { - if (throughPointList.isNotEmpty()) { - for (i in throughPointList.indices) { - val latLonPoint = throughPointList[i] - throughPointMarkerList.add( - map.addMarker( - MarkerOptions() - .position(latLonPoint) - .visible(throughPointMarkerVisible) - .icon(getThroughBit()) - .title("\u9014\u7ECF\u70B9") - ) - ) - } - } - } - - override fun searchRouteResult() { - if (mRouteSearch == null) { - return - } - val fromAndTo = createFromAndTo() ?: return - try { - showProgressDialog() - mRouteSearch!!.calculateDriveRouteAsyn( - RouteSearch.DriveRouteQuery( - fromAndTo, - RouteSearch.DRIVEING_PLAN_FASTEST_SHORTEST, - throughPointList.map { r -> r.convertToLatLonPoint() }, - null, - null - ) - ) - } catch (e: AMapException) { - dissmissProgressDialog() - showerror(context, e.errorCode) - } - - } - - private fun onDriveRouteSearched(result: DriveRouteResult?) { - map.clear() - if (result?.paths != null) { - if (result.paths.size > 0) { - drivePath = result.paths[0] ?: return - remove() - addToMap() - zoomToSpan() - - } else if (result.paths == null) { - show(context, R.string.no_result) - } - } else { - show(context, R.string.no_result) - } - } - - - fun searchRoute(args: ReadableArray?) { - val start = args?.getMap(0)?.toLatLonPoint() - val end = args?.getMap(1)?.toLatLonPoint() - val through = args?.getArray(2)?.toLatLngList() - if (start == null) { - Toast.makeText(context, "起点不能为空", Toast.LENGTH_LONG).show() - return - } - if (end == null) { - Toast.makeText(context, "终点不能为空", Toast.LENGTH_LONG).show() - return - } - setStartPoint(start) - setEndPoint(end) - if (through?.isNotEmpty() == true) { - setThroughPointList(through) - } - searchRouteResult() - } - - override fun onDriveRouteSearched(result: DriveRouteResult?, errorCode: Int) { - dissmissProgressDialog() - if (errorCode == AMapException.CODE_AMAP_SUCCESS) { - onDriveRouteSearched(result) - } else { - showerror(context, errorCode) - } - } - - override fun onBusRouteSearched(result: BusRouteResult?, errorCode: Int) { - } - - override fun onWalkRouteSearched(result: WalkRouteResult?, errorCode: Int) { - } - - override fun onRideRouteSearched(result: RideRouteResult?, errorCode: Int) { - } -} \ No newline at end of file diff --git a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt index 7656212..05d2ffa 100644 --- a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt +++ b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt @@ -10,13 +10,13 @@ import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.annotations.ReactProp @Suppress("unused") -class DrivingRouteManager : SimpleViewManager() { +class RoutePlanManager : SimpleViewManager() { override fun getName(): String { - return "DrivingRoute" + return "RoutePlan" } - override fun createViewInstance(reactContext: ThemedReactContext): DrivingRoute { - return DrivingRoute(reactContext) + override fun createViewInstance(reactContext: ThemedReactContext): RoutePlan { + return RoutePlan(reactContext) } companion object { @@ -27,69 +27,74 @@ class DrivingRouteManager : SimpleViewManager() { return mapOf("searchRoute" to searchRoute) } - override fun receiveCommand(route: DrivingRoute, commandId: Int, args: ReadableArray?) { + override fun receiveCommand(route: RoutePlan, commandId: Int, args: ReadableArray?) { when (commandId) { searchRoute -> route.searchRoute(args) } } @ReactProp(name = "startPoint") - fun setStart(route: DrivingRoute, startPoint: ReadableMap) { + fun setStart(route: RoutePlan, startPoint: ReadableMap) { route.setStartPoint(startPoint.toLatLonPoint()) } @ReactProp(name = "endPoint") - fun setEnd(route: DrivingRoute, endPoint: ReadableMap) { + fun setEnd(route: RoutePlan, endPoint: ReadableMap) { route.setEndPoint(endPoint.toLatLonPoint()) } + @ReactProp(name = "routeType") + fun setMapType(route: RoutePlan, routeType: Int = 0) { + route.setRouteType(routeType + 1) + } + @ReactProp(name = "width") - fun setWidth(route: DrivingRoute, width: Float) { + fun setWidth(route: RoutePlan, width: Float) { route.setRouteWidth(width.toPx().toFloat()) } @ReactProp(name = "lineColor", customType = "Color") - fun setColor(route: DrivingRoute, lineColor: Int) { + fun setColor(route: RoutePlan, lineColor: Int) { route.setRoadColor(lineColor) } @ReactProp(name = "throughPointVisible") - fun setThroughPointVisible(route: DrivingRoute, throughPointVisible: Boolean) { + fun setThroughPointVisible(route: RoutePlan, throughPointVisible: Boolean) { route.setThroughPointMarkerVisible(throughPointVisible) } @ReactProp(name = "colorFulLine") - fun setColorFulLine(route: DrivingRoute, colorFulLine: Boolean) { + fun setColorFulLine(route: RoutePlan, colorFulLine: Boolean) { route.setIsColorfulline(colorFulLine) } @ReactProp(name = "throughPointList") - fun setThroughPointList(route: DrivingRoute, position: ReadableArray) { + fun setThroughPointList(route: RoutePlan, position: ReadableArray) { route.setThroughPointList(position.toLatLngList()) } @ReactProp(name = "driveIcon") - fun setDriveIcon(route: DrivingRoute, driveIcon: ReadableMap?) { + fun setDriveIcon(route: RoutePlan, driveIcon: ReadableMap?) { driveIcon?.let { route.setDriveBit(it) } } @ReactProp(name = "startIcon") - fun setStartIcon(route: DrivingRoute, startIcon: ReadableMap?) { + fun setStartIcon(route: RoutePlan, startIcon: ReadableMap?) { startIcon?.let { route.setStartBit(it) } } @ReactProp(name = "endIcon") - fun setEndIcon(route: DrivingRoute, endIcon: ReadableMap?) { + fun setEndIcon(route: RoutePlan, endIcon: ReadableMap?) { endIcon?.let { route.setEndBit(it) } } @ReactProp(name = "throughPointIcon") - fun setThroughPointIcon(route: DrivingRoute, throughPoint: ReadableMap?) { + fun setThroughPointIcon(route: RoutePlan, throughPoint: ReadableMap?) { throughPoint?.let { route.setThroughBit(it) } } @ReactProp(name = "roadLine") - fun setRoadLine(route: DrivingRoute, roadLine: ReadableMap?) { + fun setRoadLine(route: RoutePlan, roadLine: ReadableMap?) { roadLine?.let { route.setRoadLine(it) } } } \ No newline at end of file diff --git a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RouteOverlay.kt b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RouteOverlay.kt index d70da63..23fd8ab 100644 --- a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RouteOverlay.kt +++ b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RouteOverlay.kt @@ -27,6 +27,7 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay private var endMarker: Marker? = null private var roadColor: Int = Color.parseColor("#537edc") private var progDialog: AlertDialog? = null + private var routeType: Int = 1 protected var mRouteSearch: RouteSearch? = null @@ -37,7 +38,7 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay * @param visible true为显示节点图标,false为不显示。 * @since V2.3.1 */ - protected var nodeIconVisible = true + protected var nodeIconVisible = false fun setNodeIconVisibility(visible: Boolean) { try { nodeIconVisible = visible @@ -185,8 +186,8 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay } } - fun getRoadLine(): BitmapDescriptor { - return roadLine ?: BitmapDescriptorFactory.fromResource(R.drawable.cqfw_custtexture) + fun getRoadLine(): BitmapDescriptor? { + return roadLine } private var routeWidth: Float = 18F @@ -219,6 +220,14 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay return roadColor } + fun setRouteType(type: Int) { + routeType = type + } + + fun getRouteType(): Int { + return routeType + } + protected fun addStartAndEndMarker() { removeMarkerFromMap() startMarker = map.addMarker( @@ -342,7 +351,7 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay private fun progressBarCircleDialog(): AlertDialog { val builder = AlertDialog.Builder( context, - AlertDialog.THEME_HOLO_LIGHT + android.R.style.Theme_Material_Light_Dialog_Alert ) val inflater = LayoutInflater.from(context.applicationContext); @SuppressLint("InflateParams") diff --git a/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt new file mode 100644 index 0000000..c700b3c --- /dev/null +++ b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt @@ -0,0 +1,278 @@ +package cn.feewee.amap3d.map_view.route + +import android.content.Context +import android.graphics.Color +import android.widget.Toast +import cn.feewee.amap3d.* +import com.amap.api.maps.AMap +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.Marker +import com.amap.api.maps.model.MarkerOptions +import com.amap.api.maps.model.PolylineOptions +import com.amap.api.services.core.AMapException +import com.amap.api.services.route.* +import com.facebook.react.bridge.ReadableArray + +class RoutePlan(context: Context) : RouteOverlay(context), RouteSearch.OnRouteSearchListener { + private var drivePath: DrivePath? = null + private var throughPointList: List = emptyList() + private var isColorfulline = true + private var throughPointMarkerList: ArrayList = ArrayList() + private var throughPointMarkerVisible = true + private var mPolylineOptions: PolylineOptions? = null + private var mPolylineOptionsColor: PolylineOptions? = null + + init { + try { + mRouteSearch = RouteSearch(context) + mRouteSearch!!.setRouteSearchListener(this) + } catch (e: AMapException) { + e.printStackTrace() + } + } + + fun setThroughPointList(throughPoints: List) { + if (throughPoints.size > 6) { + throughPointList = throughPoints.take(6) + return + } + throughPointList = throughPoints + } + + fun setIsColorfulline(iscolorfulline: Boolean) { + isColorfulline = iscolorfulline + } + + fun setThroughPointMarkerVisible(visible: Boolean) { + try { + throughPointMarkerVisible = visible + if (this.throughPointMarkerList.isNotEmpty()) { + for (i in this.throughPointMarkerList.indices) { + this.throughPointMarkerList[i].isVisible = visible + } + } + } catch (e: Throwable) { + e.printStackTrace() + } + } + + override fun add(map: AMap) { + this.map = map + if (getRouteType() == 1) { + searchRouteResult() + } + } + + override fun remove() { + removeMarkerFromMap() + removeLineFromMap() + try { + if (throughPointMarkerList.size > 0) { + for (i in throughPointMarkerList.indices) { + throughPointMarkerList[i].remove() + } + throughPointMarkerList.clear() + } + } catch (e: Throwable) { + e.printStackTrace() + } + } + + private fun addToMap() { + initPolylineOptions() + if (getRouteWidth() == 0f || drivePath == null) { + return + } + + val mLatLngsOfPath = ArrayList() + val tmcs = ArrayList() + val drivePaths = drivePath?.steps + + for (step in drivePaths!!) { + val latlonPoints = step.polyline + val tmclist = step.tmCs + tmcs.addAll(tmclist) + addDrivingStationMarkers(step, latlonPoints[0].convertToLatLng()) + for (latlonpoint in latlonPoints) { + mPolylineOptions?.add(latlonpoint.convertToLatLng()) + mLatLngsOfPath.add(latlonpoint.convertToLatLng()) + } + } + addStartAndEndMarker() + addThroughPointMarker() + if (isColorfulline && tmcs.size > 0) { + colorWayUpdate(tmcs) + addPolyLine(mPolylineOptionsColor) + } else { + addPolyLine(mPolylineOptions) + } + } + + /** + * 初始化线段属性 + */ + private fun initPolylineOptions() { + mPolylineOptions = PolylineOptions() + .color(getRoadColor()) + .setCustomTexture(getRoadLine()) + .width(getRouteWidth()) + } + + /** + * 根据不同的路段拥堵情况展示不同的颜色 + * + * @param tmcSection + */ + private fun colorWayUpdate(tmcSection: List) { + var segmentTrafficStatus: TMC + mPolylineOptionsColor = PolylineOptions().width(getRouteWidth()) + mPolylineOptionsColor?.add(tmcSection[0].polyline[0].convertToLatLng()) + + val colorList: MutableList = ArrayList() + colorList.add(getRoadColor()) + for (i in tmcSection.indices) { + segmentTrafficStatus = tmcSection[i] + val color: Int = getColor(segmentTrafficStatus.status) + val mployline = segmentTrafficStatus.polyline + for (j in 1 until mployline.size) { + mPolylineOptionsColor?.add(mployline[j].convertToLatLng()) + colorList.add(color) + } + } + colorList.add(getRoadColor()) + mPolylineOptionsColor?.colorValues(colorList) + } + + private fun getColor(status: String): Int { + return when (status) { + "畅通" -> { + Color.GREEN + } + "缓行" -> { + Color.YELLOW + } + "拥堵" -> { + Color.RED + } + "严重拥堵" -> { + Color.parseColor("#990033") + } + else -> { + Color.parseColor("#537edc") + } + } + } + + /** + * @param driveStep + * @param latLng + */ + private fun addDrivingStationMarkers(driveStep: DriveStep, latLng: LatLng) { + addStationMarker( + MarkerOptions() + .position(latLng) + .title("\u65B9\u5411:" + driveStep.instruction + "\n\u9053\u8DEF:" + driveStep.road) + .snippet(driveStep.instruction).visible(nodeIconVisible) + .anchor(0.5f, 0.5f).icon(getDriveBit()) + ) + } + + /** + * 添加途经点marker + */ + private fun addThroughPointMarker() { + if (throughPointList.isNotEmpty()) { + for (i in throughPointList.indices) { + val latLonPoint = throughPointList[i] + throughPointMarkerList.add( + map.addMarker( + MarkerOptions() + .position(latLonPoint) + .visible(throughPointMarkerVisible) + .icon(getThroughBit()) + .title("\u9014\u7ECF\u70B9") + ) + ) + } + } + } + + override fun searchRouteResult() { + if (mRouteSearch == null) { + return + } + val fromAndTo = createFromAndTo() ?: return + try { + showProgressDialog() + mRouteSearch!!.calculateDriveRouteAsyn( + RouteSearch.DriveRouteQuery( + fromAndTo, + RouteSearch.DRIVEING_PLAN_FASTEST_SHORTEST, + throughPointList.map { r -> r.convertToLatLonPoint() }, + null, + null + ) + ) + } catch (e: AMapException) { + dissmissProgressDialog() + showerror(context, e.errorCode) + } + + } + + private fun onDriveRouteSearched(result: DriveRouteResult?) { + map.clear() + if (result?.paths != null) { + if (result.paths.size > 0) { + drivePath = result.paths[0] ?: return + remove() + addToMap() + zoomToSpan() + + } else if (result.paths == null) { + show(context, R.string.no_result) + } + } else { + show(context, R.string.no_result) + } + } + + + fun searchRoute(args: ReadableArray?) { + val start = args?.getMap(0)?.toLatLonPoint() + val end = args?.getMap(1)?.toLatLonPoint() + val through = args?.getArray(2)?.toLatLngList() + if (start == null) { + Toast.makeText(context, "起点不能为空", Toast.LENGTH_LONG).show() + return + } + if (end == null) { + Toast.makeText(context, "终点不能为空", Toast.LENGTH_LONG).show() + return + } + setStartPoint(start) + setEndPoint(end) + if (through?.isNotEmpty() == true) { + setThroughPointList(through) + } + searchRouteResult() + } + + override fun onDriveRouteSearched(result: DriveRouteResult?, errorCode: Int) { + dissmissProgressDialog() + if (errorCode == AMapException.CODE_AMAP_SUCCESS) { + onDriveRouteSearched(result) + } else { + showerror(context, errorCode) + } + } + + override fun onBusRouteSearched(result: BusRouteResult?, errorCode: Int) { + } + + override fun onWalkRouteSearched(result: WalkRouteResult?, errorCode: Int) { + } + + override fun onRideRouteSearched(result: RideRouteResult?, errorCode: Int) { + } +} \ No newline at end of file diff --git a/lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png b/lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png deleted file mode 100644 index dd8f7e6..0000000 Binary files a/lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png and /dev/null differ diff --git a/lib/src/index.ts b/lib/src/index.ts index a379c6d..57e9809 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -3,7 +3,7 @@ export { default as Cluster } from "./cluster/index"; export { default as HeatMap } from "./heat-map"; export { default as MapView } from "./map-view"; export { default as Marker } from "./marker"; -export { default as DrivingRoute } from "./route/driving-route"; +export { default as RoutePlan } from "./route/route-plan"; export { default as MultiPoint } from "./multi-point"; export { default as Polygon } from "./polygon"; export { default as Polyline } from "./polyline"; diff --git a/lib/src/polyline.tsx b/lib/src/polyline.tsx index a733c31..cbd49fa 100644 --- a/lib/src/polyline.tsx +++ b/lib/src/polyline.tsx @@ -54,7 +54,7 @@ export interface PolylineProps { } export default class extends React.PureComponent { - static defaultProps = { colors: [], with: 16 }; + static defaultProps = { colors: [], width: 8 }; render() { const props = { diff --git a/lib/src/route/driving-route.tsx b/lib/src/route/driving-route.tsx index b2a1386..2f9110d 100644 --- a/lib/src/route/driving-route.tsx +++ b/lib/src/route/driving-route.tsx @@ -1,60 +1,13 @@ import * as React from "react"; -import { ColorValue, ImageSourcePropType, Platform, processColor, requireNativeComponent } from "react-native"; +import { requireNativeComponent } from "react-native"; import Component from "../component"; // @ts-ignore import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource"; -import { LatLng } from "../types"; +import { RouteProps, LatLng, RouteType } from "../types"; -export interface DrivingRouteProps { - /** - * 起点 - */ - startPoint: LatLng; - /** - * 终点 - */ - endPoint: LatLng; - /** - * 途经点 - */ - throughPointList?: LatLng[]; - /** - * 显示途经点 - */ - throughPointVisible?: boolean; - /** - * 根据不同的路段拥堵情况展示不同的颜色 - */ - colorFulLine?: boolean; - /** - * 线段宽度 - */ - width?: number; - /** - * 路线的纹理 - */ - roadLine?: ImageSourcePropType; - /** - * 起点图标 - */ - startIcon?: ImageSourcePropType; - /** - * 终点图标 - */ - endIcon?: ImageSourcePropType; - /** - * 途经点图标 - */ - throughPointIcon?: ImageSourcePropType; - /** - * 线段颜色 - */ - lineColor?: ColorValue; -} - -export default class extends Component { +export default class extends Component { name = name; - static defaultProps = { with: 16, throughPointVisible: true }; + static defaultProps = { width: 8, throughPointVisible: true, type: RouteType.DRIVE }; /** * 路线规划 @@ -68,7 +21,7 @@ export default class extends Component { ...this.props, }; return ( - { } } -const name = "DrivingRoute"; -const NativeDrivingRoute = requireNativeComponent(name); +const name = "RoutePlan"; +const NativeRoutePlan = requireNativeComponent(name); diff --git a/lib/src/types.ts b/lib/src/types.ts index aa16ba4..0e3cc44 100644 --- a/lib/src/types.ts +++ b/lib/src/types.ts @@ -1,3 +1,5 @@ +import { ImageSourcePropType, ColorValue } from "react-native"; + /** * 点坐标 */ @@ -135,3 +137,67 @@ export enum MapType { */ Bus, } + +export enum RouteType { + /**驾车 */ + DRIVE, + /**步行 */ + WALK, + /**公交 */ + BUS, + /** 骑行 */ + RIDE, + /** 货车 */ + TRUCK, +} + +/** + * 路线规划参数 + */ +export interface RouteProps { + type: RouteType; + /** + * 起点 + */ + startPoint: LatLng; + /** + * 终点 + */ + endPoint: LatLng; + /** + * 途经点 + */ + throughPointList?: LatLng[]; + /** + * 显示途经点 + */ + throughPointVisible?: boolean; + /** + * 根据不同的路段拥堵情况展示不同的颜色 + */ + colorFulLine?: boolean; + /** + * 线段宽度 + */ + width?: number; + /** + * 路线的纹理 + */ + roadLine?: ImageSourcePropType; + /** + * 起点图标 + */ + startIcon?: ImageSourcePropType; + /** + * 终点图标 + */ + endIcon?: ImageSourcePropType; + /** + * 途经点图标 + */ + throughPointIcon?: ImageSourcePropType; + /** + * 线段颜色 + */ + lineColor?: ColorValue; +} diff --git a/package.json b/package.json index e2827f4..ee7af07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cqfw/react-native-amap3d", - "version": "0.1.4", + "version": "0.1.5", "description": "react-native 高德地图组件,支持 Android + iOS", "author": "feewee", "license": "MIT", -- libgit2 0.22.2