-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (86 loc) · 3.08 KB
/
script.js
File metadata and controls
90 lines (86 loc) · 3.08 KB
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
/**
* initialize map and call drawComposition if needed
* @param {boolean} comp is composition selected?
*/
function redrawComposition(comp, curl) {
map = L.map('map').setView([49.8589393, 14.2838466], 15);
lc = new L.Control.Layers().addTo(map);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
if (comp) {
readComposition(curl);
}
}
/**
* @param {JSON} composition JSON with saved composition
*/
function drawComposition(composition) {
map.fitBounds([
[composition.extent[1], composition.extent[0]],
[composition.extent[3], composition.extent[2]]
]);
document.title = composition.title;
for (var l in composition.layers) {
var ccrs = ((composition.layers[l].params.CRS) ? composition.layers[l].params.CRS.replace(':', '') : composition.layers[l].params.FROMCRS.replace(':', ''));
var clayers = composition.layers[l].params.LAYERS;
var copacity = composition.layers[l].opacity;
var ctransparent = composition.layers[l].params.TRANSPARENT;
var cformat = ((composition.layers[l].params.FORMAT) ? composition.layers[l].params.FORMAT : 'image/png');
var options = {layers: clayers,
crs: L.CRS.ccrs,
opacity: copacity,
transparent: ctransparent,
format: cformat
};
var url = decodeURIComponent(composition.layers[l].url);
var wmslayer = L.tileLayer.wms(url, options).addTo(map);
lc.addOverlay(wmslayer, composition.layers[l].title)
}
}
/**
* @param {string} url url of saved composition
*/
function readComposition(courl) {
$.ajax({
url: 'proxy.php',
cache: false,
headers: {
'X-Proxy-URL': courl,
},
dataType: 'json', success: function(data) {
//var data = rj.parse(datain);
drawComposition(data.data);
},
error:function(xhr){
//alert("An error occured: " + xhr.status + " " + xhr.statusText);
if (xhr.status == 200) {
var data = rj.parse(xhr.responseText);
drawComposition(data.data);
}
}
});
}
function getCompositionsList(url) {
var murl = url + "csw/?request=GetRecords?request=GetRecords&query=type%3D'application'&format=application/json&language=eng&maxrecords=200&sortby=";
$.ajax({
url: 'proxy.php',
cache: false,
headers: {
'X-Proxy-URL': murl,
},
dataType: 'json',
success: function(data) {
var selComp = '';
for (var i in data.records) {
if (data.records[i].serviceType == 'WMC') selComp = selComp + '<tr onClick="map.off();map.remove();redrawComposition(true, \'' + data.records[i].link + '\');" class="feature-row" id="' + i + '"><td style="vertical-align: middle;"></td><td class="feature-name">' + data.records[i].title + '</td><td style="vertical-align: middle;"><i class="fa fa-chevron-right pull-right"></i></td></tr>';
}
document.getElementById('cselect').innerHTML = selComp;
}
});
}
$( document ).ready(function() {
getCompositionsList('http://youth.sdi4apps.eu/php/metadata/');
redrawComposition(false, false);
});
var sidebar = L.control.sidebar('sidebar').addTo(map);