GoodsMap.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <!-- -->
  2. <template>
  3. <div class="GoodsMap">
  4. <div class="box">
  5. <div id="myMap" />
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. export default {
  11. name: "GoodsMap",
  12. components: {},
  13. data() {
  14. //这里存放数据
  15. return {
  16. keywords: "",
  17. arr: [],
  18. map: {
  19. name: "中江塔",
  20. x: 118.363387,
  21. y: 31.325179,
  22. },
  23. };
  24. },
  25. //监听属性 类似于data概念
  26. computed: {},
  27. //监控data中的数据变化
  28. watch: {},
  29. //方法集合
  30. methods: {
  31. initMap() {
  32. window.onLoad = () => {
  33. this.map = new AMap.Map("myMap", {
  34. zoom: 18,
  35. center: [118.363387, 31.325179],
  36. // viewMode: '3D'
  37. });
  38. const marker = new AMap.Marker({
  39. position: [118.363387, 31.325179], // 位置
  40. label: {
  41. offset: new AMap.Pixel(20, 20),
  42. content: "点击打开高德地图",
  43. },
  44. });
  45. marker.on("click", function (e) {
  46. marker.markOnAMAP({
  47. name: "中江塔",
  48. position: marker.getPosition(),
  49. });
  50. });
  51. this.map.add(marker); // 添加到地图
  52. AMap.plugin("AMap.ToolBar", () => {
  53. // 异步加载插件
  54. const toolbar = new AMap.ToolBar();
  55. this.map.addControl(toolbar);
  56. });
  57. };
  58. const url =
  59. "https://webapi.amap.com/maps?v=1.4.15&key=93f7bfff72aa16305db5aee4f3fd6232&callback=onLoad";
  60. const jsapi = document.createElement("script");
  61. jsapi.src = url;
  62. document.head.appendChild(jsapi);
  63. },
  64. },
  65. //生命周期 - 创建完成(可以访问当前this实例)
  66. created() {
  67. window.document.title='景点导航'
  68. },
  69. //生命周期 - 挂载完成(可以访问DOM元素)
  70. mounted() {
  71. this.initMap();
  72. },
  73. beforeCreate() { }, //生命周期 - 创建之前
  74. beforeMount() { }, //生命周期 - 挂载之前
  75. beforeUpdate() { }, //生命周期 - 更新之前
  76. updated() { }, //生命周期 - 更新之后
  77. beforeDestroy() { }, //生命周期 - 销毁之前
  78. destroyed() { }, //生命周期 - 销毁完成
  79. activated() { }, //如果页面有keep-alive缓存功能,这个函数会触发
  80. };
  81. </script>
  82. <style lang='less' scoped>
  83. .GoodsMap {
  84. width: 100%;
  85. height: 100%;
  86. position: relative;
  87. .box {
  88. width: 100%;
  89. height: 100%;
  90. }
  91. #myMap {
  92. width: 100%;
  93. height: 100%;
  94. }
  95. /deep/.amap-marker-label{
  96. // color: red;
  97. }
  98. }
  99. </style>