Add control for hide/show of component layers (only regions for now)

This commit is contained in:
Mike Primm 2011-08-25 17:07:00 -05:00
parent 625b62fa36
commit bfb12e4f81
3 changed files with 15 additions and 1 deletions

View File

@ -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,

View File

@ -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');

View File

@ -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);
}
}));
}