From 14a2a86635db4d519c882baa9012f5f7a7ae4723 Mon Sep 17 00:00:00 2001 From: xianfuxing Date: Tue, 4 Sep 2018 20:19:58 +0800 Subject: [PATCH] =?UTF-8?q?#=20=E5=AE=9A=E4=BD=8D=E5=90=8E=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/counter/map2.vue | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/views/counter/map2.vue b/src/views/counter/map2.vue index cd60012..26be43a 100644 --- a/src/views/counter/map2.vue +++ b/src/views/counter/map2.vue @@ -172,6 +172,21 @@ export default { } str.push('是否经过偏移:' + (data.isConverted ? '是' : '否')) document.getElementById('geo-tip').innerHTML = str.join('
') + const drivingOptions = { + map: this.map, + panel: 'panel' + } + // 驾车路径规划 + const driving = new AMap.Driving(drivingOptions) + const button = document.getElementById('bt') + driving.search(new AMap.LngLat(113.344095, 22.673091), new AMap.LngLat(113.203460828994, 22.64902452257), (status, result) => { + button.onclick = () => { + driving.searchOnAMAP({ + origin: result.origin, + destination: result.destination + }) + } + }) }, onError() { document.getElementById('geo-tip').innerHTML = '定位失败' @@ -184,12 +199,8 @@ export default { this.coordinate = [113.203460828994, 22.64902452257] } const map = new AMap.Map('map-container') - const drivingOptions = { - map: map, - panel: 'panel' - } + this.map = map this.sleep(300) - const button = document.getElementById('bt') AMap.plugin(['AMap.ToolBar', 'AMap.Scale', 'AMap.Driving', 'AMap.Geolocation'], () => { map.addControl(new AMap.ToolBar()) map.addControl(new AMap.Scale()) @@ -198,6 +209,7 @@ export default { timeout: 10000, buttonOffset: new AMap.Pixel(10, 20), zoomToAccuracy: true, + panToLocation: false, buttonPosition: 'RB' }) map.addControl(geolocation) @@ -206,17 +218,6 @@ export default { AMap.event.addListener(geolocation, 'complete', this.onComplete) // 返回定位出错信息 AMap.event.addListener(geolocation, 'error', this.onError) - - // 驾车路径规划 - const driving = new AMap.Driving(drivingOptions) - driving.search(new AMap.LngLat(113.344095, 22.673091), new AMap.LngLat(113.203460828994, 22.64902452257), (status, result) => { - button.onclick = () => { - driving.searchOnAMAP({ - origin: result.origin, - destination: result.destination - }) - } - }) }) this.flag = true // if (AMap.UA.mobile) {