iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >Vue中使用Openlayer实现加载动画效果
  • 841
分享到

Vue中使用Openlayer实现加载动画效果

2024-04-02 19:04:59 841人浏览 泡泡鱼
摘要

注意:实现动画时不能有scoped!!!!  通过gif <template> <div class="test"> <di

注意:实现动画时不能有scoped!!!! 

通过gif


<template>
  <div class="test">
    <div id="map" ref="map" style="width: 100vw; height: 100vh"></div>
  </div>
</template>
 
<script>
import "ol/ol.CSS";
import { Map, View, Overlay } from "ol";
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
 
export default {
  name: "gif",
  data() {
    return {
      map: {},
      overlay: {},
      markerPoint: {},
      geoJSONData: {
        type: "FeatureCollection",
        features: [
          {
            type: "Feature",
            properties: {
              title: "警报1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报3",
            },
            geometry: {
              type: "Point",
              coordinates: [123.74363825288785, 44.363694825734726],
            },
          },
        ],
      },
    };
  },
  mounted() {
    this.initMap();
    this.addGif();
  },
  methods: {
    // 初始化地图
    initMap() {
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new OSM(),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [104.912777, 34.730746],
          zoom: 4.5,
        }),
      });
    },
    // 使用Overlay添加GIF动态图标点位信息
    addGif() {
      let coordinates = this.getCoordinatesByGeojson(this.geojsonData);
 
      for (const i in coordinates) {
        let gif_span = document.createElement("span");
 
        document.documentElement.appendChild(gif_span);
        this.$nextTick(() => {
          this.markerPoint = new Overlay({
            position: coordinates[i],
            element: gif_span,
            positioning: "center-center",
          });
          this.map.addOverlay(this.markerPoint);
        });
      }
    },
    //根据geojson数据获取坐标集
    getCoordinatesByGeojson(geojsonData) {
      let coordinates = [];
      geojsonData.features.map((feature) => {
        coordinates = [...coordinates, feature.geometry.coordinates];
      });
      return coordinates;
    },
  },
};
</script>
<style lang='scss' >
.test {
  span {
    display: inline-block;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: url("https://smart-garden-manage.oss-cn-chengdu.aliyuncs.com/gif.gif")
      no-repeat;
    background-size: 80px 80px;
  }
}
</style>

通过关键帧@keyframes


<template>
  <div class="test">
    <div id="map" ref="map" style="width: 100vw; height: 100vh"></div>
  </div>
</template>
 
<script>
import "ol/ol.css";
import { Map, View, Overlay } from "ol";
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
 
export default {
  name: "gif",
  data() {
    return {
      map: {},
      overlay: {},
      point_overlay: {},
      geojsonData: {
        type: "FeatureCollection",
        features: [
          {
            type: "Feature",
            properties: {
              title: "警报1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报3",
            },
            geometry: {
              type: "Point",
              coordinates: [123.74363825288785, 44.363694825734726],
            },
          },
        ],
      },
    };
  },
  mounted() {
    this.initMap();
    this.addGif();
  },
  methods: {
    // 初始化地图
    initMap() {
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new OSM(),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [104.912777, 34.730746],
          zoom: 4.5,
        }),
      });
    },
    // 使用Overlay添加GIF动态图标点位信息
    addGif() {
      let coordinates = this.getCoordinatesByGeojson(this.geojsonData);
 
      for (const i in coordinates) {
        let point_div = document.createElement("div");
        point_div.className = "css_animation";
        point_div.id = `coordinate_${i}`;
        document.documentElement.appendChild(point_div);
 
        this.$nextTick(() => {
          this.point_overlay = new Overlay({
            position: coordinates[i],
            element: point_div,
            positioning: "center-center",
          });
          this.map.addOverlay(this.point_overlay);
        });
      }
    },
    //根据geojson数据获取坐标集
    getCoordinatesByGeojson(geojsonData) {
      let coordinates = [];
      geojsonData.features.map((feature) => {
        coordinates = [...coordinates, feature.geometry.coordinates];
      });
      return coordinates;
    },
  },
};
</script>
<style lang='scss' >
.test {
  .css_animation {
    height: 50px;
    width: 50px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.9);
    box-shadow: inset 0 0 8px red;
    transfORM: scale(0);
    animation: myfirst 3s;
    animation-iteration-count: infinite; //无限循环
  }
  @keyframes myfirst {
    to {
      transform: scale(2);
      background: rgba(0, 0, 0, 0);
      box-shadow: inset 0 0 50px rgba(255, 0, 0, 0);
    }
  }
}
</style>

既可加载动画,又可获取动画所在要素点的属性

 

注意:该代码存在问题。目前只能要么点击获取属性,要么展示动画,而不能同时存在,还有待优化


<template>
  <div class="test">
    <div id="map" ref="map" style="width: 100vw; height: 100vh"></div>
    <div
      id="popup"
      style="
        position: absolute;
        background-color: rgba(47, 57, 90, 0.678);
        bottom: 20px;
        left: 30px;
        border: 1px solid white;
        padding: 10px;
        width: 60px;
      "
    >
      {{ properties.title }}
    </div>
  </div>
