Maps.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!--
  2. * @Author: gaojikai gaojikai@fehorizon.com
  3. * @Date: 2023-09-12 08:55:47
  4. * @LastEditors: gaojikai gaojikai@fehorizon.com
  5. * @LastEditTime: 2023-09-12 09:48:43
  6. * @FilePath: \electronic-file\src\components\datav\Maps.vue
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. -->
  9. <template>
  10. <div id="map" :style="{ width: mapWidth, height: mapHeight }"></div>
  11. </template>
  12. <script>
  13. import AMapLoader from "@amap/amap-jsapi-loader";
  14. export default {
  15. props: {
  16. width: {
  17. type: [Number, String],
  18. default: "",
  19. },
  20. height: {
  21. type: [Number, String],
  22. default: "500px",
  23. },
  24. },
  25. data() {
  26. return {};
  27. },
  28. computed: {
  29. mapWidth() {
  30. let width = this.width;
  31. if (typeof width === "number") {
  32. width = width + "px";
  33. }
  34. return width;
  35. },
  36. mapHeight() {
  37. let height = this.height;
  38. if (typeof height === "number") {
  39. height = height + "px";
  40. }
  41. return height;
  42. },
  43. },
  44. mounted() {
  45. this.initMap();
  46. },
  47. methods: {
  48. initMap() {
  49. AMapLoader.load({
  50. key: "40f1ba8477c8eb7f56397febfcd2a656", // 申请好的Web端开发者Key,首次调用 load 时必填
  51. version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  52. AMapUI: {
  53. version: "1.1",
  54. },
  55. plugins: [
  56. "AMap.AutoComplete",
  57. "AMap.PlaceSearch",
  58. "AMap.Scale",
  59. "AMap.OverView",
  60. "AMap.ToolBar",
  61. "AMap.MapType",
  62. "AMap.PolyEditor",
  63. "AMap.CircleEditor",
  64. "AMap.DistrictSearch",
  65. "AMap.RangingTool",
  66. "AMap.MarkerCluster",
  67. "AMap.IndexCluster",
  68. "AMap.Geocoder",
  69. ], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  70. })
  71. .then((AMap) => {
  72. this.$emit("callback", AMap);
  73. })
  74. .catch((e) => {
  75. console.log(e);
  76. });
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="scss" scoped>
  82. #map {
  83. padding: 0px;
  84. margin: 20px 10px 10px 10px;
  85. }
  86. </style>