Skip to content

Commit fb99807

Browse files
committed
feat(ol-videorecorder-control): pass-through all props and events from ol-ext
- if not `downloadName` is set, the file will not be downloaded but the `stop` event is fired with the blob data/url. - all events are now fired. In addition to the already existing `start` and `stop` event, you can now also react to the `pause` and `resume` event - docs has been updated
1 parent 470d465 commit fb99807

File tree

2 files changed

+56
-43
lines changed

2 files changed

+56
-43
lines changed

docs/componentsguide/mapcontrols/videorecorder/index.md

+36-18
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,53 @@ import VideorecorderControlDemo from "@demos/VideorecorderControlDemo.vue"
1919

2020
## Properties
2121

22-
### className
22+
### Props from OpenLayers
2323

24-
class of the control
24+
Properties are passed-trough from `ol-ext` directly.
25+
Their types and default values can be checked-out [in the official docs](https://viglino.github.io/ol-ext/doc/doc-pages/ol.control.VideoRecorder.html).
26+
Only some properties deviate caused by reserved keywords from Vue / HTML.
27+
This deviating props are described in the section below.
2528

26-
- **Type**: `String`
29+
### Deviating Properties
2730

28-
### framerate
31+
### `downloadName`
2932

30-
framerate for the video
33+
If this property is set, the file will be downloaded immediately after stopping the recording and saved as the given `downloadName`.
34+
If not defined, you need to handle the `stop` event fired on component level.
35+
By default this property is set to `mapVideo.mp4`.
3136

32-
- **Type**: `Number`
33-
- **Default**: `30`
37+
## Events
3438

35-
### videoBitsPerSecond
39+
You have access to all Events from the underlying control.
40+
Check out [the official docs](https://viglino.github.io/ol-ext/doc/doc-pages/ol.control.VideoRecorder.html) to see the available events tht will be fired.
3641

37-
bitrate for the video
42+
```html
43+
<ol-videorecorder-control @error="handleEvent" />
44+
```
3845

39-
- **Type**: `Number`
40-
- **Default**: `5000000`
46+
## Methods
4147

42-
### videoTarget
48+
You have access to all Methods from the underlying control.
49+
Check out [the official docs](https://viglino.github.io/ol-ext/doc/doc-pages/ol.control.VideoRecorder.html) to see the available methods.
4350

44-
video element or the container to add the video when finished or `'DIALOG'` to show it in a dialog.
51+
To access the source, you can use a `ref()` as shown below:
4552

46-
- **Type**: `String | DOMElement`
53+
```vue
54+
<template>
55+
<!-- ... -->
56+
<ol-videorecorder-control ref="vRef" @error="handleEvent" />
57+
<!-- ... -->
58+
</template>
4759
48-
### downloadName
60+
<script setup lang="ts">
61+
import { ref, onMounted } from "vue";
62+
import type VideoRecorder from "ol-ext/control/VideoRecorder";
4963
50-
class of the control
64+
const vRef = ref<{ control: VideoRecorder }>(null);
5165
52-
- **Type**: `String`
53-
- **Default**: `'mapVideo.mp4'`
66+
onMounted(() => {
67+
const recorder: VideoRecorder = vRef.value?.control;
68+
// call your method on `recorder`
69+
});
70+
</script>
71+
```

src/components/mapControls/OlVideoRecorderControl.vue

+20-25
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,38 @@
22
<div v-if="false"></div>
33
</template>
44
<script setup lang="ts">
5-
import VideoRecorder from "ol-ext/control/VideoRecorder";
5+
import VideoRecorder, { type Options } from "ol-ext/control/VideoRecorder";
66
import { saveAs } from "file-saver";
77
import { useAttrs } from "vue";
88
import useControl from "@/composables/useControl";
99
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
10+
import { useOpenLayersEvents } from "@/composables/useOpenLayersEvents";
11+
import type { ObjectEvent } from "ol/Object";
1012
11-
const props = withDefaults(
12-
defineProps<{
13-
className?: string;
14-
framerate?: number;
15-
videoBitsPerSecond?: number;
16-
videoTarget?: string;
17-
downloadName?: string;
18-
}>(),
19-
{
20-
framerate: 30,
21-
videoBitsPerSecond: 5000000,
22-
downloadName: "mapVideo.mp4",
23-
}
24-
);
13+
// prevent warnings caused by event pass-through via useOpenLayersEvents composable
14+
defineOptions({
15+
inheritAttrs: false,
16+
});
2517
26-
const emit = defineEmits(["start", "stop"]);
18+
const props = withDefaults(defineProps<Options & { downloadName?: string }>(), {
19+
downloadName: "mapVideo.mp4",
20+
});
2721
2822
const attrs = useAttrs();
2923
const { properties } = usePropsAsObjectProperties(props);
3024
const { control } = useControl(VideoRecorder, properties, attrs);
3125
32-
// @ts-ignore
33-
control.value.on("start", (event: Event<HTMLVideoElement>) => {
34-
emit("start", event);
35-
});
26+
useOpenLayersEvents(control, ["start", "stop", "pause", "resume"]);
3627
37-
// @ts-ignore
38-
control.value.on("stop", (event: Event<HTMLVideoElement>) => {
39-
emit("stop", event);
40-
saveAs(event.videoURL, props.downloadName);
41-
});
28+
control.value.on(
29+
// @ts-ignore
30+
"stop",
31+
(event: ObjectEvent & { videoURL: string }) => {
32+
if (props.downloadName) {
33+
saveAs(event.videoURL, props.downloadName);
34+
}
35+
}
36+
);
4237
4338
defineExpose({
4439
control,

0 commit comments

Comments
 (0)