最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue+Openlayer實(shí)現(xiàn)圖形的拖動(dòng)和旋轉(zhuǎn)變形效果

 更新時(shí)間:2021年11月26日 16:30:34   作者:浩星  
Openlayer具有自己的擴(kuò)展插件ol-ext,可以用來(lái)實(shí)現(xiàn)圖形的拖拽、旋轉(zhuǎn)、縮放、拉伸、移動(dòng)等操作,本文將主要介紹通過(guò)Openlayer實(shí)現(xiàn)圖形的拖動(dòng)和旋轉(zhuǎn),需要的同學(xué)可以學(xué)習(xí)一下

前言

openlayer 是有他自己的擴(kuò)展插件 ol-ext,我們這里用他來(lái)實(shí)現(xiàn)圖形的操作:拖拽、旋轉(zhuǎn)、縮放、拉伸、移動(dòng)等等功能,以及他的監(jiān)聽(tīng)事件,畢竟我們作圖以后是需要保存數(shù)據(jù)給后端,存到數(shù)據(jù)庫(kù)的。

相關(guān)資料

1、ol-ext官方地址:入口

2、ol-ext 對(duì)應(yīng)的資料地址:入口

3、ol-ext 源碼gitee地址:入口

4、openlayers 最新官網(wǎng):入口

5、openlayers 官網(wǎng)api:入口

實(shí)現(xiàn)效果

旋轉(zhuǎn)、拖動(dòng)

圖1、實(shí)現(xiàn)效果

圖2、旋轉(zhuǎn)效果

圖3、左右移動(dòng)效果

?實(shí)現(xiàn)步驟

1、vue中引入openlayers

npm i ol --save

附:npm下載指定版本命令,需要可以拿去

npm install --save-dev ol@6.9.0

2、vue中引入 openlayers的擴(kuò)展包? ?ol-ext

npm install ol-ext --save

附:npm下載指定版本命令,需要可以拿去

npm install --save ol-ext@3.2.16

3、創(chuàng)建地圖容器

<template>
  <div id="map" class="map"></div>
</template>

4、js中引入具體配置,根據(jù)你的具體改,我這里放的是我自己的

ol有關(guān):

import "ol/ol.css";
import View from "ol/View";
import Map from "ol/Map";
import TileLayer from "ol/layer/Tile";
import Overlay from "ol/Overlay";
import XYZ from "ol/source/XYZ";
import { Vector as SourceVec ,Cluster,Vector as VectorSource } from "ol/source";
import { Feature } from "ol";
import { Vector as LayerVec , Vector as VectorLayer } from "ol/layer";
import { Point, LineString, Polygon } from "ol/geom";
 
import {
    Style,
    Icon,
    Fill,
    Stroke,
    Text,
    Circle as CircleStyle,
  } from "ol/style";
  import { OSM, TileArcGISRest } from "ol/source";

ol-ext有關(guān):

import ExtTransform from 'ol-ext/interaction/Transform'

5、實(shí)現(xiàn)地圖方法:

