import RouteSearch from 'com.amap.api.services.route.RouteSearch'
import DriveRouteQuery from 'com.amap.api.services.route.RouteSearch.DriveRouteQuery'
import FromAndTo from 'com.amap.api.services.route.RouteSearch.FromAndTo'
import LatLonPoint from 'com.amap.api.services.core.LatLonPoint'
import OnRouteSearchListener from 'com.amap.api.services.route.RouteSearch.OnRouteSearchListener'
import DriveRouteResult from 'com.amap.api.services.route.DriveRouteResult'
import BusRouteResult from 'com.amap.api.services.route.BusRouteResult'
import WalkRouteResult from 'com.amap.api.services.route.WalkRouteResult'
import RideRouteResult from 'com.amap.api.services.route.RideRouteResult'
import { getAppContext } from "io.dcloud.uts.android";
type RouteOption = {
startLat: Number,
startLng: Number,
endLat: Number,
endLng: Number,
success: (result: DriveRouteResult) => void
}
class SingleRouteListener extends OnRouteSearchListener {
option: RouteOption
constructor(opt: RouteOption) {
super()
this.option = opt
}
public init() {
const startPoint = new LatLonPoint(this.option.startLat.toDouble(), this.option.startLng.toDouble())
const endPoint = new LatLonPoint(this.option.endLat.toDouble(), this.option.endLng.toDouble())
const routeSearch = new RouteSearch(getAppContext())
routeSearch.setRouteSearchListener(this);
const formAndTo = new FromAndTo(startPoint, endPoint)
const query = new DriveRouteQuery(formAndTo, RouteSearch.DRIVING_SINGLE_AVOID_CONGESTION, null, null, '')
routeSearch.calculateDriveRouteAsyn(query)
}
override onDriveRouteSearched(result: DriveRouteResult, errorCode: Int) {
this.option.success(result)
}
override onBusRouteSearched(result: BusRouteResult, errorCode: Int) {
console.log('onBusRouteSearched');
}
override onRideRouteSearched(result: RideRouteResult, errorCode: Int) {
console.log('onRideRouteSearched');
}
override onWalkRouteSearched(result: WalkRouteResult, errorCode: Int) {
console.log('onWalkRouteSearched');
}
}
export function getRoute(option: RouteOption) {
console.log(option);
const route = new SingleRouteListener(option)
route.init()
}