@remotion/maptiler 4.0.514 → 4.0.515

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,304 @@
1
- // src/MapOverlay.tsx
1
+ // src/MapHeatmap.tsx
2
2
  import {
3
- forwardRef,
4
- useContext,
5
- useImperativeHandle,
6
- useRef
7
- } from "react";
3
+ helpers
4
+ } from "@maptiler/sdk";
5
+ import { useContext as useContext2, useEffect, useRef } from "react";
8
6
  import {
9
- Interactive,
10
- Sequence
7
+ Sequence,
8
+ useDelayRender
11
9
  } from "remotion";
12
10
 
11
+ // src/delay-map-render.ts
12
+ var delayMapRender = ({
13
+ continueRender,
14
+ delayRender,
15
+ label,
16
+ map
17
+ }) => {
18
+ const handle = delayRender(label);
19
+ let hasFinished = false;
20
+ const finish = () => {
21
+ if (hasFinished) {
22
+ return;
23
+ }
24
+ hasFinished = true;
25
+ continueRender(handle);
26
+ };
27
+ map.once("idle", finish);
28
+ map.triggerRepaint();
29
+ return () => {
30
+ map.off("idle", finish);
31
+ finish();
32
+ };
33
+ };
34
+
13
35
  // src/MapTilerContext.ts
14
- import { createContext } from "react";
36
+ import { createContext, useContext } from "react";
15
37
  var MapTilerContext = createContext({
16
38
  cameraRevision: 0,
17
- map: null
39
+ map: null,
40
+ styleRevision: 0
18
41
  });
42
+ var useMapTiler = () => {
43
+ return useContext(MapTilerContext);
44
+ };
19
45
 
20
- // src/MapOverlay.tsx
46
+ // src/MapHeatmap.tsx
21
47
  import { jsx } from "react/jsx-runtime";
