Skip to content

RotatedOverlayImage 继承自: BaseOverlayImage, ft.BaseControl

一个基于三个角点变换的图片叠加层。

右上角由 top_left_corner、bottom_left_corner 和 bottom_right_corner 推导得出。

属性 ​

名称类型默认值说明
top_left_cornerMapLatitudeLongituderequiredThe coordinates of the top-left corner of the image.
bottom_left_cornerMapLatitudeLongituderequiredThe coordinates of the bottom-left corner of the image.
bottom_right_cornerMapLatitudeLongituderequiredThe coordinates of the bottom-right corner of the image.
srcUnion[str, bytes]requiredThe image source. It can be one of the following: - A URL or local asset file path; - A base64 string; - Raw bytes.
opacityAnnotated[ft.Number, V.between(0.0, 1.0)]1.0The opacity in which the image should get rendered on the map. 抛出异常:ValueError:若不在 0.0 到 1.0 的闭区间内。
gapless_playbackboolFalseWhether to continue showing the old image (True), or briefly show nothing (False), when the image provider changes.
filter_qualityft.FilterQualityft.FilterQuality.MEDIUMThe rendering quality of the image.
visibleboolTrueWhether this overlay image is rendered on the map.
dataAnyskip_任意类型的自定义数据。
keyOptional['KeyValue']None用于在更新之间保持控件身份稳定的 key。

只读属性 ​

名称类型默认值说明
parentOptional['BaseControl']—The direct ancestor(parent) of this control. It defaults to None and will only have a value when this control is mounted (added to the page tree). Page 控件(树的根)为例外 —— 它始终 parent=None。
page'Page'—此控件所属的页面。

方法 ​

名称类型默认值说明
is_isolated——Return whether this control is marked as isolated. 被隔离的控件不会参与父级驱动的更新遍历,需要自行管理更新边界。
init——Called after control instance initialization and before the first build / update cycle. 可重写此钩子执行依赖于已初始化字段的轻量设置。 不要在这里调用 update()。
build——在控件初始化期间调用一次,用于定义其子控件。 page 属性在此方法中可用。
before_update——每次控件即将更新时调用。 Note: 不要在此处调用 update()。
before_event——在事件处理器执行前拦截事件。 返回 False 取消分发,返回 True 或 None 则继续正常的事件处理。
did_mount——在控件挂载到页面树之后调用。 可重写以启动需要已挂载页面的资源,例如订阅、定时器或服务监听。
will_unmount——在控件从页面树移除之前调用。 可重写以释放 did_mount() 中创建的资源,例如订阅、定时器或外部句柄。
get_data_channel——Resolve the [DataChannel] allocated on the Dart side for this widget. Pattern: on_data_channel_open: Optional[ft.EventHandler[DataChannelOpenEvent]] = None def init(self): self.on_data_channel_open = self._on_open def _on_open(self, e): self._channel = self.get_data_channel(e.channel_id) Idempotent — the underlying Connection caches DataChannels by id, so repeated calls return the same instance. No error path: the id always comes from a framework-fired event, so by the time this runs the channel exists on both sides.
updateNone—请求更新该控件的 UI。 在修改控件状态或属性后调用。 控件必须已挂载到页面,并且未被冻结。

示例 ​

python
import flet as ft
import flet_map as ftm

