|
|
@@ -0,0 +1,75 @@
|
|
|
+<template>
|
|
|
+ <div id="container" class="amap-wrapper">
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import AMapLoader from '@amap/amap-jsapi-loader'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'GeoMap',
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ amap: null,
|
|
|
+ plugins: ['Scale'],
|
|
|
+ // zoom=6 的比例尺为 100km
|
|
|
+ zoom: 5,
|
|
|
+ mapCenter: [108.337237, 33.881985],
|
|
|
+ mapKeys: {
|
|
|
+ securityJsCode: '983d6ee43bab3edf3693e91508f94aa9',
|
|
|
+ key: '7b75ab2839ce68b884c7a682501ea774'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.initAMap()
|
|
|
+ },
|
|
|
+ unmounted() {
|
|
|
+ this.map?.destroy()
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ document.title = 'GeoMap'
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ initAMap() {
|
|
|
+ window._AMapSecurityConfig = {
|
|
|
+ securityJsCode: this.mapKeys.securityJsCode
|
|
|
+ }
|
|
|
+ AMapLoader.load({
|
|
|
+ key: this.mapKeys.key, // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
+ version: '1.4.15', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
+ plugins: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar',
|
|
|
+ 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.MassMarks', 'AMap.Size',
|
|
|
+ 'AMap.Pixel'], // 需要使用的的插件列表,如比例尺'AMap.Scale',支持添加多个如:['...','...']
|
|
|
+ AMapUI: { // 重点就是这个
|
|
|
+ version: '1.0',
|
|
|
+ plugins: ['misc/PathSimplifier', 'overlay/SimpleMarker']// SimpleMarker设置自定义图标,PathSimplifier轨迹展示组件
|
|
|
+ }
|
|
|
+ }).then((AMap) => {
|
|
|
+ // 设置地图容器id
|
|
|
+ this.map = new AMap.Map('container', {
|
|
|
+ viewMode: '2D', // 是否为3D地图模式
|
|
|
+ zoom: this.zoom, // 初始化地图级别
|
|
|
+ center: this.mapCenter // 初始化地图中心点位置
|
|
|
+ })
|
|
|
+
|
|
|
+ // 点击地图事件(获取经纬度)
|
|
|
+ this.map.on('click', (e) => {
|
|
|
+ var lng = e.lnglat.getLng()
|
|
|
+ var lat = e.lnglat.getLat()
|
|
|
+ this.$message.info('选中坐标: (' + lng + ',' + lat + ')')
|
|
|
+ })
|
|
|
+ }).catch((e) => {
|
|
|
+ this.$message.error(e)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+.amap-wrapper {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+</style>
|