当前位置:   article > 正文

Vue2+高德地图(仅供自己使用)_内网使用高德离线地图vue

内网使用高德离线地图vue
  1. <template>
  2. <!-- 百度地图 -->
  3. <div id="bai-du-map">
  4. <!-- 技术支持和联系方式 -->
  5. </div>
  6. </template>
  7. <script>
  8. import AMapLoader from "@amap/amap-jsapi-loader";
  9. window._AMapSecurityConfig = {
  10. // 设置安全密钥
  11. securityJsCode: "xxxxxxxxxxxxx",
  12. };
  13. export default {
  14. // props: ["iptId"],
  15. data() {
  16. return {
  17. map: null,
  18. mouseTool: null,
  19. overlays: [],
  20. auto: null,
  21. placeSearch: null,
  22. };
  23. },
  24. methods: {
  25. initMap() {
  26. AMapLoader.load({
  27. key: "xxxxxxxxxxxxxxxxx", // 申请好的Web端开发者Key,首次调用 load 时必填
  28. version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  29. plugins: ["AMap.AutoComplete", "AMap.PlaceSearch"], // 需要使用的的插件列表,如比例尺'AMap.Scale'
  30. // "plugins": [], // 需要使用的的插件列表,如比例尺'AMap.Scale'
  31. })
  32. .then((AMap) => {
  33. this.map = new AMap.Map("bai-du-map", {
  34. viewMode: "2D", // 是否为3D地图模式
  35. zoom: 13, // 初始化地图级别
  36. center: [113.65553, 34.748764], //中心点坐标 郑州
  37. resizeEnable: true,
  38. });
  39. this.auto = new AMap.AutoComplete({
  40. input: this.iptId, // 搜索框的id
  41. });
  42. this.placeSearch = new AMap.PlaceSearch({
  43. map: this.map,
  44. panel: "panel", // 结果列表将在此容器中进行展示。
  45. // city: "010", // 兴趣点城市
  46. autoFitView: true, // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
  47. extensions: "base", //返回基本地址信息
  48. });
  49. this.auto.on("select", this.select); //注册监听,当选中某条记录时会触发
  50. })
  51. .catch((e) => {
  52. console.log(e);
  53. });
  54. },
  55. select(e) {
  56. this.placeSearch.setCity(e.poi.adcode);
  57. this.placeSearch.search(e.poi.name); //关键字查询查询
  58. },
  59. },
  60. mounted() {
  61. this.initMap();
  62. },
  63. };
  64. </script>
  65. <style scoped>
  66. #bai-du-map {
  67. padding: 0px;
  68. margin: 0px;
  69. width: 100%;
  70. height: 800px;
  71. }
  72. </style>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/424961
推荐阅读
相关标签
  

闽ICP备14008679号