map.jsp 17.4 KB
Newer Older
1
2
<!DOCTYPE html>

Alexander Basov's avatar
Alexander Basov committed
3
<%@include file="/WEB-INF/jsp/init.jsp" %>
4
5
6

<html>
<head>
Alexander Basov's avatar
Alexander Basov committed
7
    <title><spring:message code="maps.accession-map"/></title>
8
9
</head>
<body>
Alexander Basov's avatar
Alexander Basov committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<cms:informative-h1 title="maps.accession-map" fancy="true" info="maps.accession-map.intro"/>

<div class="main-col-header clearfix">
    <div class="nav-header">
        <div class="pull-right">
            <a class="btn btn-default" href="<c:url value="/explore" />" id="selectArea"><spring:message
                    code="view.accessions"/></a>

            <form style="display: inline-block" method="post" action="<c:url value="/explore/kml" />">
                <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>
        <div class="results">
            <a class="btn btn-default" href="javascript: window.history.go(-1);"><spring:message
                    code="navigate.back"/></a>
        </div>
    </div>
</div>
30

Alexander Basov's avatar
Alexander Basov committed
31
32
33
<div class="applied-filters">
    <ul class="nav nav-pills ">
        <li style="margin-left: 5px" class="active dropdown form-horizontal pull-right">
igoshin's avatar
igoshin committed
34

Alexander Basov's avatar
Alexander Basov committed
35
            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><spring:message code="mapproviders.list"/></a>
igoshin's avatar
igoshin committed
36

Alexander Basov's avatar
Alexander Basov committed
37
38
39
40
41
42
43
44
            <ul class="dropdown-menu">
                <li>
                    <label><input class="map-provider" name="provider" style='margin-right: 10px;margin-left: 5px'
                                  type='radio'>MapQuest</label>
                    <label><input name="provider" class="map-provider" style='margin-right: 10px;margin-left: 5px'
                                  type='radio'>Openstreetmap</label>
                </li>
            </ul>
igoshin's avatar
igoshin committed
45

Alexander Basov's avatar
Alexander Basov committed
46
        </li>
igoshin's avatar
igoshin committed
47

Alexander Basov's avatar
Alexander Basov committed
48
        <li class="active dropdown form-horizontal pull-right">
igoshin's avatar
igoshin committed
49

Alexander Basov's avatar
Alexander Basov committed
50
            <a id="get-filters" href="#"><spring:message code="savedmaps.list"/></a>
igoshin's avatar
igoshin committed
51

Alexander Basov's avatar
Alexander Basov committed
52
            <ul id="enabled-filters" class="dropdown-menu"></ul>
igoshin's avatar
igoshin committed
53

Alexander Basov's avatar
Alexander Basov committed
54
        </li>
igoshin's avatar
igoshin committed
55

Alexander Basov's avatar
Alexander Basov committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        <li style="margin-right: 5px" class="active form-horizontal pull-right" data-toggle="modal"
            data-target="#modal-dialog">
            <a href="#"><spring:message code="savedmaps.save"/></a>
        </li>
    </ul>
</div>

<!-- Modal -->
<div class="modal fade" id="modal-dialog" tabindex="-1" role="dialog" aria-labelledby="modal-label" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="modal-label"><spring:message code="savedmaps.save"/></h4>
            </div>
            <div class="modal-body">
                <input type="text" class="form-control" placeholder="<spring:message code="filter.enter.title"/>"
                       id="filter-title">

                <div id="color">
                    <select name="colorpicker">
78
79
80
81
82
83
84
85
86
87
88
89
                        <option value="#7bd148">#7bd148</option>
                        <option value="#5484ed">#5484ed</option>
                        <option value="#a4bdfc">#a4bdfc</option>
                        <option value="#46d6db">#46d6db</option>
                        <option value="#7ae7bf">#7ae7bf</option>
                        <option value="#51b749">#51b749</option>
                        <option value="#fbd75b">#fbd75b</option>
                        <option value="#ffb878">#ffb878</option>
                        <option value="#ff887c">#ff887c</option>
                        <option value="#dc2127">#dc2127</option>
                        <option value="#dbadff">#dbadff</option>
                        <option value="#e1e1e1">#e1e1e1</option>
