gpt4 book ai didi

google-maps-api-3 - Google Maps API v3 - Mousemove 和 Click 事件组合

转载 作者:行者123 更新时间:2023-12-04 20:55:40 25 4
gpt4 key购买 nike

如果我有一个点击事件连接到我的 map ,然后我连接了一个 mousemove 事件,点击事件将不再起作用。我想没有人知道这件事吗?顺便说一下,这是在 3.4 版中。

作为一个简单的例子:

var map;
function initialize() {

var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

var secondClick = false;
var firstClick = false;
var firstClickLatLng;
var secondClickLatLng;
var lines = [];

google.maps.event.addListener(map, 'mousemove', function (event) {
redrawLine(event);
});

google.maps.event.addListener(map, 'click', function (event) {
if (!firstClick && !secondClick) {
firstClick = true;
firstClickLatLng = event.latLng;
}
else if (firstClick && !secondClick) {
secondClick = true;
firstClick = false;
// draw the polyline here
secondClickLatLng = event.latLng;

//google.maps.event.removeListener(listener);
}
else if (!firstClick && secondClick) {
secondClick = false;
// clear the polyline here
alert("what");
//google.maps.event.removeListener(listener);
}
});

function redrawLine(event) {
if (firstClickLatLng != null) {
var lineCoords = [
firstClickLatLng,
event.latLng
];

var line = new google.maps.Polyline({
path: lineCoords,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});

// You need to clear the previous line, otherwise
// it draws loads and loads of lines. I did this
// in case it doesn't manage to clear the previous
// one for some reason.
for (var i = 0; i < lines.length; i++) {
lines[i].setMap(null);
}

line.setMap(map);
lines.push(line);
}
}
}

因此,每当您移动鼠标时,都会绘制一条线。问题是如果我第二次点击,点击事件不会触发。

想法?

编辑

此问题相关: http://www.mail-archive.com/google-maps-js-api-v3@googlegroups.com/msg15878.html

虽然它并没有明确解决我的问题,但其他人已经测试并经历了这一点。

最佳答案

已排序,如该链接所示,您需要说明 clickable: false

http://code.google.com/apis/maps/documentation/javascript/reference.html#PolylineOptions

关于google-maps-api-3 - Google Maps API v3 - Mousemove 和 Click 事件组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5090174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com