华为地图服务 - 如何在地图指定位置增加气泡?-- HarmonyOS自学19

news/2024/9/21 12:46:16/

场景介绍

本章节将向您介绍如何在地图的指定位置添加气泡。

您可以通过气泡在道路上指定位置显示测速、拥堵情况。气泡支持功能:

  • 支持设置四个方向的图标(传入的图标宽高需要相同)。
  • 支持设置图标碰撞规则。
  • 支持设置当前气泡的候选坐标段,通过计算使气泡在最佳的线段位置上。
  • 支持设置图标动画。
  • 支持添加点击事件。

cke_2568.png

接口说明

添加气泡功能主要由BubbleParams、addBubble和Bubble提供,更多接口及使用方法请参见接口文档。

接口名

描述

BubbleParams

气泡相关属性。

addBubble(params: mapCommon.BubbleParams): Promise<Bubble>

在地图上添加气泡。

Bubble

气泡,支持更新和查询相关属性。

开发步骤

添加气泡

  1. 导入相关模块。
     
    1. import { MapComponent, mapCommon, map } from '@kit.MapKit';
    2. import { AsyncCallback } from '@kit.BasicServicesKit';
  2. 添加气泡,在Callback方法中创建初始化参数并新建气泡。
     
    1. @Entry
    2. @Component
    3. struct BubbleDemo {
    4. private mapOption?: mapCommon.MapOptions;
    5. private mapController?: map.MapComponentController;
    6. private callback?: AsyncCallback<map.MapComponentController>;
    7. private bubble?: map.Bubble;
    8. aboutToAppear(): void {
    9. this.mapOption = {
    10. position: {
    11. target: {
    12. latitude: 39.918,
    13. longitude: 116.397
    14. },
    15. zoom: 14
    16. }
    17. };
    18. this.callback = async (err, mapController) => {
    19. if (!err) {
    20. this.mapController = mapController;
    21. let bubbleOptions: mapCommon.BubbleParams = {
    22. // 气泡位置
    23. positions: [[{ latitude: 39.918, longitude: 116.397 }]],
    24. // 设置图标,必须提供4个方向的图标,图标存放在resources/rawfile
    25. icons: [
    26. 'speed_limit_10.png',
    27. 'speed_limit_20.png',
    28. 'speed_limit_30.png',
    29. 'speed_limit_40.png'
    30. ],
    31. // 定义气泡的显示属性,为true时,在被碰撞后仍能显示
    32. forceVisible: true,
    33. // 定义气泡碰撞优先级,数值越大,优先级越低
    34. priority: 3,
    35. // 定义气泡展示的最小层级
    36. minZoom: 2,
    37. // 定义气泡展示的最大层级
    38. maxZoom: 20,
    39. // 定义气泡是否可见
    40. visible: true,
    41. // 定义气泡叠加层级属性
    42. zIndex: 1
    43. }
    44. // 添加气泡
    45. this.bubble = await this.mapController.addBubble(bubbleOptions);
    46. }
    47. };
    48. }
    49. build() {
    50. Stack() {
    51. Column() {
    52. MapComponent({ mapOptions: this.mapOption, mapCallback: this.callback });
    53. }.width('100%')
    54. }.height('100%')
    55. }
    56. }

    cke_5708.png

设置监听气泡点击事件

 
  1. this.mapController?.on("bubbleClick", (bubble) => {
  2. console.info(`on-BubbleClick bubble = ${bubble.getId()}`);
  3. });

气泡动画

Bubble调用setAnimation(animation: Animation)设置动画。

Bubble调用startAnimation启动动画。

 
  1. let animation: map.ScaleAnimation = new map.ScaleAnimation(1, 3, 1, 3);
  2. // 设置动画单次的时长
  3. animation.setDuration(3000);
  4. // 设置动画的开始监听
  5. animation.on("start", () => {
  6. console.info('start ScaleAnimation');
  7. });
  8. // 设置动画的结束监听
  9. animation.on("end", () => {
  10. console.info('end ScaleAnimation');
  11. });
  12. // 设置动画执行完成的状态
  13. animation.setFillMode(map.AnimationFillMode.BACKWARDS);
  14. // 设置动画重复的方式
  15. animation.setRepeatMode(map.AnimationRepeatMode.REVERSE);
  16. // 设置动画插值器
  17. animation.setInterpolator(Curve.Linear);
  18. // 设置动画的重复次数
  19. animation.setRepeatCount(100);
  20. this.bubble.setAnimation(animation);
  21. this.bubble.startAnimation();

http://www.ppmy.cn/news/1528406.html

相关文章

基于YOLOv5的教室人数检测统计系统

基于YOLOv5的教室人数检测统计系统可以有效地用于监控教室内的学生数量&#xff0c;适用于多种应用场景&#xff0c;比如 自动考勤、安全监控或空间利用分析 以下是如何构建这样一个系统的概述&#xff0c;包括环境准备、数据集创建、模型训练以及如何处理不同类型的媒体输入…

notepad++的json查看

json文件查看 因为接触到3dtile模型&#xff0c;所以经常需要和json打交道&#xff0c;但是很多模型是下面这种情况&#xff0c;不好阅读&#xff0c;所以可以使用notepad的插件查看 正常打开是这样的 加载notepad插件 搜索json下载安装就可以了 如果网络抽象&#xff0c;下载…

内网渗透- 内网渗透的基本知识

攻击流程讲解 内网介绍 内网也指局域网&#xff0c;是指在某一区域内由多台计算机互联而成的计算机组&#xff0c;组网范围通常在数千米以内。在局域网中&#xff0c;可以实现文件管理、应用软件共享、打印机共享、工作组内的日程安排、电子邮件和传真通信服务等。内网是封闭的…

平安养老险阜阳中心支公司开展金融教育宣传专项活动

为全面深入开展“金融教育宣传月”的各项工作&#xff0c;不断完善金融惠民利民举措&#xff0c;提升金融服务质效&#xff0c;帮助基层群众增强维权意识、防非反诈的自我保护能力。近日&#xff0c;平安养老保险股份有限公司&#xff08;以下“平安养老险”&#xff09;阜阳中…

WPF DataGrid 赋值与修改

WPF DataGrid 赋值与修改 下方绑定给 DataGrid 控件的类模型public record DataGridModel{public string GongNeng{get; set;}public DataGridModel(string gongNeng){GongNeng gongNeng;}}一、DataGrid 绑定对应的属性 DataGrid 绑定列&#xff0c;将对应的属性绑定给对应的…

07_Python数据类型_集合

Python的基础数据类型 数值类型&#xff1a;整数、浮点数、复数、布尔字符串容器类型&#xff1a;列表、元祖、字典、集合 集合 集合&#xff08;set&#xff09;是Python中一个非常强大的数据类型&#xff0c;它存储的是一组无序且不重复的元素&#xff0c;集合中的元素必须…

css实现居中的方法

水平居中 1. 行内设置text-align 给父元素设置text-align为center&#xff0c;一般用于实现文字水平居中 2. 给当前元素设置margin&#xff1a;0 auto 原理&#xff1a;块级独占一行&#xff0c;表现为在水平方向上占满整个父容器&#xff0c;当水平方向padding&#xff0c;…

2.Seata 1.5.2 集成Springcloud-alibaba

一.Seata-server搭建已完成前提下 详见 Seata-server搭建 二.Springcloud 项目集成Seata 项目整体测试业务逻辑是创建订单后&#xff08;为了演示分布式事务&#xff0c;不做前置库存校验&#xff09;&#xff0c;再去扣减库存。库存不够的时候&#xff0c;创建的订单信息数…