base64_image = "iVBORw0KGgoAAAANSUhEUgAAABkAAAAgCAYAAADnnNMGAAAACXBIWXMAAAORAAADkQFnq8zdAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAA6dJREFUSImllltoHFUYx3/fzOzm0lt23ZrQ1AQbtBehNpvQohgkBYVo410RwQctNE3Sh0IfiiBoIAjqi6TYrKnFy4O3oiiRavDJFi3mXomIBmOxNZe63ay52GR3Zj4f2sTEzmx3m//TYf7/c35zvgPnO6KqrESXqpq3muocAikv6m+/zytj3ejik1VN21G31YA9CgJ6xC+bMyQZPVCuarciPAMYC99V6Vw5pLbFSibHmlVoRVj9P3cmPBM8tSJI/M6mzabpfoAQ9fIF7WK4bd5vvuFnLGgy2vi0abg94A0AcJGvMq3hDxGRyar9r4F+iLAm0yIiRk8m37tctS1WsrIhhrI30+Srmg+J87OXUf3lWGS1q89dC6ltsSanxk4Aj2QBABii96300g87P/rtlrWr8l+vyDMfdlXSyyEikqxsiOUAQJCBhfHdXRfCq1LSsSlcWG+KBAGStvvrMkgiuv8lUc2mREukPwLUfHG+uTQv8Eown7VL3XlbBxYhf1c17hbVF3MDwA9bts280TnaU1YYqPby07aeFlUlHt27wSQ4CLo+F8AvoTCvHmyKF+ZbEb/M77P2LgvAwmrTHAHflN3KZxVbMC2jMFNOpgPnrMSOhvvFkMezXdwV4ePbtvHtxnJAMQ0j4JtVnO+eLb5oiSlt5HDbv7t1O90lpYCCCKbhfzW5kAIwUAazR0BlfII8Ow0I6uoVmI9MyAMwbMs8CExmDbk4zgu931MyO4OI4KrYflkRjOoTI+uM9d1vjotwKPu9QMk/sxzuO8POiVFcdZ1M2YBVsMEAKOqLvaPIe7mACuw0z/80SMH58SMplxlfiDhVi7dw2pltRhjKBQTQdrSja2KKTfE551NHuaZ0QVPvWYQUn31/Vm2nDvgjF4grVJx6suSvrvrSJ/6cSW2Oz9mf264uNrB806xZ1k/CZ49dUKgDEtlCROX2hfHpx8pGuuo3PpqYulw8fjndOp1yhgtNKRevJ1FyR2Ola+jXAjdnwTkZ6o896GdWdxDw7IxFg+0DpmXchTKSBWQnIuJn9u4j7dt+13UfHXEkXQOcuQ4kMhVtqsgUyPiQiPQfHw1NB2sRjmXKuTg1NwwBYLhtPtQX26eqTwGXPDOqvmcC4Hnwfrrad94GrVsOYTqUTkQY+iTlNe/6O1miSP/x0VB/+wMIDwHn/vtV1iQC4Xv95uUEWVCoL9Y5Z+gdovoyMHUFJHv88jmVy0vTuw7cZNv2YaA61Bfb7ZX5F8SaUv2xwZevAAAAAElFTkSuQmCC"  # noqa: E501


def main(page: ft.Page):
    page.add(
        ft.SafeArea(
            expand=True,
            content=ftm.Map(
                expand=True,
                initial_center=ftm.MapLatitudeLongitude(51.5, -0.09),
                initial_zoom=6,
                layers=[
                    ftm.TileLayer(
                        url_template="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
                        user_agent_package_name="flet-map-examples/1.0",
                    ),
                    ftm.OverlayImageLayer(
                        overlay_images=[
                            ftm.OverlayImage(
                                src=base64_image,
                                bounds=ftm.MapLatitudeLongitudeBounds(
                                    corner_1=ftm.MapLatitudeLongitude(51.5, -0.09),
                                    corner_2=ftm.MapLatitudeLongitude(48.8566, 2.3522),
                                ),
                                opacity=0.8,
                            ),
                            ftm.RotatedOverlayImage(
                                src=base64_image,
                                top_left_corner=ftm.MapLatitudeLongitude(
                                    53.377, -2.999
                                ),
                                bottom_left_corner=ftm.MapLatitudeLongitude(
                                    52.503, -1.868
                                ),
                                bottom_right_corner=ftm.MapLatitudeLongitude(
                                    53.475, 0.275
                                ),
                                opacity=0.8,
                            ),
                        ]
                    ),
                    ftm.SimpleAttribution(text="OpenStreetMap contributors"),
                ],
            ),
        )
    )


if __name__ == "__main__":
    ft.run(main)

关注我,学习大模型、大数据、Python等热门技术。