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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Dec 1 04:44:12 EST 2010


Author: christoph
Date: 2010-12-01 01:44:12 -0800 (Wed, 01 Dec 2010)
New Revision: 7176

Modified:
   trunk/mapbender/http/plugins/mb_wmsTree.js
Log:
latest additions
 * sort order
 * scalehints
 * layout

Modified: trunk/mapbender/http/plugins/mb_wmsTree.js
===================================================================
--- trunk/mapbender/http/plugins/mb_wmsTree.js	2010-12-01 09:43:05 UTC (rev 7175)
+++ trunk/mapbender/http/plugins/mb_wmsTree.js	2010-12-01 09:44:12 UTC (rev 7176)
@@ -2,7 +2,7 @@
  * Package: wmsTree
  *
  * Description:
- * A basic WMS layer switch. You can turn entire WMS on or off by clicking an
+ * A basic WMS layer switcher. You can turn entire WMS on or off by clicking an
  * icon, and additionally change the display order by dragging and dropping.
  *
  * Files:
@@ -14,7 +14,7 @@
  * > e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod,
  * > e_target, e_requires, e_url) VALUES('<appId>','wmsTree',1,1,'','',
  * > 'div','','',1020,100,200,500,NULL ,'','','div',
- * > '../plugins/mb_wmsTree.js','','mapframe1','','');
+ * > '../plugins/mb_wmsTree.js','','mapframe1','jq_ui_sortable','');
  * >
  * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name, var_value,
  * > context, var_type) VALUES('<appId>', 'wmsTree', 'css',
@@ -58,6 +58,11 @@
 	var that = this;
 	var map;
 	var $list = $wmsTree.children("ul");
+	var notSortable = (o.notSortable && typeof o.notSortable === "string") ?
+		o.notSortable.split(",") : [];
+	var reverseSortOrder = (o.reverseSortOrder && 
+		(o.reverseSortOrder = "true"  || typeof o.reverseSortOrder === "number")) ?
+		true : false;
 	
 	var updateAllTicks = function () {
 		$list.find("span.wmstree-tick").each(function () {
@@ -73,12 +78,29 @@
 		var layer = wms.objLayer[0];
 		var isVisible = layer.gui_layer_visible;
 
+		var isInScale = false;
+		for (var i = 1; i < wms.objLayer.length; i++) {
+			if (wms.objLayer[i].checkScale(map)) {
+				isInScale = true;
+				break;
+			}
+		};
+		if (!isInScale) {
+			$span.parent().addClass("ui-state-disabled");
+		}
+		else {
+			$span.parent().removeClass("ui-state-disabled");
+		}
+
 		var $tick = $span.find("img");
 		$tick.css("visibility", isVisible ? "visible" : "hidden");
 	};
 
 	var toggleWmsVisibility = function () {
 		var $row = $(this).parent();
+		if ($row.hasClass("ui-state-disabled")) {
+			return;
+		}
 		var wms = $row.data("wms");
 		if (typeof wms !== "object") {
 			return;
@@ -90,7 +112,7 @@
 	};
 
 	var createRow = function (wms) {
-		if (!wms || wms.gui_wms_visible !== 1) {
+		if (!wms || wms.gui_wms_visible !== 1 || wms.objLayer[0].gui_layer_selectable === 0) {
 			return;
 		}
 		var name = wms.objLayer[0].layer_currentTitle;
@@ -98,13 +120,22 @@
 			"<span class='wmstree-label'>" + name + "</span>" +
 			"<span class='wmstree-tick'><img " +
 			"src='../img/tick.png' /></span></li>";
-		var $row = $(html);
+		var $row = $(html).data("wms", wms);
+
+		// these rows will now be sortable
+		var index = $.inArray(wms.objLayer[0].layer_name, notSortable);
+		if (index !== -1) {
+			$row.addClass("wmstree-notsortable");
+		}
+		else {
+			$row.hover(function () {
+				$(this).addClass("ui-state-hover");
+			}, function () {
+				$(this).removeClass("ui-state-hover");
+			});
+		}
+		
 		var $tick = $row.find("span.wmstree-tick");
-		$row.data("wms", wms).hover(function () {
-			$(this).addClass("ui-state-hover");
-		}, function () {
-			$(this).removeClass("ui-state-hover");
-		});
 		$tick.click(toggleWmsVisibility);
 		updateTick($tick);
 		return $row;
@@ -115,7 +146,12 @@
 			(function () {
 				var wms = map.wms[i];
 				var $row = createRow(wms);
-				$list.append($row);
+				if (reverseSortOrder) {
+					$list.prepend($row);
+				}
+				else {
+					$list.append($row);
+				}
 			})();
 		}
 
@@ -131,32 +167,67 @@
 			) {
 				return;
 			}
+			
+			// If steps > 0 the WMS is moved down in the list, hence the
+			// third parameter to the move method (moveUp) is false, which
+			// means that the WMS is moved down in the map object.
+			// If reverseSortOrder is set, this effect is canceled out.
 			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.move(wms.wms_id, null, steps < 0);
+				// A problem will occur if a WMS is not selectable:
+				// it will not appear in the tree, but it is in the
+				// map object. This will cause index trouble.
 			}
 			map.setMapRequest();
 		};
 
+		var getIndex = function (li) {
+			if (reverseSortOrder) {
+				return li.nextAll("li").length;
+			}
+			return li.prevAll("li").length;
+		};
+
+		var isPrevious = function (indexA, indexB) {
+			if (reverseSortOrder) {
+				if (indexB < indexA) {
+					return true;
+				}
+				return false;
+			}
+			if (indexA < indexB) {
+				return true;
+			}
+			return false;
+		};
+
+		var decrementIndex = function (index) {
+			if (reverseSortOrder) {
+				return index + 1;
+			}
+			return index - 1;
+		};
+
 		$list.sortable({
 			axis: "y",
+			items: "li:not(li.wmstree-notsortable)",
 			containment: $wmsTree,
 			start: function (event, ui) {
-				oldIndex = ui.item.prevAll().length;
+				oldIndex = getIndex(ui.item);
 			},
 			change: o.liveUpdate ? function (event, ui) {
-				newIndex = ui.placeholder.prevAll().length;
+				newIndex = getIndex(ui.placeholder);
 				// if the item is previous to the placeholder,
 				// do not take it into account
-				if (ui.item.prevAll().length < newIndex) {
-					newIndex--;
+				if (isPrevious(getIndex(ui.item), newIndex)) {
+					newIndex = decrementIndex(newIndex);
 				}
 				rearrangeWms(ui);
 				oldIndex = newIndex;
 			} : function () {},
 			stop: !o.liveUpdate ? function (event, ui) {
-				newIndex = ui.item.prevAll().length;
+				newIndex = getIndex(ui.item);
 				rearrangeWms(ui);
 			} : function () {}
 		}).disableSelection();



More information about the Mapbender_commits mailing list