</template>
 
<script>
import "ol/ol.css";
import { Map, View, Overlay } from "ol";
import { OSM, Vector as VectorSource } from "ol/source";
import { Vector as VectorLayer, Tile as TileLayer } from "ol/layer";
import GeoJSON from "ol/format/GeoJSON";
 
import Select from "ol/interaction/Select";
import { alTKEyOnly, click, pointerMove } from "ol/events/condition";
import { Fill, Stroke, Style, Circle } from "ol/style";
 
export default {
  name: "gif",
  data() {
    return {
      map: {},
      layer: {},
 
      overlay: {},
      point_overlay: {},
      geojsonData: {
        type: "FeatureCollection",
        features: [
          {
            type: "Feature",
            properties: {
              title: "警报1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警报3",
            },
            geometry: {
              type: "Point",
              coordinates: [123.74363825288785, 44.363694825734726],
            },
          },
        ],
      },
 
      select: {},
      properties: {
        title: "",
      },
    };
  },
  mounted() {
    this.initMap();
    // this.addGif();//注释掉后,点击可获取feature属性
  },
  methods: {
    // 初始化地图
    initMap() {
      this.layer = new VectorLayer({
        source: new VectorSource({
          features: new GeoJSON().readFeatures(this.geojsonData),
        }),
      });
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new OSM(),
          }),
          this.layer,
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [104.912777, 34.730746],
          zoom: 4.5,
        }),
      });
 
      this.select = new Select({
        condition: click, //单击选择
      });
      this.map.addInteraction(this.select);
 
      let overlayer_popup = new Overlay({
        element: document.getElementById("popup"),
        positioning: "center-center", //一定要加上,否则会有偏移
      });
 
      this.select.on("select", (e) => {
        let coordinate = e.mapBrowserEvent.coordinate; //获取选择的坐标
 
        let featureSelect = e.selected[0]; //选中的feature要素
 
        if (e.selected.length !== 0) {
          overlayer_popup.setPosition(coordinate);
          this.map.addOverlay(overlayer_popup);
        } else {
          overlayer_popup.setPosition("");
        }
 
        if (featureSelect) {
          this.properties = featureSelect.getProperties(); //获取当前要素的所有属性
          //设置选中的样式
          featureSelect.setStyle(
            new Style({
              image: new Circle({
                radius: 10,
                fill: new Fill({
                  //矢量图层填充颜色,以及透明度
                  color: "rgba(255,0,0,0.5)",
                }),
                stroke: new Stroke({
                  //边界样式
                  color: "rgba(100, 90, 209, 0.6)",
                  width: 3,
                }),
              }),
            })
          );
        }
      });
 
      // 设置鼠标划过矢量要素的样式
      this.map.on("pointermove", (e) => {
        const isHover = this.map.hasFeatureAtPixel(e.pixel);
        this.map.getTargetElement().style.cursor = isHover ? "pointer" : "";
      });
    },
    // 使用Overlay添加GIF动态图标点位信息
    addGif() {
      let coordinates = this.getCoordinatesByGeojson(this.geojsonData);
 
      for (const i in coordinates) {
        let point_div = document.createElement("div");
        point_div.className = "css_animation";
        point_div.id = `coordinate_${i}`;
        document.documentElement.appendChild(point_div);
 
        this.$nextTick(() => {
          this.point_overlay = new Overlay({
            position: coordinates[i],
            element: point_div,
            positioning: "center-center",
          });
          this.map.addOverlay(this.point_overlay);
        });
      }
    },
    //根据geojson数据获取坐标集
    getCoordinatesByGeojson(geojsonData) {
      let coordinates = [];
      geojsonData.features.map((feature) => {
        coordinates = [...coordinates, feature.geometry.coordinates];
      });
      return coordinates;
    },
  },
};
</script>
<style lang='scss' scoped>
.test {
}
</style>
<style lang='scss' >
.test {
  .css_animation {
    height: 50px;
    width: 50px;
    border-radius: 50%;
    background: rgba(255, 0, 0, 0.9);
    box-shadow: inset 0 0 8px red;
    transform: scale(0);
    animation: myfirst 3s;
    animation-iteration-count: infinite; //无限循环
  }
  @keyframes myfirst {
    to {
      transform: scale(2);
      background: rgba(0, 0, 0, 0);
      box-shadow: inset 0 0 50px rgba(255, 0, 0, 0);
    }
  }
}
</style>

到此这篇关于Vue+Openlayer加载动画的文章就介绍到这了,更多相关Vue Openlayer加载动画内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Vue中使用Openlayer实现加载动画效果