Alexander Basov's avatar
Alexander Basov committed
90
                    </select>
igoshin's avatar
igoshin committed
91
92
                </div>
            </div>
Alexander Basov's avatar
Alexander Basov committed
93
94
95
96
97
98
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal"><spring:message
                        code="cancel"/></button>
                <button id="save-filter" type="button" class="btn btn-primary" data-dismiss="modal"><spring:message
                        code="save"/></button>
            </div>
igoshin's avatar
igoshin committed
99
100
        </div>
    </div>
Alexander Basov's avatar
Alexander Basov committed
101
102
</div>
<%--End modal--%>
igoshin's avatar
igoshin committed
103

Alexander Basov's avatar
Alexander Basov committed
104
105
106
107
108
<div class="row">
    <div class="col-sm-12">
        <div id="map" class="gis-map gis-map-square"></div>
    </div>
</div>
109
110
111


<content tag="javascript">
Alexander Basov's avatar
Alexander Basov committed
112
113
114
115
116
117
118
119
    <script type="text/javascript">
        jQuery(document).ready(function () {

            var map = L.map('map').setView([20, 0], 2);
            var mapProviders = {
                Openstreetmap: L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
                }),
Alexander Basov's avatar
Alexander Basov committed
120
121
122
123
                /*  OpenMapSurfer_Grayscale: L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}', {
                 maxZoom: 19,
                 attribution: 'Imagery from <a target="_blank" href="http://giscience.uni-hd.de/">GIScience Research Group, University of Heidelberg</a>, Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
                 }),*/
Alexander Basov's avatar
Alexander Basov committed
124
125
126
127
128
129
                MapQuest: 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
                })
Alexander Basov's avatar
Alexander Basov committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
                /*Stamen_TonerLines: L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lines/{z}/{x}/{y}.png', {
                 attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
                 subdomains: 'abcd',
                 opacity: 0.3,
                 minZoom: 0,
                 maxZoom: 20,
                 ext: 'png'
                 }),

                 Acetate_labels: L.tileLayer('http://a{s}.acetate.geoiq.com/tiles/acetate-labels/{z}/{x}/{y}.png', {
                 attribution: '&copy;2012 Esri & Stamen, Data from OSM and Natural Earth',
                 subdomains: '0123',
                 opacity: 0.6,
                 minZoom: 2,
                 maxZoom: 18
                 })*/
Alexander Basov's avatar
Alexander Basov committed
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
179
180
181
182
183
184
185
186
187
188
            };

            var cookieUtils = {
                getCookie: function (name) {
                    var matches = document.cookie.match(new RegExp(
                            "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
                    ));
                    return matches ? decodeURIComponent(matches[1]) : undefined;
                },
                setCookie: function (name, value, options) {
                    options = options || {};

                    var expires = options.expires;

                    if (typeof expires == "number" && expires) {
                        var d = new Date();
                        d.setTime(d.getTime() + expires * 1000);
                        expires = options.expires = d;
                    }
                    if (expires && expires.toUTCString) {
                        options.expires = expires.toUTCString();
                    }

                    value = encodeURIComponent(value);

                    var updatedCookie = name + "=" + value;

                    for (var propName in options) {
                        updatedCookie += "; " + propName;
                        var propValue = options[propName];
                        if (propValue !== true) {
                            updatedCookie += "=" + propValue;
                        }
                    }

                    document.cookie = updatedCookie;
                },
                deleteCookie: function (name) {
                    this.setCookie(name, "", {
                        expires: -1
                    })
                }
            };
Alexander Basov's avatar
Alexander Basov committed
189
190
191
            if (cookieUtils.getCookie('mapProviders') && cookieUtils.getCookie('mapProviders') != '') {
                mapProviders[cookieUtils.getCookie('mapProviders')].addTo(map);
            } else {
Alexander Basov's avatar
Alexander Basov committed
192
193
                mapProviders.MapQuest.addTo(map);
            }
