Commit 7c94d21cc08f51b15a7ab2464746f3acccb1ab1f

Authored by 张志伟
1 parent 250fa551

封装地图路线规划bug修复

lib/android/src/main/java/cn/feewee/amap3d/AMap3DPackage.kt
... ... @@ -5,7 +5,7 @@ import com.facebook.react.bridge.NativeModule
5 5 import com.facebook.react.bridge.ReactApplicationContext
6 6 import com.facebook.react.uimanager.ViewManager
7 7 import cn.feewee.amap3d.map_view.*
8   -import cn.feewee.amap3d.map_view.route.DrivingRouteManager
  8 +import cn.feewee.amap3d.map_view.route.RoutePlanManager
9 9 import cn.feewee.amap3d.modules.SdkModule
10 10 import cn.feewee.amap3d.modules.AMapGeolocationModule
11 11  
... ... @@ -26,7 +26,7 @@ class AMap3DPackage : ReactPackage {
26 26 CircleManager(),
27 27 HeatMapManager(),
28 28 MultiPointManager(),
29   - DrivingRouteManager()
  29 + RoutePlanManager()
30 30 )
31 31 }
32 32 }
... ...
lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRouteManager.kt
... ... @@ -10,13 +10,13 @@ import com.facebook.react.uimanager.ThemedReactContext
10 10 import com.facebook.react.uimanager.annotations.ReactProp
11 11  
12 12 @Suppress("unused")
13   -class DrivingRouteManager : SimpleViewManager<DrivingRoute>() {
  13 +class RoutePlanManager : SimpleViewManager<RoutePlan>() {
14 14 override fun getName(): String {
15   - return "DrivingRoute"
  15 + return "RoutePlan"
16 16 }
17 17  
18   - override fun createViewInstance(reactContext: ThemedReactContext): DrivingRoute {
19   - return DrivingRoute(reactContext)
  18 + override fun createViewInstance(reactContext: ThemedReactContext): RoutePlan {
  19 + return RoutePlan(reactContext)
20 20 }
21 21  
22 22 companion object {
... ... @@ -27,69 +27,74 @@ class DrivingRouteManager : SimpleViewManager&lt;DrivingRoute&gt;() {
27 27 return mapOf("searchRoute" to searchRoute)
28 28 }
29 29  
30   - override fun receiveCommand(route: DrivingRoute, commandId: Int, args: ReadableArray?) {
  30 + override fun receiveCommand(route: RoutePlan, commandId: Int, args: ReadableArray?) {
31 31 when (commandId) {
32 32 searchRoute -> route.searchRoute(args)
33 33 }
34 34 }
35 35  
36 36 @ReactProp(name = "startPoint")
37   - fun setStart(route: DrivingRoute, startPoint: ReadableMap) {
  37 + fun setStart(route: RoutePlan, startPoint: ReadableMap) {
38 38 route.setStartPoint(startPoint.toLatLonPoint())
39 39 }
40 40  
41 41 @ReactProp(name = "endPoint")
42   - fun setEnd(route: DrivingRoute, endPoint: ReadableMap) {
  42 + fun setEnd(route: RoutePlan, endPoint: ReadableMap) {
43 43 route.setEndPoint(endPoint.toLatLonPoint())
44 44 }
45 45  
  46 + @ReactProp(name = "routeType")
  47 + fun setMapType(route: RoutePlan, routeType: Int = 0) {
  48 + route.setRouteType(routeType + 1)
  49 + }
  50 +
46 51 @ReactProp(name = "width")
47   - fun setWidth(route: DrivingRoute, width: Float) {
  52 + fun setWidth(route: RoutePlan, width: Float) {
48 53 route.setRouteWidth(width.toPx().toFloat())
49 54 }
50 55  
51 56 @ReactProp(name = "lineColor", customType = "Color")
52   - fun setColor(route: DrivingRoute, lineColor: Int) {
  57 + fun setColor(route: RoutePlan, lineColor: Int) {
53 58 route.setRoadColor(lineColor)
54 59 }
55 60  
56 61 @ReactProp(name = "throughPointVisible")
57   - fun setThroughPointVisible(route: DrivingRoute, throughPointVisible: Boolean) {
  62 + fun setThroughPointVisible(route: RoutePlan, throughPointVisible: Boolean) {
58 63 route.setThroughPointMarkerVisible(throughPointVisible)
59 64 }
60 65  
61 66 @ReactProp(name = "colorFulLine")
62   - fun setColorFulLine(route: DrivingRoute, colorFulLine: Boolean) {
  67 + fun setColorFulLine(route: RoutePlan, colorFulLine: Boolean) {
63 68 route.setIsColorfulline(colorFulLine)
64 69 }
65 70  
66 71 @ReactProp(name = "throughPointList")
67   - fun setThroughPointList(route: DrivingRoute, position: ReadableArray) {
  72 + fun setThroughPointList(route: RoutePlan, position: ReadableArray) {
68 73 route.setThroughPointList(position.toLatLngList())
69 74 }
70 75  
71 76 @ReactProp(name = "driveIcon")
72   - fun setDriveIcon(route: DrivingRoute, driveIcon: ReadableMap?) {
  77 + fun setDriveIcon(route: RoutePlan, driveIcon: ReadableMap?) {
73 78 driveIcon?.let { route.setDriveBit(it) }
74 79 }
75 80  
76 81 @ReactProp(name = "startIcon")
77   - fun setStartIcon(route: DrivingRoute, startIcon: ReadableMap?) {
  82 + fun setStartIcon(route: RoutePlan, startIcon: ReadableMap?) {
78 83 startIcon?.let { route.setStartBit(it) }
79 84 }
80 85  
81 86 @ReactProp(name = "endIcon")
82   - fun setEndIcon(route: DrivingRoute, endIcon: ReadableMap?) {
  87 + fun setEndIcon(route: RoutePlan, endIcon: ReadableMap?) {
83 88 endIcon?.let { route.setEndBit(it) }
84 89 }
85 90  
86 91 @ReactProp(name = "throughPointIcon")
87   - fun setThroughPointIcon(route: DrivingRoute, throughPoint: ReadableMap?) {
  92 + fun setThroughPointIcon(route: RoutePlan, throughPoint: ReadableMap?) {
88 93 throughPoint?.let { route.setThroughBit(it) }
89 94 }
90 95  
91 96 @ReactProp(name = "roadLine")
92   - fun setRoadLine(route: DrivingRoute, roadLine: ReadableMap?) {
  97 + fun setRoadLine(route: RoutePlan, roadLine: ReadableMap?) {
93 98 roadLine?.let { route.setRoadLine(it) }
94 99 }
95 100 }
96 101 \ No newline at end of file
... ...
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
27 27 private var endMarker: Marker? = null
28 28 private var roadColor: Int = Color.parseColor("#537edc")
29 29 private var progDialog: AlertDialog? = null
  30 + private var routeType: Int = 1
30 31  
31 32 protected var mRouteSearch: RouteSearch? = null
32 33  
... ... @@ -37,7 +38,7 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay
37 38 * @param visible true为显示节点图标,false为不显示。
38 39 * @since V2.3.1
39 40 */
40   - protected var nodeIconVisible = true
  41 + protected var nodeIconVisible = false
41 42 fun setNodeIconVisibility(visible: Boolean) {
42 43 try {
43 44 nodeIconVisible = visible
... ... @@ -185,8 +186,8 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay
185 186 }
186 187 }
187 188  
188   - fun getRoadLine(): BitmapDescriptor {
189   - return roadLine ?: BitmapDescriptorFactory.fromResource(R.drawable.cqfw_custtexture)
  189 + fun getRoadLine(): BitmapDescriptor? {
  190 + return roadLine
190 191 }
191 192  
192 193 private var routeWidth: Float = 18F
... ... @@ -219,6 +220,14 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay
219 220 return roadColor
220 221 }
221 222  
  223 + fun setRouteType(type: Int) {
  224 + routeType = type
  225 + }
  226 +
  227 + fun getRouteType(): Int {
  228 + return routeType
  229 + }
  230 +
222 231 protected fun addStartAndEndMarker() {
223 232 removeMarkerFromMap()
224 233 startMarker = map.addMarker(
... ... @@ -342,7 +351,7 @@ abstract class RouteOverlay(context: Context) : ReactViewGroup(context), Overlay
342 351 private fun progressBarCircleDialog(): AlertDialog {
343 352 val builder = AlertDialog.Builder(
344 353 context,
345   - AlertDialog.THEME_HOLO_LIGHT
  354 + android.R.style.Theme_Material_Light_Dialog_Alert
346 355 )
347 356 val inflater = LayoutInflater.from(context.applicationContext);
348 357 @SuppressLint("InflateParams")
... ...
lib/android/src/main/java/cn/feewee/amap3d/map_view/route/DrivingRoute.kt renamed to lib/android/src/main/java/cn/feewee/amap3d/map_view/route/RoutePlan.kt
... ... @@ -13,7 +13,7 @@ import com.amap.api.services.core.AMapException
13 13 import com.amap.api.services.route.*
14 14 import com.facebook.react.bridge.ReadableArray
15 15  
16   -class DrivingRoute(context: Context) : RouteOverlay(context), RouteSearch.OnRouteSearchListener {
  16 +class RoutePlan(context: Context) : RouteOverlay(context), RouteSearch.OnRouteSearchListener {
17 17 private var drivePath: DrivePath? = null
18 18 private var throughPointList: List<LatLng> = emptyList()
19 19 private var isColorfulline = true
... ... @@ -58,7 +58,9 @@ class DrivingRoute(context: Context) : RouteOverlay(context), RouteSearch.OnRout
58 58  
59 59 override fun add(map: AMap) {
60 60 this.map = map
61   - searchRouteResult()
  61 + if (getRouteType() == 1) {
  62 + searchRouteResult()
  63 + }
62 64 }
63 65  
64 66 override fun remove() {
... ...
lib/android/src/main/res/drawable-hdpi/cqfw_custtexture.png deleted

1.46 KB

lib/src/index.ts
... ... @@ -3,7 +3,7 @@ export { default as Cluster } from &quot;./cluster/index&quot;;
3 3 export { default as HeatMap } from "./heat-map";
4 4 export { default as MapView } from "./map-view";
5 5 export { default as Marker } from "./marker";
6   -export { default as DrivingRoute } from "./route/driving-route";
  6 +export { default as RoutePlan } from "./route/route-plan";
7 7 export { default as MultiPoint } from "./multi-point";
8 8 export { default as Polygon } from "./polygon";
9 9 export { default as Polyline } from "./polyline";
... ...
lib/src/polyline.tsx
... ... @@ -54,7 +54,7 @@ export interface PolylineProps {
54 54 }
55 55  
56 56 export default class extends React.PureComponent<PolylineProps> {
57   - static defaultProps = { colors: [], with: 16 };
  57 + static defaultProps = { colors: [], width: 8 };
58 58  
59 59 render() {
60 60 const props = {
... ...
lib/src/route/driving-route.tsx
1 1 import * as React from "react";
2   -import { ColorValue, ImageSourcePropType, Platform, processColor, requireNativeComponent } from "react-native";
  2 +import { requireNativeComponent } from "react-native";
3 3 import Component from "../component";
4 4 // @ts-ignore
5 5 import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
6   -import { LatLng } from "../types";
  6 +import { RouteProps, LatLng, RouteType } from "../types";
7 7  
8   -export interface DrivingRouteProps {
9   - /**
10   - * 起点
11   - */
12   - startPoint: LatLng;
13   - /**
14   - * 终点
15   - */
16   - endPoint: LatLng;
17   - /**
18   - * 途经点
19   - */
20   - throughPointList?: LatLng[];
21   - /**
22   - * 显示途经点
23   - */
24   - throughPointVisible?: boolean;
25   - /**
26   - * 根据不同的路段拥堵情况展示不同的颜色
27   - */
28   - colorFulLine?: boolean;
29   - /**
30   - * 线段宽度
31   - */
32   - width?: number;
33   - /**
34   - * 路线的纹理
35   - */
36   - roadLine?: ImageSourcePropType;
37   - /**
38   - * 起点图标
39   - */
40   - startIcon?: ImageSourcePropType;
41   - /**
42   - * 终点图标
43   - */
44   - endIcon?: ImageSourcePropType;
45   - /**
46   - * 途经点图标
47   - */
48   - throughPointIcon?: ImageSourcePropType;
49   - /**
50   - * 线段颜色
51   - */
52   - lineColor?: ColorValue;
53   -}
54   -
55   -export default class extends Component<DrivingRouteProps> {
  8 +export default class extends Component<RouteProps> {
56 9 name = name;
57   - static defaultProps = { with: 16, throughPointVisible: true };
  10 + static defaultProps = { width: 8, throughPointVisible: true, type: RouteType.DRIVE };
58 11  
59 12 /**
60 13 * 路线规划
... ... @@ -68,7 +21,7 @@ export default class extends Component&lt;DrivingRouteProps&gt; {
68 21 ...this.props,
69 22 };
70 23 return (
71   - <NativeDrivingRoute
  24 + <NativeRoutePlan
72 25 {...props}
73 26 startIcon={resolveAssetSource(props.startIcon)}
74 27 endIcon={resolveAssetSource(props.endIcon)}
... ... @@ -79,5 +32,5 @@ export default class extends Component&lt;DrivingRouteProps&gt; {
79 32 }
80 33 }
81 34  
82   -const name = "DrivingRoute";
83   -const NativeDrivingRoute = requireNativeComponent<DrivingRouteProps>(name);
  35 +const name = "RoutePlan";
  36 +const NativeRoutePlan = requireNativeComponent<RouteProps>(name);
... ...
lib/src/types.ts
  1 +import { ImageSourcePropType, ColorValue } from "react-native";
  2 +
1 3 /**
2 4 * 点坐标
3 5 */
... ... @@ -135,3 +137,67 @@ export enum MapType {
135 137 */
136 138 Bus,
137 139 }
  140 +
  141 +export enum RouteType {
  142 + /**驾车 */
  143 + DRIVE,
  144 + /**步行 */
  145 + WALK,
  146 + /**公交 */
  147 + BUS,
  148 + /** 骑行 */
  149 + RIDE,
  150 + /** 货车 */
  151 + TRUCK,
  152 +}
  153 +
  154 +/**
  155 + * 路线规划参数
  156 + */
  157 +export interface RouteProps {
  158 + type: RouteType;
  159 + /**
  160 + * 起点
  161 + */
  162 + startPoint: LatLng;
  163 + /**
  164 + * 终点
  165 + */
  166 + endPoint: LatLng;
  167 + /**
  168 + * 途经点
  169 + */
  170 + throughPointList?: LatLng[];
  171 + /**
  172 + * 显示途经点
  173 + */
  174 + throughPointVisible?: boolean;
  175 + /**
  176 + * 根据不同的路段拥堵情况展示不同的颜色
  177 + */
  178 + colorFulLine?: boolean;
  179 + /**
  180 + * 线段宽度
  181 + */
  182 + width?: number;
  183 + /**
  184 + * 路线的纹理
  185 + */
  186 + roadLine?: ImageSourcePropType;
  187 + /**
  188 + * 起点图标
  189 + */
  190 + startIcon?: ImageSourcePropType;
  191 + /**
  192 + * 终点图标
  193 + */
  194 + endIcon?: ImageSourcePropType;
  195 + /**
  196 + * 途经点图标
  197 + */
  198 + throughPointIcon?: ImageSourcePropType;
  199 + /**
  200 + * 线段颜色
  201 + */
  202 + lineColor?: ColorValue;
  203 +}
... ...
package.json
1 1 {
2 2 "name": "@cqfw/react-native-amap3d",
3   - "version": "0.1.4",
  3 + "version": "0.1.5",
4 4 "description": "react-native 高德地图组件,支持 Android + iOS",
5 5 "author": "feewee",
6 6 "license": "MIT",
... ...