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

Vue中使用Openlayer實(shí)現(xiàn)加載動(dòng)畫(huà)效果

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

注意:實(shí)現(xiàn)動(dòng)畫(huà)時(shí)不能有scoped!!!! 

通過(guò)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: "警報(bào)1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)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動(dòng)態(tài)圖標(biāo)點(diǎn)位信息
    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ù)獲取坐標(biāo)集
    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>

通過(guò)關(guān)鍵幀@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: "警報(bào)1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)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動(dòng)態(tài)圖標(biāo)點(diǎn)位信息
    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ù)獲取坐標(biāo)集
    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; //無(wú)限循環(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>

既可加載動(dòng)畫(huà),又可獲取動(dòng)畫(huà)所在要素點(diǎn)的屬性

 

注意:該代碼存在問(wèn)題。目前只能要么點(diǎn)擊獲取屬性,要么展示動(dòng)畫(huà),而不能同時(shí)存在,還有待優(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: "警報(bào)1",
            },
            geometry: {
              type: "Point",
              coordinates: [91.48879670091165, 37.83814884701121],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)2",
            },
            geometry: {
              type: "Point",
              coordinates: [99.19515576149941, 26.713646654711134],
            },
          },
          {
            type: "Feature",
            properties: {
              title: "警報(bào)3",
            },
            geometry: {
              type: "Point",
              coordinates: [123.74363825288785, 44.363694825734726],
            },
          },
        ],
      },
 
      select: {},
      properties: {
        title: "",
      },
    };
  },
  mounted() {
    this.initMap();
    // this.addGif();//注釋掉后,點(diǎn)擊可獲取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", //一定要加上,否則會(huì)有偏移
      });
 
      this.select.on("select", (e) => {
        let coordinate = e.mapBrowserEvent.coordinate; //獲取選擇的坐標(biāo)
 
        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(); //獲取當(dāng)前要素的所有屬性
          //設(shè)置選中的樣式
          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,
                }),
              }),
            })
          );
        }
      });
 
      // 設(shè)置鼠標(biāo)劃過(guò)矢量要素的樣式
      this.map.on("pointermove", (e) => {
        const isHover = this.map.hasFeatureAtPixel(e.pixel);
        this.map.getTargetElement().style.cursor = isHover ? "pointer" : "";
      });
    },
    // 使用Overlay添加GIF動(dòng)態(tài)圖標(biāo)點(diǎn)位信息
    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ù)獲取坐標(biāo)集
    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; //無(wú)限循環(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>

到此這篇關(guān)于Vue+Openlayer加載動(dòng)畫(huà)的文章就介紹到這了,更多相關(guān)Vue Openlayer加載動(dòng)畫(huà)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

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

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

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

    Vue3獲取DOM節(jié)點(diǎn)的3種方式實(shí)例

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

    詳解Vuex的屬性

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

    Vue實(shí)現(xiàn)文字上下滾動(dòng)動(dòng)畫(huà)的示例代碼

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

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

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

    Vue編寫炫酷的時(shí)鐘插件

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

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

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

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

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

    vue實(shí)現(xiàn)點(diǎn)擊關(guān)注后及時(shí)更新列表功能

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

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

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

最新評(píng)論