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

Vue+Openlayer使用modify修改要素的完整代碼

 更新時間:2021年09月08日 09:43:53   作者:~疆  
這篇文章主要介紹了Vue+Openlayer使用modify修改要素的完整代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

Vue+Openlayer使用modify修改要素,具體內(nèi)容如下所示:

import { Modify } from "ol/interaction";

  1. 可自動捕捉 
  2. 可修改點、線、面。不用自己聲明要修改的要素類型

直接修改要素 

 

核心代碼:  

 // 修改要素核心代碼
    modifyFeature() {
      this.modify = new Modify({
        source: this.lineStringLayer.getSource(),
      });
      this.map.addInteraction(this.modify);
    },

完整代碼: 

<template>
  <div id="map" style="height: 100vh; width: 100vw"></div>
</template>
 
<script>
import "ol/ol.css";
import { Map, View, Feature } from "ol";
import { OSM, Vector as VectorSource } from "ol/source";
import { Vector as VectorLayer, Tile as TileLayer } from "ol/layer";
 
import { Point, LineString, Polygon } from "ol/geom";
import { Modify } from "ol/interaction";
export default {
  data() {
    return {
      map: {},
      lineStringLayer: {},
      modify: {},
    };
  },
  created() {},
  mounted() {
    this.initMap();
    this.addLayer();
    this.modifyFeature();
  },
  computed: {},
  methods: {
    initMap() {
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new OSM(),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [104.2979180563, 30.528298024],
          zoom: 18,
        }),
      });
    },
    addLayer() {
      this.lineStringLayer = new VectorLayer({
        source: new VectorSource(),
      });
      this.lineStringLayer.getSource().addFeature(
        new Feature({
          geometry: new LineString([
            [104.2979180563, 30.528298024],
            [104.2987389704, 30.527798338],
          ]),
        })
      );
      this.map.addLayer(this.lineStringLayer);
    },
    // 修改要素核心代碼
    modifyFeature() {
      this.modify = new Modify({
        source: this.lineStringLayer.getSource(), //這里要用source
      });
      this.map.addInteraction(this.modify);
    },
  },
};
</script>

此外,可通過this.modify.setActive(false)來禁用modify對象,this.modify.getActive()獲取激活狀態(tài)

先選中要素,再修改要素

核心代碼:

注意:這里一定要用features屬性,不要用source?。。?!

modifyFeature() {
      this.modify = new Modify({
        //注意:這里一定要用features屬性,不要用source!?。。?
        features: this.select.getFeatures(),
      });
      this.map.addInteraction(this.modify);
    },

完整代碼: 

<template>
  <div id="map" style="height: 100vh; width: 100vw"></div>
</template>
 
<script>
import "ol/ol.css";
import { Map, View, Feature } from "ol";
import { OSM, Vector as VectorSource, XYZ } from "ol/source";
import { Vector as VectorLayer, Tile as TileLayer } from "ol/layer";
 
import Select from "ol/interaction/Select";
 
import { Point, LineString, Polygon } from "ol/geom";
import { Modify } from "ol/interaction";
export default {
  data() {
    return {
      map: {},
      lineStringLayer: {},
      draw: {},
      modify: {},
      select: {},
    };
  },
  created() {},
  mounted() {
    this.initMap();
    this.pointerMove();
    this.addLayer();
    this.selectFeature();
    this.modifyFeature();
  },
  computed: {},
  methods: {
    initMap() {
      this.map = new Map({
        target: "map",
        layers: [
          new TileLayer({
            source: new OSM(),
          }),
        ],
        view: new View({
          projection: "EPSG:4326",
          center: [104.2979180563, 30.528298024],
          zoom: 18,
        }),
      });
    },
    pointerMove() {
      this.map.on("pointermove", (e) => {
        const isHover = this.map.hasFeatureAtPixel(e.pixel);
        this.map.getTargetElement().style.cursor = isHover ? "pointer" : "";
      });
    },
    addLayer() {
      this.lineStringLayer = new VectorLayer({
        source: new VectorSource(),
      });
      this.lineStringLayer.getSource().addFeature(
        new Feature({
          geometry: new LineString([
            [104.2979180563, 30.528298024],
            [104.2987389704, 30.527798338],
          ]),
        })
      );
      this.map.addLayer(this.lineStringLayer);
    },
    selectFeature() {
      this.select = new Select();
      this.map.addInteraction(this.select);
    },
    modifyFeature() {
      this.modify = new Modify({
        //注意:這里一定要用features屬性,不要用source?。。?!
        features: this.select.getFeatures(),
      });
      this.map.addInteraction(this.modify);
    },
  },
};
</script>

ps:Openlayers修改矢量要素

將以下代碼放到demo下examples中即可運行

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Modify Feature</title>
<link rel="stylesheet" href="../theme/default/style.css" rel="external nofollow"  rel="external nofollow"  type="text/css">
<link rel="stylesheet" href="style.css" rel="external nofollow"  rel="external nofollow"  type="text/css">
<style type="text/css">