Alexander Basov's avatar
Alexander Basov committed
194
195
            $(document).on('cookieUpdate', function () {
                for (var key in mapProviders) {
Alexander Basov's avatar
Alexander Basov committed
196
197
                    map.removeLayer(mapProviders[key]);
                }
Alexander Basov's avatar
Alexander Basov committed
198
199
200
                if (cookieUtils.getCookie('mapProviders')) {
                    mapProviders[cookieUtils.getCookie('mapProviders')].addTo(map);
                } else {
Alexander Basov's avatar
Alexander Basov committed
201
202
203
204
                    mapProviders.MapQuest.addTo(map);
                }
            });
            $("body").on("click", ".map-provider", function (e) {
Alexander Basov's avatar
Alexander Basov committed
205
206
207
208
209
                var providerName = $(this).parent().text();
                console.log($(this).parent().text());
                console.log(providerName);
                if ($(this).is(":checked")) {
                    cookieUtils.setCookie('mapProviders', providerName, 0);
Alexander Basov's avatar
Alexander Basov committed
210
211
                    $(document).trigger('cookieUpdate');
                } else {
Alexander Basov's avatar
Alexander Basov committed
212
213
                    providerName = '';
                    cookieUtils.setCookie('mapProviders', providerName, 0);
Alexander Basov's avatar
Alexander Basov committed
214
215
                    $(document).trigger('cookieUpdate');
                }
igoshin's avatar
igoshin committed
216

Alexander Basov's avatar
Alexander Basov committed
217
218
            });
            $('#color select').simplecolorpicker();
igoshin's avatar
igoshin committed
219

Alexander Basov's avatar
Alexander Basov committed
220
            $("#save-filter").on("click", function (event) {
igoshin's avatar
igoshin committed
221
222
223
                event.preventDefault();

                var title = $("#filter-title").val();
Alexander Basov's avatar
Alexander Basov committed
224
                var filter =${jsonFilter};
igoshin's avatar
igoshin committed
225
226

                $.ajax({
Alexander Basov's avatar
Alexander Basov committed
227
228
229
                    url: "/savedmaps/save",
                    type: "post",
                    dataType: "json",
igoshin's avatar
igoshin committed
230
                    contentType: 'application/json; charset=utf-8',
Alexander Basov's avatar
Alexander Basov committed
231
232
233
                    data: JSON.stringify({
                        title: title,
                        filter: JSON.stringify(filter),
234
                        color: $('#color select').val()
igoshin's avatar
igoshin committed
235
                    }),
Alexander Basov's avatar
Alexander Basov committed
236
                    success: function (data) {
igoshin's avatar
igoshin committed
237
                    },
Alexander Basov's avatar
Alexander Basov committed
238
                    error: function (error) {
igoshin's avatar
igoshin committed
239
240
241
242
243
                        console.log(error)
                    }
                });
            });

Alexander Basov's avatar
Alexander Basov committed
244
            $("#get-filters").on("click", function (event) {
igoshin's avatar
igoshin committed
245
246
                event.preventDefault();
                $.ajax({
247
                    url: "/savedmaps/get",
igoshin's avatar
igoshin committed
248
249
250
251
252
253
                    type: "get",
                    dataType: "json",
                    contentType: 'application/json; charset=utf-8',
                    success: function (data) {
                        $.each(data, function (idx, filter) {

Alexander Basov's avatar
Alexander Basov committed
254
                            var li = "<li><label  class='saved-filter' x-fil='" + filter.filter + "' x-color='" + filter.color + "'><input style='margin-right: 10px;margin-left: 5px' type='checkbox'>" + filter.title + "</label></li>";
igoshin's avatar
igoshin committed
255

igoshin's avatar
igoshin committed
256
257
                            if ($("#enabled-filters").is(":visible")) {
                                $("#enabled-filters").append(li);
igoshin's avatar
igoshin committed
258
                            } else {
igoshin's avatar
igoshin committed
259
                                $("#enabled-filters").empty();
igoshin's avatar
igoshin committed
260
261
262
                            }
                        });
                    },
Alexander Basov's avatar
Alexander Basov committed
263
                    error: function (error) {
igoshin's avatar
igoshin committed
264
265
266
                        console.log(error)
                    }
                });
igoshin's avatar
igoshin committed
267
                $("#enabled-filters").toggle();
igoshin's avatar
igoshin committed
268
269
            });

