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
|
objRef.stylesheet.setParameter("layerMetadata", objRef.model.getParam("layerMetadata"));
|
32
|
}
|
33
|
|
34
|
/**
|
35
|
* Hide loading spinner when layer stops loading
|
36
|
* @param ojbRef Pointer the calling object
|
37
|
* @param layerId Id of the layer
|
38
|
*/
|
39
|
this.loadLayerStart = function(objRef, layerId) {
|
40
|
//console.info('LayerLoading Show: ' + layerId);
|
41
|
layerNode = objRef.model.getLayer(layerId);
|
42
|
if (layerNode) {
|
43
|
layerNode.setAttribute("isLoading", true);
|
44
|
objRef.refresh(objRef, layerId);
|
45
|
}
|
46
|
}
|
47
|
this.model.addListener("loadLayerStart",this.loadLayerStart, this);
|
48
|
|
49
|
/**
|
50
|
* Show loading spinner when layer starts loading
|
51
|
* @param ojbRef Pointer the calling object
|
52
|
* @param layerId Id of the layer
|
53
|
*/
|
54
|
this.loadLayerEnd = function(objRef, layerId) {
|
55
|
//console.info('LayerLoading Hide: ' + layerId);
|
56
|
layerNode = objRef.model.getLayer(layerId);
|
57
|
if (layerNode) {
|
58
|
layerNode.removeAttribute("isLoading");
|
59
|
objRef.refresh(objRef, layerId);
|
60
|
}
|
61
|
}
|
62
|
this.model.addListener("loadLayerEnd",this.loadLayerEnd, this);
|
63
|
|
64
|
|
65
|
/**
|
66
|
* Displays a layer in a preview pane when mouse is over the table row
|
67
|
* @param layerId the name of the layer to highlight
|
68
|
*/
|
69
|
this.highlightLayer = function(layerId) {
|
70
|
if (this.model && this.model.map) {
|
71
|
var layer = this.model.map.mbMapPane.oLlayers[layerId].div;
|
72
|
var previewImage = document.getElementById("previewImage");
|
73
|
try {
|
74
|
if (previewImage && layer) previewImage.src = layer.firstChild.firstChild.src;
|
75
|
} catch(e) {}
|
76
|
}
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Listener method to paint this widget
|
81
|
* @param layerName the name of the layer to highlight
|
82
|
*/
|
83
|
this.refresh = function(objRef, layerName) {
|
84
|
objRef.paint(objRef, objRef.id);
|
85
|
}
|
86
|
this.model.addListener("deleteLayer",this.refresh, this);
|
87
|
this.model.addListener("moveLayerUp",this.refresh, this);
|
88
|
this.model.addListener("moveLayerDown",this.refresh, this);
|
89
|
if (this.autoRefresh) this.model.addListener("addLayer",this.refresh, this);
|
90
|
|
91
|
this.foldUnfoldGroup = function(groupName,id) {
|
92
|
// context config stuff to maintain group folding over refresh
|
93
|
var xpathExpression = "//wmc:General/wmc:Extension/wmc:GroupList/wmc:Group[@name='" + groupName + "']";
|
94
|
//var thisGroupsLayerNodes = model.doc.selectNodes(xpathExpression);
|
95
|
var thisGroupsNode = model.doc.selectSingleNode(xpathExpression);
|
96
|
var thisGroupsFoldedState = thisGroupsNode.getAttribute('folded');
|
97
|
var e =document.getElementById(id);
|
98
|
if(thisGroupsFoldedState == "1") {
|
99
|
thisGroupsNode.setAttribute("folded", "0");
|
100
|
e.value="-";
|
101
|
|
102
|
} else {
|
103
|
thisGroupsNode.setAttribute("folded", "1");
|
104
|
e.value="+";
|
105
|
}
|
106
|
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Change image source from imageA to imageB
|
111
|
* @param id id of image tag where we want to change the source
|
112
|
* @param imageA url of imageA
|
113
|
* @param imageB url of imageB
|
114
|
*/
|
115
|
this.ChangeImage= function (id, imageA, imageB) {
|
116
|
var indexA=document.getElementById(id).src.indexOf(imageA);
|
117
|
var indexB=document.getElementById(id).src.indexOf(imageB);
|
118
|
if (document.getElementById(id) != null) {
|
119
|
if (indexA != -1) { /* HACK for IE. */
|
120
|
document.getElementById(id).src=document.getElementById(id).src.substring(0,indexA)+imageB;
|
121
|
} else {
|
122
|
document.getElementById(id).src=document.getElementById(id).src.substring(0,indexB)+imageA;
|
123
|
}
|
124
|
}
|
125
|
return;
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Display or fold the layer's legend
|
130
|
* @param id id of legend div
|
131
|
*/
|
132
|
this.switchVisibilityById = function (id) {
|
133
|
e =document.getElementById(id);
|
134
|
|
135
|
if (e.style.display=="none") {
|
136
|
e.style.display = "block";
|
137
|
} else {
|
138
|
e.style.display = "none";
|
139
|
}
|
140
|
|
141
|
|
142
|
}
|
143
|
|
144
|
/**
|
145
|
* Copy a layer from this model's context to the targetModel's context.
|
146
|
* @param layerId The id of the layer selected.
|
147
|
*/
|
148
|
this.copyToTargetModel = function(layerId) {
|
149
|
|
150
|
// Fetch layerNode from model and clone it
|
151
|
var layerNode=this.model.getLayer(layerId).cloneNode(true);
|
152
|
|
153
|
//Add layerNode to the target model
|
154
|
this.targetModel.setParam("addLayer",layerNode);
|
155
|
}
|
156
|
|
157
|
}
|
158
|
|