Showing
3 changed files
with
53 additions
and
13 deletions
| ... | @@ -2,6 +2,7 @@ | ... | @@ -2,6 +2,7 @@ |
| 2 | export {} | 2 | export {} |
| 3 | declare global { | 3 | declare global { |
| 4 | const EffectScope: typeof import('vue')['EffectScope'] | 4 | const EffectScope: typeof import('vue')['EffectScope'] |
| 5 | + const ElMessage: typeof import('element-plus/es')['ElMessage'] | ||
| 5 | const computed: typeof import('vue')['computed'] | 6 | const computed: typeof import('vue')['computed'] |
| 6 | const createApp: typeof import('vue')['createApp'] | 7 | const createApp: typeof import('vue')['createApp'] |
| 7 | const customRef: typeof import('vue')['customRef'] | 8 | const customRef: typeof import('vue')['customRef'] | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-01-22 11:40:12 | 2 | * @Date: 2025-01-22 11:40:12 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-01-24 16:57:47 | 4 | + * @LastEditTime: 2025-01-24 17:33:54 |
| 5 | * @FilePath: /map-demo/src/views/mapCutter.vue | 5 | * @FilePath: /map-demo/src/views/mapCutter.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -63,20 +63,25 @@ | ... | @@ -63,20 +63,25 @@ |
| 63 | <el-button type="primary" @click="rotateMap(10)">地图顺时针旋转</el-button> | 63 | <el-button type="primary" @click="rotateMap(10)">地图顺时针旋转</el-button> |
| 64 | <el-button type="primary" @click="rotateMap(-10)">地图逆时针旋转</el-button> | 64 | <el-button type="primary" @click="rotateMap(-10)">地图逆时针旋转</el-button> |
| 65 | </div> | 65 | </div> |
| 66 | + | ||
| 67 | + <div v-if="log_lnglat" style="position: fixed; top: 8rem; left: 1rem; color: black; background-color: white; padding: 1rem;"> | ||
| 68 | + <div style=" display: flex; align-items: center; justify-content: center;">经纬度:{{ log_lnglat }} <el-button @click="copyText(log_lnglat)" type="primary" :icon="Brush" size="small">复制</el-button></div> | ||
| 69 | + </div> | ||
| 66 | </template> | 70 | </template> |
| 67 | 71 | ||
| 68 | <script setup> | 72 | <script setup> |
| 69 | import { onMounted, ref, computed } from "vue"; | 73 | import { onMounted, ref, computed } from "vue"; |
| 70 | // import AMapLoader from "@amap/amap-jsapi-loader"; | 74 | // import AMapLoader from "@amap/amap-jsapi-loader"; |
| 71 | import { TileCutter } from "@/utils/TileCutter"; | 75 | import { TileCutter } from "@/utils/TileCutter"; |
| 72 | -import { Top, Bottom, Back, Right, Plus, Minus } from '@element-plus/icons-vue' | 76 | +import { Top, Bottom, Back, Right, Plus, Minus, Brush } from '@element-plus/icons-vue' |
| 77 | +import { ElMessage } from 'element-plus' | ||
| 73 | 78 | ||
| 74 | const map = ref(null); | 79 | const map = ref(null); |
| 75 | const imageLayer = ref(null); | 80 | const imageLayer = ref(null); |
| 76 | const imageURL = ref(""); // 存储上传的图片 | 81 | const imageURL = ref(""); // 存储上传的图片 |
| 77 | const bounds = ref(null); // 图片覆盖的边界 | 82 | const bounds = ref(null); // 图片覆盖的边界 |
| 78 | const mapRotation = ref(0); // 存储地图旋转角度 | 83 | const mapRotation = ref(0); // 存储地图旋转角度 |
| 79 | -const zooms = ref([17, 18]); | 84 | +const zooms = ref([17, 19]); |
| 80 | 85 | ||
| 81 | const map_zoom = ref(17) | 86 | const map_zoom = ref(17) |
| 82 | 87 | ||
| ... | @@ -96,6 +101,8 @@ const map_right_top_range = ref(null); // 120.591047,31.318265 | ... | @@ -96,6 +101,8 @@ const map_right_top_range = ref(null); // 120.591047,31.318265 |
| 96 | 101 | ||
| 97 | const map_center = ref(null); | 102 | const map_center = ref(null); |
| 98 | 103 | ||
| 104 | +const log_lnglat = ref('') // 获取当前地址经纬度 | ||
| 105 | + | ||
| 99 | onMounted(async () => { | 106 | onMounted(async () => { |
| 100 | loadMap(); | 107 | loadMap(); |
| 101 | }); | 108 | }); |
| ... | @@ -138,14 +145,17 @@ function loadMap() { | ... | @@ -138,14 +145,17 @@ function loadMap() { |
| 138 | layer1.setMap(map.value); | 145 | layer1.setMap(map.value); |
| 139 | 146 | ||
| 140 | // 监听 zoomchange 事件 | 147 | // 监听 zoomchange 事件 |
| 141 | - map.value.on('zoomchange', () => { | 148 | + // map.value.on('zoomchange', () => { |
| 142 | - const currentZoom = map.value.getZoom(); | 149 | + // const currentZoom = map.value.getZoom(); |
| 143 | - if (currentZoom === 18) { | 150 | + // if (currentZoom === 18) { |
| 144 | - map_zoom.value = 18; | 151 | + // map_zoom.value = 18; |
| 145 | - } else { | 152 | + // } else { |
| 146 | - map_zoom.value = 17; | 153 | + // map_zoom.value = 17; |
| 147 | - } | 154 | + // } |
| 148 | - }); | 155 | + // }); |
| 156 | + | ||
| 157 | + // 添加地图点击事件 | ||
| 158 | + map.value.on("click", showInfoClick); | ||
| 149 | } | 159 | } |
| 150 | 160 | ||
| 151 | function handleImageUpload(event) { | 161 | function handleImageUpload(event) { |
| ... | @@ -170,7 +180,7 @@ function addImageToMap(url) { | ... | @@ -170,7 +180,7 @@ function addImageToMap(url) { |
| 170 | imageLayer.value = new AMap.ImageLayer({ | 180 | imageLayer.value = new AMap.ImageLayer({ |
| 171 | url: url, | 181 | url: url, |
| 172 | bounds: bounds.value, | 182 | bounds: bounds.value, |
| 173 | - zooms: [17, 18], | 183 | + zooms: [17, 19], |
| 174 | opacity: 0.6 // 透明度 (0 完全透明, 1 完全不透明) | 184 | opacity: 0.6 // 透明度 (0 完全透明, 1 完全不透明) |
| 175 | }); | 185 | }); |
| 176 | 186 | ||
| ... | @@ -244,7 +254,7 @@ const rotateMap = (deltaAngle) => { | ... | @@ -244,7 +254,7 @@ const rotateMap = (deltaAngle) => { |
| 244 | 254 | ||
| 245 | 255 | ||
| 246 | const onZoomChange = (value) => { // 调整地图图层 | 256 | const onZoomChange = (value) => { // 调整地图图层 |
| 247 | - map.value.setZoom(value); | 257 | + // map.value.setZoom(value); |
| 248 | } | 258 | } |
| 249 | 259 | ||
| 250 | const onLBRangeBlur = () => { | 260 | const onLBRangeBlur = () => { |
| ... | @@ -267,6 +277,34 @@ const onCenterBlur = () => { | ... | @@ -267,6 +277,34 @@ const onCenterBlur = () => { |
| 267 | const formattedArray = str.split(',').map(Number); | 277 | const formattedArray = str.split(',').map(Number); |
| 268 | map.value.setCenter(formattedArray); | 278 | map.value.setCenter(formattedArray); |
| 269 | } | 279 | } |
| 280 | + | ||
| 281 | +const showInfoClick = (e) => { | ||
| 282 | + var text = | ||
| 283 | + e.lnglat.getLng() + | ||
| 284 | + "," + | ||
| 285 | + e.lnglat.getLat() | ||
| 286 | + console.log(text); | ||
| 287 | + log_lnglat.value = text; | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +const copyText = (text) => { | ||
| 291 | + navigator.clipboard.writeText(text) | ||
| 292 | + .then(() => { | ||
| 293 | + ElMessage({ | ||
| 294 | + message: '复制成功', | ||
| 295 | + type: 'success', | ||
| 296 | + plain: true, | ||
| 297 | + }) | ||
| 298 | + }) | ||
| 299 | + .catch(err => { | ||
| 300 | + ElMessage({ | ||
| 301 | + message: '复制失败', | ||
| 302 | + type: 'warning', | ||
| 303 | + plain: true, | ||
| 304 | + }) | ||
| 305 | + console.error('复制失败:', err); | ||
| 306 | + }); | ||
| 307 | +} | ||
| 270 | </script> | 308 | </script> |
| 271 | 309 | ||
| 272 | <style> | 310 | <style> | ... | ... |
-
Please register or login to post a comment