data() {
      return {
        map: null,
        center: [116.39702518856394, 39.918590567855425], //北京故宮的經(jīng)緯度
        centerSize: 11.5,
        projection: "EPSG:4326",
 
    }
}
mounted() {
  this.initMap()
}
methods: {
      //初始化地圖
      initMap() {
        //渲染地圖
        var layers = [
          //深藍(lán)色背景
          // new TileLayer({
          //   source: new XYZ({
          //     url:
          //       "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}",
          //   }),
          // }),
          //初始化背景
          // new TileLayer({
          //   source: new OSM(),
          // })
          new TileLayer({
            title: "街道圖",
            source: new XYZ({
              url: "http://localhost:8888/haoxing-map/sosomaps/roadmap/{z}/{x}/{y}.jpg",//zwh本地使用
            }),
          }),
        ];
 
        this.map = new Map({
          layers: layers,
          target: "map",
          view: new View({
            center: this.center,
            projection: this.projection,
            zoom: this.centerSize,
            maxZoom: 17,
            minZoom: 8,
          }),
        });
      },

6、地圖上加上多邊形數(shù)據(jù)

mounted() {
 this.initMap()
 this.createPolygon()
},
 methods: {    
 
    //創(chuàng)建多邊形
    createPolygon() {
        //添加圖層,并設(shè)置點(diǎn)范圍
        const polygon = new Feature({
          geometry: new Polygon([
            [
              [116.39314093500519,40.0217660530101],
              [116.47762344990831,39.921746523871924],
              [116.33244947314951,39.89892653421418],
              [116.30623076162784,40.00185925352143],
            ]
          ]),
        })
        //設(shè)置樣式
        polygon.setStyle(new Style({
          stroke: new Stroke({
            width: 4,
            color: [255, 0, 0, 1],
          }),
        }))
        //將圖形加到地圖上
        this.map.addLayer(new VectorLayer({
          source: new VectorSource({
            features: [polygon],
          }),
        }))
      },
 
}

7、地圖上添加具體的操作方法和效果?

mounted() {
  this.initMap()
  this.createPolygon()
  this.onEdit()
},
//操作事件
onEdit() {
   const transform = new ExtTransform({
       enableRotatedTransform: false,
       hitTolerance: 2,
       translate: true, // 拖拽
       stretch: false, // 拉伸
       scale: true, // 縮放
       rotate: true, // 旋轉(zhuǎn)
       translateFeature: false,
       noFlip: true,
       // layers: [],
    })
   this.map.addInteraction(transform)
 
 
  //開(kāi)始事件
        transform.on(['rotatestart','translatestart'], function(e){
          // Rotation
          let startangle = e.feature.get('angle')||0;
          // Translation
          console.log(1111);
          console.log(startangle);
        });
  //旋轉(zhuǎn)
        transform.on('rotating', function (e){
          console.log(2222);
          console.log("rotate: "+((e.angle*180/Math.PI -180)%360+180).toFixed(2));
          console.log(e);
        });
 //移動(dòng)
        transform.on('translating', function (e){
          console.log(3333);
          console.log(e.delta);
          console.log(e);
 
        });
 //拖拽事件
        transform.on('scaling', function (e){
          console.log(4444);
          console.log(e.scale);
          console.log(e);
        });
  //事件結(jié)束
        transform.on(['rotateend', 'translateend', 'scaleend'], function (e) {
          console.log(5555);
        });
 
},

到此這篇關(guān)于Vue+Openlayer實(shí)現(xiàn)圖形的拖動(dòng)和旋轉(zhuǎn)變形效果的文章就介紹到這了,更多相關(guān)Vue Openlayer內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue中router.beforeEach()的簡(jiǎn)單用法舉例

    vue中router.beforeEach()的簡(jiǎn)單用法舉例

    router.beforeEach()一般用來(lái)做一些進(jìn)入頁(yè)面的限制,比如沒(méi)有登錄,就不能進(jìn)入某些頁(yè)面,只有登錄了之后才有權(quán)限查看某些頁(yè)面,下面這篇文章主要給大家介紹了關(guān)于vue中router.beforeEach()的簡(jiǎn)單用法舉例,需要的朋友可以參考下
    2023-01-01
  • vue實(shí)現(xiàn)圖片拖動(dòng)排序

    vue實(shí)現(xiàn)圖片拖動(dòng)排序

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)圖片拖動(dòng)排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • vue新玩法VueUse工具庫(kù)具體用法@vueuse/core詳解

    vue新玩法VueUse工具庫(kù)具體用法@vueuse/core詳解

    這篇文章主要介紹了vue新玩法VueUse-工具庫(kù)@vueuse/core,VueUse不是Vue.use,它是一個(gè)基于?Composition?API?的實(shí)用函數(shù)集合,下面是具體的一些用法,需要的朋友可以參考下
    2022-08-08
  • vue3項(xiàng)目中使用three.js的操作步驟

    vue3項(xiàng)目中使用three.js的操作步驟

    最近在學(xué)習(xí)Three.js相關(guān)的技術(shù),恰逢Vue 3.0正式版也已推出,下面這篇文章主要給大家介紹了關(guān)于vue3項(xiàng)目中使用three.js的操作步驟,文中通過(guò)圖文以及實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • vue-cli-service build 環(huán)境設(shè)置方式

    vue-cli-service build 環(huán)境設(shè)置方式

    這篇文章主要介紹了vue-cli-service build 環(huán)境設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。
    2023-01-01
  • vue3+ts使用bus事件總線的示例代碼

    vue3+ts使用bus事件總線的示例代碼

    這篇文章主要介紹了vue3+ts使用bus事件總線,文中給大家提到了vue總線機(jī)制(bus)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • 基于element-UI input等組件寬度修改方式

    基于element-UI input等組件寬度修改方式

    這篇文章主要介紹了基于element-UI input等組件寬度修改方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • vue配置生產(chǎn)環(huán)境.env.production與測(cè)試環(huán)境.env.development

    vue配置生產(chǎn)環(huán)境.env.production與測(cè)試環(huán)境.env.development

    這篇文章主要介紹了vue配置生產(chǎn)環(huán)境.env.production與測(cè)試環(huán)境.env.development方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問(wèn)題

    vue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問(wèn)題

    根據(jù)vue-music視頻中slider組建的使用,當(dāng)安裝新版本的better-scroll,輪播組件,不能正常輪播。如何解決這個(gè)問(wèn)題呢,下面小編給大家?guī)?lái)了vue-music 使用better-scroll遇到輪播圖不能自動(dòng)輪播問(wèn)題,感興趣的朋友一起看看吧
    2018-12-12
  • vue中keep-alive內(nèi)置組件緩存的實(shí)例代碼

    vue中keep-alive內(nèi)置組件緩存的實(shí)例代碼

    這篇文章主要介紹了vue中的keep-alive內(nèi)置組件緩存,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04

最新評(píng)論

镇赉县| 师宗县| 兖州市| 阜新| 司法| 禹州市| 依安县| 册亨县| 延寿县| 蓬溪县| 安平县| 恩施市| 云南省| 万年县| 竹北市| 鲁甸县| 久治县| 山东| 高安市| 温泉县| 兴隆县| 丰原市| 西宁市| 乐山市| 百色市| 淮滨县| 京山县| 诸城市| 平山县| 托克逊县| 永福县| 宁河县| 博乐市| 光山县| 临西县| 乳源| 宜章县| 临城县| 安乡县| 民勤县| 威信县|