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/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/DrivingRoute.kt b/lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt index 3c53cdc..c700b3c 100644 --- 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/RoutePlan.kt @@ -13,7 +13,7 @@ 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 { +class RoutePlan(context: Context) : RouteOverlay(context), RouteSearch.OnRouteSearchListener { private var drivePath: DrivePath? = null private var throughPointList: List = emptyList() private var isColorfulline = true @@ -58,7 +58,9 @@ class DrivingRoute(context: Context) : RouteOverlay(context), RouteSearch.OnRout override fun add(map: AMap) { this.map = map - searchRouteResult() + if (getRouteType() == 1) { + searchRouteResult() + } } override fun remove() { 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 --- a/lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png +++ /dev/null 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",