Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add isMoving flag to the map (resolve issue #19)

  • Loading branch information...
commit 64dbac7494b519ab2b4f2943983c3b21da557c0d 1 parent cefdb1b
@jbafford jbafford authored
Showing with 18 additions and 5 deletions.
  1. +5 −5 README.md
  2. +13 −0 jqvmap/jquery.vmap.js
View
10 README.md
@@ -443,21 +443,21 @@ This is the Region that you are looking to have preselected (two letter ISO code
Whether to show Tooltips on Mouseover ( true or false, defaults to true)
-**onLabelShow** *function(element, label, code)*
+**onLabelShow** *function(event, label, code)*
Callback function which will be called before label is shown. Label DOM object and country code will be passed to the callback as arguments.
-**onRegionOver** *function(element, code, region)*
+**onRegionOver** *function(event, code, region)*
Callback function which will be called when the mouse cursor enters the region path. Country code will be passed to the callback as argument.
-**onRegionOut** *function(element, code, region)*
+**onRegionOut** *function(event, code, region)*
Callback function which will be called when the mouse cursor leaves the region path. Country code will be passed to the callback as argument.
-**onRegionClick** *function(element, code, region)*
+**onRegionClick** *function(event, code, region)*
-Callback function which will be called when the user clicks the region path. Country code will be passed to the callback as argument.
+Callback function which will be called when the user clicks the region path. Country code will be passed to the callback as argument. This callback may be called while the user is moving the map. If you need to distinguish between a "real" click and a click resulting from moving the map, you can inspect **$(event.currentTarget).data('mapObject').isMoving**.
Dynamic Updating
======
View
13 jqvmap/jquery.vmap.js
@@ -793,6 +793,9 @@
var mouseDown = false;
var oldPageX, oldPageY;
var self = this;
+
+ self.isMoving = false;
+ self.isMovingTimeout = false;
this.container.mousemove(function (e){
@@ -808,6 +811,11 @@
oldPageX = e.pageX;
oldPageY = e.pageY;
+
+ self.isMoving = true;
+ if (self.isMovingTimeout) {
+ clearTimeout(self.isMovingTimeout);
+ }
}
return false;
@@ -823,6 +831,11 @@
}).mouseup(function (){
mouseDown = false;
+
+ self.isMovingTimeout = setTimeout(function() {
+ self.isMoving = false;
+ }, 100);
+
return false;
});

1 comment on commit 64dbac7

@RickOnline

To fix this issue you need to add:

if (map.isMoving){
return false;
}

to the function where the click is handled:

jQuery(params.container).delegate(this.canvas.mode == 'svg' ? 'path' : 'shape', 'click', function (e){

if (map.isMoving){
return false;
}

Now if you zoom in and drag you will not selected any regions, unless you click while not moving the map.

Please sign in to comment.
Something went wrong with that request. Please try again.