driving-route.tsx 1.88 KB
import * as React from "react";
import { ColorValue, ImageSourcePropType, Platform, processColor, requireNativeComponent } from "react-native";
import Component from "../component";
// @ts-ignore
import resolveAssetSource from "react-native/Libraries/Image/resolveAssetSource";
import { LatLng } from "../types";

export interface DrivingRouteProps {
  /**
   * 起点
   */
  startPoint: LatLng;
  /**
   * 终点
   */
  endPoint: LatLng;
  /**
   * 途经点
   */
  throughPointList?: LatLng[];
  /**
   * 显示途经点
   */
  throughPointVisible?: boolean;
  /**
   * 根据不同的路段拥堵情况展示不同的颜色
   */
  colorFulLine?: boolean;
  /**
   * 线段宽度
   */
  width?: number;
  /**
   * 路线的纹理
   */
  roadLine?: ImageSourcePropType;
  /**
   * 驾车图标
   */
  driveIcon?: ImageSourcePropType;
  /**
   * 起点图标
   */
  startIcon?: ImageSourcePropType;
  /**
   * 终点图标
   */
  endIcon?: ImageSourcePropType;
  /**
   * 途经点图标
   */
  throughPointIcon?: ImageSourcePropType;
  /**
   * 线段颜色
   */
  lineColor?: ColorValue;
}

export default class extends Component<DrivingRouteProps> {
  static defaultProps = { with: 14, throughPointVisible: true };

  /**
   * 路线规划
   */
  routePlan(start: LatLng, end: LatLng, throughPointList: LatLng[] = []) {
    this.invoke("searchRoute", [start, end, throughPointList]);
  }

  render() {
    const props = {
      ...this.props,
    };
    return (
      <NativeDrivingRoute
        {...props}
        driveIcon={resolveAssetSource(props.driveIcon)}
        startIcon={resolveAssetSource(props.startIcon)}
        endIcon={resolveAssetSource(props.endIcon)}
        throughPointIcon={resolveAssetSource(props.throughPointIcon)}
        roadLine={resolveAssetSource(props.roadLine)}
      />
    );
  }
}

const NativeDrivingRoute = requireNativeComponent<DrivingRouteProps>("DrivingRoute");