vue+openlayers5学习总结(五)改装成vue的一些功能

9 篇文章 0 订阅
8 篇文章 0 订阅

1.画点线面

  • div中代码
 <form class="form-inline">
      <select v-model="selected">
        <option v-for="option in options" v-bind:value="option.value">{{ option.text }}</option>
      </select>
      <span>Selected: {{ selected }}</span>
    </form>
  • script中代码
data() {
   return {
     view: null,
     map: null,
     draw: null,
     mysource: null,
     selected: "请选择",
     options: [
       { text: "Point", value: "Point" },
       { text: "LineString", value: "LineString" },
       { text: "Polygon", value: "Polygon" },
        { text: "None", value: "None" }
     ]
   };


self.mysource = new VectorSource({ wrapX: false });
var vector = new VectorLayer({
     source: self.mysource
   });
this.map = new Map({
      target: mapcontainer,
     //地图图层
     layers: [
       new TileLayer({
         source: new OSM(),
         minResolution: 1,
         maxResolution: 500
       }),
       vector
     ],

     loadTilesWhileAnimating: true,
     //地图视图
     view: myview
   });


watch: {
   selected: function() {
     this.map.removeInteraction(this.draw);
     console.log(this.selected);
    if (this.selected != "None") {
       this.addInteraction(this.selected);
     }
   }
 },
 methods: {
   addInteraction(typevalue) {
     let self=this;
     if (typevalue !== "None") {
       self.draw = new Draw({
         source: self.mysource,
         type: typevalue
       });
       self.map.addInteraction(self.draw);
     }
   }
 }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值