From bfb12e4f8130b9fa774176e935951cbc3c748125 Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Thu, 25 Aug 2011 17:07:00 -0500 Subject: [PATCH] Add control for hide/show of component layers (only regions for now) --- web/js/dynmaputils.js | 6 ++++++ web/js/map.js | 8 +++++++- web/js/regions.js | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/web/js/dynmaputils.js b/web/js/dynmaputils.js index 14304afd..e4dfb893 100644 --- a/web/js/dynmaputils.js +++ b/web/js/dynmaputils.js @@ -43,6 +43,12 @@ if (!Array.prototype.indexOf) { } } +var DynmapLayerControl = L.Control.Layers.extend({ + getPosition: function() { + return L.Control.Position.TOP_LEFT; + } +}); + var DynmapTileLayer = L.TileLayer.extend({ _currentzoom: undefined, diff --git a/web/js/map.js b/web/js/map.js index 5f4e73b8..c558880e 100644 --- a/web/js/map.js +++ b/web/js/map.js @@ -41,6 +41,7 @@ DynMap.prototype = { inittime: new Date().getTime(), followingPlayer: '', missedupdates: 0, + layercontrol: undefined, formatUrl: function(name, options) { var url = this.options.url[name]; $.each(options, function(n,v) { @@ -137,6 +138,9 @@ DynMap.prototype = { me.followPlayer(null); });*/ + me.layercontrol = new DynmapLayerControl(); + map.addControl(me.layercontrol); + // Sidebar var panel; var sidebar; @@ -319,7 +323,8 @@ DynMap.prototype = { var prevzoom = me.map.getZoom(); if (me.maptype) { - me.map.removeLayer(me.maptype); + me.layercontrol.removeLayer(me.maptype); + //me.map.removeLayer(me.maptype); } var prevmap = me.maptype; @@ -356,6 +361,7 @@ DynMap.prototype = { me.map.setZoom(prevzoom); } me.map.addLayer(me.maptype); + //me.layercontrol.addBaseLayer(me.maptype, 'Tiles'); if (worldChanged) { $(me).trigger('worldchanged'); diff --git a/web/js/regions.js b/web/js/regions.js index 9170f97d..e3ea82fe 100644 --- a/web/js/regions.js +++ b/web/js/regions.js @@ -165,6 +165,7 @@ componentconstructors['regions'] = function(dynmap, configuration) { var activeLayer = undefined; function undraw() { if (activeLayer) { + dynmap.layercontrol.removeLayer(activeLayer); dynmap.map.removeLayer(activeLayer); activeLayer = undefined; } @@ -183,6 +184,7 @@ componentconstructors['regions'] = function(dynmap, configuration) { result: function(regionsLayer) { activeLayer = regionsLayer; dynmap.map.addLayer(activeLayer); + dynmap.layercontrol.addOverlay(activeLayer, regionType); } })); }