1

BING Maps API を使用して、地図上に棒グラフを作成します。文字にはいくつかのポリゴンが含まれていますが、コレクションにイベント ハンドラーを追加できず、ポリゴンに追加したすべてのイベントがすぐに発生します。

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