How to add video stream (WebRTC) overlay? I tried to use addSource for videoSource, but it still did not work #5422
-
Hi, I'm currently building a real-time radar video on a map, but an issue appears when showing the video overlay. The video stream in the form of a webpage (HTML) like the video record below: Screencast.from.2025-01-29.00-06-45.webmI have tried to use addSource method for videoSourceOption. addRadarVideo(name: string, mappable: Mappable, range: number, url: string[]): void {
// Get bounds
const latOffset = range/111.32;
const lngOffset = range/(111.32 * Math.cos(mappable.location.lat * Math.PI / 180));
const latNorth = mappable.location.lat + latOffset;
const latSouth = mappable.location.lat - latOffset;
const lngEast = mappable.location.lng + lngOffset;
const lngWest = mappable.location.lng - lngOffset;
// Video source option
const videoSourceOption: maplibregl.VideoSourceSpecification = {
type: 'video',
urls: url,
coordinates: [
[lngWest, latNorth],
[lngEast, latNorth],
[lngEast, latSouth],
[lngWest, latSouth],
]
}
// Add video source and layer
if (this.map.isStyleLoaded()) {
this.map.addSource('video-source', videoSourceOption);
this.map.addLayer({
id: "video-layer",
source: 'video-source',
type: 'raster',
});
} else {
this.map.on('load', () => {
this.map.addSource('video-source', videoSourceOption);
this.map.addLayer({
id: "video-layer",
source: 'video-source',
type: 'raster',
});
});
}
} the browser could not play the media and the warning appeared: Okay, since the content type is text/html, I worked around it by creating the marker. addRadar (lng, lat, htmlContent) {
// Create element for the radar (video)
const el = document.createElement('div');
el.style.width = '300px';
el.style.height = '300px';
el.style.position = 'absolute';
el.style.transform = 'translate(-50%, -50%)';
// Create the iframe for the video
const iframe = document.createElement('iframe');
iframe.src = `${htmlContent}?controls=0`;
iframe.width = '100%';
iframe.height = '100%';
iframe.style.border = 'none';
iframe.style.borderRadius = '50%';
iframe.style.objectFit = 'cover';
el.appendChild(iframe);
new maplibregl.Marker({
element: el,
opacity: '0.8',
anchor: "center"
})
.setLngLat([lng, lat])
.addTo(this.map);
} The result is that the radar can appear according to its coordinates, and progressively render a 360-degree sweep. But problems arise regarding the zoom level control as the video below. Screencast.from.2025-01-29.01-15-14.webmAny advice for the best approach to overcome this issue? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The video is coming from somewhere, instead of trying to present the html that holds the video, pass the video url to the video source. |
Beta Was this translation helpful? Give feedback.
Hi Harel, I fixed this issue based on your advice on adjusting the marker size by adding a callback function for load, zoom, and move events.