Newer
Older
urbanLifeline_YanAn / src / views / DialogTabs / component / streetscape.vue
@鲁yixuan 鲁yixuan on 22 Oct 3 KB 1
<template>
  <div id="streetscape">
    <el-carousel height="150px" style="z-index: 999">
      <el-carousel-item v-for="item in AllData.poiImages" :key="item">
        <img :src="item.imagesUrl" />
      </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';
const { proxy } = getCurrentInstance();
const AllData = reactive({
  panorama: null,
  poiCircle: null,
  poiImages: [],
});
// 初始化街景地图
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: 500,
      query: '公交站$商场$著名景点$学校',
    },
  });
  console.log(poiData, 'poiDatapoiDatapoiData');
  if (poiData && poiData.data.length) {
    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.poiImages---', AllData.poiImages);
  }
};
const a = ref('');
//获取全景静态图
const getStreetImg = async lonlat => {
  console.log(lonlat, 'lonlatlonlatlonlatlonlat');
  let data = await request({
    url: `/bdApi//baiduservice/panorama`,
    method: 'GET',
    params: {
      location: `${lonlat[0]},${lonlat[1]}`,
      fov: 180,
      height: 256,
      width: 512,
    },
  });
  if (data && data.data) {
    console.log(data.data.base64, 'data.data.base64');
    data.data.base64 = 'data:image/jpeg;base64,' + data.data.base64;
    a.value = data.data.base64;
    console.log(a.value, '22222222-');
    return data.data.base64;
  }
};
onMounted(() => {
  initePanoramaMap();

  bus.on('streetPosition', 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);
  });
});
onBeforeUnmount(() => {
  bus.off('xxinformationList');
});
</script>

<style lang="scss" scoped>
#streetscape {
  width: 100%;
  height: 100%;
}
</style>