必应地图pin's拖拽成功,但必应地图移动事件继续

Bing Map pin's dragend called successfully, but Bing Map move event continues

本文关键字:地图 事件 继续 成功 移动 pin      更新时间:2023-09-26

我使用了Bing Maps AJAX Control, Version 7.0。并在地图上显示大头针。要求是,用户可以拖放引脚,当引脚被拖放时,它应该移动到它的实际位置。

现在的问题是,当引脚的拖尾事件调用时,引脚成功地设置到其原始位置,但鼠标没有被释放,当鼠标移动时,地图也被移动。

代码如下:

var isPinDragged = false;
Microsoft.Maps.Events.addHandler(pin, 'dragstart', startDragDetails);
Microsoft.Maps.Events.addHandler(pin, 'drag', dragDetails);
Microsoft.Maps.Events.addHandler(pin, 'dragend', endDragDetails);
function startDragDetails(e) {
    lastLocation = e.entity.getLocation();
    currentLatitude = e.entity._location.latitude;
    currentLongitude = e.entity._location.longitude;
    isPinDragged = false;
    $(e.entity.cm1002_er_etr.dom).find("img").removeClass("droppable");
}
dragDetails = function (e) {
   isPinDragged = true;
};
endDragDetails = function (e) {
    if (isPinDragged) {
        isPinDragged = false;
        $(e.entity.cm1002_er_etr.dom).find("img").addClass("droppable");
        e.entity.setLocation(new Microsoft.Maps.Location(currentLatitude, currentLongitude)); //update pin: move back to old position
    }
};

更新:我不知道,这个信息。多少帮助解决。我的引脚创建是动态的,会有N个no。每个用户登录的pin。

Microsoft.Maps.loadModule('Microsoft.Maps.Overlays.Style',
{
    callback: function () {
        map = new Microsoft.Maps.Map(document.getElementById("divDailyCashMap"), mapOptions);
        var center = map.getCenter();
        var loc = null;
        var pin = null;
        var pinLayers = new Microsoft.Maps.EntityCollection();
        map.entities.push(pinLayers);
        var infoboxLayers = new Microsoft.Maps.EntityCollection();
        map.entities.push(infoboxLayers);
        pinInfobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0, 0), { visible: false });
        infoboxLayers.push(pinInfobox);
        $.each(codes, function (index, item) {
            loc = new Microsoft.Maps.Location(item.Latitude, item.Longitude);
            pin = new Microsoft.Maps.Pushpin(loc, { text: '', draggable: true });
            pin.Title = item.Title;
            pin.Description = item.CodeDescription;
            Microsoft.Maps.Events.addHandler(pin, 'click', displayInfobox);
            Microsoft.Maps.Events.addHandler(pin, 'dragstart', startDragDetails);
            Microsoft.Maps.Events.addHandler(pin, 'drag', dragDetails);
            Microsoft.Maps.Events.addHandler(pin, 'dragend', endDragDetails);
            Microsoft.Maps.Events.addHandler(map, 'viewchange', hideInfobox);
            Microsoft.Maps.Events.addHandler(map, 'mousemove', mousemoveDetails);
            pinLayers.push(pin);
                 $(pin.cm1002_er_etr.dom).find('img').addClass("droppable").attr({ "data-pinid": item.Code, "data-lat": item.Latitude, "data-long": item.Longitude });
        });
    }
}

在您的dragDetail()函数中,尝试:

e.handled = true;

它将告诉事件引擎不应该触发其他底层事件。如果它不起作用,你也可以尝试添加这个:

return false;