[Mapbender-commits] r7140 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Nov 18 12:28:19 EST 2010


Author: christoph
Date: 2010-11-18 09:28:19 -0800 (Thu, 18 Nov 2010)
New Revision: 7140

Added:
   trunk/mapbender/http/plugins/mb_wmsTree.js
Log:
#723

Added: trunk/mapbender/http/plugins/mb_wmsTree.js
===================================================================
--- trunk/mapbender/http/plugins/mb_wmsTree.js	                        (rev 0)
+++ trunk/mapbender/http/plugins/mb_wmsTree.js	2010-11-18 17:28:19 UTC (rev 7140)
@@ -0,0 +1,102 @@
+// INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('test_tree','wmsTree',1,1,'','','div','','',1100,100,500,500,NULL ,'','','div','../plugins/mb_wmsTree.js','','mapframe1','','');
+
+var $wmsTree = $(this).append("<ul></ul>");
+
+var WmsTreeApi = function (o) {
+	var that = this;
+	var map;
+	var $list = $wmsTree.children("ul");
+	
+	var updateAllTicks = function () {
+		$list.find("span.tick").each(function () {
+			updateTick($(this));
+		});
+	};
+
+	var updateTick = function ($span) {
+		var wms = $span.parent().data("wms");
+		if (typeof wms !== "object") {
+			return;
+		}
+		var layer = wms.objLayer[0];
+		var isVisible = layer.gui_layer_visible;
+
+		var $tick = $span.find("img");
+		if (isVisible) {
+			$tick.css("visibility", "visible");
+		}
+		else {
+			$tick.css("visibility", "hidden");
+		}
+	};
+
+	var toggleWmsVisibility = function () {
+		var $row = $(this).parent();
+		var $tick = $row.find("img");
+		var wms = $row.data("wms");
+		if (typeof wms !== "object") {
+			return;
+		}
+		var layer = wms.objLayer[0];
+		var isVisible = layer.gui_layer_visible;
+		if (!isVisible) {
+			wms.handleLayer(layer.layer_name, "visible", 1);
+		}
+		else {
+			wms.handleLayer(layer.layer_name, "visible", 0);
+		}
+		map.setMapRequest();
+	};
+
+	var initTree = function () {
+		for (var i = 0; i < map.wms.length; i++) {
+			(function () {
+				var wms = map.wms[i];
+				var name = wms.objLayer[0].layer_name;
+				var html = "<li class='ui-state-default'>" +
+					"<span>" + name + "</span>" +
+					"<span class='tick'><img " +
+					"src='../img/tick.png' /></span></li>";
+				var $row = $(html);
+				var $tick = $row.find("span.tick");
+				$row.data("wms", wms);
+				$tick.click(toggleWmsVisibility);
+				updateTick($tick);
+				$list.append($row);
+			})();
+		}
+		$list.sortable({
+			axis: "y",
+			stop: function (event, ui) {
+				var wms = ui.item.data("wms");
+				var oldIndex = map.getWmsIndexById(wms.wms_id);
+				var newIndex = ui.item.prevAll().length;
+				if (oldIndex === newIndex) {
+					return;
+				}
+				var steps = (newIndex - oldIndex);
+				var s = steps / Math.abs(steps);
+				for (var i = 0; i < Math.abs(steps); i++) {
+					map.move(wms.wms_id, null, s < 0);
+				}
+				map.setMapRequest();
+			}
+		}).disableSelection();
+
+	};
+
+	Mapbender.events.init.register(function () {
+		if (o.$target && o.$target.jquery) {
+			map = o.$target.mapbender();
+			map.events.afterMapRequest.register(function () {
+				updateAllTicks();
+			});
+			initTree();
+		}
+		else {
+			new Mb_exception("No target given. WmsTree not available.");
+		}
+	});
+};
+
+$wmsTree.mapbender(new WmsTreeApi(options));
\ No newline at end of file



More information about the Mapbender_commits mailing list