当前位置: 首页 > news >正文

vue3+arcgisAPI4示例:轨迹点模拟移动(附源码下载)

demo源码运行环境以及配置

运行环境:依赖Node安装环境,需要安装Node。 运行工具:vscode或者其他工具。
配置方式:下载demo源码,vscode打开,然后顺序执行以下命令:
(1)下载demo环境依赖包命令:npm install -g
(2)yarn install
(3)启动demo命令:yarn dev
(4)打包demo命令: yarn build:prod

示例效果
在这里插入图片描述
实现思路

使用模拟数据线图层geojson,获取线的点集合数据,然后点和点之间直线插值点,获取到插值点数据集,最后结合arcgis api
4实现达到轨迹点模拟圆滑移动效果。

核心部分代码

<template><div id="viewDiv"></div><div class="titleContainer center"><span>vue3+arcgisAPI4示例:轨迹点模拟移动效果</span></div><el-button type="primary" class="buttonRight btn1" @click="starBtn">开始模拟</el-button><el-button type="primary" class="buttonRight btn2" @click="clearBtn">清除模拟</el-button>
</template>
<script setup>
import { onMounted, onUnmounted, ref } from "vue";
import "@arcgis/core/assets/esri/themes/light/main.css";
import Map from "@arcgis/core/Map";
import MapView from "@arcgis/core/views/MapView";
import Basemap from "@arcgis/core/Basemap.js";
import esriConfig from "@arcgis/core/config";
import GeoJSONLayer from "@arcgis/core/layers/GeoJSONLayer.js";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import GroupLayer from "@arcgis/core/layers/GroupLayer.js";
import Graphic from "@arcgis/core/Graphic.js";
import Point from "@arcgis/core/geometry/Point.js";
import { distance } from "@arcgis/core/geometry/geometryEngine.js";
import { geographicToWebMercator } from "@arcgis/core/geometry/support/webMercatorUtils.js";
import { removeElementById } from '@/utils/index';
import axios from "axios";
let view, map, graphicsLayer = null;
let animationFrameId = null; // 动画帧ID
let features = []; // 存储轨迹点
onMounted(() => {initMap();
});
// 组件卸载时取消动画
onUnmounted(() => {if (animationFrameId) {cancelAnimationFrame(animationFrameId);animationFrameId = null;}
});
const initMap = () => {esriConfig.apiKey = 'AAPKca495ea263b64e44b61eaaecdbddebfcwEQjC8k8-6XGMrrXyCie6xzybboRl4REq-TwDQTm8Wz-8sL6REARz1wcm14Kq9ny';// 初始化创建地图对象const novaLayer = Basemap.fromId("arcgis-imagery-standard");map = new Map({// basemap: "satellite",basemap: novaLayer,});// 初始化创建视图view对象view = new MapView({container: "viewDiv",map: map,center: [111.69795926864639, 23.2026556059399],zoom: 15});// 去除logoview.ui.remove(["attribution", "zoom"]);// 监听视图view初始化加载完成执行view.when(function () {removeElementById('loader-wrapper');loadPointLineLayer();});
}
const loadPointLineLayer = async () => {// 使用axios请求获取GeoJSON数据const response = await axios.get("./src/views/carTrack/carTrackPoint.geojson");const geojsonData = response.data;features = geojsonData.features;// 创建GeoJSON图层,使用blob URL而不是文件URLconst blob = new Blob([JSON.stringify(geojsonData)], { type: "application/json" });const blobUrl = URL.createObjectURL(blob);let pointsLayer = new GeoJSONLayer({url: blobUrl})const response1 = await axios.get("./src/views/carTrack/carTrackLine.geojson");const geojsonData1 = response1.data;// 创建GeoJSON图层,使用blob URL而不是文件URLconst blob1 = new Blob([JSON.stringify(geojsonData1)], { type: "application/json" });const blobUrl1 = URL.createObjectURL(blob1);let lineLayer = new GeoJSONLayer({url: blobUrl1})const groupLayer = new GroupLayer({layers: [pointsLayer,lineLayer]});map.add(groupLayer);graphicsLayer = new GraphicsLayer({ id: 'graphicsLayer' });map.add(graphicsLayer);
}
const starBtn = () => {// 读取模拟车辆轨迹数据let points = [];// 取消可能存在的动画if (animationFrameId) {cancelAnimationFrame(animationFrameId);animationFrameId = null;}// 生成所有轨迹点for (let i = 0; i < features.length; i++) {const feature = features[i];if (i !== features.length - 1) {points = points.concat(getPointSAlongLine(feature, features[i + 1], 1))}else {points = points.concat(getPointSAlongLine(feature, feature, 1))}}// 使用requestAnimationFrame实现动画let currentIndex = 0;let lastTimestamp = 0;const frameInterval = 100; // 控制动画速度,相当于之前的100msconst animate = (timestamp) => {// 计算时间差if (!lastTimestamp) lastTimestamp = timestamp;const elapsed = timestamp - lastTimestamp;// 当经过的时间超过帧间隔时更新位置if (elapsed >= frameInterval) {lastTimestamp = timestamp;if (currentIndex < points.length) {refreshAlarmPoint(points[currentIndex]);currentIndex++;      // 继续动画animationFrameId = requestAnimationFrame(animate);} else {// 动画结束animationFrameId = null;}} else {// 如果时间间隔不够,继续等待animationFrameId = requestAnimationFrame(animate);}};// 启动动画animationFrameId = requestAnimationFrame(animate);
}
const clearBtn = () => {// 取消可能存在的动画if (animationFrameId) {cancelAnimationFrame(animationFrameId);animationFrameId = null;}if (graphicsLayer) {graphicsLayer.removeAll();}
}
// 刷新绘制实时报警点
const refreshAlarmPoint = (point) => {if (graphicsLayer) {graphicsLayer.removeAll();}// 创建节点圆圈符号const symbol = {type: "simple-marker",style: "circle",color: [255, 255, 255], // 白色填充size: 12,outline: {color: [66, 135, 245], // 蓝色边框width: 2}};const graphic = new Graphic({geometry: point,symbol: symbol});graphicsLayer.add(graphic);
}
/*** 计算起点和终点连线上距离起点指定距离的坐标点* @param {Array} startPoint - 起点坐标* @param {Array} endPoint - 终点坐标* @param {Number} dis- 距离起点的距离,单位:米* @returns {Array} - 计算得到的坐标点*/
……
</script>
http://www.lryc.cn/news/606049.html

