map.jsp 4.71 KB
Newer Older
1
2
3
4
5
6
<!DOCTYPE html>

<%@include file="/WEB-INF/jsp/init.jsp"%>

<html>
<head>
Matija Obreza's avatar
Matija Obreza committed
7
<title><spring:message code="maps.accession-map" /></title>
8
9
10
</head>
<body>
	<h1>
Matija Obreza's avatar
Matija Obreza committed
11
		<spring:message code="maps.accession-map" />
12
13
	</h1>

Matija Obreza's avatar
Matija Obreza committed
14
15
	<div class="main-col-header clearfix">
	<div class="nav-header">
16
17
		<div class="pull-right">
			<a class="btn btn-default" href="<c:url value="/explore" />" id="selectArea"><spring:message code="view.accessions" /></a>
18
			<form style="display: inline-block" method="post" action="/explore/kml">
19
20
21
22
23
				<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
				<input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />" />
				<button class="btn btn-default" type="submit"><spring:message code="download.kml" /></button>
			</form>
		</div>
Matija Obreza's avatar
Matija Obreza committed
24
25
26
27
		<div class="results">
			<a href="javascript: window.history.go(-1);"><spring:message code="navigate.back" /></a>
		</div>
	</div>
28
	</div>
Matija Obreza's avatar
Matija Obreza committed
29
	
30
	<div class="row">
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
		<div class="col-sm-12">
			<div id="map" class="gis-map gis-map-square"></div>
		</div>
	</div>


<content tag="javascript">
		<script type="text/javascript">
		jQuery(document).ready(function() {	
			var map = L.map('map').setView([20,0], 2);
			L.tileLayer('https://otile{s}-s.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.png', {
			    attribution: "MapQuest",
			    styleId: 22677,
			    subdomains: ['1','2','3','4'],
			    opacity: 0.6
			}).addTo(map);
Matija Obreza's avatar
Matija Obreza committed
47
			L.tileLayer("{s}/explore/tile/{z}/{x}/{y}?filter=" + '${jsonFilter}', {
Matija Obreza's avatar
Matija Obreza committed
48
			    attribution: "<a href='${props.baseUrl}'>Genesys</a>",
49
			    styleId: 22677,
Matija Obreza's avatar
Matija Obreza committed
50
			    subdomains: [${props.tileserverCdn}]
51
			}).addTo(map);
52

53
54
55
			 $("#selectArea").hide();
			var filterJson=${jsonFilter};
			
56
57
			
			var locationFilter = new L.LocationFilter({adjustButton: false, bounds: map.getBounds().pad(-0.1) }).addTo(map);
58
59
60
61
62
63
64
65
			locationFilter.on("change", function (e) {
			    // Do something when the bounds change.
			    // Bounds are available in `e.bounds`.
				var bounds=locationFilter.getBounds();	
				filterJson.latitude=[{range:[bounds.getSouth(),bounds.getNorth()]}];
				filterJson.longitude=[{range:[bounds.getWest(),bounds.getEast()]}];
			});
			
66
67
68
69
70
71
			map.on("viewreset", function() {
				if (locationFilter.isEnabled())
					return;
				var mapBounds=map.getBounds().pad(-0.1);
				locationFilter.setBounds(mapBounds);
			});
72
73
			locationFilter.on("enabled", function () {
			    // Do something when enabled.
Matija Obreza's avatar
Matija Obreza committed
74
75
76
				var bounds=locationFilter.getBounds();	
				filterJson.latitude=[{range:[bounds.getSouth(),bounds.getNorth()]}];
				filterJson.longitude=[{range:[bounds.getWest(),bounds.getEast()]}];
77
78
79
80
81
82
83
84
85
86
87
			    $("#selectArea").show();
			});
			
			locationFilter.on("disabled", function () {
			    // Do something when disabled.
			    $("#selectArea").hide();
			});
			
			$("#selectArea").on("click", function(e) {
				this.href=this.href+'?filter='+JSON.stringify(filterJson);
			});
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
			
			var loadDetailsTimeout = null;
			var clickMarker=null;
			map.on("click", function(e) {
				if (clickMarker!=null) {
					map.removeLayer(clickMarker);
					clickMarker=null;
				}
				if (map.getZoom()>4) {
					if (loadDetailsTimeout!=null) {
						clearTimeout(loadDetailsTimeout);
					}
					
					var point=this.latLngToLayerPoint(e.latlng);
					point.x-=5; point.y+=5;
					var sw=this.layerPointToLatLng(point);
					point.x+=10; point.y-=10;
					var ne=this.layerPointToLatLng(point);
					loadDetailsTimeout=setTimeout(function() {
						var filterBounds=JSON.parse(JSON.stringify(filterJson));
						filterBounds.latitude=[{range:[sw.lat, ne.lat]}];
						filterBounds.longitude=[{range:[sw.lng, ne.lng]}];
						//console.log(JSON.stringify(filterBounds));
Matija Obreza's avatar
Matija Obreza committed
111
						$.ajax("<c:url value="/explore/geoJson"><c:param name="limit" value="11" /></c:url>&filter="+JSON.stringify(filterBounds), {
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
							type : "GET",
							dataType : 'json',
							success : function(respObject) {
								if (respObject.features == null || respObject.features.length == 0)
									return;
								
								var c="";
								respObject.features.forEach(function(a, b) {
									if (b<10)
										c+="<a href='<c:url value="/acn/id/" />" + a.id + "'>" + a.properties.acceNumb + " " + a.properties.instCode + "</a><br />";
									else
										c+="...";
								});
								clickMarker=L.rectangle([sw, ne], {stroke: false, fill: true}).addTo(map);
								clickMarker.bindPopup(c).openPopup();
							},
							error: function(jqXHR, textStatus, errorThrown) {
								console.log(textStatus);
								console.log(errorThrown);
							}
						});
						
					}, 200);
				}
			});
			map.on("dblclick", function(e) {
				if (loadDetailsTimeout!=null) {
					//console.log("cleared" + loadDetailsTimeout);
					clearTimeout(loadDetailsTimeout);
					loadDetailsTimeout=null;
				}
			});
144
145
146
147
148
		});
		</script>
</content>
</body>
</html>