本文链接: https://www.lsjlt.com/news/134159.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Vue中使用Openlayer实现加载动画效果
    注意:实现动画时不能有scoped!!!!  通过gif <template> <div class="test"> <di...
    99+
    2024-04-02
  • android怎么实现加载动画效果
    Android中实现加载动画效果可以通过以下几种方式:1. 使用ProgressBar:ProgressBar是Android系统提...
    99+
    2023-08-08
    android
  • vue中使用animate.css实现炫酷动画效果
    目录1.安装(在vscode终端中,使用npm安装)2.引入3.代码实现animate.css 是一个来自国外的 CSS3 动画库,它提供了抖动(shake)、闪烁(flash)、弹...
    99+
    2024-04-02
  • 怎么使用vue实现动画效果
    这篇文章主要介绍了怎么使用vue实现动画效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么使用vue实现动画效果文章都会有所收获,下面我们一起来看看吧。Vue封装的过度与动画1.作用在插入,更新,移除DOM...
    99+
    2023-07-05
  • 怎么用css3实现loading加载动画效果
    这篇文章主要介绍“怎么用css3实现loading加载动画效果”,在日常操作中,相信很多人在怎么用css3实现loading加载动画效果问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大...
    99+
    2024-04-02
  • 如何使用纯css实现简单加载动画效果
    小编给大家分享一下如何使用纯css实现简单加载动画效果,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!效果图思路CSS 用于修饰 HTML,所以即便是再简单的效果,...
    99+
    2023-06-14
  • vue使用动画实现滚动表格效果
    本文实例为大家分享了vue使用动画实现滚动表格效果的具体代码,供大家参考,具体内容如下 需求 在一些大屏项目中,需要使用到表格行数据滚动。本文介绍在vue项目中使用动画实现滚动表格。...
    99+
    2024-04-02
  • 如何使用HTML+CSS实现页面加载动画效果
    这篇“如何使用HTML+CSS实现页面加载动画效果”除了程序员外大部分人都不太理解,今天小编为了让大家更加理解“如何使用HTML+CSS实现页面加载动画效果”,给大家总结了以下内容,具有一定借鉴价值,内容详...
    99+
    2024-04-02
  • 使用Vue transition 实现点赞动画效果
    要实现点赞动画效果,你可以使用Vue的过渡(transition)组件。下面是一个简单的示例代码:```html<templa...
    99+
    2023-09-21
    Vue
  • 基于Vue+Openlayer实现动态加载geojson的方法
    加载1个或多个要素 <template> <div id="map" style="width: 100vw; height: 100vh"><...
    99+
    2024-04-02
  • Android怎么实现加载视差动画效果
    本篇内容主要讲解“Android怎么实现加载视差动画效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android怎么实现加载视差动画效果”吧!基础知识继 Android实现旋转动画...
    99+
    2023-06-20
  • 用CSS3实现的加载动画效果代码分享
    这篇文章主要讲解了“用CSS3实现的加载动画效果代码分享”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“用CSS3实现的加载动画效果代码分享”吧!很棒的loa...
    99+
    2024-04-02
  • Vue如何实现动画效果
    这篇文章主要介绍Vue如何实现动画效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!具体如下:1.哪些元素/那些组件适合在那些条件下实现动画效果条件渲染 (使用 v-if)条件展示 ...
    99+
    2024-04-02
  • vue怎么使用动画实现滚动表格效果
    这篇文章主要介绍“vue怎么使用动画实现滚动表格效果”,在日常操作中,相信很多人在vue怎么使用动画实现滚动表格效果问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vue怎么使用动画实现滚动表格效果”的疑惑有所...
    99+
    2023-06-29
  • css如何实现吃豆豆加载动画效果
    本文小编为大家详细介绍“css如何实现吃豆豆加载动画效果”,内容详细,步骤清晰,细节处理妥当,希望这篇“css如何实现吃豆豆加载动画效果”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。豆豆加载效果 poi...
    99+
    2023-07-04
  • Android实现仿iOS菊花加载圈动画效果
    目录常见的实现方式效果图:完整代码布局代码 常见的实现方式 切图,做旋转动画 自定义View,绘制效果 gif图 1、切图会增加体积,但相对简单,不过在换...
    99+
    2024-04-02
  • Android实现仿微软系统加载动画效果
    目录效果图:实现步骤:具体代码实现:1、创建Circle对象2、自定义MinSoftLoadingView实现代码3、布局文件中使用效果图: 实现步骤: 初始化五个圆球分...
    99+
    2024-04-02
  • 怎么用纯CSS3实现页面loading加载动画效果
    小编给大家分享一下怎么用纯CSS3实现页面loading加载动画效果,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!  ...
    99+
    2024-04-02
  • Vue实现网页首屏加载动画及页面内请求数据加载loading效果
    目录简介:使用范例:1、四圆点加载动画2、旋涡加载动画3、电池状态加载动画4、请求数据缓慢实现loading提示【推荐】Ⅰ、封装loading组件【推荐】Ⅱ、通过elementUI实...
    99+
    2023-02-10
    vue 加载动画 vue 页面加载动画 vue 页面加载
  • CSS实现加载动画效果的技巧和方法
    随着互联网的发展,加载速度成为了用户体验的重要指标之一。为了提升页面加载时的用户体验,我们通常会使用加载动画效果来增加页面的互动性和吸引力。而CSS作为前端开发中的重要技术之一,提供了许多实现加载动画效果的技巧和方法。本文将介绍几种常见的C...
    99+
    2023-10-21
    旋转 CSS加载动画效果
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作