admin管理员组文章数量:1425734
I want to draw a circle by clickin on the google maps (to set the center) and moving over the map (to set the radius).
It works when I make the circle bigger but not when I make the circle smaller.
The problem is that mousemove event don't pass through the circle so the map don't fire any mousemouse when the mouse is over the circle...
Here is the fiddle: /
I also try to used mousemove on the circle without any success.
Here is the code:
var map = new GMaps({
div: '#map',
lat: 52.521832,
lng: 13.413168,
click: function(e) {
var lat = e.latLng.lat();
var lng = e.latLng.lng();
if (circle) {
// TODO how to really remove the circle?
circle.setVisible(false);
}
circle = map.drawCircle({
lat: lat,
lng: lng,
radius: 100,
strokeColor: '#BBD8E9',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: 'transparent'
});
},
mousemove: function(e) {
if (!circle) {
return ;
}
var distance = calculateDistance(circle.getCenter().lat(), circle.getCenter().lng(), e.latLng.lat(), e.latLng.lng());
circle.setRadius(distance);
}
});
I want to draw a circle by clickin on the google maps (to set the center) and moving over the map (to set the radius).
It works when I make the circle bigger but not when I make the circle smaller.
The problem is that mousemove event don't pass through the circle so the map don't fire any mousemouse when the mouse is over the circle...
Here is the fiddle: http://jsfiddle/charlesbourasseau/m2Cjc/4/
I also try to used mousemove on the circle without any success.
Here is the code:
var map = new GMaps({
div: '#map',
lat: 52.521832,
lng: 13.413168,
click: function(e) {
var lat = e.latLng.lat();
var lng = e.latLng.lng();
if (circle) {
// TODO how to really remove the circle?
circle.setVisible(false);
}
circle = map.drawCircle({
lat: lat,
lng: lng,
radius: 100,
strokeColor: '#BBD8E9',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: 'transparent'
});
},
mousemove: function(e) {
if (!circle) {
return ;
}
var distance = calculateDistance(circle.getCenter().lat(), circle.getCenter().lng(), e.latLng.lat(), e.latLng.lng());
circle.setRadius(distance);
}
});
Share
Improve this question
asked Jun 12, 2013 at 16:00
CharlesCharles
11.8k10 gold badges81 silver badges122 bronze badges
2 Answers
Reset to default 4Your problem is that your circle has a transparent fill but the mousemove event is still being captured by the circle fill and doesn't get propagated to the map. That's why the mousemove event on the map doesn't get triggered.
The simple solution is just to make the circle unclickable so that it doesn't capture mouse events:
var map = new GMaps({
div: '#map',
lat: 52.521832,
lng: 13.413168,
click: function(e) {
var lat = e.latLng.lat();
var lng = e.latLng.lng();
if (circle) {
// TODO how to really remove the circle?
circle.setVisible(false);
}
circle = map.drawCircle({
lat: lat,
lng: lng,
radius: 100,
strokeColor: '#BBD8E9',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: 'transparent',
clickable: false
});
},
mousemove: function(e) {
if (!circle) {
return ;
}
var distance = calculateDistance(circle.getCenter().lat(), circle.getCenter().lng(), e.latLng.lat(), e.latLng.lng());
circle.setRadius(distance);
}
});
Example: http://jsfiddle/pjfs/PRX7y/
I also tried adding a mousemove event to the circle and then triggering the mousemove map event manually with no luck.
Seems to work if you just add the same mouse move handler to the circle as well. Check out this updated fiddle: http://jsfiddle/m2Cjc/7/
circle = map.drawCircle({
lat: lat,
lng: lng,
radius: 100,
strokeColor: '#BBD8E9',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: 'transparent',
mousemove: function(e) {
var distance = calculateDistance(circle.getCenter().lat(), circle.getCenter().lng(), e.latLng.lat(), e.latLng.lng());
circle.setRadius(distance);
}
}
本文标签: javascriptGmaps mousemove over CirclePolygon or RectangleStack Overflow
版权声明:本文标题:javascript - Gmaps mousemove over Circle, Polygon or Rectangle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745420500a2657878.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论