天地图弹窗实现打点的公共组件封装

效果

@desc: 弹窗获取点位后,父组件获取点位数据。

index.html (天地图官网申请key)

弹窗核心代码

<template>
  <div v-if="visible" class="add--user">
    <el-dialog
      :visible.sync="visible"
      :before-close="hideDialog"
      :modal-append-to-body="false"
      append-to-body
      width="1200px"
      class="my-dialog-map-mark"
      title="点位选择"
    >
      <div id="MarkMapDiv" class="map-box"></div>
      <div class="footer">
        <el-button
          v-if="mapPointArr.length === 0"
          @click="markPoint"
          size="small"
          round
          type="primary"
          icon="el-icon-location-information"
          >开始打点
        </el-button>
        <el-button
          v-if="mapPointArr.length > 0"
          @click="clearPoint"
          size="small"
          round
          type="primary"
          icon="el-icon-delete-locationn"
          >清除点
        </el-button>
        <el-button @click="close" size="small" round icon="el-icon-close"
          >关闭</el-button
        >
        <el-button
          @click="save"
          size="small"
          round
          type="primary"
          icon="el-icon-finished"
          >保存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
let map;
const zoom = 14;
const handler = [];
let img;
export default {
  name: "mapMarkers1",
  components: {},
  props: {},
  computed: {},
  filters: {},
  watch: {},
  data() {
    return {
      arr: [],
      visible: false,
      mapPointArr: [],
      img_nj: "",
      img_jzs: "",
      index: 0
    };
  },
  methods: {
    markPoint() {
      if (this.mapPointArr > 0) {
        return false;
      }
      if (handler[this.index]) handler[this.index].close();
      handler[this.index] = new T.MarkTool(map, { follow: true });
      handler[this.index].open();
      handler[this.index].addEventListener("mouseup", e => {
        console.log(e);
        this.mapPointArr.push(e.currentLnglat);
        // this.index += 1;
      });
    },

    clearPoint() {
      this.mapPointArr = [];
      map.clearOverLays();
      this.setMapImg();
    },

    hideDialog() {
      this.close();
    },

    showDialog(pointArr) {
      console.log(this.mapPointArr);
      // pointArr: [{lng:104.55,lat:22.9}]
      this.mapPointArr = pointArr || [];
      this.visible = true;
      this.$nextTick(() => {
        this.showMap();
      });
      if (this.mapPointArr[0].lat === null) {
        this.mapPointArr.length = 0;
      }
    },

    showMap() {
      // ??? 填入申请的秘钥即可
      const imageURL =
        "http://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=你的秘钥";
      //创建自定义图层对象
      const lay = new T.TileLayer(imageURL, { minZoom: 13, maxZoom: 18 });
      map = new T.Map("MarkMapDiv", { layers: [lay] });
      console.log(map);
      map.centerAndZoom(new T.LngLat(104.55, 22.9), zoom);

      const typeArr = [
        {
          // title: '卫星',
          title: "",
          icon:
            " http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellite.png",
          layer: TMAP_SATELLITE_MAP
        },
        {
          // title: '地图', //地图控件上所要显示的图层名称
          title: "", //地图控件上所要显示的图层名称
          icon: "http://api.tianditu.gov.cn/v4.0/image/map/maptype/vector.png", //地图控件上所要显示的图层图标(默认图标大小80x80)
          layer: TMAP_NORMAL_MAP //地图类型对象,即MapType。
        }
      ];
      const ctrl = new T.Control.MapType(typeArr);
      //添加控件
      map.addControl(ctrl);

      map.addEventListener("maptypechange", e => {
        console.log(e);
        //e.mapType 就是 当前切换的MapType 配置的地图
        if (e.mapType.name == "TMAP_NORMAL_MAP") {
          // 普通地图 覆盖图隐藏
          this.img_nj.hide();
          this.img_jzs.hide();
        } else {
          this.img_nj.show();
          this.img_jzs.show();
        }
      });

      map.setMinZoom(13);
      map.setMaxZoom(18);

      map.setMaxBounds(
        new T.LngLatBounds(
          new T.LngLat(104.45, 22.84),
          new T.LngLat(104.65, 22.96)
        )
      );

      this.setMapImg();

      this.mapPointArr &&
        this.mapPointArr.forEach(item => {
          const marker = new T.Marker(new T.LngLat(item.lng, item.lat));
          //向地图上添加标注
          map.addOverLay(marker);
        });

      const config = {
        showLabel: true,
        color: "#f14343",
        weight: 2,
        opacity: 1,
        fillColor: "#f14343",
        fillOpacity: 0.2
      };
      //创建标注工具对象
      const polygonTool = new T.PolygonTool(map, config);
    },

    setMapImg() {
      const bd = new T.LngLatBounds(
        new T.LngLat(104.5548, 22.8871),
        new T.LngLat(104.5648, 22.8924)
      );
      this.img_jzs = new T.ImageOverlay("map/img/map-s-jzs.png", bd, {
        opacity: 1,
        alt: "" // 名称
      });
      map.addOverLay(this.img_jzs);

      const bd_nj = new T.LngLatBounds(
        new T.LngLat(104.5573, 22.8752),
        new T.LngLat(104.5773, 22.8856)
      );
      this.img_nj = new T.ImageOverlay("map/img/map-s-nj.png", bd_nj, {
        opacity: 1,
        alt: "" // 名称
      });
      map.addOverLay(this.img_nj);
    },

    close() {
      this.visible = false;
    },

    save() {
      const data = this.mapPointArr;
      console.log(data);
      this.$emit("backData", data);
      this.hideDialog();
    }
  },
  created() {},
  mounted() {}
};
</script>

