1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| //TMap.vue
<template> //用于挂载实例的容器 <div id="container"></div> </template>
<script> import Vue from "vue";
export default { name: "TMap", methods: { initMap() { window.onLoad = function () { var map = new AMap.Map("container", { zoom: 11, center: [116.397428, 39.90923], viewMode: "3D", }); Vue.prototype.$map = map;
AMap.plugin( ["AMap.Scale", "AMap.ToolBar", "AMap.OverView"], function () { let scale = new AMap.Scale({ visible: false, }); let toolbar = new AMap.ToolBar({ visible: false, }); let overview = new AMap.OverView({ visible: false, isOpen: true, }); map.addControl(scale); map.addControl(toolbar); map.addControl(overview); let obj = { scale, toolbar, overview, }; Vue.prototype.$plugin = obj; } ); }; var url = "https://webapi.amap.com/maps?v=1.4.15&key=此处填申领的Key值&callback=onLoad"; var jsapi = document.createElement("script"); jsapi.charset = "utf-8"; jsapi.src = url; document.head.appendChild(jsapi); }, }, mounted() { this.initMap(); }, }; </script>
<style> #container { height: 100%; } </style>
|