Firefox 中未触发点击事件(Google 地图)
Click events not triggered in firefox (Google Maps)
此代码在除 firefox 浏览器之外的所有浏览器中都可以正常工作。
事件点击不起作用。
var marker = new RichMarker({
position: new google.maps.LatLng( _latitude, _longitude ),
map: map,
draggable: draggableMarker,
content: markerContent,
flat: true
});
google.maps.event.addListener(marker, "click", function(event) {
alert(this.position);
});
我该如何解决?谢谢
问题似乎是 http://googlemaps.github.io/js-rich-marker/src/richmarker.js
的第 615 行
this.markerWrapper_.setCapture(true);
如果您在内部向标记添加点击侦听器,则当您点击标记的内容时将触发点击事件。使用上面的行,单击事件将仅针对内容的包装器触发(当标记可拖动时发生)。
您需要修改函数 addDraggingListeners_
,将其设置为:
RichMarker.prototype.addDraggingListeners_ = function() {
var that = this;
this.draggingListeners_ = [
google.maps.event.addDomListener(window, 'mousemove', function(e) {
that.drag(e);
}, true),
google.maps.event.addDomListener(window, 'mouseup', function() {
that.stopDrag();
}, true)
];
};
此代码在除 firefox 浏览器之外的所有浏览器中都可以正常工作。 事件点击不起作用。
var marker = new RichMarker({
position: new google.maps.LatLng( _latitude, _longitude ),
map: map,
draggable: draggableMarker,
content: markerContent,
flat: true
});
google.maps.event.addListener(marker, "click", function(event) {
alert(this.position);
});
我该如何解决?谢谢
问题似乎是 http://googlemaps.github.io/js-rich-marker/src/richmarker.js
的第 615 行 this.markerWrapper_.setCapture(true);
如果您在内部向标记添加点击侦听器,则当您点击标记的内容时将触发点击事件。使用上面的行,单击事件将仅针对内容的包装器触发(当标记可拖动时发生)。
您需要修改函数 addDraggingListeners_
,将其设置为:
RichMarker.prototype.addDraggingListeners_ = function() {
var that = this;
this.draggingListeners_ = [
google.maps.event.addDomListener(window, 'mousemove', function(e) {
that.drag(e);
}, true),
google.maps.event.addDomListener(window, 'mouseup', function() {
that.stopDrag();
}, true)
];
};