Internet Explorer + Windows8触摸屏问题

7
我们遇到了与Google Maps API V3相关的问题。问题是,当我们拖动标记时,地图也开始拖动。
我们仅在Windows 8环境和Internet Explorer的触摸屏上出现了这个问题,正常屏幕/移动屏幕 - iPadi /其他浏览器(Safari和FireFox)上运行良好。
我们尝试过以下解决方案,但在Internet Explorer9和10中会抛出错误(eval javascript error):
google.maps.event.addListener(marker, 'dragstart', function(){
    mapObject.setOptions({ draggable: false });
});
google.maps.event.addListener(marker, 'dragend', function(){
    mapObject.setOptions({ draggable: true });
}); 

这里是样例代码。

我们在此处也报告了这个问题:gmaps-api-issues

编辑:

我们还在这里发布了相关问题

1个回答

4

终于有些成功了(地图仍然会稍微移动,但目前可以忽略)!

声明了两个变量:

var isAnyMarkerIsInDraggingState = false;// if a marker is in drag state this value will be TRUE otherwise FALSE
var mapCenterPositionAtTheTimeWhenMarkerWasDragged;// Map Center Position

拖动标记时:


   google.maps.event.addListener(objMarker, 'dragstart', function () {
        // Store map center position when a marker is dragged
        mapCenterPositionAtTheTimeWhenMarkerWasDragged = mapObject.getCenter();
        isAnyMarkerIsInDraggingState = true;
    });

当拖动结束时放置标记(Marker):
google.maps.event.addListener(objMarker, 'dragend', function () {
    // Make Map draggable
    // Set isAnyMarkerIsInDraggingState = false. Because no marker is in drag state
    mapObject.setOptions({ draggable: true });
    isAnyMarkerIsInDraggingState = false;
});

当地图开始拖动时:

google.maps.event.addListener(mapObject, 'dragstart', function () {
    // isAnyMarkerIsInDraggingState = true: means the user is dragging a marker.
    // If the user is dragging the Marker then don't allow the Map to be Dragged
    if (isAnyMarkerIsInDraggingState) {
        mapObject.setOptions({ draggable: false });
    }
});

当地图处于拖动状态时:

google.maps.event.addListener(mapObject, 'drag', function () {
    // isAnyMarkerIsInDraggingState = true: means the user is dragging a marker.
    // If the user is dragging the Marker then don't allow the Map to be Dragged and set its CenterPosition
    // to mapCenterPositionAtTheTimeWhenMarkerWasDragged

    if (isAnyMarkerIsInDraggingState) {
        mapObject.setCenter(mapCenterPositionAtTheTimeWhenMarkerWasDragged);
    }
});

这里是完整的示例代码


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接