1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| <template> <div class="traffic"> <ul> <li v-for="(item,index) in sceneryMapdata" :key="index" style="cursor:pointer;" @mousemove="choose(item)"> <span>{{item.name}}</span> <span>{{item.biz_ext.rating}}公里</span> </li> </ul> </div> </template>
data() { return { activeName:"first", sceneryMapdata:null, loading:true, content: "高级酒店", map: null, markers: null, infoWindow: null, center: [118.796623, 32.059352] }; }, methods: { choose(data){ let temp = data.location.split(","); temp = [temp[0]-0,temp[1]-0] this.content = data.name this.infoWindow = new AMap.InfoWindow({ offset: new AMap.Pixel(-5, -50), content: this.content }); this.infoWindow.open(this.map, temp); }, setMarker(markers, position, data) { this.markers = new AMap.Marker({ content: `<div style="width:20px;height:28px;text-align:center;" class="el-icon-location"></div>`, position: position, offset: new AMap.Pixel(-17, -42), map: this.map }); AMap.event.addListener(this.markers,"mousemove", ()=>{ this.content = data.name; this.infoWindow = new AMap.InfoWindow({ offset: new AMap.Pixel(-5, -50), content: this.content }); this.infoWindow.open(this.map, position); }); }, setMapInfo() { const {location} = this.sceneryMapdata[3] const temp = location.split(","); this.center = [temp[0]-0,temp[1]-0] this.map = new AMap.Map("detailMap", { zoom: 14, center: this.center, viewMode: "3D" }); this.sceneryMapdata.forEach(v => { let str = v.location.split(","); this.setMarker(v.name, [str[0]-0,str[1]-0], v); }); }, getMapdata(){ this.$axios({ url:`https://restapi.amap.com/v3/place/text`, params:{ keyword:'', location:"118.732841,32.077242", city:"南京市", types:"风景名胜", output:'json', page:1, offset:10, key:'key私人定制' } }).then(res=>{ this.sceneryMapdata = res.data.pois }) } }, mounted() { setTimeout(() => { this.setMapInfo(); }, 3000); this.getMapdata() } };
|