<style lang="scss" scoped>
::v-deep .tdt-left {
  display: none;
}

::v-deep .tdt-iconLayers-layer {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
}

.map-box {
  height: 500px;
  border-radius: 8px;
}
</style>
<style lang="scss">
* {
  .my-dialog-map-mark {
    .el-dialog {
      border-radius: 20px;
      background: #ffffff;

      .el-dialog__body {
        padding-top: 10px;
        padding-bottom: 0;
      }

      .el-dialog__title {
        border-left: 5px solid #4c64fe;
        text-indent: 10px;
        display: inline-block;
        line-height: unset;
        font-size: 16px;
        font-weight: 600;
      }
    }
  }

  .icon_color {
    color: #4c64fe;
    margin-right: 5px;
  }

  /* 底部按钮区域 */
  .footer {
    height: 80px;
    line-height: 80px;
    max-width: calc(100% - (100% - 1140px) / 2);
    margin: 0 auto;
    text-align: right;
  }
}
</style>

父组件

<mapMarkers1 ref="mapMarkers1" @backData="getMapPoint" />
  

import mapMarkers1 from "./mapMarkers1.vue"; // 注册

  components: {
    mapMarkers1,
  },

 <el-button @click="openMap" size="small"> 开始定位</el-button>
<mapMarkers1 ref="mapMarkers1" @backData="getMapPoint" /> // 使用

 resultPosition: [
        {
          lat: "", // 纬度
          lng: "" // 经度
        }
      ]

 methods: {  
    openMap() {
      const refName = "mapMarkers1";
      const dialog = this.$refs[refName];
      dialog.showDialog(this.resultPosition);
    },
   getMapPoint(data) {
      if (data.length > 0) {
        this.$set(this.resultPosition[0], "lat", data[0].lat.toString());
        this.$set(this.resultPosition[0], "lng", data[0].lng.toString());
      } else {
        this.resultPosition = [];
      }
      console.log('resultPosition', this.resultPosition);
    },
 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
AT89C51的液体点滴速度监控系统是一种基于单片机的设备,用于监控和调节液体点滴的输送速度。该系统主要包括传感器、单片机、液晶显示屏和执行器等模块,通过这些模块协同工作,实现对液体点滴速度的实时监控和调节。 系统中的传感器负责监测液体点滴的滴落频率,并将信号传输给单片机进行处理。单片机通过计算传感器采集到的数据,得到当前的滴液速度,并通过液晶显示屏实时显示出来。同时,单片机还能根据设定的目标速度,通过执行器控制液体点滴的进给装置,实现对滴液速度的调节。另外,系统还可以设置报警功能,当检测到滴液速度超出设定范围时,可以及时发出警报信号,提醒使用者进行处理。 在实现过程中,我们首先需要对AT89C51单片机进行编程,编写程序实现对传感器数据的采集和处理,以及对液体点滴进给装置的控制。其次,需要设计相应的电路板,将单片机、传感器、执行器等模块连接起来,实现各模块之间的数据传输和控制信号传递。最后,进行系统的整体调试和测试,确保系统能够准确地监控和调节液体点滴的速度。 因此,AT89C51的液体点滴速度监控系统的设计与实现需要综合运用单片机编程、传感器技木、电路设计等多方面的知识和技术,通过各模块的协同工作,实现对液体点滴速度的精准监控和调节。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值