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

百度网站服务器建设工程管理有限公司

百度网站服务器,建设工程管理有限公司,做网站制作较好的公司,申请号的网站引言 在 Web 开发中#xff0c;地图可视化和互动功能是越来越重要的应用场景。OpenLayers 是一个强大的开源 JavaScript 库#xff0c;用于显示和处理地图数据#xff0c;支持多种地图服务和交互功能。在这个教程中#xff0c;我们将介绍如何在 Vue 3 中集成 OpenLayers地图可视化和互动功能是越来越重要的应用场景。OpenLayers 是一个强大的开源 JavaScript 库用于显示和处理地图数据支持多种地图服务和交互功能。在这个教程中我们将介绍如何在 Vue 3 中集成 OpenLayers并通过鼠标点击地图上的点来播放视频。 本文将展示如何使用 Vue 3 的 Composition API 构建一个动态的地图应用点击地图上的标记如城市时弹出一个视频播放框展示相关视频内容。我们将结合 OpenLayers 和 Vue 3 的强大功能实现一个简单的示例帮助大家更好地理解和运用这两者的结合。 技术栈 Vue 3现代前端框架使用 Composition API。OpenLayers开源地图渲染库用于处理和展示地图。TypeScript增强的 JavaScript提供静态类型检查和类型推导。CSS用于样式的编写。 项目概述 我们将通过以下步骤来实现项目 在 Vue 3 中安装并配置 OpenLayers。初始化地图并在地图上添加自定义标记。实现鼠标点击标记播放视频的功能。创建一个简单的视频弹窗展示视频内容。 步骤 1安装 OpenLayers 首先我们需要在 Vue 3 项目中安装 OpenLayers。你可以使用 npm 或 yarn 来安装 npm install ol 步骤 2创建 Vue 3 组件 接下来我们将创建一个 Vue 3 组件包含一个 OpenLayers 地图和视频播放功能。 !--* Author: 彭麒* Date: 2024/12/26* Email: 1062470959qq.com* Description: 此源码版权归吉檀迦俐所有可供学习和借鉴或商用。-- templatebutton classback-button clickgoBack返回/buttondiv classcontainerdiv classw-full flex justify-center flex-wrapdiv classfont-bold text-[24px]在Vue3中使用OpenLayers鼠标点击播放视频/div/divdiv idvue-openlayers/divdiv idpopup-box classol-popupdiv idpopup-contentvideo idvideoid width202 height184 controls autoplaysource srchttps://www.apple.com/newsroom/videos/vision-pro-visionos/large_2x.mp4 typevideo/mp4/video/div/div/div /templatescript setup langts import { ref, onMounted } from vue; import ol/ol.css; import { Map, View } from ol; import Tile from ol/layer/Tile; import OSM from ol/source/OSM; import Overlay from ol/Overlay; import VectorLayer from ol/layer/Vector; import VectorSource from ol/source/Vector; import Style from ol/style/Style; import Icon from ol/style/Icon; import Feature from ol/Feature; import { Point } from ol/geom; import rocketImg from /assets/OpenLaysers/maker.png; const map ref(null); const overlayer ref(null); const vsource ref(new VectorSource({})); const videoUrl ref(); const cname ref(); const cimgurl ref(); import router from /router;const goBack () {router.push(/OpenLayers); }; const citys ref([{position: [116.00, 39.80],videourl: https://www.apple.com/newsroom/videos/vision-pro-visionos/large_2x.mp4,imgurl: rocketImg,}, ]);const companyPoint () {let features [];let data citys.value;for (let i 0; i data.length; i) {let feature new Feature({geometry: new Point(data[i].position),citydata: data[i],});let img data[i].imgurl;feature.setStyle(pointStyle(img));features.push(feature);}vsource.value.addFeatures(features); };const pointStyle (img) {let Styles [];Styles.push(new Style({image: new Icon({src: img,anchor: [0.5, 0.5],scale: 0.8,}),}));return Styles; };const clickPoint () {const box document.getElementById(popup-box);overlayer.value new Overlay({element: box,autoPan: {animation: {duration: 250,},},});map.value.addOverlay(overlayer.value);map.value.on(singleclick, (e) {let feature map.value.forEachFeatureAtPixel(e.pixel, (feature, layer) {return feature;});if (feature) {let cityInfo feature.get(citydata);console.log(cityInfo);cname.value cityInfo.name;cimgurl.value cityInfo.imgurl;overlayer.value.setPosition(e.coordinate);videoUrl.value cityInfo.videourl;} else {overlayer.value.setPosition(undefined);}}); };const initMap () {let osmLayer new Tile({source: new OSM(),});let cityLayer new VectorLayer({source: vsource.value,});map.value new Map({target: vue-openlayers,layers: [osmLayer, cityLayer],view: new View({center: [116.4074, 39.9042],zoom: 6,projection: EPSG:4326,}),});clickPoint(); };onMounted(() {initMap();companyPoint(); }); /scriptstyle scoped .container {width: 840px;height: 590px;margin: 50px auto;border: 1px solid #42B983; }#vue-openlayers {width: 800px;height: 470px;margin: 0 auto;border: 1px solid #42B983;position: relative; }.ol-popup {position: absolute;background-color: rgba(255, 0, 255, 0.8);padding: 5px;border-radius: 5px;border: 1px solid #cccccc;bottom: 12px;left: -50px;color: #FFFFFF;min-width: 200px; }.ol-popup:after, .ol-popup:before {top: 100%;border: solid transparent;content: ;height: 0;width: 0;position: absolute;pointer-events: none; }.ol-popup:after {border-top-color: rgba(255, 0, 255, 0.8);border-width: 10px;left: 48px;margin-left: -10px; }.ol-popup:before {border-top-color: #cccccc;border-width: 11px;left: 48px;margin-left: -11px; }#popup-content {width: 202px;height: 184px;border-radius: 10px;border: 1px solid #fff;padding: 10px; } /style 代码讲解 1. 地图初始化 通过 OpenLayers 的 Map 和 View 对象我们创建了一个简单的地图并设置了中心点和缩放级别。地图层使用了 Tile 和 OSMOpenStreetMap作为底图。 2. 自定义标记和视频源 我们在地图上添加了一个标记表示一个城市并且将视频 URL 和图标 URL 绑定到该标记上。当用户点击标记时会弹出一个视频播放器。 3. 鼠标点击事件 通过监听地图的 singleclick 事件我们获取到点击位置的城市信息并在弹窗中更新视频 URL显示相关视频内容。 4. 视频弹窗 视频播放器被嵌入在一个 ol-popup 弹窗中用户点击标记时弹窗会显示并播放相应的视频。 结语 通过本教程你可以在 Vue 3 项目中集成 OpenLayers实现通过鼠标点击地图标记来播放视频的功能。这种交互方式在很多地图可视化应用中都非常有用比如在城市地图中查看视频介绍、展示产品演示视频等。 希望这篇文章对你有所帮助鼓励大家进一步探索 OpenLayers 的强大功能结合 Vue 3 开发出更多富有创意和交互性的地图应用
http://www.hkea.cn/news/14566167/

