<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: [], 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: '公交站$商场$著名景点$学校', }, }); console.log(poiData, 'poiDatapoiDatapoiData'); 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.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); }; 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(); //getStreetImg(); gcoord.transform(position_Street, gcoord.BD09, gcoord.WGS84); }); }); onBeforeUnmount(() => { bus.off('xxinformationList'); }); </script> <style lang="scss" scoped> #streetscape { width: 100%; height: 100%; } </style>