Commit 2d70bdcf by chenwq

切换地图

1 parent 95899c19
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2020-11-25 20:11:22
* @LastEditors: limin
* @LastEditTime: 2020-11-25 20:29:36
*/
export default function loadMap ({key='qRLkZJN32WsQe2LMSTjduuTs2TObie3x', v = '3.0'}={}) {
return new Promise(function (resolve, reject) {
if (typeof BMap !== 'undefined') {
resolve(BMap)
return true
}
window.onCallback = function () {
resolve(BMap)
}
let script = document.createElement('script')
script.type = 'text/javascript'
script.src = `//api.map.baidu.com/api?v=${v}&ak=${key}&callback=onCallback`
script.onerror = reject
document.head.appendChild(script)
})
}
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
<template slot-scope="scope"> <template slot-scope="scope">
<template v-if='i.prop === "address"'> <template v-if='i.prop === "address"'>
<a <a
@click="openMap(scope.row)" @click="openBMap(scope.row)"
class="el-button el-button--text address" class="el-button el-button--text address"
>{{collisionTable.data[scope.$index][i.prop]}}</a> >{{collisionTable.data[scope.$index][i.prop]}}</a>
</template> </template>
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
<div class="amap-wrapper"> <div class="amap-wrapper">
<div <div
id="container" id="container"
style="width:100%;height:500px;" style="width:556px;height:500px;"
></div> ></div>
</div> </div>
</el-dialog> </el-dialog>
...@@ -172,7 +172,9 @@ ...@@ -172,7 +172,9 @@
<script> <script>
import { collisionMethods, request } from '@/api' import { collisionMethods, request } from '@/api'
import { businessList, pickerOptions } from '@/common/constants' import { businessList, pickerOptions } from '@/common/constants'
import loadMap from '@/common/loadmap' // import loadMap from '@/common/loadmap'
import loadBMap from '@/common/loadBmap'
let checkLoadedTimeoutId = "";
export default { export default {
name: 'collision', name: 'collision',
data() { data() {
...@@ -251,31 +253,73 @@ export default { ...@@ -251,31 +253,73 @@ export default {
this.findAll() this.findAll()
}, },
methods: { methods: {
openMap(row) { // openAMap(row) {
// this.dialogVisible = true
// loadMap().then(AMap => {
// var map = new AMap.Map('container')
// console.log('-------', map)
// // 创建一个 Marker 实例:
// var marker = new AMap.Marker({
// position: new AMap.LngLat(row.longitude, row.latitude), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
// title: '北京'
// })
// var center = [row.longitude, row.latitude]
// // 将创建的点标记添加到已有的地图实例:
// map.add(marker)
// map.setCenter(center)
// map.setZoom(13)
// })
// },
openBMap(row) {
this.dialogVisible = true this.dialogVisible = true
loadMap().then(AMap => { loadBMap().then(BMap => {
var map = new AMap.Map('container') var map = new BMap.Map('container')
console.log('-------', map) map.clearOverlays()
// 创建一个 Marker 实例: var point = new BMap.Point(Number(row.longitude), Number(row.latitude))
var marker = new AMap.Marker({ map.centerAndZoom(point, 15)
position: new AMap.LngLat(row.longitude, row.latitude), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9] map.addEventListener("tilesloaded", function() {
title: '北京' var marker = new BMap.Marker(point)
}) map.addOverlay(marker)
var center = [row.longitude, row.latitude] map.panTo(point)
// 将创建的点标记添加到已有的地图实例: });
map.add(marker)
map.setCenter(center)
map.setZoom(13)
}) })
}, },
findAll(searcher) { findAll(searcher) {
this.loading = true this.loading = true
const { pager } = this const { pager } = this
let res = {
data: {
count: 51867,
rows: [{
address: "山东省滨州市邹平市孙镇孙章路",
collision_time: "2025-01-02 16:38:36",
created_date: "2025-01-02 16:38:42",
latitude: "39.915",
longitude: "116.404",
merchant_name: "滨州泰岳星徽汽车有限公司",
sn: "8701206357",
}, {
address: "sz",
collision_time: "2025-01-02 16:38:36",
created_date: "2025-01-02 16:38:42",
latitude: "22.545552",
longitude: "114.056556",
merchant_name: "滨州泰岳星徽汽车有限公司",
sn: "8701206357",
}],
},
msg: "SUCCESS!",
status: 0
}
this.pager.total = res.data.count
this.collisionTable.data = res.data.rows
this.loading = false
this.$refs.collisionPopover.doClose()
request request
.req(collisionMethods.FindAll, { pager, searcher }) .req(collisionMethods.FindAll, { pager, searcher })
.then(res => { .then(res => {
this.pager.total = res.count this.pager.total = res.data.count
this.collisionTable.data = res.rows this.collisionTable.data = res.data.rows
this.loading = false this.loading = false
this.$refs.collisionPopover.doClose() this.$refs.collisionPopover.doClose()
}) })
...@@ -335,6 +379,10 @@ export default { ...@@ -335,6 +379,10 @@ export default {
} }
</script> </script>
<style> <style>
.collision .amap-wrapper {
width:556px;
height:500px;
}
.collision .el-dialog__body { .collision .el-dialog__body {
padding: 10px; padding: 10px;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!