|
18 | 18 |
|
19 | 19 | return this.each(function() { |
20 | 20 |
|
21 | | - var $tooltip = $("<div>").addClass(options.map.tooltip.cssClass).css("display", "none") |
| 21 | + var self = this |
| 22 | + , $tooltip = $("<div>").addClass(options.map.tooltip.cssClass).css("display", "none") |
22 | 23 | , $container = $('.' + options.map.cssClass, this).empty().append($tooltip) |
23 | 24 | , mapConf = $.fn.mapael.maps[options.map.name] |
24 | 25 | , paper = new Raphael($container[0], mapConf.width, mapConf.height) |
|
76 | 77 | if (options.map.zoom.enabled) |
77 | 78 | $.fn.mapael.initZoom($container, paper, mapConf.width, mapConf.height, options.map.zoom); |
78 | 79 |
|
| 80 | + // Create the legends for areas |
| 81 | + if (options.legend.area.slices && options.legend.area.display) |
| 82 | + areaLegend = $.fn.mapael.createLegend($(this), options, 'area', areas, 1); |
| 83 | + |
79 | 84 | /** |
80 | 85 | * |
81 | 86 | * Update the current map |
|
178 | 183 | if (options.map.width) { |
179 | 184 | paper.setSize(options.map.width, mapConf.height * (options.map.width / mapConf.width)); |
180 | 185 |
|
181 | | - // Create the legends for areas and plots taking into account the scale of the map |
182 | | - if (options.legend.area.slices && options.legend.area.display) |
183 | | - areaLegend = $.fn.mapael.createLegend($(this), options, 'area', areas, 1); |
| 186 | + // Create the legends for plots taking into account the scale of the map |
184 | 187 | if (options.legend.plot.slices && options.legend.plot.display) |
185 | 188 | plotLegend = $.fn.mapael.createLegend($(this), options, 'plot', plots, (options.map.width / mapConf.width)); |
186 | 189 | } else { |
187 | | - $(window).on('resize', function(){ |
| 190 | + $(window).on('resize', function() { |
188 | 191 | clearTimeout(resizeTO); |
189 | 192 | resizeTO = setTimeout(function(){$container.trigger('resizeEnd');}, 150); |
190 | 193 | }); |
191 | | - $container.on('resizeEnd', function(e) { |
| 194 | + |
| 195 | + // Create the legends for plots taking into account the scale of the map |
| 196 | + var createPlotLegend = function() { |
| 197 | + if (options.legend.plot.slices && options.legend.plot.display) |
| 198 | + plotLegend = $.fn.mapael.createLegend($(self), options, 'plot', plots, ($container.width() / mapConf.width)); |
| 199 | + |
| 200 | + $container.unbind('resizeEnd', createPlotLegend); |
| 201 | + }; |
| 202 | + |
| 203 | + $container.on('resizeEnd', function() { |
192 | 204 | var containerWidth = $container.width(); |
193 | 205 | if (paper.width != containerWidth) { |
194 | 206 | paper.setSize(containerWidth, mapConf.height * (containerWidth / mapConf.width)); |
195 | 207 | } |
196 | | - }); |
197 | | - (function(self, $container, options, areas, plots) { |
198 | | - $(document).on('ready', function(){ |
199 | | - $container.trigger('resizeEnd'); |
200 | | - |
201 | | - // Create the legends for areas and plots taking into account the scale of the map |
202 | | - if (options.legend.area.slices && options.legend.area.display) |
203 | | - areaLegend = $.fn.mapael.createLegend($(self), options, 'area', areas, 1); |
204 | | - if (options.legend.plot.slices && options.legend.plot.display) |
205 | | - plotLegend = $.fn.mapael.createLegend($(self), options, 'plot', plots, ($container.width() / mapConf.width)); |
206 | | - }); |
207 | | - })(this, $container, options, areas, plots); |
208 | | - |
209 | | - $container.trigger('resizeEnd'); |
| 208 | + }).on('resizeEnd', createPlotLegend).trigger('resizeEnd'); |
210 | 209 | } |
211 | 210 |
|
212 | 211 | $(paper.desc).append(" and Mapael (http://neveldo.fr/mapael)"); |
|
298 | 297 | $.fn.mapael.setEventHandlers = function(id, elemOptions, mapElem, textElem) { |
299 | 298 | for(var event in elemOptions.eventHandlers) { |
300 | 299 | (function(event) { |
301 | | - $(mapElem.node).on(event, function() {!$.fn.mapael.panning && elemOptions.eventHandlers[event](id, mapElem, textElem)}); |
302 | | - textElem && $(textElem.node).on(event, function() {!$.fn.mapael.panning && elemOptions.eventHandlers[event](id, mapElem, textElem)}); |
| 300 | + $(mapElem.node).on(event, function(e) {!$.fn.mapael.panning && elemOptions.eventHandlers[event](e, id, mapElem, textElem)}); |
| 301 | + textElem && $(textElem.node).on(event, function(e) {!$.fn.mapael.panning && elemOptions.eventHandlers[event](e, id, mapElem, textElem)}); |
303 | 302 | })(event); |
304 | 303 | } |
305 | 304 | } |
|
0 commit comments