pc端引用百度地图

 

<template>
  <div class="mod-p-delivery">
    <div class="search-bar">
      <div class="input-row">
        <el-form
          @submit.native.prevent
          :inline="true"
          :model="searchForm"
          @keyup.enter.native="searchChange()"
          size="small"
        >
          <el-form-item label="司机姓名:" class="search-form-item">
            <el-input
              style="width: 210px"
              v-model="searchForm.driverName"
              placeholder="请输入司机姓名"
              clearable
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="searchChange(true)" type="primary"
              >搜索</el-button
            >
            <el-button @click="clear()">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>

    <baidu-map
      class="bm-view"
      :center="{ lng: center.longitude, lat: center.latitude }"
      :zoom="zoom"
      :scroll-wheel-zoom="true"
    >
    <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
      <bm-marker
        :icon="{ url: mapIcon, size: { width: 120, height: 120} }"
        :position="{ lng: item.longitude, lat: item.latitude }"
        @click="clickMarker(item)"
        v-for="item in mapData"
        :key="item.id"
      >
      </bm-marker>
      <bm-info-window
        :position="windowPosition"
        :show="show"
        @close="infoWindowClose"
        @open="infoWindowOpen"
      >
        <div>司机: {{ windowData.driverName }}</div>
        <div>车牌: {{ windowData.licenseNumber }}</div>
      </bm-info-window>
    </baidu-map>
  </div>
</template>

<script>
import mapIconPath from "@/assets/img/smallCar.png";
export default {
  data() {
    return {
      mapIcon: mapIconPath,
      position: { lng: "", lat: "", title: "" },
      searchForm: {
        driverName: "",
      },
      center: {},
      zoom: 11,
      show: false,
      mapData: [],
      positiaon: {},
      windowData: {}, //信息窗体数据
      windowPosition: {}, //信息窗体位置坐标
    };
  },
  created() {
    this.getgps();
  },
  mounted() {},
  methods: {
    initMaker() {
      var latitudeSum = 0;
      var longitudeSum = 0;
      if (this.mapData.length) {
        this.mapData.forEach((item) => {
          (latitudeSum += Number(item.latitude)),
            (longitudeSum += Number(item.longitude));
        });
        this.center.latitude = Number(latitudeSum) / this.mapData.length;
        this.center.longitude = Number(longitudeSum) / this.mapData.length;
      }
    },
    infoWindowClose() {
      this.show = false;
    },
    infoWindowOpen() {
      this.show = true;
    },
    // 点击点标志
    clickMarker(data) {
      this.show = !this.show;
      this.windowData = data;
      this.windowPosition = {
        lng: data.longitude,
        lat: data.latitude,
      };
    },
    getgps() {
      this.$http({
        url: 接口,  // 接口
        method: "get",
        params: {
          driverName: this.searchForm.driverName,
        },
      }).then(({ data }) => {
        this.mapData = data;
        this.initMaker();
      });
    },
    // 搜索
    searchChange() {
      this.getgps();
      this.infoWindowClose()
    },
    // 重置
    clear() {
      this.searchForm.driverName = ''
      this.getgps()
      this.ininfoWindowClose()
    },
  },
};
</script>
<style lang="scss" scoped>
.bm-view {
  width: 100%;
  height: 600px;
  .sample {
    width: 120px;
    height: 600px;
    text-align: center;
    padding: 10px;
    position: absolute;
  }
}
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值