diff --git a/web/js/dynmaputils.js b/web/js/dynmaputils.js
index e09b9419..9b628133 100644
--- a/web/js/dynmaputils.js
+++ b/web/js/dynmaputils.js
@@ -182,3 +182,27 @@ function Location(world, x, y, z) {
this.y = y;
this.z = z;
}
+
+function namedReplace(str, obj)
+{
+ var startIndex = 0;
+ var result = '';
+ while(true) {
+ var variableBegin = str.indexOf('{', startIndex);
+ var variableEnd = str.indexOf('}', variableBegin+1);
+ if (variableBegin < 0 || variableEnd < 0) {
+ result += str.substr(startIndex);
+ break;
+ }
+ if (variableBegin < variableEnd) {
+ var variableName = str.substring(variableBegin+1, variableEnd-1);
+ result += str.substring(startIndex, variableBegin-1);
+ result += obj[variableName];
+ } else /* found '{}' */ {
+ result += str.substring(startIndex, variableBegin-1);
+ result += '';
+ }
+ startIndex = variableEnd+1;
+ }
+ return result;
+}
\ No newline at end of file
diff --git a/web/js/map.js b/web/js/map.js
index 39e821a3..e3ad9c90 100644
--- a/web/js/map.js
+++ b/web/js/map.js
@@ -19,63 +19,6 @@ componentconstructors['testcomponent'] = function(dynmap, configuration) {
$(dynmap).bind('playerupdated', function() { console.log('playerupdated'); });
};
-function loadjs(url, completed) {
- var script = document.createElement('script');
- script.setAttribute('src', url);
- script.setAttribute('type', 'text/javascript');
- var isloaded = false;
- script.onload = function() {
- if (isloaded) { return; }
- isloaded = true;
- completed();
- };
-
- // Hack for IE, don't know whether this still applies to IE9.
- script.onreadystatechange = function() {
- script.onload();
- };
- (document.head || document.getElementsByTagName('head')[0]).appendChild(script);
-}
-
-function splitArgs(s) {
- var r = s.split(' ');
- delete arguments[0];
- var obj = {};
- var index = 0;
- $.each(arguments, function(argumentIndex, argument) {
- if (!argumentIndex) { return; }
- var value = r[argumentIndex-1];
- obj[argument] = value;
- });
- return obj;
-}
-
-function swtch(value, options, defaultOption) {
- return (options[value] || defaultOption || function(){})(value);
-}
-(function( $ ){
- $.fn.scrollHeight = function(height) {
- return this[0].scrollHeight;
- };
-})($);
-
-function DynMapType() { }
-DynMapType.prototype = {
- onTileUpdated: function(tile, tileName) {
- var src = this.dynmap.getTileUrl(tileName);
- tile.attr('src', src);
- tile.show();
- },
- updateTileSize: function(zoom) {}
-};
-
-function Location(world, x, y, z) {
- this.world = world;
- this.x = x;
- this.y = y;
- this.z = z;
-}
-
function DynMap(options) {
var me = this;
me.options = options;
diff --git a/web/js/regions.js b/web/js/regions.js
index 3fd8a76c..7a890dd9 100644
--- a/web/js/regions.js
+++ b/web/js/regions.js
@@ -1,36 +1,33 @@
-// Author: nidefawl. contact me at bukkit.org or irc.esper.net #nide
-
-var regionCfg;
-var regionPolygons = {} ;
-var regionInfoWindow = new google.maps.InfoWindow();
var regionConstructors = {};
-function makeRegionPolygonCube(map, name, region)
-{
- new regionConstructors['polygon'](map, name, region);
-}
-function regionInfo(event, name, region)
-{
- new regionConstructors['info'](event, name, region);
-}
-componentconstructors['regions'] = function(dynmap, configuration)
-{
+
+componentconstructors['regions'] = function(dynmap, configuration) {
regionCfg = configuration;
-
- loadjs('js/regions_' + regionCfg.name + '.js', function()
- {
- var world_info = dynmap.map.mapTypeId.split('.');
- new regionConstructors['update'](world_info[0]);
-
- $(dynmap).bind('mapchanged', function() {
- var world_info = dynmap.map.mapTypeId.split('.');
- new regionConstructors['update'](world_info[0]);
- });
+ var regionType = regionCfg.name;
+ loadjs('js/regions_' + regionType + '.js', function() {
+ var regionsLayer = undefined;
+ function undraw() {
+ if (regionsLayer) {
+ dynmap.map.removeLayer(regionsLayer);
+ regionsLayer = undefined;
+ }
+ }
+ function redraw() {
+ undraw();
+ var worldName = dynmap.world && dynmap.world.name;
+ if (worldName) {
+ regionConstructors[regionType](dynmap, worldName, function(regionLayers) {
+ var newRegionsLayer = new L.LayerGroup();
+ $.each(regionLayers, function(name, layer) {
+ console.log(name, layer);
+ newRegionsLayer.addLayer(layer);
+ });
+ regionsLayer = newRegionsLayer;
+ dynmap.map.addLayer(newRegionsLayer);
+ });
+ }
+ }
+ $(dynmap).bind('mapchanged', redraw);
+ $(dynmap).bind('mapchanging', undraw);
+ redraw();
});
-}
-
-function arrayReplace(replace, by, str)
-{
- for (var i=0; i