1
|
/*
|
2
|
License: GPL as per: http://www.gnu.org/copyleft/gpl.html
|
3
|
$Id: LayerControl.js 3607 2007-11-16 05:06:51Z rdewit $
|
4
|
*/
|
5
|
|
6
|
// Ensure this object's dependancies are loaded.
|
7
|
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
|
8
|
|
9
|
/**
|
10
|
* Widget to allow control of layer odering, visibility, deletion
|
11
|
* @constructor
|
12
|
* @base WidgetBaseXSL
|
13
|
* @author adair
|
14
|
* @param widgetNode The widget's XML object node from the configuration document.
|
15
|
* @param model The model object that this widget belongs to.
|
16
|
*/
|
17
|
function LayerControl(widgetNode, model) {
|
18
|
WidgetBaseXSL.apply(this,new Array(widgetNode, model));
|
19
|
|
20
|
/**
|
21
|
* Override of widget prepaint to set some stylesheet parameters including
|
22
|
* featureName (for OWS Context) and hidden attribute.
|
23
|
* @param objRef Pointer to this object.
|
24
|
*/
|
25
|
this.prePaint = function(objRef) {
|
26
|
if (objRef.model.featureName) {
|
27
|
|
28
|
objRef.stylesheet.setParameter("featureName", objRef.model.featureName );
|
29
|
objRef.stylesheet.setParameter("hidden", objRef.model.getHidden(objRef.model.featureName).toString() );
|
30
|
}
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Displays a layer in a preview pane when mouse is over the table row
|
35
|
* @param layerId the name of the layer to highlight
|
36
|
*/
|
37
|
this.highlightLayer = function(layerId) {
|
38
|
var layer = this.model.map.mbMapPane.oLlayers[layerId].div;
|
39
|
var previewImage = document.getElementById("previewImage");
|
40
|
try {
|
41
|
if (previewImage && layer) previewImage.src = layer.firstChild.firstChild.src;
|
42
|
} catch(e) {}
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Listener method to paint this widget
|
47
|
* @param layerName the name of the layer to highlight
|
48
|
*/
|
49
|
this.refresh = function(objRef, layerName) {
|
50
|
objRef.paint(objRef, objRef.id);
|
51
|
}
|
52
|
|
53
|
this.foldUnfoldGroup = function(groupName,id) {
|
54
|
// context config stuff to maintain group folding over refresh
|
55
|
var xpathExpression = "//wmc:General/wmc:Extension/wmc:GroupList/wmc:Group[@name='" + groupName + "']";
|
56
|
//var thisGroupsLayerNodes = model.doc.selectNodes(xpathExpression);
|
57
|
var thisGroupsNode = model.doc.selectSingleNode(xpathExpression);
|
58
|
var thisGroupsFoldedState = thisGroupsNode.getAttribute('folded');
|
59
|
var e =document.getElementById(id);
|
60
|
if(thisGroupsFoldedState == "1") {
|
61
|
thisGroupsNode.setAttribute("folded", "0");
|
62
|
e.value="-";
|
63
|
|
64
|
} else {
|
65
|
thisGroupsNode.setAttribute("folded", "1");
|
66
|
e.value="+";
|
67
|
}
|
68
|
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* not working yet
|
73
|
* @param layerId the name of the layer to highlight
|
74
|
*/
|
75
|
this.showLayerMetadata = function(layerId) {
|
76
|
var metadataWidget = config.objects.layerMetadata;
|
77
|
if (metadataWidget) {
|
78
|
metadataWidget.stylesheet.setParameter("featureName",layerId);
|
79
|
metadataWidget.node = document.getElementById(metadataWidget.htmlTagId);
|
80
|
metadataWidget.paint(metadataWidget);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Change image source from imageA to imageB
|
86
|
* @param id id of image tag where we want to change the source
|
87
|
* @param imageA url of imageA
|
88
|
* @param imageB url of imageB
|
89
|
*/
|
90
|
this.ChangeImage= function (id, imageA, imageB) {
|
91
|
var indexA=document.getElementById(id).src.indexOf(imageA);
|
92
|
var indexB=document.getElementById(id).src.indexOf(imageB);
|
93
|
if (document.getElementById(id) != null) {
|
94
|
if (indexA != -1) { /* HACK for IE. */
|
95
|
document.getElementById(id).src=document.getElementById(id).src.substring(0,indexA)+imageB;
|
96
|
} else {
|
97
|
document.getElementById(id).src=document.getElementById(id).src.substring(0,indexB)+imageA;
|
98
|
}
|
99
|
}
|
100
|
return;
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Display or fold the layer's legend
|
105
|
* @param id id of legend div
|
106
|
*/
|
107
|
this.switchVisibilityById = function (id) {
|
108
|
e =document.getElementById(id);
|
109
|
|
110
|
if (e.style.display=="none") {
|
111
|
e.style.display = "block";
|
112
|
} else {
|
113
|
e.style.display = "none";
|
114
|
}
|
115
|
|
116
|
|
117
|
}
|
118
|
this.model.addListener("deleteLayer",this.refresh, this);
|
119
|
this.model.addListener("moveLayerUp",this.refresh, this);
|
120
|
this.model.addListener("moveLayerDown",this.refresh, this);
|
121
|
if (this.autoRefresh) this.model.addListener("addLayer",this.refresh, this);
|
122
|
}
|
123
|
|