BusLineSearch
公交路线搜索类。
构造函数
| 构造函数 | 描述 |
|---|---|
| BusLineSearch(location: Map | Point | String, options: BusLineSearchOptions) | 创建公交线搜索类。其中location表示检索区域,其类型可为地图实例、坐标点或城市名称的字符串。当参数为地图实例时,检索位置由当前地图中心点确定;当参数为坐标时,检索位置由该点所在位置确定;当参数为城市名称时,检索会在该城市内进行 |
BusLineSearchOptions
此类表示BusLineSearch类的可选参数,没有构造参数,可以通过对象字面量表示。
| 属性 | 类型 | 描述 |
|---|---|---|
| renderOptions | RenderOptions | RenderOptions结果呈现设置 |
| onGetBusListComplete | Function | 设置公交列表查询后的回调函数.参数:rs: BusListResult类型 |
| onGetBusLineComplete | Function | 设置公交线路查询后的回调函数.参数:rs: BusLine类型 |
| onBusListHtmlSet | Function | 公交列表结果页渲染后回调函数.参数:container: HTMLElement,结果列表所用的HTML元素 |
| onBusLineHtmlSet | Function | 公交线路结果页渲染后回调函数.参数:container: HTMLElement,结果列表所用的HTML元素 |
| onPolylinesSet | Function | 添加公交线时候回调函数.参数:ply:Polyline 公交线路几何对象 |
| onMarkersSet | Function | 添加公交站点时候回调函数.参数:sts:Array 公交站坐标组成的Marker对象数组 |
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
| getBusList(keyword: String) | none | 在用户配置的回调函数中返回公交列表结果,其类型为BusListResult |
| getBusLine(busLstItem: BusListItem) | none | 在用户配置的回调函数中返回该条线路的公交信息,其类型为BusLine类型 |
| clearResults() | none | 清除本次公交线检索结果 |
| enableAutoViewport() | none | 启用自动调整地图视野功能 |
| disableAutoViewport() | none | 禁用自动调整地图视野功能 |
| setLocation(location: Map | Point | String) | none | 设置检索范围,参数类型可以为地图实例、坐标点或字符串。例:setLocation("北京市") |
| getStatus() | StatusCodes | 返回状态码 |
| toString() | String | 返回类型说明 |
| setGetBusListCompleteCallback(callback: Function) | none | 设置公交列表查询后的回调函数。参数:rs: BusListResult类型 |
| setGetBusLineCompleteCallback(callback: Function) | none | 设置公交线路查询后的回调函数。参数:rs: BusLine类型 |
| setBusListHtmlSetCallback(callback: Function) | none | 公交列表结果页渲染后回调函数。参数:container: HTMLElement,结果列表所用的HTML元素 |
| setBusLineHtmlSetCallback(callback: Function) | none | 公交线路结果页渲染后回调函数。参数:container: HTMLElement,结果列表所用的HTML元素 |
| setPolylinesSetCallback(callback: Function) | none | 添加公交线时候回调函数。参数:ply:Polyline 公交线路几何对象 |
| setMarkersSetCallback(callback: Function) | none | 添加公交站点时候回调函数。参数:sts:Array 公交站坐标组成的Marker对象数组 |
BusListResult
公交列表查询成功回调函数的参数对象。
属性
| 属性 | 类型 | 描述 |
|---|---|---|
| keyword | String | 本次检索关键字 |
| city | String | 本次检索所在城市 |
| moreResultsUrl | String | 到百度地图查看url |
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
getNumBusList() | Number | 公交列表个数 |
getBusListItem(i: Number) | BusListItem | 获取某一个具体的公交列表中的对象。0表示上行,1表示下行 |
示例
ts
// 创建公交线搜索实例
const busLineSearch = new BMapGL.BusLineSearch(map, {
renderOptions: {
map: map
},
onGetBusListComplete: (result: BMapGL.BusListResult) => {
console.log('公交列表查询完成');
console.log('检索关键字:', result.keyword);
console.log('所在城市:', result.city);
// 获取公交列表数量
const num = result.getNumBusList();
console.log('公交线路数量:', num);
// 获取第一条公交线路
if (num > 0) {
const busListItem = result.getBusListItem(0);
busLineSearch.getBusLine(busListItem);
}
},
onGetBusLineComplete: (result: BMapGL.BusLine) => {
console.log('公交线路查询完成');
// 处理公交线路信息
}
});
// 搜索公交线路
busLineSearch.getBusList('1路');