48
+ var MapHeatmapDrawing = ({
49
+ beforeId,
50
+ colorRamp,
51
+ data,
52
+ intensity,
53
+ layerId,
54
+ maxzoom,
55
+ minzoom,
56
+ opacity,
57
+ property,
58
+ radius,
59
+ sourceId = `${layerId}-source`,
60
+ weight,
61
+ zoomCompensation
62
+ }) => {
63
+ const { map, styleRevision } = useContext2(MapTilerContext);
64
+ const { continueRender, delayRender } = useDelayRender();
65
+ const layerIdsRef = useRef(null);
66
+ const optionsRef = useRef(null);
67
+ const intensityIsDynamic = typeof intensity === "number";
68
+ const opacityIsDynamic = typeof opacity === "number";
69
+ const radiusIsDynamic = typeof radius === "number";
70
+ const structuralKey = JSON.stringify({
71
+ beforeId,
72
+ colorRamp,
73
+ data: typeof data === "string" ? data : null,
74
+ intensity: intensityIsDynamic ? null : intensity,
75
+ maxzoom,
76
+ minzoom,
77
+ opacity: opacityIsDynamic ? null : opacity,
78
+ property,
79
+ radius: radiusIsDynamic ? null : radius,
80
+ weight,
81
+ zoomCompensation
82
+ });
83
+ optionsRef.current = {
84
+ ...beforeId === undefined ? {} : { beforeId },
85
+ ...colorRamp === undefined ? {} : { colorRamp },
86
+ data,
87
+ ...intensity === undefined ? {} : { intensity },
88
+ layerId,
89
+ ...maxzoom === undefined ? {} : { maxzoom },
90
+ ...minzoom === undefined ? {} : { minzoom },
91
+ ...opacity === undefined ? {} : { opacity },
92
+ ...property === undefined ? {} : { property },
93
+ ...radius === undefined ? {} : { radius },
94
+ sourceId,
95
+ ...weight === undefined ? {} : { weight },
96
+ ...zoomCompensation === undefined ? {} : { zoomCompensation }
97
+ };
98
+ useEffect(() => {
99
+ if (!map || !optionsRef.current) {
100
+ return;
101
+ }
102
+ const loadingHandle = delayRender(`Loading MapTiler heatmap ${layerId}`);
103
+ let hasFinished = false;
104
+ const finish = () => {
105
+ if (hasFinished) {
106
+ return;
107
+ }
108
+ hasFinished = true;
109
+ continueRender(loadingHandle);
110
+ };
111
+ layerIdsRef.current = helpers.addHeatmap(map, optionsRef.current);
112
+ map.once("idle", finish);
113
+ map.triggerRepaint();
114
+ return () => {
115
+ map.off("idle", finish);
116
+ finish();
117
+ const ids = layerIdsRef.current;
118
+ if (!ids) {
119
+ return;
120
+ }
121
+ if (map.getLayer(ids.heatmapLayerId)) {
122
+ map.removeLayer(ids.heatmapLayerId);
123
+ }
124
+ if (map.getSource(ids.heatmapSourceId)) {
125
+ map.removeSource(ids.heatmapSourceId);
126
+ }
127
+ layerIdsRef.current = null;
128
+ map.triggerRepaint();
129
+ };
130
+ }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
131
+ useEffect(() => {
132
+ if (!map || typeof data === "string") {
133
+ return;
134
+ }
135
+ const ids = layerIdsRef.current;
136
+ if (ids && map.getSource(ids.heatmapSourceId)) {
137
+ map.getSource(ids.heatmapSourceId).setData(data);
138
+ return delayMapRender({
139
+ continueRender,
140
+ delayRender,
141
+ label: `Updating MapTiler heatmap source ${layerId}`,
142
+ map
143
+ });
144
+ }
145
+ }, [continueRender, data, delayRender, layerId, map]);
146
+ useEffect(() => {
147
+ if (!map) {
148
+ return;
149
+ }
150
+ const id = layerIdsRef.current?.heatmapLayerId;
151
+ if (!id || !map.getLayer(id)) {
152
+ return;
153
+ }
154
+ if (intensityIsDynamic) {
155
+ map.setPaintProperty(id, "heatmap-intensity", intensity);
156
+ }
157
+ if (opacityIsDynamic) {
158
+ map.setPaintProperty(id, "heatmap-opacity", opacity);
159
+ }
160
+ if (radiusIsDynamic) {
161
+ map.setPaintProperty(id, "heatmap-radius", radius);
162
+ }
163
+ return delayMapRender({
164
+ continueRender,
165
+ delayRender,
166
+ label: `Drawing MapTiler heatmap ${layerId}`,
167
+ map
168
+ });
169
+ }, [
170
+ continueRender,
171
+ delayRender,
172
+ intensity,
173
+ intensityIsDynamic,
174
+ layerId,
175
+ map,
176
+ opacity,
177
+ opacityIsDynamic,
178
+ radius,
179
+ radiusIsDynamic,
180
+ structuralKey,
181
+ styleRevision
182
+ ]);
183
+ return null;
184
+ };
185
+ var MapHeatmap = (props) => {
186
+ const {
187
+ controls,
188
+ durationInFrames,
189
+ freeze,
190
+ from,
191
+ hidden,
192
+ name,
193
+ showInTimeline,
194
+ trimBefore
195
+ } = props;
196
+ return /* @__PURE__ */ jsx(Sequence, {
197
+ layout: "none",
198
+ from: from ?? 0,
199
+ trimBefore,
200
+ durationInFrames: durationInFrames ?? Infinity,
201
+ freeze,
202
+ hidden,
203
+ name: name ?? "<MapHeatmap>",
204
+ showInTimeline: showInTimeline ?? true,
205
+ controls,
206
+ children: /* @__PURE__ */ jsx(MapHeatmapDrawing, {
207
+ ...props
208
+ })
209
+ });
210
+ };
211
+ // src/MapLayer.tsx
212
+ import { useContext as useContext3, useEffect as useEffect2, useRef as useRef2 } from "react";
213
+ import { useDelayRender as useDelayRender2 } from "remotion";
214
+ var MapLayer = ({ beforeId, layer }) => {
215
+ const { map, styleRevision } = useContext3(MapTilerContext);
216
+ const previousLayerRef = useRef2(null);
217
+ const { continueRender, delayRender } = useDelayRender2();
218
+ useEffect2(() => {
219
+ if (!map) {
220
+ return;
221
+ }
222
+ const loadingHandle = delayRender(`Drawing MapTiler layer ${layer.id}`);
223
+ let hasFinished = false;
224
+ const finish = () => {
225
+ if (hasFinished) {
226
+ return;
227
+ }
228
+ hasFinished = true;
229
+ continueRender(loadingHandle);
230
+ };
231
+ const previousLayer = previousLayerRef.current;
232
+ const existingLayer = map.getLayer(layer.id);
233
+ const layerWithDefinedProperties = Object.fromEntries(Object.entries(layer).filter(([, value]) => value !== undefined));
234
+ const sourceChanged = previousLayer !== null && "source" in previousLayer && "source" in layer && (previousLayer.source !== layer.source || previousLayer["source-layer"] !== layer["source-layer"]);
235
+ if (existingLayer && (existingLayer.type !== layer.type || sourceChanged)) {
236
+ map.removeLayer(layer.id);
237
+ }
238
+ if (!map.getLayer(layer.id)) {
239
+ map.addLayer(layerWithDefinedProperties, beforeId);
240
+ } else {
241
+ if ("paint" in layer || previousLayer && "paint" in previousLayer) {
242
+ const previousPaint = previousLayer && "paint" in previousLayer ? previousLayer.paint : undefined;
243
+ const paint = "paint" in layer ? layer.paint : undefined;
244
+ for (const property of new Set([
245
+ ...Object.keys(previousPaint ?? {}),
246
+ ...Object.keys(paint ?? {})
247
+ ])) {
248
+ map.setPaintProperty(layer.id, property, paint?.[property] ?? null);
249
+ }
250
+ }
251
+ if ("layout" in layer || previousLayer && "layout" in previousLayer) {
252
+ const previousLayout = previousLayer && "layout" in previousLayer ? previousLayer.layout : undefined;
253
+ const layout = "layout" in layer ? layer.layout : undefined;
254
+ for (const property of new Set([
255
+ ...Object.keys(previousLayout ?? {}),
256
+ ...Object.keys(layout ?? {})
257
+ ])) {
258
+ map.setLayoutProperty(layer.id, property, layout?.[property] ?? null);
259
+ }
260
+ }
261
+ if ("filter" in layer) {
262
+ map.setFilter(layer.id, layer.filter ?? null);
263
+ }
264
+ map.setLayerZoomRange(layer.id, layer.minzoom ?? 0, layer.maxzoom ?? 24);
265
+ if (beforeId && map.getLayer(beforeId)) {
266
+ map.moveLayer(layer.id, beforeId);
267
+ }
268
+ }
269
+ previousLayerRef.current = layer;
270
+ map.once("idle", finish);
271
+ map.triggerRepaint();
272
+ return () => {
273
+ map.off("idle", finish);
274
+ finish();
275
+ };
276
+ }, [beforeId, continueRender, delayRender, layer, map, styleRevision]);
277
+ useEffect2(() => {
278
+ if (!map) {
279
+ return;
280
+ }
281
+ return () => {
282
+ if (map.getLayer(layer.id)) {
283
+ map.removeLayer(layer.id);
284
+ map.triggerRepaint();
285
+ }
286
+ };
287
+ }, [layer.id, map]);
288
+ return null;
289
+ };
290
+ // src/MapOverlay.tsx
291
+ import {
292
+ forwardRef,
293
+ useContext as useContext4,
294
+ useImperativeHandle,
295
+ useRef as useRef3
296
+ } from "react";
297
+ import {
298
+ Interactive,
299
+ Sequence as Sequence2
300
+ } from "remotion";
301
+ import { jsx as jsx2 } from "react/jsx-runtime";
22
302
  var mapOverlaySchema = {
23
303
  ...Interactive.baseSchema,
24
304
  longitude: {
@@ -39,76 +319,979 @@ var mapOverlaySchema = {
39
319
  description: "Latitude",
40
320
  hiddenFromList: false
41
321
  },
322
+ offsetX: {
323
+ type: "number",
324
+ min: -2000,
325
+ max: 2000,
326
+ step: 1,
327
+ default: 0,
328
+ description: "Horizontal marker offset",
329
+ hiddenFromList: false,
330
+ keyframable: true
331
+ },
332
+ offsetY: {
333
+ type: "number",
334
+ min: -2000,
335
+ max: 2000,
336
+ step: 1,
337
+ default: 0,
338
+ description: "Vertical marker offset",
339
+ hiddenFromList: false,
340
+ keyframable: true
341
+ },
342
+ opacity: {
343
+ type: "number",
344
+ min: 0,
345
+ max: 1,
346
+ step: 0.01,
347
+ default: 1,
348
+ description: "Marker opacity",
349
+ hiddenFromList: false,
350
+ keyframable: true
351
+ },
352
+ rotation: {
353
+ type: "number",
354
+ min: -360,
355
+ max: 360,
356
+ step: 1,
357
+ default: 0,
358
+ description: "Marker rotation",
359
+ hiddenFromList: false,
360
+ keyframable: true
361
+ },
42
362
  ...Interactive.transformSchema
43
363
  };
44
- var MapOverlayRefForwardingFunction = ({
45
- children,
46
- latitude,
47
- longitude,
48
- style,
49
- durationInFrames,
50
- from,
51
- trimBefore,
52
- freeze,
53
- hidden,
54
- name,
55
- showInTimeline,
56
- controls
57
- }, ref) => {
58
- const { map } = useContext(MapTilerContext);
59
- const refForOutline = useRef(null);
60
- const point = map?.project([longitude, latitude]);
61
- useImperativeHandle(ref, () => refForOutline.current, []);
62
- return /* @__PURE__ */ jsx(Sequence, {
364
+ var MapOverlayRefForwardingFunction = ({
365
+ anchor = "center",
366
+ children,
367
+ latitude,
368
+ longitude,
369
+ offsetX = 0,
370
+ offsetY = 0,
371
+ opacity = 1,
372
+ rotation = 0,
373
+ rotationAlignment = "viewport",
374
+ style,
375
+ durationInFrames,
376
+ from,
377
+ trimBefore,
378
+ freeze,
379
+ hidden,
380
+ name,
381
+ showInTimeline,
382
+ controls
383
+ }, ref) => {
384
+ const { map } = useContext4(MapTilerContext);
385
+ const refForOutline = useRef3(null);
386
+ const point = map?.project([longitude, latitude]);
387
+ const horizontalAnchor = anchor.includes("left") ? 0 : anchor.includes("right") ? -100 : -50;
388
+ const verticalAnchor = anchor.includes("top") ? 0 : anchor.includes("bottom") ? -100 : -50;
389
+ useImperativeHandle(ref, () => refForOutline.current, []);
390
+ return /* @__PURE__ */ jsx2(Sequence2, {
391
+ layout: "none",
392
+ from: from ?? 0,
393
+ trimBefore,
394
+ durationInFrames: durationInFrames ?? Infinity,
395
+ freeze,
396
+ hidden,
397
+ name: name ?? "<MapOverlay>",
398
+ showInTimeline: showInTimeline ?? true,
399
+ controls,
400
+ outlineRef: refForOutline,
401
+ children: /* @__PURE__ */ jsx2("div", {
402
+ ref: refForOutline,
403
+ style: {
404
+ left: (point?.x ?? 0) + offsetX,
405
+ opacity,
406
+ pointerEvents: "none",
407
+ position: "absolute",
408
+ rotate: `${rotation + (rotationAlignment === "map" ? map?.getBearing() ?? 0 : 0)}deg`,
409
+ top: (point?.y ?? 0) + offsetY,
410
+ translate: `${horizontalAnchor}% ${verticalAnchor}%`,
411
+ zIndex: 1,
412
+ ...style
413
+ },
414
+ children
415
+ })
416
+ });
417
+ };
418
+ var MapOverlayInner = forwardRef(MapOverlayRefForwardingFunction);
419
+ var MapOverlay = Interactive.withSchema({
420
+ Component: MapOverlayInner,
421
+ componentName: "<MapOverlay>",
422
+ componentIdentity: null,
423
+ schema: mapOverlaySchema,
424
+ supportsEffects: false
425
+ });
426
+ var MapMarker = MapOverlay;
427
+ // src/MapPoint.tsx
428
+ import {
429
+ helpers as helpers2
430
+ } from "@maptiler/sdk";
431
+ import { useContext as useContext5, useEffect as useEffect3, useRef as useRef4 } from "react";
432
+ import {
433
+ Sequence as Sequence3,
434
+ useDelayRender as useDelayRender3
435
+ } from "remotion";
436
+ import { jsx as jsx3 } from "react/jsx-runtime";
437
+ var MapPointDrawing = ({
438
+ alignOnViewport,
439
+ beforeId,
440
+ cluster,
441
+ data,
442
+ labelColor,
443
+ labelSize,
444
+ layerId,
445
+ maxPointRadius,
446
+ maxzoom,
447
+ minPointRadius,
448
+ minzoom,
449
+ outline,
450
+ outlineColor,
451
+ outlineOpacity,
452
+ outlineWidth,
453
+ pointColor,
454
+ pointOpacity,
455
+ pointRadius,
456
+ property,
457
+ showLabel,
458
+ sourceId = `${layerId}-source`,
459
+ zoomCompensation
460
+ }) => {
461
+ const { map, styleRevision } = useContext5(MapTilerContext);
462
+ const { continueRender, delayRender } = useDelayRender3();
463
+ const layerIdsRef = useRef4(null);
464
+ const optionsRef = useRef4(null);
465
+ const outlineColorIsDynamic = typeof outlineColor === "string";
466
+ const outlineOpacityIsDynamic = typeof outlineOpacity === "number";
467
+ const outlineWidthIsDynamic = typeof outlineWidth === "number";
468
+ const pointColorIsDynamic = typeof pointColor === "string";
469
+ const pointOpacityIsDynamic = typeof pointOpacity === "number";
470
+ const pointRadiusIsDynamic = typeof pointRadius === "number";
471
+ const structuralKey = JSON.stringify({
472
+ alignOnViewport,
473
+ beforeId,
474
+ cluster,
475
+ data: typeof data === "string" ? data : null,
476
+ maxPointRadius,
477
+ maxzoom,
478
+ minPointRadius,
479
+ minzoom,
480
+ outline,
481
+ outlineColor: outlineColorIsDynamic ? null : outlineColor,
482
+ outlineOpacity: outlineOpacityIsDynamic ? null : outlineOpacity,
483
+ outlineWidth: outlineWidthIsDynamic ? null : outlineWidth,
484
+ pointColor: pointColorIsDynamic ? null : pointColor,
485
+ pointOpacity: pointOpacityIsDynamic ? null : pointOpacity,
486
+ pointRadius: pointRadiusIsDynamic ? null : pointRadius,
487
+ property,
488
+ showLabel,
489
+ zoomCompensation
490
+ });
491
+ optionsRef.current = {
492
+ ...alignOnViewport === undefined ? {} : { alignOnViewport },
493
+ ...beforeId === undefined ? {} : { beforeId },
494
+ ...cluster === undefined ? {} : { cluster },
495
+ data,
496
+ ...labelColor === undefined ? {} : { labelColor },
497
+ ...labelSize === undefined ? {} : { labelSize },
498
+ layerId,
499
+ ...maxPointRadius === undefined ? {} : { maxPointRadius },
500
+ ...maxzoom === undefined ? {} : { maxzoom },
501
+ ...minPointRadius === undefined ? {} : { minPointRadius },
502
+ ...minzoom === undefined ? {} : { minzoom },
503
+ ...outline === undefined ? {} : { outline },
504
+ ...outlineColor === undefined ? {} : { outlineColor },
505
+ ...outlineOpacity === undefined ? {} : { outlineOpacity },
506
+ ...outlineWidth === undefined ? {} : { outlineWidth },
507
+ ...pointColor === undefined ? {} : { pointColor },
508
+ ...pointOpacity === undefined ? {} : { pointOpacity },
509
+ ...pointRadius === undefined ? {} : { pointRadius },
510
+ ...property === undefined ? {} : { property },
511
+ ...showLabel === undefined ? {} : { showLabel },
512
+ sourceId,
513
+ ...zoomCompensation === undefined ? {} : { zoomCompensation }
514
+ };
515
+ useEffect3(() => {
516
+ if (!map || !optionsRef.current) {
517
+ return;
518
+ }
519
+ const loadingHandle = delayRender(`Loading MapTiler point layer ${layerId}`);
520
+ let hasFinished = false;
521
+ const finish = () => {
522
+ if (hasFinished) {
523
+ return;
524
+ }
525
+ hasFinished = true;
526
+ continueRender(loadingHandle);
527
+ };
528
+ layerIdsRef.current = helpers2.addPoint(map, optionsRef.current);
529
+ map.once("idle", finish);
530
+ map.triggerRepaint();
531
+ return () => {
532
+ map.off("idle", finish);
533
+ finish();
534
+ const ids = layerIdsRef.current;
535
+ if (!ids) {
536
+ return;
537
+ }
538
+ for (const id of [
539
+ ids.labelLayerId,
540
+ ids.clusterLayerId,
541
+ ids.pointLayerId
542
+ ]) {
543
+ if (id && map.getLayer(id)) {
544
+ map.removeLayer(id);
545
+ }
546
+ }
547
+ if (map.getSource(ids.pointSourceId)) {
548
+ map.removeSource(ids.pointSourceId);
549
+ }
550
+ layerIdsRef.current = null;
551
+ map.triggerRepaint();
552
+ };
553
+ }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
554
+ useEffect3(() => {
555
+ if (!map || typeof data === "string") {
556
+ return;
557
+ }
558
+ const ids = layerIdsRef.current;
559
+ if (ids && map.getSource(ids.pointSourceId)) {
560
+ map.getSource(ids.pointSourceId).setData(data);
561
+ return delayMapRender({
562
+ continueRender,
563
+ delayRender,
564
+ label: `Updating MapTiler point source ${layerId}`,
565
+ map
566
+ });
567
+ }
568
+ }, [continueRender, data, delayRender, layerId, map]);
569
+ useEffect3(() => {
570
+ if (!map) {
571
+ return;
572
+ }
573
+ const ids = layerIdsRef.current;
574
+ if (!ids) {
575
+ return;
576
+ }
577
+ for (const id of [ids.pointLayerId, ids.clusterLayerId]) {
578
+ if (!id || !map.getLayer(id)) {
579
+ continue;
580
+ }
581
+ if (pointColorIsDynamic) {
582
+ map.setPaintProperty(id, "circle-color", pointColor);
583
+ }
584
+ if (pointOpacityIsDynamic) {
585
+ map.setPaintProperty(id, "circle-opacity", pointOpacity);
586
+ }
587
+ if (pointRadiusIsDynamic) {
588
+ map.setPaintProperty(id, "circle-radius", pointRadius);
589
+ }
590
+ if (outlineColorIsDynamic) {
591
+ map.setPaintProperty(id, "circle-stroke-color", outlineColor);
592
+ }
593
+ if (outlineOpacityIsDynamic) {
594
+ map.setPaintProperty(id, "circle-stroke-opacity", outlineOpacity);
595
+ }
596
+ if (outlineWidthIsDynamic) {
597
+ map.setPaintProperty(id, "circle-stroke-width", outlineWidth);
598
+ }
599
+ }
600
+ if (ids.labelLayerId && map.getLayer(ids.labelLayerId)) {
601
+ if (labelColor !== undefined) {
602
+ map.setPaintProperty(ids.labelLayerId, "text-color", labelColor);
603
+ }
604
+ if (labelSize !== undefined) {
605
+ map.setLayoutProperty(ids.labelLayerId, "text-size", labelSize);
606
+ }
607
+ }
608
+ return delayMapRender({
609
+ continueRender,
610
+ delayRender,
611
+ label: `Drawing MapTiler point layer ${layerId}`,
612
+ map
613
+ });
614
+ }, [
615
+ continueRender,
616
+ delayRender,
617
+ labelColor,
618
+ labelSize,
619
+ layerId,
620
+ map,
621
+ outlineColor,
622
+ outlineColorIsDynamic,
623
+ outlineOpacity,
624
+ outlineOpacityIsDynamic,
625
+ outlineWidth,
626
+ outlineWidthIsDynamic,
627
+ pointColor,
628
+ pointColorIsDynamic,
629
+ pointOpacity,
630
+ pointOpacityIsDynamic,
631
+ pointRadius,
632
+ pointRadiusIsDynamic,
633
+ structuralKey,
634
+ styleRevision
635
+ ]);
636
+ return null;
637
+ };
638
+ var MapPoint = (props) => {
639
+ const {
640
+ controls,
641
+ durationInFrames,
642
+ freeze,
643
+ from,
644
+ hidden,
645
+ name,
646
+ showInTimeline,
647
+ trimBefore
648
+ } = props;
649
+ return /* @__PURE__ */ jsx3(Sequence3, {
650
+ layout: "none",
651
+ from: from ?? 0,
652
+ trimBefore,
653
+ durationInFrames: durationInFrames ?? Infinity,
654
+ freeze,
655
+ hidden,
656
+ name: name ?? "<MapPoint>",
657
+ showInTimeline: showInTimeline ?? true,
658
+ controls,
659
+ children: /* @__PURE__ */ jsx3(MapPointDrawing, {
660
+ ...props
661
+ })
662
+ });
663
+ };
664
+ // src/MapPolygon.tsx
665
+ import {
666
+ helpers as helpers4
667
+ } from "@maptiler/sdk";
668
+ import { useContext as useContext7, useEffect as useEffect5, useMemo, useRef as useRef6 } from "react";
669
+ import {
670
+ Sequence as Sequence5,
671
+ useDelayRender as useDelayRender5
672
+ } from "remotion";
673
+
674
+ // src/MapPolyline.tsx
675
+ import {
676
+ helpers as helpers3
677
+ } from "@maptiler/sdk";
678
+ import { length as getLineLength, lineSliceAlong, lineString } from "@turf/turf";
679
+ import { useContext as useContext6, useEffect as useEffect4, useRef as useRef5, useState } from "react";
680
+ import {
681
+ Sequence as Sequence4,
682
+ useDelayRender as useDelayRender4
683
+ } from "remotion";
684
+ import { jsx as jsx4 } from "react/jsx-runtime";
685
+ var normalizeData = (data) => {
686
+ if (typeof data === "string" || data.type === "FeatureCollection") {
687
+ return data;
688
+ }
689
+ return { features: [data], type: "FeatureCollection" };
690
+ };
691
+ var revealData = (data, progress) => {
692
+ if (typeof data === "string") {
693
+ return data;
694
+ }
695
+ const normalizedData = normalizeData(data);
696
+ if (typeof normalizedData === "string") {
697
+ return normalizedData;
698
+ }
699
+ const lineCoordinates = normalizedData.features.flatMap((feature) => {
700
+ if (feature.geometry.type === "LineString") {
701
+ return [feature.geometry.coordinates];
702
+ }
703
+ if (feature.geometry.type === "MultiLineString") {
704
+ return feature.geometry.coordinates;
705
+ }
706
+ return [];
707
+ });
708
+ const lines = lineCoordinates.map((coordinates) => lineString(coordinates));
709
+ const lineLengths = lines.map((line) => getLineLength(line));
710
+ let remainingLength = lineLengths.reduce((sum, lineLength) => sum + lineLength, 0) * Math.min(1, Math.max(0, progress));
711
+ let lineIndex = 0;
712
+ return {
713
+ ...normalizedData,
714
+ features: normalizedData.features.map((feature) => {
715
+ if (feature.geometry.type !== "LineString" && feature.geometry.type !== "MultiLineString") {
716
+ return feature;
717
+ }
718
+ const featureLines = feature.geometry.type === "LineString" ? [feature.geometry.coordinates] : feature.geometry.coordinates;
719
+ const revealedLines = featureLines.map(() => {
720
+ const line = lines[lineIndex];
721
+ const lineLength = lineLengths[lineIndex];
722
+ lineIndex++;
723
+ const revealedLength = Math.min(lineLength, remainingLength);
724
+ remainingLength = Math.max(0, remainingLength - lineLength);
725
+ return lineSliceAlong(line, 0, Math.max(0.001, revealedLength)).geometry.coordinates;
726
+ });
727
+ return {
728
+ ...feature,
729
+ geometry: feature.geometry.type === "LineString" ? { coordinates: revealedLines[0], type: "LineString" } : {
730
+ coordinates: revealedLines,
731
+ type: "MultiLineString"
732
+ }
733
+ };
734
+ })
735
+ };
736
+ };
737
+ var MapPolylineDrawing = ({
738
+ beforeId,
739
+ data,
740
+ layerId,
741
+ lineBlur,
742
+ lineCap,
743
+ lineColor,
744
+ lineDashArray,
745
+ lineGapWidth,
746
+ lineJoin,
747
+ lineOpacity,
748
+ lineWidth,
749
+ maxzoom,
750
+ minzoom,
751
+ outline,
752
+ outlineBlur,
753
+ outlineColor,
754
+ outlineOpacity,
755
+ outlineWidth,
756
+ progress = 1,
757
+ sourceId = `${layerId}-source`
758
+ }) => {
759
+ const { map, styleRevision } = useContext6(MapTilerContext);
760
+ const { cancelRender, continueRender, delayRender } = useDelayRender4();
761
+ const layerIdsRef = useRef5(null);
762
+ const optionsRef = useRef5(null);
763
+ const [layerRevision, setLayerRevision] = useState(0);
764
+ const lineBlurIsDynamic = typeof lineBlur === "number";
765
+ const lineColorIsDynamic = typeof lineColor === "string";
766
+ const lineGapWidthIsDynamic = typeof lineGapWidth === "number";
767
+ const lineOpacityIsDynamic = typeof lineOpacity === "number";
768
+ const lineWidthIsDynamic = typeof lineWidth === "number";
769
+ const outlineBlurIsDynamic = typeof outlineBlur === "number";
770
+ const outlineColorIsDynamic = typeof outlineColor === "string";
771
+ const outlineOpacityIsDynamic = typeof outlineOpacity === "number";
772
+ const outlineWidthIsDynamic = typeof outlineWidth === "number";
773
+ const structuralKey = JSON.stringify({
774
+ beforeId,
775
+ data: typeof data === "string" ? data : null,
776
+ lineBlur: lineBlurIsDynamic ? null : lineBlur,
777
+ lineCap,
778
+ lineColor: lineColorIsDynamic ? null : lineColor,
779
+ lineDashArray,
780
+ lineGapWidth: lineGapWidthIsDynamic ? null : lineGapWidth,
781
+ lineJoin,
782
+ lineOpacity: lineOpacityIsDynamic ? null : lineOpacity,
783
+ lineWidth: lineWidthIsDynamic ? null : lineWidth,
784
+ maxzoom,
785
+ minzoom,
786
+ outline,
787
+ outlineBlur: outlineBlurIsDynamic ? null : outlineBlur,
788
+ outlineColor: outlineColorIsDynamic ? null : outlineColor,
789
+ outlineOpacity: outlineOpacityIsDynamic ? null : outlineOpacity,
790
+ outlineWidth: outlineWidthIsDynamic ? null : outlineWidth
791
+ });
792
+ optionsRef.current = {
793
+ ...beforeId === undefined ? {} : { beforeId },
794
+ data: revealData(data, progress),
795
+ layerId,
796
+ ...lineBlur === undefined ? {} : { lineBlur },
797
+ ...lineCap === undefined ? {} : { lineCap },
798
+ ...lineColor === undefined ? {} : { lineColor },
799
+ ...lineDashArray === undefined ? {} : { lineDashArray },
800
+ ...lineGapWidth === undefined ? {} : { lineGapWidth },
801
+ ...lineJoin === undefined ? {} : { lineJoin },
802
+ ...lineOpacity === undefined ? {} : { lineOpacity },
803
+ ...lineWidth === undefined ? {} : { lineWidth },
804
+ ...maxzoom === undefined ? {} : { maxzoom },
805
+ ...minzoom === undefined ? {} : { minzoom },
806
+ ...outline === undefined ? {} : { outline },
807
+ ...outlineBlur === undefined ? {} : { outlineBlur },
808
+ ...outlineColor === undefined ? {} : { outlineColor },
809
+ ...outlineOpacity === undefined ? {} : { outlineOpacity },
810
+ ...outlineWidth === undefined ? {} : { outlineWidth },
811
+ sourceId
812
+ };
813
+ useEffect4(() => {
814
+ if (!map || !optionsRef.current) {
815
+ return;
816
+ }
817
+ const loadingHandle = delayRender(`Loading MapTiler polyline ${layerId}`);
818
+ let hasFinished = false;
819
+ let hasCancelled = false;
820
+ const finish = () => {
821
+ if (hasFinished) {
822
+ return;
823
+ }
824
+ hasFinished = true;
825
+ continueRender(loadingHandle);
826
+ };
827
+ const removeLayers = (ids) => {
828
+ for (const id of [ids.polylineLayerId, ids.polylineOutlineLayerId]) {
829
+ if (id && map.getLayer(id)) {
830
+ map.removeLayer(id);
831
+ }
832
+ }
833
+ if (map.getSource(ids.polylineSourceId)) {
834
+ map.removeSource(ids.polylineSourceId);
835
+ }
836
+ };
837
+ helpers3.addPolyline(map, optionsRef.current).then((ids) => {
838
+ if (hasCancelled) {
839
+ removeLayers(ids);
840
+ finish();
841
+ return;
842
+ }
843
+ layerIdsRef.current = ids;
844
+ setLayerRevision((revision) => revision + 1);
845
+ map.once("idle", finish);
846
+ map.triggerRepaint();
847
+ }).catch((error) => {
848
+ finish();
849
+ if (!hasCancelled) {
850
+ cancelRender(error);
851
+ }
852
+ });
853
+ return () => {
854
+ hasCancelled = true;
855
+ map.off("idle", finish);
856
+ finish();
857
+ const ids = layerIdsRef.current;
858
+ if (ids) {
859
+ removeLayers(ids);
860
+ layerIdsRef.current = null;
861
+ map.triggerRepaint();
862
+ }
863
+ };
864
+ }, [
865
+ cancelRender,
866
+ continueRender,
867
+ delayRender,
868
+ layerId,
869
+ map,
870
+ structuralKey,
871
+ styleRevision
872
+ ]);
873
+ useEffect4(() => {
874
+ if (!map || typeof data === "string") {
875
+ return;
876
+ }
877
+ const ids = layerIdsRef.current;
878
+ if (ids && map.getSource(ids.polylineSourceId)) {
879
+ map.getSource(ids.polylineSourceId).setData(revealData(data, progress));
880
+ return delayMapRender({
881
+ continueRender,
882
+ delayRender,
883
+ label: `Drawing MapTiler polyline ${layerId}`,
884
+ map
885
+ });
886
+ }
887
+ }, [
888
+ continueRender,
889
+ data,
890
+ delayRender,
891
+ layerId,
892
+ layerRevision,
893
+ map,
894
+ progress
895
+ ]);
896
+ useEffect4(() => {
897
+ if (!map) {
898
+ return;
899
+ }
900
+ const ids = layerIdsRef.current;
901
+ if (!ids || !map.getLayer(ids.polylineLayerId)) {
902
+ return;
903
+ }
904
+ if (lineBlurIsDynamic) {
905
+ map.setPaintProperty(ids.polylineLayerId, "line-blur", lineBlur);
906
+ }
907
+ if (lineColorIsDynamic) {
908
+ map.setPaintProperty(ids.polylineLayerId, "line-color", lineColor);
909
+ }
910
+ if (lineGapWidthIsDynamic) {
911
+ map.setPaintProperty(ids.polylineLayerId, "line-gap-width", lineGapWidth);
912
+ }
913
+ if (lineOpacityIsDynamic) {
914
+ map.setPaintProperty(ids.polylineLayerId, "line-opacity", lineOpacity);
915
+ }
916
+ if (lineWidthIsDynamic) {
917
+ map.setPaintProperty(ids.polylineLayerId, "line-width", lineWidth);
918
+ }
919
+ if (ids.polylineOutlineLayerId && map.getLayer(ids.polylineOutlineLayerId)) {
920
+ if (outlineBlurIsDynamic) {
921
+ map.setPaintProperty(ids.polylineOutlineLayerId, "line-blur", outlineBlur);
922
+ }
923
+ if (outlineColorIsDynamic) {
924
+ map.setPaintProperty(ids.polylineOutlineLayerId, "line-color", outlineColor);
925
+ }
926
+ if (outlineOpacityIsDynamic) {
927
+ map.setPaintProperty(ids.polylineOutlineLayerId, "line-opacity", outlineOpacity);
928
+ }
929
+ if (outlineWidthIsDynamic || lineWidthIsDynamic) {
930
+ const actualLineWidth = lineWidth ?? 3;
931
+ const actualOutlineWidth = outlineWidth ?? 1;
932
+ const combinedOutlineWidth = typeof actualLineWidth === "number" ? typeof actualOutlineWidth === "number" ? actualLineWidth + actualOutlineWidth * 2 : [
933
+ "interpolate",
934
+ ["linear"],
935
+ ["zoom"],
936
+ ...actualOutlineWidth.flatMap(({ value, zoom }) => [
937
+ zoom,
938
+ actualLineWidth + value * 2
939
+ ])
940
+ ] : [
941
+ "interpolate",
942
+ ["linear"],
943
+ ["zoom"],
944
+ ...actualLineWidth.flatMap(({ value, zoom }) => [
945
+ zoom,
946
+ value + (typeof actualOutlineWidth === "number" ? actualOutlineWidth : 1) * 2
947
+ ])
948
+ ];
949
+ map.setPaintProperty(ids.polylineOutlineLayerId, "line-width", combinedOutlineWidth);
950
+ }
951
+ }
952
+ return delayMapRender({
953
+ continueRender,
954
+ delayRender,
955
+ label: `Styling MapTiler polyline ${layerId}`,
956
+ map
957
+ });
958
+ }, [
959
+ continueRender,
960
+ delayRender,
961
+ lineBlur,
962
+ lineBlurIsDynamic,
963
+ lineColor,
964
+ lineColorIsDynamic,
965
+ lineGapWidth,
966
+ lineGapWidthIsDynamic,
967
+ lineOpacity,
968
+ lineOpacityIsDynamic,
969
+ lineWidth,
970
+ lineWidthIsDynamic,
971
+ layerId,
972
+ layerRevision,
973
+ map,
974
+ outlineBlur,
975
+ outlineBlurIsDynamic,
976
+ outlineColor,
977
+ outlineColorIsDynamic,
978
+ outlineOpacity,
979
+ outlineOpacityIsDynamic,
980
+ outlineWidth,
981
+ outlineWidthIsDynamic
982
+ ]);
983
+ return null;
984
+ };
985
+ var MapPolyline = (props) => {
986
+ const {
987
+ controls,
988
+ durationInFrames,
989
+ freeze,
990
+ from,
991
+ hidden,
992
+ name,
993
+ showInTimeline,
994
+ trimBefore
995
+ } = props;
996
+ return /* @__PURE__ */ jsx4(Sequence4, {
997
+ layout: "none",
998
+ from: from ?? 0,
999
+ trimBefore,
1000
+ durationInFrames: durationInFrames ?? Infinity,
1001
+ freeze,
1002
+ hidden,
1003
+ name: name ?? "<MapPolyline>",
1004
+ showInTimeline: showInTimeline ?? true,
1005
+ controls,
1006
+ children: /* @__PURE__ */ jsx4(MapPolylineDrawing, {
1007
+ ...props
1008
+ })
1009
+ });
1010
+ };
1011
+
1012
+ // src/MapPolygon.tsx
1013
+ import { jsx as jsx5 } from "react/jsx-runtime";
1014
+ var normalizeData2 = (data) => {
1015
+ if (typeof data === "string" || data.type === "FeatureCollection") {
1016
+ return data;
1017
+ }
1018
+ return { features: [data], type: "FeatureCollection" };
1019
+ };
1020
+ var getOutlineData = (data) => {
1021
+ if (typeof data === "string") {
1022
+ return null;
1023
+ }
1024
+ const normalizedData = normalizeData2(data);
1025
+ if (typeof normalizedData === "string") {
1026
+ return null;
1027
+ }
1028
+ const features = [];
1029
+ for (const feature of normalizedData.features) {
1030
+ if (feature.geometry.type === "Polygon") {
1031
+ for (const coordinates of feature.geometry.coordinates) {
1032
+ features.push({
1033
+ geometry: { coordinates, type: "LineString" },
1034
+ properties: feature.properties,
1035
+ type: "Feature"
1036
+ });
1037
+ }
1038
+ }
1039
+ if (feature.geometry.type === "MultiPolygon") {
1040
+ for (const polygon of feature.geometry.coordinates) {
1041
+ for (const coordinates of polygon) {
1042
+ features.push({
1043
+ geometry: { coordinates, type: "LineString" },
1044
+ properties: feature.properties,
1045
+ type: "Feature"
1046
+ });
1047
+ }
1048
+ }
1049
+ }
1050
+ }
1051
+ return { features, type: "FeatureCollection" };
1052
+ };
1053
+ var MapPolygonDrawing = ({
1054
+ beforeId,
1055
+ data,
1056
+ fillColor,
1057
+ fillOpacity,
1058
+ layerId,
1059
+ maxzoom,
1060
+ minzoom,
1061
+ outline,
1062
+ outlineBlur,
1063
+ outlineCap,
1064
+ outlineColor,
1065
+ outlineDashArray,
1066
+ outlineJoin,
1067
+ outlineOpacity,
1068
+ outlinePosition,
1069
+ outlineWidth,
1070
+ pattern,
1071
+ progress,
1072
+ sourceId = `${layerId}-source`
1073
+ }) => {
1074
+ const { map, styleRevision } = useContext7(MapTilerContext);
1075
+ const { continueRender, delayRender } = useDelayRender5();
1076
+ const layerIdsRef = useRef6(null);
1077
+ const optionsRef = useRef6(null);
1078
+ const fillColorIsDynamic = typeof fillColor === "string";
1079
+ const fillOpacityIsDynamic = typeof fillOpacity === "number";
1080
+ const outlineBlurIsDynamic = typeof outlineBlur === "number";
1081
+ const outlineColorIsDynamic = typeof outlineColor === "string";
1082
+ const outlineOpacityIsDynamic = typeof outlineOpacity === "number";
1083
+ const outlineWidthIsDynamic = typeof outlineWidth === "number";
1084
+ const shouldAnimateOutline = progress !== undefined;
1085
+ const outlineData = useMemo(() => shouldAnimateOutline ? getOutlineData(data) : null, [data, shouldAnimateOutline]);
1086
+ const hasAnimatedOutline = outlineData !== null && outline !== false;
1087
+ const structuralKey = JSON.stringify({
1088
+ beforeId,
1089
+ data: typeof data === "string" ? data : null,
1090
+ fillColor: fillColorIsDynamic ? null : fillColor,
1091
+ fillOpacity: fillOpacityIsDynamic ? null : fillOpacity,
1092
+ maxzoom,
1093
+ minzoom,
1094
+ outline,
1095
+ outlineBlur: outlineBlurIsDynamic ? null : outlineBlur,
1096
+ outlineCap,
1097
+ outlineColor: outlineColorIsDynamic ? null : outlineColor,
1098
+ outlineDashArray,
1099
+ outlineJoin,
1100
+ outlineOpacity: outlineOpacityIsDynamic ? null : outlineOpacity,
1101
+ outlinePosition,
1102
+ outlineWidth: outlineWidthIsDynamic ? null : outlineWidth,
1103
+ pattern,
1104
+ hasAnimatedOutline
1105
+ });
1106
+ optionsRef.current = {
1107
+ ...beforeId === undefined ? {} : { beforeId },
1108
+ data: normalizeData2(data),
1109
+ ...fillColor === undefined ? {} : { fillColor },
1110
+ ...fillOpacity === undefined || typeof fillOpacity === "number" ? {} : { fillOpacity },
1111
+ layerId,
1112
+ ...maxzoom === undefined ? {} : { maxzoom },
1113
+ ...minzoom === undefined ? {} : { minzoom },
1114
+ ...hasAnimatedOutline ? { outline: false } : outline === undefined ? {} : { outline },
1115
+ ...outlineBlur === undefined ? {} : { outlineBlur },
1116
+ ...outlineCap === undefined ? {} : { outlineCap },
1117
+ ...outlineColor === undefined ? {} : { outlineColor },
1118
+ ...outlineDashArray === undefined ? {} : { outlineDashArray },
1119
+ ...outlineJoin === undefined ? {} : { outlineJoin },
1120
+ ...outlineOpacity === undefined ? {} : { outlineOpacity },
1121
+ outlinePosition: outlinePosition ?? "center",
1122
+ ...outlineWidth === undefined ? {} : { outlineWidth },
1123
+ ...pattern === undefined ? {} : { pattern },
1124
+ sourceId
1125
+ };
1126
+ useEffect5(() => {
1127
+ if (!map || !optionsRef.current) {
1128
+ return;
1129
+ }
1130
+ const loadingHandle = delayRender(`Loading MapTiler polygon ${layerId}`);
1131
+ let hasFinished = false;
1132
+ const finish = () => {
1133
+ if (hasFinished) {
1134
+ return;
1135
+ }
1136
+ hasFinished = true;
1137
+ continueRender(loadingHandle);
1138
+ };
1139
+ layerIdsRef.current = helpers4.addPolygon(map, optionsRef.current);
1140
+ map.once("idle", finish);
1141
+ map.triggerRepaint();
1142
+ return () => {
1143
+ map.off("idle", finish);
1144
+ finish();
1145
+ const ids = layerIdsRef.current;
1146
+ if (!ids) {
1147
+ return;
1148
+ }
1149
+ for (const id of [ids.polygonOutlineLayerId, ids.polygonLayerId]) {
1150
+ if (id && map.getLayer(id)) {
1151
+ map.removeLayer(id);
1152
+ }
1153
+ }
1154
+ if (map.getSource(ids.polygonSourceId)) {
1155
+ map.removeSource(ids.polygonSourceId);
1156
+ }
1157
+ layerIdsRef.current = null;
1158
+ map.triggerRepaint();
1159
+ };
1160
+ }, [continueRender, delayRender, layerId, map, structuralKey, styleRevision]);
1161
+ useEffect5(() => {
1162
+ if (!map || typeof data === "string") {
1163
+ return;
1164
+ }
1165
+ const ids = layerIdsRef.current;
1166
+ if (ids && map.getSource(ids.polygonSourceId)) {
1167
+ map.getSource(ids.polygonSourceId).setData(normalizeData2(data));
1168
+ return delayMapRender({
1169
+ continueRender,
1170
+ delayRender,
1171
+ label: `Updating MapTiler polygon source ${layerId}`,
1172
+ map
1173
+ });
1174
+ }
1175
+ }, [continueRender, data, delayRender, layerId, map]);
1176
+ useEffect5(() => {
1177
+ if (!map) {
1178
+ return;
1179
+ }
1180
+ const ids = layerIdsRef.current;
1181
+ if (!ids || !map.getLayer(ids.polygonLayerId)) {
1182
+ return;
1183
+ }
1184
+ if (fillColorIsDynamic) {
1185
+ map.setPaintProperty(ids.polygonLayerId, "fill-color", fillColor);
1186
+ }
1187
+ if (fillOpacityIsDynamic) {
1188
+ map.setPaintProperty(ids.polygonLayerId, "fill-opacity", fillOpacity);
1189
+ }
1190
+ if (ids.polygonOutlineLayerId && map.getLayer(ids.polygonOutlineLayerId)) {
1191
+ if (outlineBlurIsDynamic) {
1192
+ map.setPaintProperty(ids.polygonOutlineLayerId, "line-blur", outlineBlur);
1193
+ }
1194
+ if (outlineColorIsDynamic) {
1195
+ map.setPaintProperty(ids.polygonOutlineLayerId, "line-color", outlineColor);
1196
+ }
1197
+ if (outlineOpacityIsDynamic) {
1198
+ map.setPaintProperty(ids.polygonOutlineLayerId, "line-opacity", outlineOpacity);
1199
+ }
1200
+ if (outlineWidthIsDynamic) {
1201
+ map.setPaintProperty(ids.polygonOutlineLayerId, "line-width", outlineWidth);
1202
+ }
1203
+ }
1204
+ return delayMapRender({
1205
+ continueRender,
1206
+ delayRender,
1207
+ label: `Drawing MapTiler polygon ${layerId}`,
1208
+ map
1209
+ });
1210
+ }, [
1211
+ continueRender,
1212
+ delayRender,
1213
+ fillColor,
1214
+ fillColorIsDynamic,
1215
+ fillOpacity,
1216
+ fillOpacityIsDynamic,
1217
+ layerId,
1218
+ map,
1219
+ outlineBlur,
1220
+ outlineBlurIsDynamic,
1221
+ outlineColor,
1222
+ outlineColorIsDynamic,
1223
+ outlineOpacity,
1224
+ outlineOpacityIsDynamic,
1225
+ outlineWidth,
1226
+ outlineWidthIsDynamic,
1227
+ structuralKey,
1228
+ styleRevision
1229
+ ]);
1230
+ if (!hasAnimatedOutline) {
1231
+ return null;
1232
+ }
1233
+ return /* @__PURE__ */ jsx5(MapPolyline, {
1234
+ beforeId,
1235
+ data: outlineData,
1236
+ layerId: `${layerId}-outline`,
1237
+ lineBlur: outlineBlur,
1238
+ lineCap: outlineCap,
1239
+ lineColor: outlineColor ?? "#ffffff",
1240
+ lineDashArray: outlineDashArray,
1241
+ lineJoin: outlineJoin,
1242
+ lineOpacity: outlineOpacity,
1243
+ lineWidth: outlineWidth,
1244
+ maxzoom,
1245
+ minzoom,
1246
+ name: "Map polygon outline",
1247
+ progress,
1248
+ showInTimeline: false,
1249
+ sourceId: `${sourceId}-outline`
1250
+ });
1251
+ };
1252
+ var MapPolygon = (props) => {
1253
+ const {
1254
+ controls,
1255
+ durationInFrames,
1256
+ freeze,
1257
+ from,
1258
+ hidden,
1259
+ name,
1260
+ showInTimeline,
1261
+ trimBefore
1262
+ } = props;
1263
+ return /* @__PURE__ */ jsx5(Sequence5, {
63
1264
  layout: "none",
64
1265
  from: from ?? 0,
65
1266
  trimBefore,
66
1267
  durationInFrames: durationInFrames ?? Infinity,
67
1268
  freeze,
68
1269
  hidden,
69
- name: name ?? "<MapOverlay>",
1270
+ name: name ?? "<MapPolygon>",
70
1271
  showInTimeline: showInTimeline ?? true,
71
1272
  controls,
72
- outlineRef: refForOutline,
73
- children: /* @__PURE__ */ jsx("div", {
74
- ref: refForOutline,
75
- style: {
76
- left: point?.x ?? 0,
77
- pointerEvents: "none",
78
- position: "absolute",
79
- top: point?.y ?? 0,
80
- zIndex: 1,
81
- ...style
82
- },
83
- children
1273
+ children: /* @__PURE__ */ jsx5(MapPolygonDrawing, {
1274
+ ...props
84
1275
  })
85
1276
  });
86
1277
  };
87
- var MapOverlayInner = forwardRef(MapOverlayRefForwardingFunction);
88
- var MapOverlay = Interactive.withSchema({
89
- Component: MapOverlayInner,
90
- componentName: "<MapOverlay>",
91
- componentIdentity: null,
92
- schema: mapOverlaySchema,
93
- supportsEffects: false
94
- });
95
1278
  // src/MapRegion.tsx
96
- import { length as getLineLength, lineSliceAlong, lineString } from "@turf/turf";
1279
+ import { length as getLineLength2, lineSliceAlong as lineSliceAlong2, lineString as lineString2 } from "@turf/turf";
97
1280
  import {
98
1281
  forwardRef as forwardRef2,
99
- useContext as useContext2,
100
- useEffect,
1282
+ useContext as useContext8,
1283
+ useEffect as useEffect6,
101
1284
  useImperativeHandle as useImperativeHandle2,
102
- useMemo,
103
- useRef as useRef2,
104
- useState
1285
+ useMemo as useMemo2,
1286
+ useRef as useRef7,
1287
+ useState as useState2
105
1288
  } from "react";
106
1289
  import {
107
1290
  Interactive as Interactive2,
108
- Sequence as Sequence2,
109
- useDelayRender
1291
+ Sequence as Sequence6,
1292
+ useDelayRender as useDelayRender6
110
1293
  } from "remotion";
111
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
1294
+ import { jsx as jsx6, jsxs } from "react/jsx-runtime";
112
1295
  var mapRegionSchema = {
113
1296
  ...Interactive2.baseSchema,
114
1297
  fill: {
@@ -170,16 +1353,16 @@ var MapRegionDrawing = ({
170
1353
  strokeColor = "#8f1712",
171
1354
  strokeWidth = 9
172
1355
  }) => {
173
- const { map } = useContext2(MapTilerContext);
174
- const { continueRender, delayRender } = useDelayRender();
175
- const [isReady, setIsReady] = useState(false);
176
- const [loadingHandle] = useState(() => delayRender(`Loading ${feature.properties.name} geometry`));
177
- const outline = useMemo(() => lineString(feature.geometry.coordinates[0]), [feature]);
178
- const outlineLength = useMemo(() => getLineLength(outline), [outline]);
1356
+ const { map } = useContext8(MapTilerContext);
1357
+ const { continueRender, delayRender } = useDelayRender6();
1358
+ const [isReady, setIsReady] = useState2(false);
1359
+ const [loadingHandle] = useState2(() => delayRender(`Loading ${feature.properties.name} geometry`));
1360
+ const outline = useMemo2(() => lineString2(feature.geometry.coordinates[0]), [feature]);
1361
+ const outlineLength = useMemo2(() => getLineLength2(outline), [outline]);
179
1362
  const fillSourceId = `${id}-fill`;
180
1363
  const outlineSourceId = `${id}-outline`;
181
1364
  const outlineGlowLayerId = `${id}-outline-glow`;
182
- useEffect(() => {
1365
+ useEffect6(() => {
183
1366
  if (!map) {
184
1367
  return;
185
1368
  }
@@ -205,7 +1388,7 @@ var MapRegionDrawing = ({
205
1388
  map.setPaintProperty(fillSourceId, "fill-color", fillColor);
206
1389
  if (!map.getSource(outlineSourceId)) {
207
1390
  map.addSource(outlineSourceId, {
208
- data: lineSliceAlong(outline, 0, 0.001),
1391
+ data: lineSliceAlong2(outline, 0, 0.001),
209
1392
  type: "geojson"
210
1393
  });
211
1394
  }
@@ -261,12 +1444,12 @@ var MapRegionDrawing = ({
261
1444
  strokeColor,
262
1445
  strokeWidth
263
1446
  ]);
264
- useEffect(() => {
1447
+ useEffect6(() => {
265
1448
  if (!isReady || !map) {
266
1449
  return;
267
1450
  }
268
1451
  const frameHandle = delayRender(`Drawing ${feature.properties.name}`);
269
- map.getSource(outlineSourceId).setData(lineSliceAlong(outline, 0, Math.max(0.001, outlineLength * Math.min(1, Math.max(0, progress)))));
1452
+ map.getSource(outlineSourceId).setData(lineSliceAlong2(outline, 0, Math.max(0.001, outlineLength * Math.min(1, Math.max(0, progress)))));
270
1453
  map.setPaintProperty(fillSourceId, "fill-opacity", Math.min(1, Math.max(0, fill)));
271
1454
  map.once("idle", () => continueRender(frameHandle));
272
1455
  map.triggerRepaint();
@@ -283,7 +1466,7 @@ var MapRegionDrawing = ({
283
1466
  outlineSourceId,
284
1467
  progress
285
1468
  ]);
286
- useEffect(() => {
1469
+ useEffect6(() => {
287
1470
  if (!map) {
288
1471
  return;
289
1472
  }
@@ -312,9 +1495,9 @@ var MapRegionBounds = ({
312
1495
  feature,
313
1496
  refForOutline
314
1497
  }) => {
315
- const { map } = useContext2(MapTilerContext);
1498
+ const { map } = useContext8(MapTilerContext);
316
1499
  if (!map) {
317
- return /* @__PURE__ */ jsx2("div", {
1500
+ return /* @__PURE__ */ jsx6("div", {
318
1501
  ref: refForOutline
319
1502
  });
320
1503
  }
@@ -323,7 +1506,7 @@ var MapRegionBounds = ({
323
1506
  const right = Math.max(...points.map((point) => point.x));
324
1507
  const top = Math.min(...points.map((point) => point.y));
325
1508
  const bottom = Math.max(...points.map((point) => point.y));
326
- return /* @__PURE__ */ jsx2("div", {
1509
+ return /* @__PURE__ */ jsx6("div", {
327
1510
  ref: refForOutline,
328
1511
  style: {
329
1512
  height: bottom - top,
@@ -355,9 +1538,9 @@ var MapRegionRefForwardingFunction = ({
355
1538
  showInTimeline,
356
1539
  controls
357
1540
  }, ref) => {
358
- const refForOutline = useRef2(null);
1541
+ const refForOutline = useRef7(null);
359
1542
  useImperativeHandle2(ref, () => refForOutline.current, []);
360
- return /* @__PURE__ */ jsxs(Sequence2, {
1543
+ return /* @__PURE__ */ jsxs(Sequence6, {
361
1544
  layout: "none",
362
1545
  from: from ?? 0,
363
1546
  trimBefore,
@@ -369,7 +1552,7 @@ var MapRegionRefForwardingFunction = ({
369
1552
  controls,
370
1553
  outlineRef: refForOutline,
371
1554
  children: [
372
- /* @__PURE__ */ jsx2(MapRegionDrawing, {
1555
+ /* @__PURE__ */ jsx6(MapRegionDrawing, {
373
1556
  feature,
374
1557
  fill,
375
1558
  fillColor,
@@ -379,7 +1562,7 @@ var MapRegionRefForwardingFunction = ({
379
1562
  strokeColor,
380
1563
  strokeWidth
381
1564
  }),
382
- /* @__PURE__ */ jsx2(MapRegionBounds, {
1565
+ /* @__PURE__ */ jsx6(MapRegionBounds, {
383
1566
  feature,
384
1567
  refForOutline
385
1568
  })
@@ -395,22 +1578,22 @@ var MapRegion = Interactive2.withSchema({
395
1578
  supportsEffects: false
396
1579
  });
397
1580
  // src/MapRoute.tsx
398
- import { length as getLineLength2, lineSliceAlong as lineSliceAlong2, lineString as lineString2 } from "@turf/turf";
1581
+ import { length as getLineLength3, lineSliceAlong as lineSliceAlong3, lineString as lineString3 } from "@turf/turf";
399
1582
  import {
400
1583
  forwardRef as forwardRef3,
401
- useContext as useContext3,
402
- useEffect as useEffect2,
1584
+ useContext as useContext9,
1585
+ useEffect as useEffect7,
403
1586
  useImperativeHandle as useImperativeHandle3,
404
- useMemo as useMemo2,
405
- useRef as useRef3,
406
- useState as useState2
1587
+ useMemo as useMemo3,
1588
+ useRef as useRef8,
1589
+ useState as useState3
407
1590
  } from "react";
408
1591
  import {
409
1592
  Interactive as Interactive3,
410
- Sequence as Sequence3,
411
- useDelayRender as useDelayRender2
1593
+ Sequence as Sequence7,
1594
+ useDelayRender as useDelayRender7
412
1595
  } from "remotion";
413
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1596
+ import { jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
414
1597
  var mapRouteSchema = {
415
1598
  ...Interactive3.baseSchema,
416
1599
  glow: {
@@ -455,21 +1638,21 @@ var MapRouteDrawing = ({
455
1638
  strokeColor = "#006cff",
456
1639
  strokeWidth = 9
457
1640
  }) => {
458
- const { map } = useContext3(MapTilerContext);
459
- const { continueRender, delayRender } = useDelayRender2();
460
- const [isReady, setIsReady] = useState2(false);
461
- const [loadingHandle] = useState2(() => delayRender(`Loading ${feature.properties.name} route`));
462
- const route = useMemo2(() => lineString2(feature.geometry.coordinates), [feature]);
463
- const routeLength = useMemo2(() => getLineLength2(route), [route]);
1641
+ const { map } = useContext9(MapTilerContext);
1642
+ const { continueRender, delayRender } = useDelayRender7();
1643
+ const [isReady, setIsReady] = useState3(false);
1644
+ const [loadingHandle] = useState3(() => delayRender(`Loading ${feature.properties.name} route`));
1645
+ const route = useMemo3(() => lineString3(feature.geometry.coordinates), [feature]);
1646
+ const routeLength = useMemo3(() => getLineLength3(route), [route]);
464
1647
  const sourceId = `${id}-route`;
465
1648
  const glowLayerId = `${id}-route-glow`;
466
- useEffect2(() => {
1649
+ useEffect7(() => {
467
1650
  if (!map) {
468
1651
  return;
469
1652
  }
470
1653
  if (!map.getSource(sourceId)) {
471
1654
  map.addSource(sourceId, {
472
- data: lineSliceAlong2(route, 0, 0.001),
1655
+ data: lineSliceAlong3(route, 0, 0.001),
473
1656
  type: "geojson"
474
1657
  });
475
1658
  }
@@ -522,12 +1705,12 @@ var MapRouteDrawing = ({
522
1705
  strokeColor,
523
1706
  strokeWidth
524
1707
  ]);
525
- useEffect2(() => {
1708
+ useEffect7(() => {
526
1709
  if (!isReady || !map) {
527
1710
  return;
528
1711
  }
529
1712
  const frameHandle = delayRender(`Drawing ${feature.properties.name} route`);
530
- map.getSource(sourceId).setData(lineSliceAlong2(route, 0, Math.max(0.001, routeLength * Math.min(1, Math.max(0, progress)))));
1713
+ map.getSource(sourceId).setData(lineSliceAlong3(route, 0, Math.max(0.001, routeLength * Math.min(1, Math.max(0, progress)))));
531
1714
  map.once("idle", () => continueRender(frameHandle));
532
1715
  map.triggerRepaint();
533
1716
  }, [
@@ -541,7 +1724,7 @@ var MapRouteDrawing = ({
541
1724
  routeLength,
542
1725
  sourceId
543
1726
  ]);
544
- useEffect2(() => {
1727
+ useEffect7(() => {
545
1728
  if (!map) {
546
1729
  return;
547
1730
  }
@@ -564,9 +1747,9 @@ var MapRouteBounds = ({
564
1747
  feature,
565
1748
  refForOutline
566
1749
  }) => {
567
- const { map } = useContext3(MapTilerContext);
1750
+ const { map } = useContext9(MapTilerContext);
568
1751
  if (!map) {
569
- return /* @__PURE__ */ jsx3("div", {
1752
+ return /* @__PURE__ */ jsx7("div", {
570
1753
  ref: refForOutline
571
1754
  });
572
1755
  }
@@ -575,7 +1758,7 @@ var MapRouteBounds = ({
575
1758
  const right = Math.max(...points.map((point) => point.x));
576
1759
  const top = Math.min(...points.map((point) => point.y));
577
1760
  const bottom = Math.max(...points.map((point) => point.y));
578
- return /* @__PURE__ */ jsx3("div", {
1761
+ return /* @__PURE__ */ jsx7("div", {
579
1762
  ref: refForOutline,
580
1763
  style: {
581
1764
  height: bottom - top,
@@ -605,9 +1788,9 @@ var MapRouteRefForwardingFunction = ({
605
1788
  showInTimeline,
606
1789
  controls
607
1790
  }, ref) => {
608
- const refForOutline = useRef3(null);
1791
+ const refForOutline = useRef8(null);
609
1792
  useImperativeHandle3(ref, () => refForOutline.current, []);
610
- return /* @__PURE__ */ jsxs2(Sequence3, {
1793
+ return /* @__PURE__ */ jsxs2(Sequence7, {
611
1794
  layout: "none",
612
1795
  from: from ?? 0,
613
1796
  trimBefore,
@@ -619,7 +1802,7 @@ var MapRouteRefForwardingFunction = ({
619
1802
  controls,
620
1803
  outlineRef: refForOutline,
621
1804
  children: [
622
- /* @__PURE__ */ jsx3(MapRouteDrawing, {
1805
+ /* @__PURE__ */ jsx7(MapRouteDrawing, {
623
1806
  feature,
624
1807
  glow,
625
1808
  id,
@@ -627,7 +1810,7 @@ var MapRouteRefForwardingFunction = ({
627
1810
  strokeColor,
628
1811
  strokeWidth
629
1812
  }),
630
- /* @__PURE__ */ jsx3(MapRouteBounds, {
1813
+ /* @__PURE__ */ jsx7(MapRouteBounds, {
631
1814
  feature,
632
1815
  refForOutline
633
1816
  })
@@ -642,23 +1825,94 @@ var MapRoute = Interactive3.withSchema({
642
1825
  schema: mapRouteSchema,
643
1826
  supportsEffects: false
644
1827
  });
1828
+ // src/MapSource.tsx
1829
+ import { useContext as useContext10, useEffect as useEffect8, useRef as useRef9 } from "react";
1830
+ import { useDelayRender as useDelayRender8 } from "remotion";
1831
+ var MapSource = ({ children, id, source }) => {
1832
+ const { map, styleRevision } = useContext10(MapTilerContext);
1833
+ const sourceRef = useRef9(source);
1834
+ const { continueRender, delayRender } = useDelayRender8();
1835
+ sourceRef.current = source;
1836
+ useEffect8(() => {
1837
+ if (!map) {
1838
+ return;
1839
+ }
1840
+ const loadingHandle = delayRender(`Loading MapTiler source ${id}`);
1841
+ let hasFinished = false;
1842
+ const finish = () => {
1843
+ if (hasFinished) {
1844
+ return;
1845
+ }
1846
+ hasFinished = true;
1847
+ continueRender(loadingHandle);
1848
+ };
1849
+ if (!map.getSource(id)) {
1850
+ map.addSource(id, sourceRef.current);
1851
+ }
1852
+ map.once("idle", finish);
1853
+ map.triggerRepaint();
1854
+ return () => {
1855
+ map.off("idle", finish);
1856
+ finish();
1857
+ for (const layer of map.getStyle().layers ?? []) {
1858
+ if ("source" in layer && layer.source === id && map.getLayer(layer.id)) {
1859
+ map.removeLayer(layer.id);
1860
+ }
1861
+ }
1862
+ if (map.getSource(id)) {
1863
+ map.removeSource(id);
1864
+ }
1865
+ map.triggerRepaint();
1866
+ };
1867
+ }, [continueRender, delayRender, id, map, styleRevision]);
1868
+ useEffect8(() => {
1869
+ if (!map || source.type !== "geojson") {
1870
+ return;
1871
+ }
1872
+ const existingSource = map.getSource(id);
1873
+ if (!existingSource) {
1874
+ return;
1875
+ }
1876
+ existingSource.setData(source.data);
1877
+ return delayMapRender({
1878
+ continueRender,
1879
+ delayRender,
1880
+ label: `Updating MapTiler source ${id}`,
1881
+ map
1882
+ });
1883
+ }, [continueRender, delayRender, id, map, source]);
1884
+ return children;
1885
+ };
645
1886
  // src/MapViewport.tsx
646
1887
  import { Map as MapTilerMap, MapStyle } from "@maptiler/sdk";
647
1888
  import"@maptiler/sdk/style.css";
648
1889
  import {
649
1890
  forwardRef as forwardRef4,
650
- useEffect as useEffect3,
1891
+ useEffect as useEffect9,
651
1892
  useImperativeHandle as useImperativeHandle4,
652
- useMemo as useMemo3,
653
- useRef as useRef4,
654
- useState as useState3
1893
+ useMemo as useMemo4,
1894
+ useRef as useRef10,
1895
+ useState as useState4
655
1896
  } from "react";
656
1897
  import {
657
1898
  Interactive as Interactive4,
658
- Sequence as Sequence4,
659
- useDelayRender as useDelayRender3
1899
+ Sequence as Sequence8,
1900
+ useDelayRender as useDelayRender9
660
1901
  } from "remotion";
661
- import { jsx as jsx4, jsxs as jsxs3, Fragment } from "react/jsx-runtime";
1902
+ import { jsx as jsx8, jsxs as jsxs3, Fragment } from "react/jsx-runtime";
1903
+ var stripStyleLayers = ({
1904
+ administrativeBorders,
1905
+ map,
1906
+ showLabels
1907
+ }) => {
1908
+ for (const layer of [...map.getStyle().layers ?? []]) {
1909
+ const shouldRemoveLabel = !showLabels && layer.type === "symbol";
1910
+ const shouldRemoveAdministrativeBorder = administrativeBorders === "none" ? /border/i.test(layer.id) : administrativeBorders === "country-only" && /other border/i.test(layer.id);
1911
+ if (shouldRemoveLabel || shouldRemoveAdministrativeBorder) {
1912
+ map.removeLayer(layer.id);
1913
+ }
1914
+ }
1915
+ };
662
1916
  var mapViewportSchema = {
663
1917
  ...Interactive4.baseSchema,
664
1918
  centerLongitude: {
@@ -701,6 +1955,56 @@ var mapViewportSchema = {
701
1955
  hiddenFromList: false,
702
1956
  keyframable: true
703
1957
  },
1958
+ pitch: {
1959
+ type: "number",
1960
+ min: 0,
1961
+ max: 85,
1962
+ step: 1,
1963
+ default: 0,
1964
+ description: "Pitch",
1965
+ hiddenFromList: false,
1966
+ keyframable: true
1967
+ },
1968
+ paddingTop: {
1969
+ type: "number",
1970
+ min: 0,
1971
+ max: 2000,
1972
+ step: 1,
1973
+ default: 0,
1974
+ description: "Top camera padding",
1975
+ hiddenFromList: false,
1976
+ keyframable: true
1977
+ },
1978
+ paddingRight: {
1979
+ type: "number",
1980
+ min: 0,
1981
+ max: 2000,
1982
+ step: 1,
1983
+ default: 0,
1984
+ description: "Right camera padding",
1985
+ hiddenFromList: false,
1986
+ keyframable: true
1987
+ },
1988
+ paddingBottom: {
1989
+ type: "number",
1990
+ min: 0,
1991
+ max: 2000,
1992
+ step: 1,
1993
+ default: 0,
1994
+ description: "Bottom camera padding",
1995
+ hiddenFromList: false,
1996
+ keyframable: true
1997
+ },
1998
+ paddingLeft: {
1999
+ type: "number",
2000
+ min: 0,
2001
+ max: 2000,
2002
+ step: 1,
2003
+ default: 0,
2004
+ description: "Left camera padding",
2005
+ hiddenFromList: false,
2006
+ keyframable: true
2007
+ },
704
2008
  backgroundColor: {
705
2009
  type: "color",
706
2010
  default: "#dfe7e2",
@@ -722,11 +2026,11 @@ var MissingApiKey = () => {
722
2026
  textAlign: "center"
723
2027
  },
724
2028
  children: [
725
- /* @__PURE__ */ jsx4("div", {
2029
+ /* @__PURE__ */ jsx8("div", {
726
2030
  style: { fontSize: 64, fontWeight: 700 },
727
2031
  children: "MapTiler key needed"
728
2032
  }),
729
- /* @__PURE__ */ jsx4("div", {
2033
+ /* @__PURE__ */ jsx8("div", {
730
2034
  style: { fontSize: 32, lineHeight: 1.4, marginTop: 24 },
731
2035
  children: "Pass an apiKey prop to <MapViewport>."
732
2036
  })
@@ -740,6 +2044,20 @@ var MapViewportRefForwardingFunction = ({
740
2044
  centerLatitude = 0,
741
2045
  centerLongitude = 0,
742
2046
  children,
2047
+ language,
2048
+ mapOptions,
2049
+ mapStyle = MapStyle.BASIC,
2050
+ onMapReady,
2051
+ paddingBottom = 0,
2052
+ paddingLeft = 0,
2053
+ paddingRight = 0,
2054
+ paddingTop = 0,
2055
+ pitch = 0,
2056
+ projection,
2057
+ showLabels = true,
2058
+ administrativeBorders = "all",
2059
+ terrain = false,
2060
+ terrainExaggeration = 1,
743
2061
  durationInFrames,
744
2062
  from,
745
2063
  trimBefore,
@@ -750,22 +2068,45 @@ var MapViewportRefForwardingFunction = ({
750
2068
  zoom = 4,
751
2069
  controls
752
2070
  }, ref) => {
753
- const mapContainerRef = useRef4(null);
754
- const mapRef = useRef4(null);
755
- const viewportRef = useRef4(null);
756
- const initialCameraRef = useRef4({
2071
+ const mapContainerRef = useRef10(null);
2072
+ const mapRef = useRef10(null);
2073
+ const viewportRef = useRef10(null);
2074
+ const initialCameraRef = useRef10({
757
2075
  bearing,
758
2076
  centerLatitude,
759
2077
  centerLongitude,
2078
+ paddingBottom,
2079
+ paddingLeft,
2080
+ paddingRight,
2081
+ paddingTop,
2082
+ pitch,
760
2083
  zoom
761
2084
  });
762
- const { continueRender, delayRender } = useDelayRender3();
763
- const [map, setMap] = useState3(null);
764
- const [cameraRevision, setCameraRevision] = useState3(0);
765
- const [loadingHandle] = useState3(() => delayRender("Loading MapTiler map"));
766
- const contextValue = useMemo3(() => ({ cameraRevision, map }), [cameraRevision, map]);
2085
+ const initialMapOptionsRef = useRef10({
2086
+ administrativeBorders,
2087
+ language,
2088
+ mapOptions,
2089
+ mapStyle,
2090
+ projection,
2091
+ showLabels,
2092
+ terrain,
2093
+ terrainExaggeration
2094
+ });
2095
+ const lastMapStyleRef = useRef10(mapStyle);
2096
+ const lastLayerVisibilityRef = useRef10({
2097
+ administrativeBorders,
2098
+ showLabels
2099
+ });
2100
+ const onMapReadyRef = useRef10(onMapReady);
2101
+ onMapReadyRef.current = onMapReady;
2102
+ const { continueRender, delayRender } = useDelayRender9();
2103
+ const [map, setMap] = useState4(null);
2104
+ const [cameraRevision, setCameraRevision] = useState4(0);
2105
+ const [styleRevision, setStyleRevision] = useState4(0);
2106
+ const [loadingHandle] = useState4(() => delayRender("Loading MapTiler map"));
2107
+ const contextValue = useMemo4(() => ({ cameraRevision, map, styleRevision }), [cameraRevision, map, styleRevision]);
767
2108
  useImperativeHandle4(ref, () => viewportRef.current, []);
768
- useEffect3(() => {
2109
+ useEffect9(() => {
769
2110
  if (!apiKey) {
770
2111
  continueRender(loadingHandle);
771
2112
  return;
@@ -774,31 +2115,48 @@ var MapViewportRefForwardingFunction = ({
774
2115
  return;
775
2116
  }
776
2117
  const initialCamera = initialCameraRef.current;
2118
+ const initialOptions = initialMapOptionsRef.current;
777
2119
  const mapInstance = new MapTilerMap({
2120
+ fullscreenControl: false,
2121
+ geolocateControl: false,
2122
+ navigationControl: false,
2123
+ scaleControl: false,
2124
+ terrainControl: false,
2125
+ ...initialOptions.mapOptions,
778
2126
  apiKey,
779
2127
  bearing: initialCamera.bearing,
780
- canvasContextAttributes: { preserveDrawingBuffer: true },
2128
+ canvasContextAttributes: {
2129
+ ...initialOptions.mapOptions?.canvasContextAttributes,
2130
+ preserveDrawingBuffer: true
2131
+ },
781
2132
  center: [initialCamera.centerLongitude, initialCamera.centerLatitude],
782
2133
  container: mapContainerRef.current,
783
2134
  fadeDuration: 0,
784
- fullscreenControl: false,
785
- geolocateControl: false,
786
2135
  interactive: false,
787
- navigationControl: false,
788
- scaleControl: false,
789
- style: MapStyle.BASIC,
790
- terrainControl: false,
2136
+ language: initialOptions.language,
2137
+ pitch: initialCamera.pitch,
2138
+ projection: initialOptions.projection,
2139
+ style: initialOptions.mapStyle,
2140
+ terrain: initialOptions.terrain,
2141
+ terrainExaggeration: initialOptions.terrainExaggeration,
791
2142
  zoom: initialCamera.zoom
792
2143
  });
2144
+ mapInstance.setPadding({
2145
+ bottom: initialCamera.paddingBottom,
2146
+ left: initialCamera.paddingLeft,
2147
+ right: initialCamera.paddingRight,
2148
+ top: initialCamera.paddingTop
2149
+ });
793
2150
  mapRef.current = mapInstance;
794
2151
  mapInstance.on("load", () => {
795
- for (const layer of [...mapInstance.getStyle().layers ?? []]) {
796
- if (layer.type === "symbol" || /other border/i.test(layer.id)) {
797
- mapInstance.removeLayer(layer.id);
798
- }
799
- }
2152
+ stripStyleLayers({
2153
+ administrativeBorders: initialOptions.administrativeBorders,
2154
+ map: mapInstance,
2155
+ showLabels: initialOptions.showLabels
2156
+ });
800
2157
  mapInstance.once("idle", () => {
801
2158
  setMap(mapInstance);
2159
+ onMapReadyRef.current?.(mapInstance);
802
2160
  continueRender(loadingHandle);
803
2161
  });
804
2162
  mapInstance.triggerRepaint();
@@ -808,12 +2166,13 @@ var MapViewportRefForwardingFunction = ({
808
2166
  mapRef.current = null;
809
2167
  };
810
2168
  }, [apiKey, continueRender, loadingHandle]);
811
- useEffect3(() => {
2169
+ useEffect9(() => {
812
2170
  if (!map) {
813
2171
  return;
814
2172
  }
815
2173
  const currentCenter = map.getCenter();
816
- const cameraIsCurrent = Math.abs(currentCenter.lng - centerLongitude) < 0.0000001 && Math.abs(currentCenter.lat - centerLatitude) < 0.0000001 && Math.abs(map.getZoom() - zoom) < 0.0000001 && Math.abs(map.getBearing() - bearing) < 0.0000001;
2174
+ const currentPadding = map.getPadding();
2175
+ const cameraIsCurrent = Math.abs(currentCenter.lng - centerLongitude) < 0.0000001 && Math.abs(currentCenter.lat - centerLatitude) < 0.0000001 && Math.abs(map.getZoom() - zoom) < 0.0000001 && Math.abs(map.getBearing() - bearing) < 0.0000001 && Math.abs(map.getPitch() - pitch) < 0.0000001 && Math.abs((currentPadding.top ?? 0) - paddingTop) < 0.0000001 && Math.abs((currentPadding.right ?? 0) - paddingRight) < 0.0000001 && Math.abs((currentPadding.bottom ?? 0) - paddingBottom) < 0.0000001 && Math.abs((currentPadding.left ?? 0) - paddingLeft) < 0.0000001;
817
2176
  if (cameraIsCurrent) {
818
2177
  return;
819
2178
  }
@@ -831,6 +2190,13 @@ var MapViewportRefForwardingFunction = ({
831
2190
  map.jumpTo({
832
2191
  bearing,
833
2192
  center: [centerLongitude, centerLatitude],
2193
+ padding: {
2194
+ bottom: paddingBottom,
2195
+ left: paddingLeft,
2196
+ right: paddingRight,
2197
+ top: paddingTop
2198
+ },
2199
+ pitch,
834
2200
  zoom
835
2201
  });
836
2202
  setCameraRevision((revision) => revision + 1);
@@ -846,9 +2212,77 @@ var MapViewportRefForwardingFunction = ({
846
2212
  continueRender,
847
2213
  delayRender,
848
2214
  map,
2215
+ paddingBottom,
2216
+ paddingLeft,
2217
+ paddingRight,
2218
+ paddingTop,
2219
+ pitch,
849
2220
  zoom
850
2221
  ]);
851
- return /* @__PURE__ */ jsx4(Sequence4, {
2222
+ useEffect9(() => {
2223
+ if (!map || lastMapStyleRef.current === mapStyle && lastLayerVisibilityRef.current.showLabels === showLabels && lastLayerVisibilityRef.current.administrativeBorders === administrativeBorders) {
2224
+ return;
2225
+ }
2226
+ const styleHandle = delayRender("Updating MapTiler style");
2227
+ let hasFinished = false;
2228
+ const finish = () => {
2229
+ if (hasFinished) {
2230
+ return;
2231
+ }
2232
+ hasFinished = true;
2233
+ lastMapStyleRef.current = mapStyle;
2234
+ lastLayerVisibilityRef.current = {
2235
+ administrativeBorders,
2236
+ showLabels
2237
+ };
2238
+ setStyleRevision((revision) => revision + 1);
2239
+ continueRender(styleHandle);
2240
+ };
2241
+ const onStyleLoad = () => {
2242
+ stripStyleLayers({ administrativeBorders, map, showLabels });
2243
+ map.once("idle", finish);
2244
+ map.triggerRepaint();
2245
+ };
2246
+ map.once("style.load", onStyleLoad);
2247
+ map.setStyle(mapStyle ?? null);
2248
+ map.triggerRepaint();
2249
+ return () => {
2250
+ map.off("style.load", onStyleLoad);
2251
+ map.off("idle", finish);
2252
+ finish();
2253
+ };
2254
+ }, [
2255
+ administrativeBorders,
2256
+ continueRender,
2257
+ delayRender,
2258
+ map,
2259
+ mapStyle,
2260
+ showLabels
2261
+ ]);
2262
+ useEffect9(() => {
2263
+ if (map && language) {
2264
+ map.setLanguage(language);
2265
+ map.triggerRepaint();
2266
+ }
2267
+ }, [language, map]);
2268
+ useEffect9(() => {
2269
+ if (!map) {
2270
+ return;
2271
+ }
2272
+ if (terrain) {
2273
+ map.enableTerrain(terrainExaggeration);
2274
+ } else {
2275
+ map.disableTerrain();
2276
+ }
2277
+ map.triggerRepaint();
2278
+ }, [map, terrain, terrainExaggeration]);
2279
+ useEffect9(() => {
2280
+ if (map && projection) {
2281
+ map.setProjection(projection, { persist: true });
2282
+ map.triggerRepaint();
2283
+ }
2284
+ }, [map, projection]);
2285
+ return /* @__PURE__ */ jsx8(Sequence8, {
852
2286
  layout: "none",
853
2287
  from: from ?? 0,
854
2288
  trimBefore,
@@ -858,7 +2292,7 @@ var MapViewportRefForwardingFunction = ({
858
2292
  name: name ?? "<MapViewport>",
859
2293
  showInTimeline: showInTimeline ?? true,
860
2294
  controls,
861
- children: /* @__PURE__ */ jsx4("div", {
2295
+ children: /* @__PURE__ */ jsx8("div", {
862
2296
  ref: viewportRef,
863
2297
  style: {
864
2298
  backgroundColor,
@@ -868,19 +2302,19 @@ var MapViewportRefForwardingFunction = ({
868
2302
  },
869
2303
  children: apiKey ? /* @__PURE__ */ jsxs3(Fragment, {
870
2304
  children: [
871
- /* @__PURE__ */ jsx4("div", {
2305
+ /* @__PURE__ */ jsx8("div", {
872
2306
  ref: mapContainerRef,
873
2307
  style: {
874
2308
  inset: 0,
875
2309
  position: "absolute"
876
2310
  }
877
2311
  }),
878
- /* @__PURE__ */ jsx4(MapTilerContext.Provider, {
2312
+ /* @__PURE__ */ jsx8(MapTilerContext.Provider, {
879
2313
  value: contextValue,
880
2314
  children
881
2315
  })
882
2316
  ]
883
- }) : /* @__PURE__ */ jsx4(MissingApiKey, {})
2317
+ }) : /* @__PURE__ */ jsx8(MissingApiKey, {})
884
2318
  })
885
2319
  });
886
2320
  };
@@ -893,8 +2327,16 @@ var MapViewport = Interactive4.withSchema({
893
2327
  supportsEffects: false
894
2328
  });
895
2329
  export {
2330
+ useMapTiler,
896
2331
  MapViewport,
2332
+ MapSource,
897
2333
  MapRoute,
898
2334
  MapRegion,
899
- MapOverlay
2335
+ MapPolyline,
2336
+ MapPolygon,
2337
+ MapPoint,
2338
+ MapOverlay,
2339
+ MapMarker,
2340
+ MapLayer,
2341
+ MapHeatmap
900
2342
  };