#javascript #bing-maps
#javascript #bing-карты
Вопрос:
Я впервые использую DirectionsManager для создания маршрутов в Bing Maps AJAX версии 7. Маршрут создан правильно, но поставляется с двумя маленькими «информационными ящиками», показывающими «A» в начале маршрута и «B» в конце. Я хочу удалить эти информационные ящики, но, честно говоря, после прочтения всей документации (http://msdn.microsoft.com/en-us/library/hh312832.aspx ) и некоторое время «перебираю / гуглю», я не могу найти ничего полезного. Кроме того, я перепробовал все опции внутри setRenderOptions. Есть идеи?
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
directionsManager.resetDirections();
directionsManager.setRenderOptions({autoDisplayDisambiguation: false,
autoUpdateMapView: true, displayManeuverIcons: false, displayPreItineraryItemHints: false, displayPostItineraryItemHints: false, displayRouteSelector: false, displayStepWarnings: false, drivingPolylineOptions: { strokeColor: new Microsoft.Maps.Color(150, 255, 51, 51), strokeThickness: 8 }
});
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving });
var seattleWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: '000 fake street, Houston TX 77000' });
directionsManager.addWaypoint(seattleWaypoint);
var tacomaWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: '111 fake street, Houston TX 77111' });
directionsManager.addWaypoint(tacomaWaypoint);
directionsManager.calculateDirections();
Ответ №1:
Одним из возможных решений является настройка кнопки для отображения пустой кнопки небольшого размера (я пробовал использовать другую кнопку размером 15×15 пикселей):
// Set the render options
directionsManager.setRenderOptions({
itineraryContainer: document.getElementById('itineraryDiv'),
displayWalkingWarning: false,
walkingPolylineOptions:{strokeColor: new Microsoft.Maps.Color(200, 0, 255, 0)},
waypointPushpinOptions: {icon:'pin_blank.png', height:1, width:1}
});
Другой способ может заключаться в самостоятельном вызове службы и обработке запроса и ответа в вашем коде. Вот пример:http://msdn.microsoft.com/en-us/library/gg427607.aspx
Вот код, который может быть тем, что вам поможет:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function GetMap()
{
// Initialize the map
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Maps Key", mapTypeId: Microsoft.Maps.MapTypeId.road });
}
function ClickRoute(credentials)
{
map.getCredentials(MakeRouteRequest);
}
function MakeRouteRequest(credentials)
{
var routeRequest = "http://dev.virtualearth.net/REST/v1/Routes?wp.0=" document.getElementById('txtStart').value "amp;wp.1=" document.getElementById('txtEnd').value "amp;routePathOutput=Pointsamp;output=jsonamp;jsonp=RouteCallbackamp;key=" credentials;
CallRestService(routeRequest);
}
function RouteCallback(result) {
if (result amp;amp;
result.resourceSets amp;amp;
result.resourceSets.length > 0 amp;amp;
result.resourceSets[0].resources amp;amp;
result.resourceSets[0].resources.length > 0) {
// Set the map view
var bbox = result.resourceSets[0].resources[0].bbox;
var viewBoundaries = Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(bbox[0], bbox[1]), new Microsoft.Maps.Location(bbox[2], bbox[3]));
map.setView({ bounds: viewBoundaries});
// Draw the route
var routeline = result.resourceSets[0].resources[0].routePath.line;
var routepoints = new Array();
for (var i = 0; i < routeline.coordinates.length; i ) {
routepoints[i]=new Microsoft.Maps.Location(routeline.coordinates[i][0], routeline.coordinates[i][1]);
}
// Draw the route on the map
var routeshape = new Microsoft.Maps.Polyline(routepoints, {strokeColor:new Microsoft.Maps.Color(200,0,0,200)});
map.entities.push(routeshape);
}
}
function CallRestService(request)
{
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
document.body.appendChild(script);
}
</script>
</head>
<body onload="GetMap();">
<div id='mapDiv' style="position:relative; width:400px; height:400px;"></div>
<input id="txtStart" type="text" value="Seattle"/>
<input id="txtEnd" type="text" value="Portland"/>
<input type="button" value="Calculate Route" onclick="ClickRoute()"/>
</body>
</html>
Комментарии:
1. Спасибо за ваш ответ, Николас. Я создал пустой файл png и заменил свои параметры setRenderOptions на: directionsManager.setRenderOptions({waypointPushpinOptions: { icon: ‘images / blank.png’, height: 2, width: 2 }, drivingPolylineOptions: { strokeColor: новый Microsoft.Maps. Цвет(150, 255, 51, 51), Толщина строки: 8 } но в начальной точке по-прежнему отображается «A», а в конечной точке отображается «информационный ящик» с «B», но на этот раз B находится за пределами поля. Я попробую использовать второй вариант…