@@ -9,6 +9,10 @@ var App = (function ($, publ) {
9
9
var map , vector , bounds , contents , toolbar , geolocation = null ;
10
10
var features = [ ] ;
11
11
var layerArr = [ ] ;
12
+ var filters = {
13
+ location : false ,
14
+ distance : false
15
+ } ;
12
16
13
17
// Quick hack
14
18
var quick_hack = {
@@ -149,15 +153,14 @@ var App = (function ($, publ) {
149
153
this . setView ( ) ;
150
154
this . setGeolocation ( ) ;
151
155
this . setGeocoding ( ) ;
152
- this . zoomToExtent ( ) ;
153
156
this . parseHistory ( ) ;
154
157
155
158
// Control button
156
159
var maximizeCtrl = new ol . control . Button ( {
157
160
html : '<i class="icon-maximize" ></i>' ,
158
161
title : "Maximize" ,
159
162
handleClick : function ( ) {
160
- publ . zoomToExtent ( ) ;
163
+ publ . zoomToExtent ( true ) ;
161
164
}
162
165
} ) ;
163
166
toolbar . addControl ( maximizeCtrl ) ;
@@ -194,8 +197,19 @@ var App = (function ($, publ) {
194
197
// Add LayerSwitcher Image Toolbar
195
198
map . addControl ( new ol . control . LayerPopup ( ) ) ;
196
199
197
- // Add map events
198
- map . on ( 'moveend' , publ . updateFilter ) ;
200
+ // Because Redmine filter functions are applied later, the Window onload
201
+ // event provides a workaround to have filters loaded before executing
202
+ // the following code
203
+ $ ( window ) . bind ( 'load' , function ( ) {
204
+ if ( $ ( "tr#tr_bbox" ) . length > 0 ) {
205
+ filters . location = true ;
206
+ }
207
+ if ( $ ( "tr#tr_distance" ) . length > 0 ) {
208
+ filters . distance = true ;
209
+ }
210
+ publ . zoomToExtent ( ) ;
211
+ map . on ( 'moveend' , publ . updateFilter ) ;
212
+ } ) ;
199
213
} ;
200
214
201
215
/**
@@ -204,7 +218,7 @@ var App = (function ($, publ) {
204
218
publ . setBasemap = function ( layers ) {
205
219
206
220
if ( layers . length === 0 ) {
207
- console . error ( "There is no baselayer availaable !" ) ;
221
+ console . error ( "There is no baselayer available !" ) ;
208
222
return ;
209
223
}
210
224
@@ -326,8 +340,18 @@ var App = (function ($, publ) {
326
340
/**
327
341
*
328
342
*/
329
- publ . zoomToExtent = function ( ) {
330
- if ( vector . getSource ( ) . getFeatures ( ) . length > 0 ) {
343
+ publ . zoomToExtent = function ( force ) {
344
+ if ( ! force && ( filters . distance || filters . location ) ) {
345
+ // Do not zoom to extent but show the previous extent stored as cookie
346
+ var parts = ( getCookie ( "_redmine_gtt_permalink" ) ) . split ( "/" ) ;
347
+ map . getView ( ) . setZoom ( parseInt ( parts [ 0 ] , 10 ) ) ;
348
+ map . getView ( ) . setCenter ( ol . proj . transform ( [
349
+ parseFloat ( parts [ 1 ] ) ,
350
+ parseFloat ( parts [ 2 ] )
351
+ ] , 'EPSG:4326' , 'EPSG:3857' ) ) ;
352
+ map . getView ( ) . setRotation ( parseFloat ( parts [ 3 ] ) ) ;
353
+ }
354
+ else if ( vector . getSource ( ) . getFeatures ( ) . length > 0 ) {
331
355
var extent = ol . extent . createEmpty ( ) ;
332
356
// Because the vector layer is set to "useSpatialIndex": false, we cannot
333
357
// make use of "vector.getSource().getExtent()"
@@ -354,14 +378,23 @@ var App = (function ($, publ) {
354
378
var extent = map . getView ( ) . calculateExtent ( map . getSize ( ) ) ;
355
379
356
380
center = ol . proj . transform ( center , 'EPSG:3857' , 'EPSG:4326' ) ;
357
- console . log ( "Map Center (WGS84): " , center ) ;
381
+ // console.log("Map Center (WGS84): ", center);
358
382
$ ( 'fieldset#location' ) . data ( 'center' , center ) ;
359
383
$ ( '#tr_distance #values_distance_3' ) . val ( center [ 0 ] ) ;
360
384
$ ( '#tr_distance #values_distance_4' ) . val ( center [ 1 ] ) ;
361
385
386
+ // Set Permalink as Cookie
387
+ var cookie = [ ] ;
388
+ var hash = map . getView ( ) . getZoom ( ) + '/' +
389
+ Math . round ( center [ 0 ] * 1000000 ) / 1000000 + '/' +
390
+ Math . round ( center [ 1 ] * 1000000 ) / 1000000 + '/' +
391
+ map . getView ( ) . getRotation ( ) ;
392
+ cookie . push ( "_redmine_gtt_permalink=" + hash ) ;
393
+ cookie . push ( "path=" + window . location . pathname ) ;
394
+ document . cookie = cookie . join ( ";" ) ;
362
395
363
396
extent = ol . proj . transformExtent ( extent , 'EPSG:3857' , 'EPSG:4326' ) . join ( '|' ) ;
364
- console . log ( "Map Extent (WGS84): " , extent ) ;
397
+ // console.log("Map Extent (WGS84): ",extent);
365
398
$ ( 'select[name="v[bbox][]"]' ) . find ( 'option' ) . first ( ) . val ( extent ) ;
366
399
// adjust the value of the 'On map' option tag
367
400
// Also adjust the JSON data that's the basis for building the filter row
@@ -730,15 +763,14 @@ function buildDistanceFilterRow(operator, values){
730
763
}
731
764
var x , y ;
732
765
if ( values . length > 2 ) {
733
- console . log ( 'distance center point from values: ' , values [ base_idx ] , values [ base_idx + 1 ] ) ;
766
+ // console.log('distance center point from values: ', values[base_idx], values[base_idx+1]);
734
767
x = values [ base_idx ] ;
735
768
y = values [ base_idx + 1 ] ;
736
769
} else {
737
- console . log ( 'taking distance from map fieldset: ' , $ ( 'fieldset#location' ) . data ( 'center' ) ) ;
770
+ // console.log('taking distance from map fieldset: ', $('fieldset#location').data('center'));
738
771
var xy = $ ( 'fieldset#location' ) . data ( 'center' ) ;
739
772
x = xy [ 0 ] ; y = xy [ 1 ] ;
740
773
}
741
774
$ ( '#values_' + fieldId + '_3' ) . val ( x ) ;
742
775
$ ( '#values_' + fieldId + '_4' ) . val ( y ) ;
743
776
}
744
-
0 commit comments