Newer
Older
urbanLifeline_YanAn / src / views / DialogTabs / component / streetscape.vue
@jimengfei jimengfei on 23 Oct 5 KB updata
<template>
  <div id="streetscape"></div>
  <div class="carouselClas">
    <el-carousel type="card" style="z-index: 999" height="150px" motion-blur>
      <el-carousel-item v-for="item in AllData.poiImages" :key="item" @click="selectPoiImgUrl(item)" style="height: 150px">
        <el-image :src="item.imagesUrl" style="width: 100%; height: 150px" />
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup name="streetscape">
import { ref, reactive, toRefs, onMounted, nextTick } from 'vue';
import bus from '@/bus';
import request from '@/utils/request';
import dialogTabsStore from '@/store/modules/dialogTabs';

const useDialogTabs = dialogTabsStore();
const { proxy } = getCurrentInstance();
const AllData = reactive({
  panorama: null,
  poiCircle: null,
  poiImages: [],
  poiData: [],
});
// 初始化街景地图
const initePanoramaMap = () => {
  AllData.panorama = BMapGL.Panorama('streetscape');
  AllData.panorama.setPov({
    // 修改全景的视角
    pitch: 10,
    heading: 0,
  });
  AllData.panorama.setOptions({
    linksControl: true, // 隐藏道路指示控件,默认true
    navigationControl: true, // 隐藏导航控件,默认true
  });
};
//根据中心点查找poi
const searchPoiByLonlat = async () => {
  AllData.poiImages = [];
  let poiData = await request({
    url: `/bdApi/baiduservice/placeSearch`,
    method: 'GET',
    params: {
      location: `${AllData.poiCircle[1]},${AllData.poiCircle[0]}`,
      radius: 1000,
      query: '公交站$商场$著名景点$学校',
    },
  });
  if (poiData && poiData.data.length) {
    AllData.poiData = poiData.data;
    // console.log('poiData---', poiData);
    // poiData.data.forEach(element => {
    //   console.log(element, 'elementelementelement');
    //   getStreetImg([element.location.lng, element.location.lat]);
    //   console.log(a.value, '111111111----');
    //   AllData.poiImages.push({
    //     name: element.name,
    //     lonlat: [element.location.lng, element.location.lat],
    //     imagesUrl: data.data.base64,
    //   });
    // });
    //console.log('AllData.poiData---', AllData.poiData);
    getStreetImg();
  }
};
const a = ref('');
//获取全景静态图
const getStreetImg = async () => {
  AllData.poiImages = [];
  console.log('AllData.poiData---', AllData.poiData);
  AllData.poiData.forEach(async element => {
    let data = await request({
      url: `/bdApi//baiduservice/panorama`,
      method: 'GET',
      params: {
        location: `${element.location.lng},${element.location.lat}`,
        fov: 180,
        height: 256,
        width: 512,
      },
    });
    if (data && data.data && data.data.status == 200) {
      data.data.base64 = 'data:image/jpeg;base64,' + data.data.base64;
      AllData.poiImages.push({
        name: element.name,
        lonlat: [element.location.lng, element.location.lat],
        imagesUrl: data.data.base64,
      });
    }
  });
  console.log('AllData.poiImages---', AllData.poiImages);
};

// 全局事件监听
const showAllStreet = e => {
  console.log('streetPosition---', e);
  let position_Street = turf.point(e);
  // console.log("🚀 ~ showAllStreet ~ position_Street:", position_Street)
  gcoord.transform(position_Street, gcoord.WGS84, gcoord.BD09);
  AllData.poiCircle = position_Street.geometry.coordinates;
  console.log('🚀 ~ showAllStreet ~ AllData.poiCircle:', AllData.poiCircle);
  setTimeout(() => {
    AllData.panorama.setPosition(
      new BMapGL.Point(position_Street.geometry.coordinates[0], position_Street.geometry.coordinates[1])
    );
  }, 2000);

  searchPoiByLonlat();
  gcoord.transform(position_Street, gcoord.BD09, gcoord.WGS84);
};
//轮播图点击事件
const selectPoiImgUrl = item => {
  AllData.panorama.setPosition(new BMapGL.Point(item.lonlat[0], item.lonlat[1]));
};

onMounted(() => {
  initePanoramaMap();
  // AllData.panorama.addEventListener('position_changed', function (pos) {
  //   console.log('pos---', pos);
  //   // AllData.panorama.setPosition(new BMapGL.Point(pos.lng, pos.lat));
  // });

  console.log('useDialogTabs.pointLocation', useDialogTabs.pointLocation);
  showAllStreet(useDialogTabs.pointLocation);

  // bus.on('streetPosition', e => {
  //   showAllStreet(e);
  //   // console.log('streetPosition---', e);
  //   // let position_Street = turf.point(e);
  //   // gcoord.transform(position_Street, gcoord.WGS84, gcoord.BD09);
  //   // AllData.poiCircle = position_Street.geometry.coordinates;
  //   // AllData.panorama.setPosition(
  //   //   new BMapGL.Point(position_Street.geometry.coordinates[0], position_Street.geometry.coordinates[1])
  //   // );
  //   // //searchPoiByLonlat();
  //   // gcoord.transform(position_Street, gcoord.BD09, gcoord.WGS84);
  // });
});
console.log('🚀 ~ onMounted ~ useDialogTabs.pointLocation:', useDialogTabs.pointLocation);
console.log('🚀 ~ onMounted ~ useDialogTabs.pointLocation:', useDialogTabs.pointLocation);
console.log('🚀 ~ onMounted ~ useDialogTabs.pointLocation:', useDialogTabs.pointLocation);
onBeforeUnmount(() => {
  bus.off('xxinformationList');
});
</script>

<style lang="scss" scoped>
#streetscape {
  width: 100%;
  height: 100%;
  // background: red;
}
.carouselClas {
  width: 50%;
  height: 150px;
  // background: red;
  position: absolute;
  bottom: 25px;
  left: 25%;

  .el-carousel__container {
    height: 150px;
  }
}
</style>