|
@@ -1,6 +1,6 @@
|
|
|
<template>
|
|
|
- <div class="map-container">
|
|
|
- <div id="aMap" class="map-container"></div>
|
|
|
+ <div ref="containerRef" class="map-container">
|
|
|
+ <div id="aMap" class="map-container" :style="{width: width, height: height}"></div>
|
|
|
<!-- 右下工具 -->
|
|
|
<div v-show="mapState.showScale" class="zoom-text">{{ mapState.zoom }}级</div>
|
|
|
<div class="right-tool">
|
|
@@ -30,10 +30,15 @@ interface Props {
|
|
|
color: string;
|
|
|
drawType: string;
|
|
|
graphicsType: string;
|
|
|
+ containerWidth: number;
|
|
|
+ containerHeight: number;
|
|
|
}
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {});
|
|
|
const emits = defineEmits(['update:drawing', 'selectGraphics', 'unSelectGraphics']);
|
|
|
+const containerRef = ref();
|
|
|
+const width = ref('3483px');
|
|
|
+const height = ref('2140px');
|
|
|
|
|
|
const mapState = reactive({
|
|
|
center: [110.93154257997, 21.669064031332],
|
|
@@ -93,6 +98,7 @@ const { getAMap, getMap, switchMap, addMarker, addSearchMarker, clearMarker, get
|
|
|
map.on('zoomchange', zoomChangeHandler);
|
|
|
initMouseTool({ map, AMap });
|
|
|
initRuler(map, AMap);
|
|
|
+ handleResize()
|
|
|
}
|
|
|
});
|
|
|
// 监听地图类型变化
|
|
@@ -179,12 +185,22 @@ const setCenter = (item) => {
|
|
|
};
|
|
|
|
|
|
defineExpose({ addMarker, addSearchMarker, setCenter, getMarkers, clearMarker, handleUndo });
|
|
|
-
|
|
|
+const handleResize = () => {
|
|
|
+ const containerWidth = props.containerWidth * (document.body.clientWidth / 8960);
|
|
|
+ const containerHeight = props.containerHeight * (document.body.clientHeight / 2520);
|
|
|
+ width.value = containerWidth + 'px'
|
|
|
+ height.value = containerHeight + 'px'
|
|
|
+ map.resize();
|
|
|
+}
|
|
|
+onMounted(() => {
|
|
|
+ window.addEventListener('resize', handleResize);
|
|
|
+})
|
|
|
// 卸载事件
|
|
|
onUnmounted(() => {
|
|
|
if (map) {
|
|
|
map.off('zoomchange', zoomChangeHandler);
|
|
|
}
|
|
|
+ window.removeEventListener('resize', handleResize);
|
|
|
});
|
|
|
</script>
|
|
|
|
|
@@ -194,7 +210,7 @@ onUnmounted(() => {
|
|
|
height: 100%;
|
|
|
position: relative;
|
|
|
.zoom-text {
|
|
|
- position: absolute;
|
|
|
+ position: fixed;
|
|
|
bottom: 0;
|
|
|
right: 170px;
|
|
|
color: #eaf3fc;
|
|
@@ -202,7 +218,7 @@ onUnmounted(() => {
|
|
|
font-family: 'SourceHanSansCN';
|
|
|
}
|
|
|
.right-tool {
|
|
|
- position: absolute;
|
|
|
+ position: fixed;
|
|
|
bottom: 50px;
|
|
|
right: 5px;
|
|
|
}
|