File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
lib/components/data-vis/map
wrappers/components/data-vis/map Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 28
28
import { page } from " $app/state" ;
29
29
import { joinData } from " ./dataJoin.js" ;
30
30
31
+ import type { LngLatBoundsLike } from " maplibre-gl" ;
32
+ import { LngLatBounds } from " maplibre-gl" ;
33
+
31
34
let {
32
35
data,
33
36
cooperativeGestures = true ,
59
62
zoom = 5 ,
60
63
minZoom,
61
64
maxZoom,
65
+ maxBounds,
62
66
hash = false ,
63
67
updateHash = (u ) => {
64
68
replaceState (u , page .state );
96
100
zoom? : number ;
97
101
minZoom? : number ;
98
102
maxZoom? : number ;
103
+ maxBounds: [number , number ][];
99
104
hash? : boolean ;
100
105
updateHash? : (URL ) => void ;
101
106
useInitialHash? : boolean ;
102
107
mapHeight? : number ;
103
108
} = $props ();
104
- $inspect (data );
109
+ $inspect (maxBounds );
105
110
let styleLookup = {
106
111
" Carto-light" :
107
112
" https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" ,
208
213
let hoveredAreaData = $state ();
209
214
let currentMousePosition = $state ();
210
215
216
+ function convertToLngLatBounds(coords : [number , number ][]): LngLatBoundsLike {
217
+ const bounds = new LngLatBounds (coords [0 ], coords [0 ]);
218
+
219
+ for (let i = 1 ; i < coords .length ; i ++ ) {
220
+ bounds .extend (coords [i ]);
221
+ }
222
+
223
+ return bounds ;
224
+ }
225
+
226
+ let boundary = convertToLngLatBounds (maxBounds );
211
227
function zoomToArea(e ) {
212
228
if (clickToZoom ) {
213
229
let coordArray =
259
275
{zoom }
260
276
{maxZoom }
261
277
{minZoom }
278
+ maxBounds ={boundary }
262
279
{hash }
263
280
{updateHash }
264
281
class =" map"
Original file line number Diff line number Diff line change 501
501
value: [- 2.5 , 53 ],
502
502
description: " The initial centre of the map, in [lng, lat] form" ,
503
503
},
504
+ {
505
+ name: " maxBounds" ,
506
+ isProp: true ,
507
+ category: " View" ,
508
+ value: [
509
+ [- 23.899 , 47.5943 ],
510
+ [13.421 , 59.8988 ],
511
+ ],
512
+ description: " The initial centre of the map, in [lng, lat] form" ,
513
+ },
504
514
{
505
515
name: " zoom" ,
506
516
isProp: true ,
You can’t perform that action at this time.
0 commit comments