Handle multiple instances of same component type (regions)

This commit is contained in:
Mike Primm 2011-08-26 13:55:53 +08:00 committed by mikeprimm
parent c353d9aae6
commit bc357dd188

View File

@ -284,12 +284,21 @@ DynMap.prototype = {
me.selectMap(me.defaultworld.defaultmap); me.selectMap(me.defaultworld.defaultmap);
var componentstoload = me.options.components.length; var configset = { };
$.each(me.options.components, function(index, configuration) { $.each(me.options.components, function(index, configuration) {
loadjs('js/' + configuration.type + '.js', function() { if(!configset[configuration.type])
var componentconstructor = componentconstructors[configuration.type]; configset[configuration.type] = [];
configset[configuration.type].push(configuration);
});
var componentstoload = configset.length;
$.each(configset, function(type, configlist) {
loadjs('js/' + type + '.js', function() {
var componentconstructor = componentconstructors[type];
if (componentconstructor) { if (componentconstructor) {
me.components.push(new componentconstructor(me, configuration)); $.each(configlist, function(idx, configuration) {
me.components.push(new componentconstructor(me, configuration));
});
} else { } else {
// Could not load component. We'll ignore this for the moment. // Could not load component. We'll ignore this for the moment.
} }
@ -323,8 +332,7 @@ DynMap.prototype = {
var prevzoom = me.map.getZoom(); var prevzoom = me.map.getZoom();
if (me.maptype) { if (me.maptype) {
me.layercontrol.removeLayer(me.maptype); me.map.removeLayer(me.maptype);
//me.map.removeLayer(me.maptype);
} }
var prevmap = me.maptype; var prevmap = me.maptype;
@ -361,7 +369,6 @@ DynMap.prototype = {
me.map.setZoom(prevzoom); me.map.setZoom(prevzoom);
} }
me.map.addLayer(me.maptype); me.map.addLayer(me.maptype);
//me.layercontrol.addBaseLayer(me.maptype, 'Tiles');
if (worldChanged) { if (worldChanged) {
$(me).trigger('worldchanged'); $(me).trigger('worldchanged');