flutter - 如何创建混合路线,如(行人和汽车)?
问题描述
我有一条包含车辆和行人模式的路线。当 HERE 创建这个时,我想用虚线或不同颜色显示行人部分,以便用户理解。
我像这样解析了 sectionTransportMode 的路线部分
_routeCalculator.calculatePedestrianRoute(waypoints, (HERE.RoutingError? routingError, List<HERE.Route>? routeList) async {
if (routingError == null) {
HERE.Route _calculatedRoute = routeList!.first;
_calculatedRoute.sections.forEach((element) {
print('TransportMode: ' + element.sectionTransportMode.toString());
});
_showRouteOnMap(_calculatedRoute);
_startNavigationOnRoute(isSimulated, _calculatedRoute);
} else {
final error = routingError.toString();
_showDialog('Error', 'Error while calculating a pedestrian route: $error');
}
});
但是在这个代码片段之后我怎么能做到这一点。
解决方案
MapPolyline 由三个元素组成:
- 定义在地图上放置折线的位置的两个或多个地理坐标的列表。
- 包含此坐标列表的 GeoPolyline。
- 样式参数,例如DashPattern或LineCap,用于定义如何可视化折线。
调用 showRouteOnMap 时,您可以创建带有虚线的 MapPolyline,如下面的示例所示。
这是一个例子:
private void showRouteOnMap(Route route) {
// Show route as polyline.
GeoPolyline routeGeoPolyline;
try {
routeGeoPolyline = new GeoPolyline(route.getPolyline());
} catch (InstantiationErrorException e) {
// It should never happen that a route polyline contains less than two vertices.
return;
}
float widthInPixels = 20;
//Blue Color
//Color lineColor = Color.valueOf(0, 0f, 0f, 139f);
MapPolyline routeMapPolyline = new MapPolyline(routeGeoPolyline,
widthInPixels,
Color.valueOf(0, 0.56f, 0.54f, 0.63f)); // RGBA
//Setting polyline to DashPattern
routeMapPolyline.setDashPattern(new DashPattern(10));
// routeMapPolyline.setDashFillColor(lineColor);
mapView.getMapScene().addMapPolyline(routeMapPolyline);
mapPolylines.add(routeMapPolyline);
// Draw a circle to indicate starting point and destination.
addCircleMapMarker(startGeoCoordinates, R.drawable.green_dot);
addCircleMapMarker(destinationGeoCoordinates, R.drawable.green_dot);
// Log maneuver instructions per route section.
List<Section> sections = route.getSections();
for (Section section : sections) {
logManeuverInstructions(section);
}
}
请参考 git 中的这个示例: https ://github.com/hermaps/here-sdk-examples/tree/master/examples/latest/navigate/flutter/routing_hybrid_app
推荐阅读
- qt - QT 覆盖 .txt 文件
- docker - 基于参数运行 docker build
- r - 计算区域中的对象数
- javascript - 我有一个包含所有项目的 JSON,我想要一种将项目自动添加到嵌入页面的方法,但它会为每个项目发送新的嵌入
- reactjs - 错误:尝试预期。ts(1005)。在反应中使用firebase实现登录/注册时
- python - NUMPY (python) 和 ARMADILLO (c++) 给出不同的结果
- java - 使用 javax.persistence.EntityManager 将实体添加到我的 SQL 数据库时出错
- php - POST 类型的路由在 Laravel 的服务器上不起作用
- pandas - Pandas:如何获取非唯一索引的索引值
- aws-api-gateway - AWS API网关,同名不同参数的get和post