Skip to content

Commit e31ba75

Browse files
committed
EventObject transmitted to handlers & improvements for scaling plots in the legend
1 parent 09e413f commit e31ba75

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

examples.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $(function(){
7474
animDuration:0
7575
},
7676
eventHandlers : {
77-
click: function(id, mapElem, textElem) {
77+
click: function(e, id, mapElem, textElem) {
7878
var newData = {'areas' : {}};
7979
if (mapElem.originalAttrs.fill == "#5ba4ff") {
8080
newData.areas[id] = {
@@ -104,7 +104,7 @@ $(function(){
104104
tooltip: {content : "Finistère (29)"},
105105
eventHandlers : {
106106
click: function() {},
107-
dblclick: function(id, mapElem, textElem) {
107+
dblclick: function(e, id, mapElem, textElem) {
108108
var newData = {'areas' : {}};
109109
if (mapElem.originalAttrs.fill == "#5ba4ff") {
110110
newData.areas[id] = {

js/jquery.mapael.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
return this.each(function() {
2020

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")
2223
, $container = $('.' + options.map.cssClass, this).empty().append($tooltip)
2324
, mapConf = $.fn.mapael.maps[options.map.name]
2425
, paper = new Raphael($container[0], mapConf.width, mapConf.height)
@@ -76,6 +77,10 @@
7677
if (options.map.zoom.enabled)
7778
$.fn.mapael.initZoom($container, paper, mapConf.width, mapConf.height, options.map.zoom);
7879

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+
7984
/**
8085
*
8186
* Update the current map
@@ -178,35 +183,29 @@
178183
if (options.map.width) {
179184
paper.setSize(options.map.width, mapConf.height * (options.map.width / mapConf.width));
180185

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
184187
if (options.legend.plot.slices && options.legend.plot.display)
185188
plotLegend = $.fn.mapael.createLegend($(this), options, 'plot', plots, (options.map.width / mapConf.width));
186189
} else {
187-
$(window).on('resize', function(){
190+
$(window).on('resize', function() {
188191
clearTimeout(resizeTO);
189192
resizeTO = setTimeout(function(){$container.trigger('resizeEnd');}, 150);
190193
});
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() {
192204
var containerWidth = $container.width();
193205
if (paper.width != containerWidth) {
194206
paper.setSize(containerWidth, mapConf.height * (containerWidth / mapConf.width));
195207
}
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');
210209
}
211210

212211
$(paper.desc).append(" and Mapael (http://neveldo.fr/mapael)");
@@ -298,8 +297,8 @@
298297
$.fn.mapael.setEventHandlers = function(id, elemOptions, mapElem, textElem) {
299298
for(var event in elemOptions.eventHandlers) {
300299
(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)});
303302
})(event);
304303
}
305304
}

0 commit comments

Comments
 (0)