From f584b7e43596120601087acb43681e5fd0583cb0 Mon Sep 17 00:00:00 2001 From: xianfuxing Date: Thu, 6 Sep 2018 17:02:04 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E7=AA=97=E4=BD=93=EF=BC=8C=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/counter/map2.vue | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/views/counter/map2.vue b/src/views/counter/map2.vue index c4aaf42..d553652 100644 --- a/src/views/counter/map2.vue +++ b/src/views/counter/map2.vue @@ -92,6 +92,7 @@ export default { message: '跳转成功!' }) }).catch(() => { + document.getElementById('map-container').removeEventListener this.$message({ type: 'info', message: '已取消跳转' @@ -127,6 +128,7 @@ export default { createInfoWindow(title, content) { const info = document.createElement('div') info.className = 'info' + info.setAttribute('id', 'info') // 可以通过下面的方式修改自定义窗体的宽高 // info.style.width = "400px" @@ -163,13 +165,16 @@ export default { // console.log(info) return info }, - instantiateInforWindow(item) { + instantiateInforWindow(item, drivingButton = false) { const content = [] const curTime = moment().format('YYYY-MM-DD HH:mm:ss') content.push('
' + item.count + '
') content.push('
时间:' + curTime + '
') content.push('
信号:' + item.signal + '电量:' + item.energy + '
') content.push('
区域:尖沙咀
\n') + if (drivingButton) { + content.push('') + } const infoWindow = new AMap.InfoWindow({ isCustom: true, closeWhenClickMap: true, @@ -233,10 +238,20 @@ export default { AMap.event.addListener(geolocation, 'error', this.onError) }) }, + gotoDrivingEvent(e) { + const event = e || window.event + const target = event.target || event.srcElement + if (target.nodeName.toLocaleLowerCase() === 'button') { + console.log('the content is: ', target.innerHTML) + this.gotoDriving() + this.flag = true + } + }, getDevicesInitMap(params) { fetchDeviceList(params).then(response => { this.deviceList = response.data.results - this.coordinate = this.deviceList[0].coordinate + const item = this.deviceList[0] + this.coordinate = item.coordinate if (this.coordinate === null) { this.coordinate = [113.203460828994, 22.64902452257] } @@ -250,9 +265,11 @@ export default { zIndex: 10, map: this.map }) + + item.title = '东岸灯饰工业区' + const infoWindow = this.instantiateInforWindow(item, true) AMap.event.addListener(marker, 'click', () => { - this.gotoDriving() - this.flag = true + infoWindow.open(this.map, marker.getPosition()) }) // this.handleDrivingClick() // this.flag = true @@ -261,6 +278,8 @@ export default { // // document.getElementById('bt-wrapper').style.display = 'normal' // } }) + const mapContainer = document.getElementById('map-container') + mapContainer.addEventListener('click', this.gotoDrivingEvent) } }, created() { @@ -389,4 +408,29 @@ export default { color: white; margin: 0 auto; } + #btn { + display: inline-block; + line-height: 1; + white-space: nowrap; + cursor: pointer; + background: #fff; + border: 1px solid #dcdfe6; + border-color: #dcdfe6; + color: #606266; + -webkit-appearance: none; + text-align: center; + box-sizing: border-box; + outline: none; + margin: 0; + transition: .1s; + font-weight: 500; + padding: 5px 5px; + font-size: 12px; + border-radius: 2px; + } + #btn:focus, #btn:hover { + color: #409eff; + border-color: #c6e2ff; + background-color: #ecf5ff; + }