-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoparams.js
178 lines (163 loc) · 4.85 KB
/
geoparams.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var extractParams = function(){
// /////////////////////////////////////////////////////
// Extra parameters to add layers at startup
// /////////////////////////////////////////////////////
var layName; var layTitle; var wmsurl; var gsturl; var urlformat; var useCookies;
// //////////////////////////////////////////////////
// Parsing the request to get the parameters
// //////////////////////////////////////////////////
var params = location.search.replace(/^\?/,'').replace(/&/g,'&').split("&");
for (var j=0; j < params.length; j++) {
var param = params[j].split("=");
if(param[0]){
switch ( param[0] ) {
case "mapId":
try{
mapIdentifier = parseInt(param[1]);
}catch(e){
mapIdentifier = -1;
}
break;
case "auth" :
authorization = param[1];
if(param.length > 2){
for(var i = 2; i < param.length; i++){
authorization += "=";
}
}
break;
case "fullScreen" :
if(param[1] == 'true')
fullScreen = true;
else
fullScreen = false;
break;
case "layName" :
layName = param[1];
layName = decodeURIComponent(layName);
break;
case "layTitle" :
layTitle = param[1];
layTitle = decodeURIComponent(layTitle);
break;
case "wmsurl" :
wmsurl = param[1];
wmsurl = decodeURIComponent(wmsurl);
break;
case "gsturl" :
gsturl = param[1];
gsturl = decodeURIComponent(gsturl);
break;
case "useCookies" :
useCookies = param[1];
break;
case "config":
customConfigName = param[1];
break;
case "bbox":
try{
bbox = new OpenLayers.Bounds.fromString(param[1]);
}catch(e){
bbox = undefined;
}
break;
case "configId":
try{
templateId = parseInt(param[1]);
}catch(e){
templateId = -1;
}
break;
case "format":
urlformat = param[1];
break;
default :
//mapIdentifier = -1;
//authorization = false;
//fullScreen = false;
}
}
}
return { layName: layName, layTitle: layTitle, wmsurl: wmsurl, useCookies: useCookies };
};
var extendMapAndSourcesFromParams = function(map,sources){
var pdata = extractParams();
var new_layers = [];
var hasLayer = false;
if (pdata.useCookies){
//if in cookies or session
var layersList = extractLayersList(pdata.useCookies, content);
if (layersList){
new_layers = addLayersFromList(map, sources, layersList);
}
} else if (pdata.wmsurl) {
//if in url params
addSource(sources, "params", pdata.wmsurl, new URL(pdata.wmsurl).hostname);
if (pdata.layName) {
if (pdata.layTitle == undefined){ pdata.layTitle = pdata.layName; }
new_layers.push(addLayer(map, "params", pdata.layName, pdata.layName));
}
}
if (new_layers.length > 0) {
hasLayer = true;
pdata.layName = new_layers[0].name;
pdata.layTitle = new_layers[0].title;
}
pdata.hasLayer = hasLayer;
return pdata;
};
var extractLayersList = function(useCookies){
//if we have content.data or cookies
var layersList;
if(useCookies){
var cookie = window.document.cookie;
var cookies = cookie.split(";");
var layersList;
for(var i=0; i<cookies.length; i++){
//go through each cookie and the useCookies key
if(cookies[i].indexOf(useCookies) != -1){
layersList = cookies[i].split("=")[1];
}
}
}
return layersList;
};
var addLayersFromList = function(map, sources, layersList){
var layers = layersList.split("#");
var new_layers = [];
for(var i=0; i<layers.length; i++){
var kees = layers[i];
kees = unescape(kees);
kees = Ext.util.JSON.decode(kees);
var lname = kees.layer;
var lwms = decodeURIComponent(kees.wms);
var source_key;
//check if we already have the source
$.each(sources, function(k,v) {
if(v.url === lwms){ source_key = k; }
});
if (!source_key){
source_key = "layer_source_"+i;
addSource(sources, source_key, lwms, new URL(lwms).hostname);
}
new_layers.push(addLayer(map, source_key, lname, lname));
}
return new_layers;
};
var addSource = function(sources, source_key, wmsurl, title){
var new_source = { url: wmsurl, title: title }
sources[source_key] = new_source;
return new_source;
};
var addLayer = function(map, source_key, layName, layTitle){
var new_layer = { source: source_key, name: layName, title: layTitle }
map.layers.push(new_layer);
return new_layer;
};
var zoomToLayer = function(app, pdata){
if (pdata.hasLayer){
var chosenLayer = app.mapPanel.map.getLayersByName(pdata.layName)[0];
var extent = chosenLayer.maxExtent;
app.mapPanel.map.zoomToExtent(extent);
}
};