Bing上的Bing Maps tryPixelToLocation

时间:2015-10-06 19:43:51

标签: javascript bing-maps

我正在尝试通过在地图上获得用户点击来创建凹面多边形。我可以创建凸多边形。但是当我尝试创建凹面多边形时,我必须单击多边形本身,这给出了以下错误:

  

e.target.tryPixelToLocation不是函数

请允许我进一步阐述。用户点击地图并在地图上放置一个图钉以显示他们刚刚点击的位置。他们再点击两次,他们现在在地图上绘制了一个三角形。当他们试图在该三角形内部点击以绘制第四个点时,创建一个凹多边形,他们会得到上述错误。

我正在使用的代码在

之下
function GetMap(sender, args) {
    map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), {
        credentials: "XXXXX",
        enableSearchLogo: false,
        enableClickableLogo: false,
        disableBirdseye: true
    });
    map.setView({
        zoom: 17,
        center: new Microsoft.Maps.Location($('#startLatitude').val(), $('#startLongitude').val()),
        mapTypeId: Microsoft.Maps.MapTypeId.aerial,
        labelOverlay: Microsoft.Maps.LabelOverlay.visible
    });
    Microsoft.Maps.Events.addHandler(map, 'click', getUserClick);
}

function getUserClick(e) {
    alert(e.targetType); // <--- When this is 'Polygon' we get the error 
    if (e.mouseMoved === false && e.isPrimary === true) {
        var p = new Microsoft.Maps.Point(e.getX(), e.getY());
        var t = e.target.tryPixelToLocation(p);
        var l = new Microsoft.Maps.Location(t.latitude, t.longitude);

        // Clear and draw polygon with new point //                  
    }
}

targetType是多边形时如何获得点击的纬度/经度?

1 个答案:

答案 0 :(得分:1)

当click事件在Polygon类上时,使用map.tryPixelToLocation作为多边形类没有该功能。