map.jsp 18.1 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 id="get-providers" href="#"><spring:message code="mapproviders.list"/></a>
igoshin's avatar
igoshin committed
36

Alexander Basov's avatar
Alexander Basov committed
37
            <ul id="enabled-providers" class="dropdown-menu"></ul>
igoshin's avatar
igoshin committed
38

Alexander Basov's avatar
Alexander Basov committed
39
        </li>
igoshin's avatar
igoshin committed
40

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

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

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

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

Alexander Basov's avatar
Alexander Basov committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
        <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">
71
72
73
74
75
76
77
78
79
80
81
82
                        <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
83
                    </select>
igoshin's avatar
igoshin committed
84
85
                </div>
            </div>
Alexander Basov's avatar
Alexander Basov committed
86
87
88
89
90
91
            <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
92
93
        </div>
    </div>
Alexander Basov's avatar
Alexander Basov committed
94
95
</div>
<%--End modal--%>
igoshin's avatar
igoshin committed
96

Alexander Basov's avatar
Alexander Basov committed
97
98
99
100
101
<div class="row">
    <div class="col-sm-12">
        <div id="map" class="gis-map gis-map-square"></div>
    </div>
</div>
102
103
104


<content tag="javascript">
Alexander Basov's avatar
Alexander Basov committed
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    <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>'
                }),
                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>'
                }),
                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
                }),
                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
                })
            };
            for(var key in mapProviders){
                var li = "<li><label  class='map-provider'><input style='margin-right: 10px;margin-left: 5px' type='checkbox'>" + key + "</label></li>";
                $('#enabled-providers').append(li);
            }
            $('#get-providers').on('click', function(){
                $('#enabled-providers').toggle();
            });

            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
                    })
                }
            };
//            cookieUtils.deleteCookie('mapProviders');
            if(cookieUtils.getCookie('mapProviders') && cookieUtils.getCookie('mapProviders')!=''){
                cookieUtils.getCookie('mapProviders').split(',').forEach(function(provider){
                    [].forEach.call($('.map-provider'), function(li){
                        if($(li).text() == provider){
                            $(li).find('input:checkbox').prop('checked', true);
                        }else{
                            $(li).find('input:checkbox').prop('checked', false);
                        }
                    });
                    mapProviders[provider].addTo(map);
                });
            }else{
                mapProviders.MapQuest.addTo(map);
            }
            $(document).on('cookieUpdate', function(){
                for(var key in mapProviders){
                    map.removeLayer(mapProviders[key]);
                }
                if(cookieUtils.getCookie('mapProviders')){
                    cookieUtils.getCookie('mapProviders').split(',').forEach(function(provider){
                        mapProviders[provider].addTo(map);
                    });
                }else{
                    mapProviders.MapQuest.addTo(map);
                }
            });
            $("body").on("click", ".map-provider", function (e) {
                var title = $(this).text();
                var providers = cookieUtils.getCookie('mapProviders') && cookieUtils.getCookie('mapProviders')!=''?cookieUtils.getCookie('mapProviders').split(','):[];

                if ($(this).find("input:checkbox").is(":checked")) {
                    providers.push(title);
                    cookieUtils.setCookie('mapProviders', providers, 0);
                    $(document).trigger('cookieUpdate');
                } else {
                    providers.splice(providers.indexOf(title), 1);
                    cookieUtils.setCookie('mapProviders', providers, 0);
                    $(document).trigger('cookieUpdate');
                }
igoshin's avatar
igoshin committed
229

Alexander Basov's avatar
Alexander Basov committed
230
231
            });
            $('#color select').simplecolorpicker();
igoshin's avatar
igoshin committed
232

