-
Notifications
You must be signed in to change notification settings - Fork 0
/
SII.html
149 lines (127 loc) · 4.57 KB
/
SII.html
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
<!DOCTYPE html>
<html>
<head>
<!-- INFORMATION
To get this example application running, make sure to enable CORS on your local geosever by editing the WEB.XML file.
Without doing this the application is not working!-->
<!-- Encoding -->
<meta charset="UTF-8">
<!-- Description of Web Page -->
<meta name="description" content="SII Final Project">
<!-- Keywords important for Google -->
<meta name="keywords" content="Akhil Patil, Pramit Ghosh, Shenaha Savikumar, Raphael Witt, Zhendong Yuan, Geoinformatics, Students">
<!-- Author -->
<meta name="author" content="Akhil Patil, Pramit Ghosh, Shenaha Savikumar, Raphael Witt, Zhendong Yuan">
<!-- Title -->
<title>SII - Final project</title>
<!-- Implementing Leaflet resources and AJAX -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css" integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js" integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log==" crossorigin=""></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Style -->
<style>
#mapid {
height: 450px;
width: 50%;
border-radius: 10px;
border-style: solid;
border-color: gray;
border-width: 0.1px;
position: absolute;
top: 17.5%;
margin-left: 25%;
margin-right: 25%;
}
#left {
position: absolute;
margin-left: 7%;
margin-top: 10%;
}
#button {
position: absolute;
margin-left: 20%;
margin-top: 15%;
}
.buttonstyle {
width: 100px;
height: 35px;
border-radius: 10px;
}
hr {
display: block;
margin-left: auto;
margin-right: auto;
border-style: solid;
border-width: 1px;
color: gray;
}
</style>
</head>
<body>
<!-- Heading -->
<h1 style="text-align:center;font-family: sans-serif">Visualisation of crimes in London</h1>
<hr></hr>
<!-- Controlpanel with date selection and buttons -->
<div id="left">
<input id="startdate" type="date" value="2016-04-01"><br>
<input id="enddate" type="date" value="2016-06-01">
<div id="button">
<button id="showdata" class="buttonstyle">Show Data</button>
<br>
<br>
<button id="removedata" class="buttonstyle" onclick="removeData()">Remove Data</button>
</div>
</div>
<!-- Div container for map -->
<div id="mapid"></div>
<!-- JavaScript -->
<script>
//Creating map
var mymap = L.map('mapid', {zoomControl:true}).setView([51.5197230, -0.098044], 13);
mymap.zoomControl.setPosition('bottomleft');
//Adding a tile layer from OSM
var osmmap = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 20,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a>',
}).addTo(mymap);
//Using public geoserver for retrieving map tiles
var wmsLayer = L.tileLayer.wms('https://demo.boundlessgeo.com/geoserver/ows?', {
layers: 'ne:ne'
}).addTo(mymap);
//Basemap and overlaymap for LayerControl
var baseMaps = {
"Grayscale": wmsLayer
};
var overlayMaps = {
"Streetmap": osmmap,
};
//Adding LayerControl to enable overlay
L.control.layers(baseMaps, overlayMaps).addTo(mymap);
//Creating layer 'crimes'
var crimes = new L.GeoJSON();
//On success and if the layer is not already added to the map, add the data to the layer crimes
function loadGeoJson(data) {
if (mymap.hasLayer(crimes)) {
return false;
} else {
crimes.addData(data);
mymap.addLayer(crimes);
}
};
//When button "showdata" is clicked, retrieve data from local geoserver
$("#showdata").click(function(){
start = document.getElementById("startdate");
end = document.getElementById("enddate");
$.ajax({
url: "http://localhost:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=cite%3Acrimes&outputFormat=application%2Fjson&CQL_FILTER=%22ymonth%22%20AFTER%20" + start.value + "T00%3A00%3A00Z%20AND%20%22ymonth%22%20BEFORE%20" + end.value + "T23%3A59%3A59Z",
jsonCallback: 'getJson',
success: loadGeoJson
});
});
//Function to remove the layer
function removeData(){
mymap.removeLayer(crimes);
}
</script>
</body>
</html>