Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newarch: add init() function #133

Merged
merged 3 commits into from
Nov 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions js/jquery.mapael.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

var pluginName = "mapael";


// Default map options
var defaultOptions = {
map : {
Expand Down Expand Up @@ -132,6 +131,7 @@
, links : {}
};

// Default legends option
var legendDefaultOptions = {
area : {
cssClass : "areaLegend"
Expand Down Expand Up @@ -194,11 +194,17 @@
}
};

/*
* Mapael constructor
* Called directly on DOM element to apply the plugin
* @param options the user options
*/
var Mapael = function(options) {

// Extend legend default options with user options
// Extend default options with user options
options = $.extend(true, {}, defaultOptions, options);

// Extend each legend default options with user options
$.each(options.legend, function(type) {
if ($.isArray(options.legend[type])) {
for (var i = 0; i < options.legend[type].length; ++i)
Expand All @@ -208,18 +214,48 @@
}
});

// Init the plugin on each DOM element
return this.each(function() {

// Avoid multiple instanciation
if ($.data(this, pluginName)) throw new Error("Mapael already exists on this element.");

// Save instanciation on element
// This allow external access to Mapael using $(".mapcontainer").data("mapael")
$.data(this, pluginName, Mapael);

var $container = $(this) // the current element
// Initialize
Mapael.init(this, options);
});
};

/*
* Version number of jQuery Mapael. See http://semver.org/ for more information.
* @type string
*/
Mapael.version = '1.1.0';

/* zoom TimeOut handler (used to set and clear) */
Mapael.zoomTO = 0;

/* Panning: tell if panning action is in progress */
Mapael.panning = false;
/* Panning TimeOut handler (used to set and clear) */
Mapael.panningTO = 0;

/* Animate view box Interval handler (used to set and clear) */
Mapael.animationIntervalID = null;

/*
* Initialize the plugin
* Called by the constructor
* @param container the DOM element on which to apply the plugin
* @param options the complete options to use
*/
Mapael.init = function(container, options) {
var $container = $(container) // the current element
, $tooltip = $("<div>").addClass(options.map.tooltip.cssClass).css("display", "none") // the tooltip container
, $map = $("." + options.map.cssClass, this).empty().append($tooltip) // the map container
, $map = $("." + options.map.cssClass, container).empty().append($tooltip) // the map container
, mapConf = $.fn[pluginName].maps[options.map.name]
, paper = new Raphael($map[0], mapConf.width, mapConf.height)
, elemOptions = {}
Expand Down Expand Up @@ -638,16 +674,8 @@
if (options.map.afterInit) options.map.afterInit($container, paper, areas, plots, options);

$(paper.desc).append(" and Mapael (http://www.vincentbroute.fr/mapael/)");
});
};

/*
* Version number of jQuery Mapael. See http://semver.org/ for more information.
* @type string
*/
Mapael.version = '1.1.0';

Mapael.zoomTO = 0;
};

/*
* Init the element "elem" on the map (drawing, setting attributes, events, tooltip, ...)
Expand Down Expand Up @@ -1009,9 +1037,6 @@
});
};

Mapael.panning = false;
Mapael.panningTO = 0;

/*
* Init zoom and panning for the map
* @param $map
Expand Down Expand Up @@ -1569,7 +1594,6 @@
return {};
};

Mapael.animationIntervalID = null;

/*
* Animated view box changes
Expand Down