Commit 5140825 1 parent 368d52e commit 5140825 Copy full SHA for 5140825
File tree 1 file changed +27
-1
lines changed
cookbooks/imagery/templates/default
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
1
< % require 'uri' % >
2
+ function getUrlParams ( ) {
3
+ const params = { } ;
4
+ const queryString = window . location . search . substring ( 1 ) ;
5
+ const regex = / ( [ ^ & = ] + ) = ( [ ^ & ] * ) / g;
6
+ let match ;
7
+
8
+ while ( match = regex . exec ( queryString ) ) {
9
+ params [ decodeURIComponent ( match [ 1 ] ) ] = decodeURIComponent ( match [ 2 ] ) ;
10
+ }
11
+
12
+ return params ;
13
+ }
14
+
2
15
function createMap ( divName ) {
16
+ // Get URL parameters
17
+ const params = getUrlParams ( ) ;
18
+ const lon = params . lon ? parseFloat ( params . lon ) : null ;
19
+ const lat = params . lat ? parseFloat ( params . lat ) : null ;
20
+ const zoom = params . zoom ? parseInt ( params . zoom ) : null ;
21
+
3
22
// Create a map
4
23
var map = L . map ( divName , {
5
24
worldCopyJump : true
6
- } ) . fitBounds ( < %= @bbox . to_json % > ) ;
25
+ } ) ;
26
+
27
+ // Set initial view if URL parameters are available, otherwise fitBounds
28
+ if ( lat !== null && lon !== null && zoom !== null ) {
29
+ map . setView ( [ lat , lon ] , zoom ) ;
30
+ } else {
31
+ map . fitBounds ( < %= @bbox . to_json % > ) ;
32
+ }
7
33
8
34
// Create a layer switcher
9
35
var layers = L . control . layers ( null , null , { collapsed :false } ) . addTo ( map ) ;
You can’t perform that action at this time.
0 commit comments