1

我使用 BING Maps API 在地图上创建条形图。char 包含一些多边形,但我无法将事件处理程序添加到集合中,并且我添加到多边形的所有事件都会立即触发。

var map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {credentials:"CREDENTIALS",
                            mapTypeId: Microsoft.Maps.MapTypeId.road,
                            zoom: 13,
                            center: new Microsoft.Maps.Location(51.363247,12.467959)});

var center = map.getCenter();
var chart = drawBarChart(map.getCenter(),10,20,30, 0.005);               
map.entities.push(chart);

...

function drawBarChart(location, value1, value2, value3, zoom) {

    var chart = new Microsoft.Maps.EntityCollection();

    var sum = value1 + value2 + value3;
    var height1 = value1 / sum * zoom;

    var maxHeight = Math.max(height1, height2, height3) + 0.1 * zoom;

    var rectPoints = new Array(5)
    rectPoints[0] = new Microsoft.Maps.Location(location.latitude - 0.1 * zoom, location.longitude - 0.1 * zoom);
    rectPoints[1] = new Microsoft.Maps.Location(location.latitude - 0.1 * zoom, location.longitude + 0.7 * zoom);
    rectPoints[2] = new Microsoft.Maps.Location(location.latitude + maxHeight, location.longitude + 0.7 * zoom);
    rectPoints[3] = new Microsoft.Maps.Location(location.latitude + maxHeight, location.longitude - 0.1 * zoom);
    rectPoints[4] = new Microsoft.Maps.Location(location.latitude - 0.1 * zoom, location.longitude - 0.1 * zoom);
            var black = new Microsoft.Maps.Color(200, 50, 50, 50);
    var white = new Microsoft.Maps.Color(200, 255, 255, 255);
    var transparent = new Microsoft.Maps.Color(0, 255, 255, 255);

    var border = new Microsoft.Maps.Polygon(rectPoints, {
        strokeColor: transparent,
        fillColor: white
    });
     chart.push(border);
     Microsoft.Maps.Events.addHandler(chart , 'mouseover', displayEventInfo);   
     return chart;

怎么了?

4

1 回答 1

1

您的问题是您尝试在 EntityCollection 上添加“鼠标悬停”事件,但参考msdn EntityCollection 类不支持此类事件。

我想你可能想为每个多边形添加事件,所以编辑你的代码是这样的:

Microsoft.Maps.Events.addHandler(border, 'mouseover', displayEventInfo); 

一切都会如你所愿。

希望它有所帮助。

于 2013-04-02T13:55:35.873 回答