点击bingmap的航点

时间:2016-06-23 13:54:31

标签: javascript routes bing-maps directions

我有一张带有bingmap的地图,我实施了航点。我想点击一个航点时会显示一个信息窗口。

if (!$scope.directionsManager) { _createDirectionsManager(); }
    if($scope.directionsManager.getAllWaypoints().length < 2)
    {
      $scope.directionsManager.resetDirections();
      $scope.waypoints.forEach(function (waypoint) {
        var order_waypoint = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(waypoint.lat, waypoint.lng) });
        console.log("order_waypoint", order_waypoint)
        $scope.directionsManager.addWaypoint(order_waypoint);
      })
    }
    var renderOption = {
        itineraryContainer: document.getElementById('directionsItinerary'),

        waypointPushpinOptions:{
            // icon: "http://vignette3.wikia.nocookie.net/freeciv/images/1/1c/Crystal_128_penguin.png/revision/latest?cb=20071106133132&path-prefix=es",
            // hoverIcon: "http://vignette3.wikia.nocookie.net/freeciv/images/1/1c/Crystal_128_penguin.png/revision/latest?cb=20071106133132&path-prefix=es",
            // height: 10,
            // width: 10,
            draggable: false,
            textOffset: new Microsoft.Maps.Point(-1, 3)
        }
    }
    $scope.directionsManager.setRenderOptions(renderOption);
    $scope.directionsManager.calculateDirections();

谢谢!

1 个答案:

答案 0 :(得分:1)

我还没有使用Bing地图API,但the docs on the Waypoint class看起来可能需要a custom pushpin才能拦截its click event

var location = new Microsoft.Maps.Location(waypoint.lat, waypoint.lng);
var pushpin = new Microsoft.Maps.Pushpin(location);
Microsoft.Maps.Events.addHandler(pushpin, 'click', function() {
    // Implementation can go here
});

var order_waypoint = new Microsoft.Maps.Directions.Waypoint(
    {location: location, pushpin: pushpin});
$scope.directionsManager.addWaypoint(order_waypoint);

您可以在pushpin上获得对order_waypoint的默认addHandler的引用,而无需创建自己的自定义,并使用order_waypoint.getPushpin()将click事件绑定到它。我没有运行代码来测试它,I don't see a way to get a reference to the default pushpin, only the custom one。您无论如何都可以尝试(com.lpa.utils.*)并查看它是否有效。