navigation.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <view class="amap-container">
  3. <view id="amap"></view>
  4. <view class="" id="panel"></view>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {}
  11. },
  12. mounted() {},
  13. methods: {}
  14. }
  15. </script>
  16. <script module="amap" lang="renderjs">
  17. import config from './config.js'
  18. export default {
  19. data() {
  20. return {
  21. map: null,
  22. ownerInstanceObj: null //service层对象
  23. }
  24. },
  25. mounted() {
  26. if (typeof window.AMap === 'function') {
  27. this.initAmap()
  28. } else {
  29. // 动态引入较大类库避免影响页面展示
  30. const script = document.createElement('script')
  31. script.src = 'https://webapi.amap.com/maps?v=1.4.15&key=' + config.JSAPIAK
  32. script.onload = this.initAmap.bind(this)
  33. document.head.appendChild(script)
  34. }
  35. },
  36. methods: {
  37. initAmap() {
  38. this.map = new AMap.Map('amap', {
  39. resizeEnable: true,
  40. center: [116.397428, 39.90923], //地图中心点
  41. zoom: 13 //地图显示的缩放级别
  42. })
  43. this.map.plugin('AMap.Driving', () => {
  44. let driving = new AMap.Driving({
  45. map: this.map,
  46. panel: 'panel'
  47. })
  48. // 根据起终点经纬度规划驾车导航路线
  49. driving.search(new AMap.LngLat(116.379028, 39.865042), new AMap.LngLat(116.427281, 39.903719),
  50. (status, result) => {
  51. console.log(status,"00000000000000000000")
  52. if (status === 'complete') {
  53. console.log('绘制驾车路线完成')
  54. } else {
  55. console.log('获取驾车数据失败:' + result)
  56. }
  57. })
  58. })
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. #amap {
  65. width: 100%;
  66. height: 1200rpx;
  67. }
  68. </style>