Skip to content

Commit 8ea707e

Browse files
committed
Fixes #238 Pins Positioned Incorrectly
1 parent 09e369f commit 8ea707e

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

dist/jquery.vmap.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @version 1.5.1
55
* @link http://jqvmap.com
66
* @license https://github.com/manifestinteractive/jqvmap/blob/master/LICENSE
7-
* @builddate 2016/05/18
7+
* @builddate 2016/06/02
88
*/
99

1010
var VectorCanvas = function (width, height, params) {
@@ -848,16 +848,23 @@ JQVMap.prototype.positionPins = function(){
848848
pinObj = jQuery(pinObj);
849849
var countryId = map.getCountryId(pinObj.attr('for').toLowerCase());
850850
var countryObj = jQuery('#' + countryId);
851-
852-
var bbox = document.getElementById(countryId).getBBox();
853-
var position = countryObj.position();
851+
var bbox = countryObj[0].getBBox();
854852

855853
var scale = map.scale;
854+
var rootCoords = map.canvas.rootGroup.getBoundingClientRect();
855+
var mapCoords = map.container[0].getBoundingClientRect();
856+
var coords = {
857+
left: rootCoords.left - mapCoords.left,
858+
top: rootCoords.top - mapCoords.top
859+
};
856860

857-
var left = position.left + (bbox.width / 2) * scale - pinObj.width() / 2,
858-
top = position.top + (bbox.height / 2) * scale - pinObj.height() / 2;
861+
var middleX = (bbox.x * scale) + ((bbox.width * scale) / 2);
862+
var middleY = (bbox.y * scale) + ((bbox.height * scale) / 2);
859863

860-
pinObj.css('left', left).css('top', top);
864+
pinObj.css({
865+
left: coords.left + middleX - (pinObj.width() / 2),
866+
top: coords.top + middleY - (pinObj.height() / 2)
867+
});
861868
});
862869
};
863870

0 commit comments

Comments
 (0)