小程序集arcgis地图显示自定义坐标的功能实现记录!(学习笔记)

最近再做一个新能源回收项目,项目中有个根据回收点坐标数据显示区域内回收点位置,点击图标直接导航到该位置,及分布的需求,研究了一下,实现效果如下,实现起来很简单,代码及效果

回收点位置及分布效果如图:

点击图标导航直达效果:

代码如下

bash 复制代码
data() {
    return {
      longitude: 118.796877, // 初始经度
      latitude: 32.060255,  // 初始纬度
      scale: 14,           // 初始缩放级别
      markers: [],         // 用于存储地图上的标记数据
    };
  },
  onLoad() {
    // 假设这里你已经通过API获取了ArcGIS图层中的点位数据,并解析成了以下格式:  
    const pointsData = [  
      { id: 1, latitude: 32.060255, longitude: 118.796877, iconPath: '/static/icondc/icon2.png' },
  	  { id: 2, latitude: 31.943066, longitude: 118.795807, iconPath: '/static/icondc/icon2.png' },
  	  { id: 3, latitude: 32.060005, longitude: 118.788877, iconPath: '/static/icondc/icon2.png' },
	   { id: 4, latitude: 32.056232, longitude: 118.797241, iconPath: '/static/icondc/icon2.png' },
	    { id: 5, latitude: 32.05338585150547, longitude: 118.79315867787933, iconPath: '/static/icondc/icon2.png' },
	  
      // ... 其他点位数据  
    ];  
  
    // 将点位数据转换为小程序map组件可以识别的markers数组  
    const markers = pointsData.map(point => ({  
      id: point.id,  
      latitude: point.latitude,  
      longitude: point.longitude,  
      iconPath: point.iconPath, // 自定义图标路径,注意路径可能需要是相对于项目的静态资源路径  
      width: 50, // 标记宽度  
      height: 50, // 标记高度  
    }));  
  
    this.markers = markers; // 在 uni-app 中,你可以直接修改 data 中的属性来触发视图更新  
  },
  methods: {
    // 用于处理 marker 的点击事件
    onMarkerTap(event) {
      const markerId = event.markerId; // 获取当前点击的 marker 的 id
      const tappedMarker = this.markers.find(marker => marker.id === markerId); // 根据 id 获取点击的 marker 数据
      
      if (!tappedMarker) return; // 如果找不到 marker,则不执行后续操作
      
      // 在这里可以弹出一个浮窗提示用户是否导航到这里
      // 假设有一个自定义的弹窗组件 showDialog 可以接收一个回调函数
      this.showDialog(() => {
        // 当用户点击确认后,执行导航操作
        uni.openLocation({
          latitude: tappedMarker.latitude,
          longitude: tappedMarker.longitude,
          success() {
            console.log('导航成功');
          },
          fail() {
            console.log('导航失败');
          }
        });
      });
    },
相关推荐
m0_526119402 天前
iconfont我修改好颜色,但是在小程序项目是黑色的
小程序
通信小呆呆2 天前
当算法有了“五感”:多模态数据融合如何向人体感官协同学习?
人工智能·学习·算法·机器学习·机器人
H__Rick2 天前
自动对焦学习-3
人工智能·学习·计算机视觉
Daisy Lee2 天前
量化学习-第1章-什么是量化金融
学习·金融·datawhale
Inhand陈工2 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
Alsn862 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
YM52e2 天前
买菜计算器小应用 - HarmonyOS ArkUI 开发实战-PC版本
学习·华为·harmonyos·鸿蒙·鸿蒙系统
小雨下雨的雨2 天前
HarmonyOS ArkUI训练营入门-组件掌握系列-Animation 动画效果实现-PC版本
学习·华为·harmonyos·鸿蒙
cqbzcsq2 天前
CellFlow虚拟细胞论文阅读
论文阅读·人工智能·笔记·学习·生物信息
半条-咸鱼2 天前
【STM32】I2C协议原理、HAL读写与OLED显示操作
嵌入式硬件·c·信息与通信