Jquery 地图覆盖圈,谷歌文档中缺少拖动事件
我有一张上面有一个圆圈的谷歌地图,只要我改变半径,我就会提交一张带有新参数的表格 这在Jquery 地图覆盖圈,谷歌文档中缺少拖动事件,jquery,google-maps,google-maps-api-3,jquery-gmap3,Jquery,Google Maps,Google Maps Api 3,Jquery Gmap3,我有一张上面有一个圆圈的谷歌地图,只要我改变半径,我就会提交一张带有新参数的表格 这在editable:true和radius\u changed-事件中非常有效 因为当您完成调整大小移动时,radius_changed事件将触发 我想对中心事件做同样的事情 但这一个不会在我“放下”圆圈时触发,它会在圆心改变时一直触发 我在文档中找不到任何圆的拖动事件 问题是,我的表单会在我将圆圈移动到px后立即提交 这是我的gmap3代码片段 circle:{ options:{ center:
editable:true
和radius\u changed
-事件中非常有效
因为当您完成调整大小移动时,radius_changed事件将触发
我想对中心事件做同样的事情
但这一个不会在我“放下”圆圈时触发,它会在圆心改变时一直触发
我在文档中找不到任何圆的拖动事件
问题是,我的表单会在我将圆圈移动到px后立即提交
这是我的gmap3代码片段
circle:{
options:{
center: destination,
radius : distance,
fillColor : "white",
fillOpacity:0.3,
strokeColor : "#c9311b",
editable:true,
draggable:true
},
events:{
click: function(circle){
circle.setOptions({
fillColor : "white",
fillOpacity:0.1,
strokeColor : "#FF512F"
});
},
radius_changed: function(circle){
var radius =circle.getRadius() ;
var newradius = parseInt(radius) / 1000;
alert(parseInt(newradius,10));
$('#seldistance').val(parseInt(newradius,10));
$('.sucheen').submit();
},
center_changed: function(circle){ //
var center = circle.getCenter(); // Here´s the center change event,
console.log(center); //it really spams the console when you drag
} //
},
callback: function(circle){
if(distance != '0'){
if ( distance < '1000'){
$(this).gmap3('get').setZoom(15);
console.log('radius ='+distance);
}
else if ( distance < '5000'){
$(this).gmap3('get').setZoom(13);
console.log('radius ='+distance);
}
else if ( distance < '10000'){
$(this).gmap3('get').setZoom(12);
console.log('radius ='+distance);
}
else if ( distance < '20000'){
$(this).gmap3('get').setZoom(11);
console.log('radius ='+distance);
}
else if ( distance < '35000'){
$(this).gmap3('get').setZoom(10);
console.log('radius ='+distance);
}
else{
$(this).gmap3('get').setZoom(10);
}
}
else {
//Clear circle if no radius is set
$(this).gmap3({
clear: {
name:["circle"],
last: true
}
});
$(this).gmap3('get').setZoom(12);
}
}
},//close circle
圆圈:{
选项:{
中心:目的地,
半径:距离,
填充颜色:“白色”,
填充不透明度:0.3,
strokeColor:#c9311b“,
是的,
德拉格布尔:是的
},
活动:{
单击:函数(圆){
circle.setOptions({
填充颜色:“白色”,
填充不透明度:0.1,
strokeColor:#FF512F
});
},
半径_已更改:功能(圆){
var radius=circle.getRadius();
var newradius=parseInt(半径)/1000;
警报(parseInt(newradius,10));
$('seldestance').val(parseInt(newradius,10));
$('.sucheen').submit();
},
更改中心:函数(圆){//
var center=circle.getCenter();//这里是中心更改事件,
console.log(中间);//当你拖动时,它确实会对控制台进行垃圾处理
} //
},
回调:函数(圆){
如果(距离!=“0”){
如果(距离<'1000'){
$(this.gmap3('get').setZoom(15);
console.log('半径='+距离);
}
否则,如果(距离<'5000'){
$(this).gmap3('get').setZoom(13);
console.log('半径='+距离);
}
否则如果(距离<'10000'){
$(this.gmap3('get').setZoom(12);
console.log('半径='+距离);
}
否则如果(距离<'20000'){
$(this).gmap3('get').setZoom(11);
console.log('半径='+距离);
}
否则,如果(距离<'35000'){
$(this).gmap3('get').setZoom(10);
console.log('半径='+距离);
}
否则{
$(this).gmap3('get').setZoom(10);
}
}
否则{
//如果未设置半径,则清除圆
$(本文件)。gmap3({
清楚:{
名称:[“圆圈”],
最后:是的
}
});
$(this.gmap3('get').setZoom(12);
}
}
},//闭合圆
有人知道如何触发dragend事件吗?=
好的,我意识到我想要的函数带有editable:true
但只有当我使用小圆心拖动时,我才会喜欢将整个圆拖动到任何地方
提前感谢任何提示我也遇到了同样的问题,我的解决办法就是这样。我知道鼠标是否向下-在这种情况下,圆中心还没有设置。当鼠标向上时,设置中心。我需要使用timeout,因为中心更改事件比mouseup事件快 由于某些原因,在结束时会触发两次center_changed事件。如果这让你不安,可以用本·阿尔曼的
var mousedown;
$(document).mousedown(function() {
mousedown = true;
});
$(document).mouseup(function() {
mousedown = false;
});
gmaps.event.addListener(this.circle, 'center_changed', function() {
setTimeout(function(){
if (!mousedown) {
console.log('center changed');
}
}, 10);
}