Skip to content

Commit c06daac

Browse files
committed
1 parent 30e3859 commit c06daac

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

js/jquery.mapael.js

+28
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
// Create Raphael paper
154154
self.paper = new Raphael(self.$map[0], self.mapConf.width, self.mapConf.height);
155155

156+
// issue #135: Check if we are drawing on a hidden paper
157+
// This is known to cause problem for Raphael and text element boundaries
158+
if (self.isPaperHidden() === true) {
159+
throw new Error("Drawing on hidden paper is not supported (see src/doc for workaround)");
160+
}
161+
156162
// add plugin class name on element
157163
self.$container.addClass(pluginName);
158164

@@ -1681,6 +1687,28 @@
16811687
}, interval
16821688
);
16831689
},
1690+
1691+
/*
1692+
* Check for Raphael bug regarding drawing while beeing hidden (under display:none)
1693+
* See https://github.com/neveldo/jQuery-Mapael/issues/135
1694+
* @return true/false
1695+
*
1696+
* Wants to override this behavior? Use prototype overriding:
1697+
* $.mapael.prototype.isPaperHidden = function() {return false;};
1698+
*/
1699+
isPaperHidden: function(){
1700+
// Draw text, then get its boundaries
1701+
var text_elem = self.paper.text(-50, -50, "TEST");
1702+
var text_elem_bbox = text_elem.getBBox();
1703+
// remove element
1704+
text_elem.remove();
1705+
// If it has no height and width, then the paper is hidden
1706+
if (text_elem_bbox.width === 0 && text_elem_bbox.height === 0){
1707+
return true;
1708+
} else {
1709+
return false;
1710+
}
1711+
},
16841712

16851713
// Default map options
16861714
defaultOptions: {

0 commit comments

Comments
 (0)