相关文章:

  • 江苏建设信息官网网站在线crm系统crm
  • 微梦网站建设加大整合力度网站集约建设
  • 做网站设计前景怎么样什么网站比较少人做
  • 计科专业毕设做网站广州做网站优化公司报价
  • 网站做等保备案有机农产品网站开发方案
  • 沈阳做网站的公司常州网站建设czyzj
  • 电子购物网站建设目的企业站seo价格
  • 做网站的服务器怎么选建立网站费用怎么做会计分录
  • 连接国外网站的app打开网站显示404
  • 河北省城乡和建设厅网站首页怎么才能在百度上搜到自己的网站
  • 备案的网站建设书是什么石家庄网站开发设计
  • 怎么用ps做网站ui室内装饰设计怎么样
  • 微信上浏览自己做的网站百度导航下载2022最新版官网
  • 一般网站栏目结构网站开发中网页之间的链接形式有什么
  • wordpress手机端主题插件seo网站优化网站编辑招聘
  • 网站开发工作进度表中国新闻社和新华社有什么区别
  • 新郑龙湖网站建设电子商务网站建设也管理
  • 南阳网站排名seo诊断工具
  • 免费空间如何放网站如何做网络营销推广工作
  • 建网站啦动漫做a视频网站有哪些
  • 网上做任务网站有哪些富阳建设局网站电话
  • 网站免费认证联盟合肥哪里有做网站的
  • 重庆网站seo多少钱上海发布官网app下载
  • 网站维护托管深圳移动网站建设公司价格
  • dw建设的网站上传connect wordpress 主题
  • 公司网站建设工作通知自己在线制作logo免费 生成器
  • 申请自助网站wordpress title修改
  • 怎么给网站做seo优化新手如何优化网站排名
  • 建网站用哪个好做网站一年赚多少钱
  • 网站建设系统怎么样女性健康网站源码