Alexander Basov's avatar
Alexander Basov committed
270
271
272
273
274
275
276
            L.tileLayer("{s}/explore/tile/{z}/{x}/{y}?filter=" + '${jsonFilter}', {
                attribution: "Accession localities from <a href='${props.baseUrl}'>Genesys PGR</a>",
                styleId: 22677,
                subdomains: [${props.tileserverCdn}]
            }).addTo(map);

            $("#selectArea").hide();
igoshin's avatar
igoshin committed
277
            var filterJson =${jsonFilter};
igoshin's avatar
igoshin committed
278
279
280
            var filterJsonObj = {};
            if (typeof filterJson !== 'undefined') {
                filterJsonObj = JSON.parse(JSON.stringify(filterJson));
igoshin's avatar
igoshin committed
281

igoshin's avatar
igoshin committed
282
283
284
            }


Alexander Basov's avatar
Alexander Basov committed
285
            var layers = {};
286
            $("body").on("click", ".saved-filter", function (e) {
igoshin's avatar
igoshin committed
287
                var title = $(this).text();
288
289
                var filter = $(this).attr("x-fil");
                var tilesColor = $(this).attr("x-color").substring(1);
Alexander Basov's avatar
Alexander Basov committed
290
                var savedFilterObj = JSON.parse(filter);
igoshin's avatar
igoshin committed
291
292

                if ($(this).find("input:checkbox").is(":checked")) {
Alexander Basov's avatar
Alexander Basov committed
293
294
295
296
297
298
299
                    if (layers[title] == null) {
                        layers[title] = L.tileLayer("{s}/explore/tile/{z}/{x}/{y}?filter=" + filter + "&color=" + tilesColor, {
                            attribution: "<a href='${props.baseUrl}'>Genesys</a>",
                            styleId: 22677,
                            subdomains: [${props.tileserverCdn}]
                        }).addTo(map);
                    }
igoshin's avatar
igoshin committed
300
                } else {
Alexander Basov's avatar
Alexander Basov committed
301
302
303
304
                    if (layers[title] != null) {
                        map.removeLayer(layers[title]);
                        layers[title] = null;
                    }
igoshin's avatar
igoshin committed
305
306
                }

igoshin's avatar
igoshin committed
307
308
            });

Alexander Basov's avatar
Alexander Basov committed
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
            var locationFilter = new L.LocationFilter({
                adjustButton: false,
                bounds: map.getBounds().pad(-0.1)
            }).addTo(map);
            locationFilter.on("change", function (e) {
                // Do something when the bounds change.
                // Bounds are available in `e.bounds`.
                var bounds = locationFilter.getBounds();
                filterJson['geo.latitude'] = [{range: [bounds.getSouth(), bounds.getNorth()]}];
                filterJson['geo.longitude'] = [{range: [bounds.getWest(), bounds.getEast()]}];
            });

            map.on("viewreset", function () {
                if (locationFilter.isEnabled())
                    return;
                var mapBounds = map.getBounds().pad(-0.1);
                locationFilter.setBounds(mapBounds);
            });
            locationFilter.on("enabled", function () {
                // Do something when enabled.
                var bounds = locationFilter.getBounds();
                filterJson['geo.latitude'] = [{range: [bounds.getSouth(), bounds.getNorth()]}];
                filterJson['geo.longitude'] = [{range: [bounds.getWest(), bounds.getEast()]}];
                $("#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);
            });

            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 = filterJsonObj;
igoshin's avatar
igoshin committed
366
                        console.log(filterBounds)
Alexander Basov's avatar
Alexander Basov committed
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
                        filterBounds['geo.latitude'] = [{range: [sw.lat, ne.lat]}];
                        filterBounds['geo.longitude'] = [{range: [sw.lng, ne.lng]}];
                        //console.log(JSON.stringify(filterBounds));
                        $.ajax("<c:url value="/explore/geoJson"><c:param name="limit" value="11" /></c:url>&filter=" + JSON.stringify(filterBounds), {
                            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;
                }
            });
        });
    </script>
405
406
407
</content>
</body>
</html>