Alexander Basov's avatar
Alexander Basov committed
233
            $("#save-filter").on("click", function (event) {
igoshin's avatar
igoshin committed
234
235
236
                event.preventDefault();

                var title = $("#filter-title").val();
Alexander Basov's avatar
Alexander Basov committed
237
                var filter =${jsonFilter};
igoshin's avatar
igoshin committed
238
239

                $.ajax({
Alexander Basov's avatar
Alexander Basov committed
240
241
242
                    url: "/savedmaps/save",
                    type: "post",
                    dataType: "json",
igoshin's avatar
igoshin committed
243
                    contentType: 'application/json; charset=utf-8',
Alexander Basov's avatar
Alexander Basov committed
244
245
246
                    data: JSON.stringify({
                        title: title,
                        filter: JSON.stringify(filter),
247
                        color: $('#color select').val()
igoshin's avatar
igoshin committed
248
                    }),
Alexander Basov's avatar
Alexander Basov committed
249
                    success: function (data) {
igoshin's avatar
igoshin committed
250
                    },
Alexander Basov's avatar
Alexander Basov committed
251
                    error: function (error) {
igoshin's avatar
igoshin committed
252
253
254
255
256
                        console.log(error)
                    }
                });
            });

Alexander Basov's avatar
Alexander Basov committed
257
            $("#get-filters").on("click", function (event) {
igoshin's avatar
igoshin committed
258
259
                event.preventDefault();
                $.ajax({
260
                    url: "/savedmaps/get",
igoshin's avatar
igoshin committed
261
262
263
264
265
266
                    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
267
                            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
268

igoshin's avatar
igoshin committed
269
270
                            if ($("#enabled-filters").is(":visible")) {
                                $("#enabled-filters").append(li);
igoshin's avatar
igoshin committed
271
                            } else {
igoshin's avatar
igoshin committed
272
                                $("#enabled-filters").empty();
igoshin's avatar
igoshin committed
273
274
275
                            }
                        });
                    },
Alexander Basov's avatar
Alexander Basov committed
276
                    error: function (error) {
igoshin's avatar
igoshin committed
277
278
279
                        console.log(error)
                    }
                });
igoshin's avatar
igoshin committed
280
                $("#enabled-filters").toggle();
igoshin's avatar
igoshin committed
281
282
            });

Alexander Basov's avatar
Alexander Basov committed
283
284
285
286
287
288
289
            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
290
            var filterJson =${jsonFilter};
igoshin's avatar
igoshin committed
291
292
293
            var filterJsonObj = {};
            if (typeof filterJson !== 'undefined') {
                filterJsonObj = JSON.parse(JSON.stringify(filterJson));
igoshin's avatar
igoshin committed
294

igoshin's avatar
igoshin committed
295
296
297
            }


Alexander Basov's avatar
Alexander Basov committed
298
            var layers = {};
299
            $("body").on("click", ".saved-filter", function (e) {
igoshin's avatar
igoshin committed
300
                var title = $(this).text();
301
302
                var filter = $(this).attr("x-fil");
                var tilesColor = $(this).attr("x-color").substring(1);
Alexander Basov's avatar
Alexander Basov committed
303
                var savedFilterObj = JSON.parse(filter);
igoshin's avatar
igoshin committed
304
305

                if ($(this).find("input:checkbox").is(":checked")) {
Alexander Basov's avatar
Alexander Basov committed
306
307
308
309
310
311
312
                    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
313
                } else {
Alexander Basov's avatar
Alexander Basov committed
314
315
316
317
                    if (layers[title] != null) {
                        map.removeLayer(layers[title]);
                        layers[title] = null;
                    }
igoshin's avatar
igoshin committed
318
319
                }

igoshin's avatar
igoshin committed
320
321
            });

Alexander Basov's avatar
Alexander Basov committed
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
366
367
368
369
370
371
372
373
374
375
376
377
378
            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
379
                        console.log(filterBounds)
Alexander Basov's avatar
Alexander Basov committed
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
405
406
407
408
409
410
411
412
413
414
415
416
417
                        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>
418
419
420
</content>
</body>
</html>