相关文章:

  • 实战教程 ---- Nginx结合Lua实现WAF拦截并可视化配置教程框架
  • 融合数字孪生的智慧能源光伏场站检测系统应用解析
  • 生产管理升级:盘古IMS MES解锁全链路可控可溯,激活制造效率
  • 从 MySQL 迁移到 TiDB:使用 SQL-Replay 工具进行真实线上流量回放测试 SOP
  • 【NLP舆情分析】基于python微博舆情分析可视化系统(flask+pandas+echarts) 视频教程 - 微博评论数据可视化分析-点赞区间折线图实现
  • 保姆级别IDEA关联数据库方式、在IDEA中进行数据库的可视化操作(包含图解过程)
  • 技术速递|GitHub Copilot for Eclipse 迈出重要一步
  • SQL极简函数实战:巧用GREATEST()与LEAST()实现智能数据截断
  • Promise.all Promise.race Promise.any三个对比
  • 【Flask基础②】 | 路由、响应与异常处理
  • 在嵌入式系统或 STM32 平台中常见的外设芯片和接口
  • 《通信原理》学习笔记——第六章
  • 乱删文件,电脑不能开机,怎么办
  • 深入解析 Spring AI 系列:剖析OpenAI接口接入组件
  • 常见的中间件漏洞(tomcat,weblogic,jboss,apache)
  • 微信小程序中进行参数传递的方法
  • 5 种智能策略,从 iQOO 到 iQOO 转移照片
  • Apache RocketMQ 中 Topic 的概念、属性、行为约束和最佳实践
  • 【机器人+相机通讯】宇树科技相机通信
  • ChatGPT的下一站:从“答案引擎”到“思维教练”
  • 基于单片机胎压检测/锅炉蒸汽压力/气压检测系统
  • 从姑苏区人工智能大模型基础设施招标|学习服务器、AI处理器、GPU
  • 深度学习(鱼书)day07--误差反向传播(前四节)
  • 项目推进难的原因有哪些?问题及应对
  • TOML介绍
  • 14day-ai入门-人工智能基础学习-OpenCV-图像预处理4
  • 我在 Arch Linux Plasma 6 Wayland 下驯服 Chromium 输入法的完整记录
  • ACOSRAR改进连续蚁群算法用于优化复杂环境下无人机路径规划,Matlab代码实现
  • 智慧工地系统:建筑工程管理的智能化革新与实践
  • 淘宝 API HTTP/2 多路复用与连接优化实践:提升商品数据采集吞吐量