Jquery 具有Openlayers的Body缺少鼠标向下事件
我使用jQuery的Jquery 具有Openlayers的Body缺少鼠标向下事件,jquery,dom,openlayers,jquery-events,Jquery,Dom,Openlayers,Jquery Events,我使用jQuery的.bind()函数向添加了一个mousedown事件,如下代码所示: $('body').bind('mousedown', function(){alert(1)}); 它在页面上的其他任何位置都能完美工作。但它将被(???)一个“地图”分区阻止。 (我不知道这个词是否精确到可以说“被阻挡”,这个词是不是随我的感觉而来) 函数.mousedown()也不起作用: $('body').mousedown(function(){alert(1)}); 以下是使用OpenLa
.bind()
函数向
添加了一个mousedown
事件,如下代码所示:
$('body').bind('mousedown', function(){alert(1)});
它在页面上的其他任何位置都能完美工作。但它将被(???)一个“地图”分区阻止。
(我不知道这个词是否精确到可以说“被阻挡”,这个词是不是随我的感觉而来)
函数.mousedown()
也不起作用:
$('body').mousedown(function(){alert(1)});
以下是使用OpenLayers的map div:
<script type='text/javascript'>
var map;
function init() {
var controls_array = [
new OpenLayers.Control.Navigation({}),
new OpenLayers.Control.PanZoomBar({}),
new OpenLayers.Control.LayerSwitcher(),
];
var mapOptions = {
controls: controls_array,
projection: new OpenLayers.Projection("EPSG:900913")
};
map = new OpenLayers.Map('map', mapOptions);
var googleLayer = new OpenLayers.Layer.Google(
'Google Map Layer',
{
numZoomLevels: 20,
isBaseLayer: true,
sphericalMercator: true,
projection: "EPSG:900913"
}
);
map.addLayer(googleLayer);
map.zoomToExtent(
new OpenLayers.Bounds(3235795.723665,493480.6015713,
3716431.757455,911132.5240634), true
);
}
</script>
<body onload='init();'>
<div id="map" style='width: 800px; height: 700px;'></div>
</body>
我猜这是因为OpenLayers.Controls.DragPan()
函数对mousedown
事件作出反应
那么我该怎么做来修复它呢?让事件传递到
?OpenLayers有自己的eventListener,因此您需要覆盖它们,例如
map.events.listeners.mousedown.unshift({
func: function(){
alert('hola muheres');
}
});
签入
OpenLayers.Controls.DragPan()
函数,如果其中有.preventdefault
或.stopPropagation
行,将其删除,然后测试感谢您的提醒,我看到了OpenLayers.Event.preventdefault(evt)
在OpenLayers.Handler.Drag
中拖动dragstart
以防止文档拖动,但似乎我不应该删除它。还有别的办法吗?
map.events.listeners.mousedown.unshift({
func: function(){
alert('hola muheres');
}
});