diff --git a/js/jquery.mapael.js b/js/jquery.mapael.js index cb274c5..2de8226 100644 --- a/js/jquery.mapael.js +++ b/js/jquery.mapael.js @@ -234,27 +234,15 @@ var i = 0 , id = 0 , animDuration = 0 - , elemOptions = {}, - showlegendElems = true; + , elemOptions = {} + , showlegendElems = true; // Set showlegendElems variable - // If not defined, or badly defined, revert to TRUE + // Keep default (true) if opt.setLegendElemsState not defined, or badly defined if (typeof opt != "undefined" && typeof opt.setLegendElemsState === "string") { showlegendElems = (opt.setLegendElemsState === "hide") ? false : true; } - // Hide/Show all elements based on showlegendElems - // Toggle (i.e. click) only if: - // - slice legend is shown AND we want to hide - // - slice legend is hidden AND we want to show - $("[data-type='elem']", $(this)).each(function() { - if (($(this).attr('data-hidden') === "0" && showlegendElems === false) || - ($(this).attr('data-hidden') === "1" && showlegendElems === true)) { - // Toggle state of element by clicking - $(this).trigger('click', false); - } - }); - if (typeof opt != "undefined") { (opt.resetAreas) && (options.areas = {}); (opt.resetPlots) && (options.plots = {}); @@ -392,13 +380,27 @@ } // Update legends - Mapael.createLegends($self, options, "area", areas, 1); - if (options.map.width) { - Mapael.createLegends($self, options, "plot", plots, (options.map.width / mapConf.width)); - } else { - Mapael.createLegends($self, options, "plot", plots, ($container.width() / mapConf.width)); + if (typeof updatedOptions != "undefined" && typeof updatedOptions.legend === "object") { + Mapael.createLegends($self, options, "area", areas, 1); + if (options.map.width) { + Mapael.createLegends($self, options, "plot", plots, (options.map.width / mapConf.width)); + } else { + Mapael.createLegends($self, options, "plot", plots, ($container.width() / mapConf.width)); + } } + // Hide/Show all elements based on showlegendElems + // Toggle (i.e. click) only if: + // - slice legend is shown AND we want to hide + // - slice legend is hidden AND we want to show + $("[data-type='elem']", $(this)).each(function() { + if (($(this).attr('data-hidden') === "0" && showlegendElems === false) || + ($(this).attr('data-hidden') === "1" && showlegendElems === true)) { + // Toggle state of element by clicking + $(this).trigger('click', false); + } + }); + if(typeof opt != "undefined") opt.afterUpdate && opt.afterUpdate($self, paper, areas, plots, options); });