</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectors, controls;
function init(){
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';

vectors = new OpenLayers.Layer.Vector("Vector Layer");

var geometry = OpenLayers.Geometry.fromWKT(
'POLYGON((110 20,120 20,120 10,110 10,110 20),(112 17,118 18,118 16,112 15,112 17))'
);

vectors.addFeatures([new OpenLayers.Feature.Vector(geometry)]);

map.addLayers([wms, vectors]);
//畫圖形
controls = new OpenLayers.Control.DrawFeature(vectors,
OpenLayers.Handler.Polygon);

map.addControl(controls);
controls.activate();
map.setCenter(new OpenLayers.LonLat(110, 20), 3);
}

function update() {
// 修改
controls.deactivate();
controls = new OpenLayers.Control.ModifyFeature(vectors);
map.addControl(controls);
controls.activate();

}

function deactivate(){
controls.deactivate();
}

</script>
</head>
<body onload="init()">
<div id="map" class="smallmap"></div>
<div><input type = "button" value = "修改" onclick = "update()"/>
<input type = "button" value = "取消" onclick = "deactivate()"/>
</div>
</body>
</html>

到此這篇關(guān)于Vue+Openlayer使用modify修改要素的文章就介紹到這了,更多相關(guān)Vue Openlayer修改要素內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue刷新修改頁面中數(shù)據(jù)的方法

    Vue刷新修改頁面中數(shù)據(jù)的方法

    今天小編就為大家分享一篇Vue刷新修改頁面中數(shù)據(jù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue+tsc+noEmit導(dǎo)致打包報TS類型錯誤問題及解決方法

    vue+tsc+noEmit導(dǎo)致打包報TS類型錯誤問題及解決方法

    當(dāng)我們新建vue3項目,package.json文件會自動給我添加一些配置選項,這寫選項基本沒有問題,但是在實際操作過程中,當(dāng)項目越來越復(fù)雜就會出現(xiàn)問題,本文給大家分享vue+tsc+noEmit導(dǎo)致打包報TS類型錯誤問題及解決方法,感興趣的朋友一起看看吧
    2023-10-10
  • 基于vue-cli3創(chuàng)建libs庫的實現(xiàn)方法

    基于vue-cli3創(chuàng)建libs庫的實現(xiàn)方法

    這篇文章主要介紹了基于vue-cli3創(chuàng)建libs庫的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • vue3中超好用的插件整理

    vue3中超好用的插件整理

    最近找到幾個好用的插件,這里分享一下,下面這篇文章主要給大家介紹了關(guān)于vue3中超好用的插件整理,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • vue實現(xiàn)下拉多選、可搜索、全選功能(示例代碼)

    vue實現(xiàn)下拉多選、可搜索、全選功能(示例代碼)

    本文介紹了如何在Vue中實現(xiàn)一個樹形結(jié)構(gòu)的下拉多選組件,支持任意一級選項的選擇,全選功能,以及搜索功能,通過在mounted生命周期中獲取數(shù)據(jù),并使用handleTree函數(shù)將接口返回的數(shù)據(jù)整理成樹形結(jié)構(gòu),實現(xiàn)了這一功能,感興趣的朋友一起看看吧
    2025-01-01
  • 詳解如何在vue項目中使用eslint+prettier格式化代碼

    詳解如何在vue項目中使用eslint+prettier格式化代碼

    在開發(fā)中我們需要一種能夠統(tǒng)一團隊代碼風(fēng)格的工具,作為強制性的規(guī)范,統(tǒng)一整個項目的代碼風(fēng)格,這篇文章主要介紹了詳解如何在vue項目中使用eslint+prettier格式化代碼,需要的朋友可以參考下
    2018-11-11
  • vue-cli3+echarts實現(xiàn)漸變色儀表盤組件封裝

    vue-cli3+echarts實現(xiàn)漸變色儀表盤組件封裝

    這篇文章主要為大家詳細(xì)介紹了vue-cli3+echarts實現(xiàn)漸變色儀表盤組件封裝,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Vue自定義元素身上的右鍵事件問題

    Vue自定義元素身上的右鍵事件問題

    這篇文章主要介紹了Vue自定義元素身上的右鍵事件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • vue實現(xiàn)簡單的MVVM框架

    vue實現(xiàn)簡單的MVVM框架

    這篇文章給大家分享了基于vue實現(xiàn)一個簡單的MVVM框架的相關(guān)內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。
    2018-08-08
  • 如何解決this.$refs.form.validate()不執(zhí)行的問題

    如何解決this.$refs.form.validate()不執(zhí)行的問題

    這篇文章主要介紹了如何解決this.$refs.form.validate()不執(zhí)行的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09

最新評論

庄浪县| 隆尧县| 长宁县| 枞阳县| 浦县| 梁平县| 瑞丽市| 澄城县| 泉州市| 右玉县| 滦南县| 合江县| 衡阳市| 芜湖县| 乐清市| 隆尧县| 万州区| 兴文县| 平顺县| 兴义市| 武宁县| 焦作市| 藁城市| 运城市| 海口市| 北京市| 邹平县| 张掖市| 比如县| 满城县| 鹿邑县| 买车| 平邑县| 拉孜县| 唐山市| 明溪县| 余庆县| 桃园市| 肇庆市| 福贡县| 丹阳市|