一张 Ovi 地图上有 2 条或更多路线
2 or more routes on one Ovi map
我需要使用 Ovi 映射显示 2 条不同的、未连接的路由。但我无法让它工作。在谷歌地图中,我只需要为每条路线定义一个路由对象,但这在 Ovi 中似乎不起作用。有人知道如何吗?
作为参考,下面是一个路由的代码:
router = new ovi.mapsapi.routing.Manager();
var onRouteCalculated = function(observedRouter, key, value)
{
if (value == "finished")
{
var routes = observedRouter.getRoutes();
var mapRoute = new ovi.mapsapi.routing.component.RouteResultSet(routes[0]).container;
map.objects.add(mapRoute);
map.zoomTo(mapRoute.getBoundingBox(), false, "default");
}
else if(value == "failed")
{
alert("The routing request failed.");
}
};
router.addObserver("state", onRouteCalculated);
var waypoints = new ovi.mapsapi.routing.WaypointParameterList();
waypoints.addCoordinate(new ovi.mapsapi.geo.Coordinate(x, y))
// coords are ommited, but just a line for every stop point in Lat/Lng format
var modes =
[{
type: "shortest",
transportModes: ["car"],
options: "avoidTollroad",
trafficMode: "default"
}];
router.calculateRoute(waypoints, modes);
创建另一个 ovi.mapsapi.routing.Manager() 对象并将其用于另一个路由是行不通的。让现有的处理第二条路线也不起作用
此外,我需要在每个标记上显示一个信息气泡,但我无法找到它们所在的容器中
使用诺基亚地图比使用Ovi地图更好,因为诺基亚地图是Ovi Map API的2.0版本。可以通过创建多个管理器来检索多个路由,然后使用相同的回调 - 下面的示例就是这样做的:
在示例中,A 和 B 标记保存在名为 "mapRoute" 的容器中,单独的路由保存在名为 routesArr[] 的数组中。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.0/jsl.js?routing=auto"></script>
<title>Concurrent Routing example</title>
</head>
<body>
<div id="mapContainer" style="top:30%; width:100%; height:70%; position: absolute;"></div>
<script type="text/javascript">
/////////////////////////////////////////////////////////////////////////////////////
// Don't forget to set your API credentials
//
// Replace with your appId and token which you can obtain when you
// register on http://api.developer.nokia.com/
//
nokia.Settings.set( "appId", "YOUR APP ID GOES HERE");
nokia.Settings.set( "authenticationToken", "YOUR AUTHENTICATION TOKEN GOES HERE");
//
/////////////////////////////////////////////////////////////////////////////////////
//initialize a new map
var display = new nokia.maps.map.Display(document.getElementById("mapContainer"),
{ "components": [
new nokia.maps.map.component.ZoomBar(),
new nokia.maps.map.component.Behavior(),
new nokia.maps.map.component.TypeSelector()],
"zoomLevel": 13,
"center" : [52.500556, 13.398889] });
var onAllManagersFinished = function() {
for (i = 0; i <routesArr.length; i++){
console.log(routesArr[i]);
var mapRoute = new nokia.maps.routing.component.RouteResultSet(routesArr[i]).container;
display.objects.add(mapRoute);
display.zoomTo(mapRoute.getBoundingBox(), true);
}
};
// we will use the same state observer function for all managers
var onRouteCalculated = function (observedRouter, key, value) {
if (value == "finished") {
routesArr[observedRouter.$index] = observedRouter.getRoutes()[0];
managersFinished++;
} else if (value == "failed") {
// Something has gone horribly wrong e.g. route too long.
alert("The routing request failed.");
managersFinished++;
}
if(managersFinished === waypointsArr.length) {
onAllManagersFinished();
}
};
var routesArr = new Array();
var waypointsArr = new Array();
var MunichBerlin = new nokia.maps.routing.WaypointParameterList();
MunichBerlin.addCoordinate (new nokia.maps.geo.Coordinate(48.133333, 11.566667));
MunichBerlin.addCoordinate (new nokia.maps.geo.Coordinate(52.500556, 13.398889));
var BerlinHamburg = new nokia.maps.routing.WaypointParameterList();
BerlinHamburg.addCoordinate(new nokia.maps.geo.Coordinate(52.500556, 13.398889));
BerlinHamburg.addCoordinate(new nokia.maps.geo.Coordinate(53.565278, 10.001389));
waypointsArr.push(MunichBerlin);
waypointsArr.push(BerlinHamburg);
var i = waypointsArr.length;
var managersFinished = 0;
// iterate over all route requests, create a manager for each of them,
// add the observer and call the claculateRoute method
while(i--) {
var router = new nokia.maps.routing.Manager();
router.$index = i;
router.calculateRoute(waypointsArr[i], [{
type: "shortest",
transportModes: ["car"],
options: "",
trafficMode: "default"
}]);
router.addObserver("state", onRouteCalculated);
}
</script>
</body>
</html>
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 多个单选按钮组相互干扰
- onkeyup无法动态创建多个文本区域
- 借助asp.net验证或java脚本对多个文本进行验证
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- 如何删除多行HTML排列中的空白
- jQuery自定义验证比较多个输入的序列
- Html页面上的多个Base64图像和平滑加载
- 使用javascript检查多个输入值,并在1次检查中标记多个输入框
- KnockoutJS-组件-多个实例
- 用与线条相同的颜色填充多折线图上的点
- 主体上的addEventListener('mousemove',..)-有多糟糕
- 如何从科尔多瓦发出多路请求
- 如何存储多个连接的路点
- 一张 Ovi 地图上有 2 条或更多路线
- 带承诺的多路流的正确模式
- 替换多个链路
- 为多层树实现d3-2路树
- 使用javascript/jQuery实现多路切换的最佳方式是什么?
- 如何为多个 url 状态设置仅使用反应路由器激活一个链路