|
@@ -1,11 +1,18 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <div class="map" id="container"></div>
|
|
|
|
|
|
|
+ <div class="map" id="container" :style="{height:mapHeight + 'px'}"></div>
|
|
|
</template>
|
|
</template>
|
|
|
<script>
|
|
<script>
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
export default {
|
|
export default {
|
|
|
|
|
+ props: {
|
|
|
|
|
+ mapHeight: {
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ default: 650
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ mapInstance: null,
|
|
|
markers: [
|
|
markers: [
|
|
|
{
|
|
{
|
|
|
position: [116.397428, 39.90923],
|
|
position: [116.397428, 39.90923],
|
|
@@ -30,8 +37,31 @@
|
|
|
]
|
|
]
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
|
|
+ watch: {
|
|
|
|
|
+ mapHeight(v) {
|
|
|
|
|
+ console.log(v,'dsds')
|
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
|
+ this.reloadMap();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ reloadMap() {
|
|
|
|
|
+ console.log('Reloading map...');
|
|
|
|
|
+ if (this.mapInstance) {
|
|
|
|
|
+ this.mapInstance.destroy();
|
|
|
|
|
+ this.mapInstance = null;
|
|
|
|
|
+ const container = document.getElementById('container');
|
|
|
|
|
+ if (container) {
|
|
|
|
|
+ container.innerHTML = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ this.mapInit();
|
|
|
|
|
+ },
|
|
|
mapInit() {
|
|
mapInit() {
|
|
|
|
|
+ const container = document.getElementById('container');
|
|
|
|
|
+ if (!container) return;
|
|
|
|
|
+
|
|
|
window._AMapSecurityConfig = {
|
|
window._AMapSecurityConfig = {
|
|
|
securityJsCode: 'd60df9c6f47866f10b465156ca098ca4'
|
|
securityJsCode: 'd60df9c6f47866f10b465156ca098ca4'
|
|
|
};
|
|
};
|
|
@@ -51,6 +81,8 @@
|
|
|
zooms: [2, 20], //地图显示的缩放级别范围
|
|
zooms: [2, 20], //地图显示的缩放级别范围
|
|
|
center: [112.889159, 28.213475] //初始地图中心经纬度
|
|
center: [112.889159, 28.213475] //初始地图中心经纬度
|
|
|
}); //"container"为 <div> 容器的 id
|
|
}); //"container"为 <div> 容器的 id
|
|
|
|
|
+ this.mapInstance = map;
|
|
|
|
|
+ // 使用 map.setFitView() 或让地图自动适应容器大小
|
|
|
// 开启卫星图模式
|
|
// 开启卫星图模式
|
|
|
let layers = new AMap.TileLayer.Satellite({ map: map });
|
|
let layers = new AMap.TileLayer.Satellite({ map: map });
|
|
|
layers && layers.show();
|
|
layers && layers.show();
|
|
@@ -134,7 +166,8 @@
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
|
.map {
|
|
.map {
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- height: 100%;
|
|
|
|
|
|
|
+ height: v-bind(mapHeight + 'px');
|
|
|
|
|
+ min-height: 650px;
|
|
|
background: #fff;
|
|
background: #fff;
|
|
|
position: absolute;
|
|
position: absolute;
|
|
|
}
|
|
}
|