欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue中使用Openlayer實現(xiàn)加載動畫效果

 更新時間:2021年08月31日 16:28:03   作者:~疆  
這篇文章主要介紹了Vue+Openlayer加載動畫效果的實現(xiàn)代碼,代碼簡單易懂,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

注意:實現(xiàn)動畫時不能有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動態(tài)圖標點位信息
    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);
        });
      }
    },
    //根據(jù)geojson數(shù)據(jù)獲取坐標集
    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動態(tài)圖標點位信息
    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);
        });
      }
    },
    //根據(jù)geojson數(shù)據(jù)獲取坐標集
    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; //無限循環(huán)
  }
  @keyframes myfirst {
    to {
      transform: scale(2);
      background: rgba(0, 0, 0, 0);
      box-shadow: inset 0 0 50px rgba(255, 0, 0, 0);
    }
  }
}
</style>

既可加載動畫,又可獲取動畫所在要素點的屬性

 

注意:該代碼存在問題。目前只能要么點擊獲取屬性,要么展示動畫,而不能同時存在,還有待優(yōu)化!

<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動態(tài)圖標點位信息
    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);
        });
      }
    },
    //根據(jù)geojson數(shù)據(jù)獲取坐標集
    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; //無限循環(huán)
  }
  @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加載動畫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Vue通過axios調(diào)用json地址數(shù)據(jù)的方法

    Vue通過axios調(diào)用json地址數(shù)據(jù)的方法

    在現(xiàn)代Web開發(fā)中,前后端分離已成為標準做法,Vue.js作為前端框架中的佼佼者,提供了豐富的API來處理數(shù)據(jù)和服務端的交互,其中一個常用的庫是axios,本文將詳細介紹如何在Vue項目中使用axios來調(diào)用JSON數(shù)據(jù),需要的朋友可以參考下
    2024-09-09
  • Vue3獲取DOM節(jié)點的3種方式實例

    Vue3獲取DOM節(jié)點的3種方式實例

    Vue本來無需操作DOM來更新界面,而且Vue也不推薦我們直接操作DOM,但是我們非要拿到DOM操作DOM怎么辦,下面這篇文章主要給大家介紹了關于Vue3獲取DOM節(jié)點的3種方式,需要的朋友可以參考下
    2023-02-02
  • 詳解Vuex的屬性

    詳解Vuex的屬性

    Vuex是專為Vue.js應用程序開發(fā)的狀態(tài)管理模式,這篇文章主要介紹了Vuex的屬性,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • Vue實現(xiàn)文字上下滾動動畫的示例代碼

    Vue實現(xiàn)文字上下滾動動畫的示例代碼

    這篇文章主要為大家詳細介紹了如何使用Vue實現(xiàn)超酷文字上下滾動動畫,文中的示例代碼講解詳細,具有一定的借鑒價值,有需要的小伙伴可以參考下
    2024-03-03
  • vue傳值方式的十二種方法總結(jié)

    vue傳值方式的十二種方法總結(jié)

    這篇文章主要介紹了vue傳值方式的十二種方法總結(jié),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-04-04
  • Vue編寫炫酷的時鐘插件

    Vue編寫炫酷的時鐘插件

    這篇文章主要為大家詳細介紹了Vue編寫炫酷的時鐘插件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Vue-Cli配置代理轉(zhuǎn)發(fā)解決跨域問題的方法

    Vue-Cli配置代理轉(zhuǎn)發(fā)解決跨域問題的方法

    本文主要介紹了Vue-Cli配置代理轉(zhuǎn)發(fā)解決跨域問題的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • vue3集成Element-plus實現(xiàn)按需自動引入組件的方法總結(jié)

    vue3集成Element-plus實現(xiàn)按需自動引入組件的方法總結(jié)

    vue3出來一段時間了,element也更新了版本去兼容vue3,下面這篇文章主要給大家介紹了關于vue3集成Element-plus實現(xiàn)按需自動引入組件的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-07-07
  • vue實現(xiàn)點擊關注后及時更新列表功能

    vue實現(xiàn)點擊關注后及時更新列表功能

    這篇文章主要介紹了vue實現(xiàn)點擊關注后及時更新列表功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-06-06
  • Vue中通過Vue.extend動態(tài)創(chuàng)建實例的方法

    Vue中通過Vue.extend動態(tài)創(chuàng)建實例的方法

    這篇文章主要介紹了Vue中通過Vue.extend動態(tài)創(chuàng)建實例的方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-08-08

最新評論