Skip to content

Commit 37e98a7

Browse files
committed
Redraw legends on resize
1 parent 3d5f092 commit 37e98a7

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

Diff for: js/jquery.mapael.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,6 @@
287287

288288
handleMapResizing: function () {
289289
var self = this;
290-
// Create the legends for plots taking into account the scale of the map
291-
var createPlotLegend = function () {
292-
self.createLegends("plot", self.plots, (self.$map.width() / self.mapConf.width));
293-
294-
self.$map.off("resizeEnd." + pluginName, createPlotLegend);
295-
};
296290

297291
// onResizeEvent: call when the window element trigger the resize event
298292
// We create it inside this function (and not in the prototype) in order to have a closure
@@ -309,12 +303,17 @@
309303
// Attach resize handler
310304
$(window).on("resize." + pluginName, self.onResizeEvent);
311305

306+
// Attach resize end handler, and call it once
312307
self.$map.on("resizeEnd." + pluginName, function () {
313308
var containerWidth = self.$map.width();
314309
if (self.paper.width != containerWidth) {
315-
self.paper.setSize(containerWidth, self.mapConf.height * (containerWidth / self.mapConf.width));
310+
var newScale = containerWidth / self.mapConf.width;
311+
// Set new size
312+
self.paper.setSize(containerWidth, self.mapConf.height * newScale);
313+
// Create plots legend again to take into account the new scale
314+
self.createLegends("plot", self.plots, newScale);
316315
}
317-
}).on("resizeEnd." + pluginName, createPlotLegend).trigger("resizeEnd." + pluginName);
316+
}).trigger("resizeEnd." + pluginName);
318317
},
319318

320319
/*
@@ -1365,6 +1364,9 @@
13651364

13661365
$legend = $("." + legendOptions.cssClass, self.$container).empty();
13671366
legendPaper = new Raphael($legend.get(0));
1367+
// Set some data to object
1368+
$(legendPaper.canvas).attr({"data-type": legendType, "data-index": legendIndex});
1369+
13681370
height = width = 0;
13691371

13701372
// Set the title of the legend
@@ -1542,7 +1544,6 @@
15421544
width = legendOptions.VMLWidth;
15431545

15441546
legendPaper.setSize(width, height);
1545-
return legendPaper;
15461547
},
15471548

15481549
/*
@@ -1642,7 +1643,6 @@
16421643
createLegends: function (legendType, elems, scale) {
16431644
var self = this;
16441645
var legendsOptions = self.options.legend[legendType];
1645-
var legends = [];
16461646

16471647
if (!$.isArray(self.options.legend[legendType])) {
16481648
legendsOptions = [self.options.legend[legendType]];
@@ -1654,10 +1654,9 @@
16541654
throw new Error("The legend class `" + legendsOptions[j].cssClass + "` doesn't exists.");
16551655
}
16561656
if (legendsOptions[j].display === true && $.isArray(legendsOptions[j].slices) && legendsOptions[j].slices.length > 0) {
1657-
legends.push(self.drawLegend(legendsOptions[j], legendType, elems, scale, j));
1657+
self.drawLegend(legendsOptions[j], legendType, elems, scale, j);
16581658
}
16591659
}
1660-
return legends;
16611660
},
16621661

16631662
/*

0 commit comments

Comments
 (0)