step 6: add stable overlays and live update stress tests
This commit is contained in:
66
examples/markers_live_thread.py
Normal file
66
examples/markers_live_thread.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from math import cos, sin
|
||||
from threading import Event, Thread
|
||||
from time import sleep
|
||||
from typing import Any
|
||||
|
||||
import dearpygui.dearpygui as _dpg
|
||||
|
||||
import dpg_map as dpgm
|
||||
|
||||
dpg: Any = _dpg
|
||||
|
||||
|
||||
def main() -> None:
|
||||
dpgm.configure(user_agent="dpg-map markers_live_thread example")
|
||||
stop = Event()
|
||||
|
||||
dpg.create_context()
|
||||
dpg.create_viewport(title="dpg-map live markers", width=1000, height=700)
|
||||
|
||||
with (
|
||||
dpg.window(label="Live Markers", width=-1, height=-1),
|
||||
dpgm.map_widget(
|
||||
tag="live-markers-map", center=(47.9029, 1.9093), zoom=15, width=-1, height=-1
|
||||
),
|
||||
):
|
||||
for index in range(12):
|
||||
dpgm.add_marker(
|
||||
f"vehicle-{index}",
|
||||
lat=47.9029,
|
||||
lon=1.9093,
|
||||
label=str(index + 1),
|
||||
show_label=True,
|
||||
color=(240, 92, 70, 255),
|
||||
)
|
||||
|
||||
def update_markers() -> None:
|
||||
tick = 0
|
||||
while not stop.is_set():
|
||||
for index in range(12):
|
||||
angle = tick * 0.08 + index * 0.52
|
||||
radius = 0.0015 + (index % 4) * 0.0002
|
||||
dpgm.update_marker(
|
||||
f"vehicle-{index}",
|
||||
lat=47.9029 + sin(angle) * radius,
|
||||
lon=1.9093 + cos(angle) * radius,
|
||||
map_tag="live-markers-map",
|
||||
)
|
||||
tick += 1
|
||||
sleep(1 / 30)
|
||||
|
||||
worker = Thread(target=update_markers, name="dpg-map-live-markers", daemon=True)
|
||||
worker.start()
|
||||
try:
|
||||
dpg.setup_dearpygui()
|
||||
dpg.show_viewport()
|
||||
dpg.start_dearpygui()
|
||||
finally:
|
||||
stop.set()
|
||||
worker.join(timeout=1.0)
|
||||
dpg.destroy_context()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user