From bc357dd18877e3f985d30c2501710bcffb369a9e Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 26 Aug 2011 13:55:53 +0800 Subject: [PATCH] Handle multiple instances of same component type (regions) --- web/js/map.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/web/js/map.js b/web/js/map.js index c558880e..6693021b 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -284,12 +284,21 @@ DynMap.prototype = { me.selectMap(me.defaultworld.defaultmap); - var componentstoload = me.options.components.length; + var configset = { }; $.each(me.options.components, function(index, configuration) { - loadjs('js/' + configuration.type + '.js', function() { - var componentconstructor = componentconstructors[configuration.type]; + if(!configset[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) { - me.components.push(new componentconstructor(me, configuration)); + $.each(configlist, function(idx, configuration) { + me.components.push(new componentconstructor(me, configuration)); + }); } else { // Could not load component. We'll ignore this for the moment. } @@ -323,8 +332,7 @@ DynMap.prototype = { var prevzoom = me.map.getZoom(); if (me.maptype) { - me.layercontrol.removeLayer(me.maptype); - //me.map.removeLayer(me.maptype); + me.map.removeLayer(me.maptype); } var prevmap = me.maptype; @@ -361,7 +369,6 @@ DynMap.prototype = { me.map.setZoom(prevzoom); } me.map.addLayer(me.maptype); - //me.layercontrol.addBaseLayer(me.maptype, 'Tiles'); if (worldChanged) { $(me).trigger('worldchanged');