File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
lib/components/data-vis/map
wrappers/components/data-vis/map Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 25
25
quantileBreaks ,
26
26
} from " ./mapUtils.js" ;
27
27
import NonStandardControls from " ./NonStandardControls.svelte" ;
28
+ import { replaceState } from " $app/navigation" ;
28
29
29
30
import { joinData } from " ./dataJoin" ;
31
+ import { page } from " $app/state" ;
30
32
31
33
let {
32
34
data,
57
59
hoverOpacity = 0.8 ,
58
60
center = [- 2.5 , 53 ],
59
61
zoom = 5 ,
62
+ hash = false ,
63
+ updateHash = (u ) => {
64
+ replaceState (u , page .state );
65
+ },
60
66
mapHeight = 200 ,
61
67
} = $props ();
62
68
188
194
]);
189
195
}
190
196
}
197
+ // Even if hash is false, if the page is loaded with a location hash use that as the initial settings, rather than than the values passed to the component
198
+ const initialLocationHash = page .url .hash .replace (" #" , " " ).split (" /" );
199
+ const useLocationHash = initialLocationHash .length >= 3 ? true : false ;
191
200
</script >
192
201
193
202
<div style ="height: {mapHeight }px;" >
196
205
bind:loaded
197
206
{style }
198
207
{standardControls }
199
- {center }
200
- {zoom }
208
+ center ={useLocationHash
209
+ ? [initialLocationHash [2 ], initialLocationHash [1 ]]
210
+ : center }
211
+ zoom ={useLocationHash ? initialLocationHash [0 ] : zoom }
212
+ {hash }
213
+ {updateHash }
201
214
class =" map"
202
215
>
203
216
{#if ! standardControls }
Original file line number Diff line number Diff line change 489
489
value: 5 ,
490
490
description: " The initial zoom level" ,
491
491
},
492
+ {
493
+ name: " hash" ,
494
+ isProp: true ,
495
+ description:
496
+ " Set to true to track the map viewport in the URL hash. If the URL hash is set, that overrides initial viewport settings." ,
497
+ category: " View" ,
498
+ value: false ,
499
+ },
492
500
]),
493
501
);
494
502
You can’t perform that action at this time.
0 commit comments