Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
map-demo
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-01-24 17:39:15 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
93598256ac66cf6fbc363ae1bface77ca7a51dd0
93598256
1 parent
5f091e80
新增点击查看复制经纬度功能
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
13 deletions
.eslintrc-auto-import.json
src/auto-imports.d.ts
src/views/mapCutter.vue
.eslintrc-auto-import.json
View file @
9359825
{
"globals"
:
{
"EffectScope"
:
true
,
"ElMessage"
:
true
,
"computed"
:
true
,
"createApp"
:
true
,
"customRef"
:
true
,
...
...
src/auto-imports.d.ts
View file @
9359825
...
...
@@ -2,6 +2,7 @@
export
{}
declare
global
{
const
EffectScope
:
typeof
import
(
'vue'
)[
'EffectScope'
]
const
ElMessage
:
typeof
import
(
'element-plus/es'
)[
'ElMessage'
]
const
computed
:
typeof
import
(
'vue'
)[
'computed'
]
const
createApp
:
typeof
import
(
'vue'
)[
'createApp'
]
const
customRef
:
typeof
import
(
'vue'
)[
'customRef'
]
...
...
src/views/mapCutter.vue
View file @
9359825
<!--
* @Date: 2025-01-22 11:40:12
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-01-24 1
6:57:47
* @LastEditTime: 2025-01-24 1
7:33:54
* @FilePath: /map-demo/src/views/mapCutter.vue
* @Description: 文件描述
-->
...
...
@@ -63,20 +63,25 @@
<el-button type="primary" @click="rotateMap(10)">地图顺时针旋转</el-button>
<el-button type="primary" @click="rotateMap(-10)">地图逆时针旋转</el-button>
</div>
<div v-if="log_lnglat" style="position: fixed; top: 8rem; left: 1rem; color: black; background-color: white; padding: 1rem;">
<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>
</div>
</template>
<script setup>
import { onMounted, ref, computed } from "vue";
// import AMapLoader from "@amap/amap-jsapi-loader";
import { TileCutter } from "@/utils/TileCutter";
import { Top, Bottom, Back, Right, Plus, Minus } from '@element-plus/icons-vue'
import { Top, Bottom, Back, Right, Plus, Minus, Brush } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
const map = ref(null);
const imageLayer = ref(null);
const imageURL = ref(""); // 存储上传的图片
const bounds = ref(null); // 图片覆盖的边界
const mapRotation = ref(0); // 存储地图旋转角度
const zooms = ref([17, 1
8
]);
const zooms = ref([17, 1
9
]);
const map_zoom = ref(17)
...
...
@@ -96,6 +101,8 @@ const map_right_top_range = ref(null); // 120.591047,31.318265
const map_center = ref(null);
const log_lnglat = ref('') // 获取当前地址经纬度
onMounted(async () => {
loadMap();
});
...
...
@@ -138,14 +145,17 @@ function loadMap() {
layer1.setMap(map.value);
// 监听 zoomchange 事件
map.value.on('zoomchange', () => {
const currentZoom = map.value.getZoom();
if (currentZoom === 18) {
map_zoom.value = 18;
} else {
map_zoom.value = 17;
}
});
// map.value.on('zoomchange', () => {
// const currentZoom = map.value.getZoom();
// if (currentZoom === 18) {
// map_zoom.value = 18;
// } else {
// map_zoom.value = 17;
// }
// });
// 添加地图点击事件
map.value.on("click", showInfoClick);
}
function handleImageUpload(event) {
...
...
@@ -170,7 +180,7 @@ function addImageToMap(url) {
imageLayer.value = new AMap.ImageLayer({
url: url,
bounds: bounds.value,
zooms: [17, 1
8
],
zooms: [17, 1
9
],
opacity: 0.6 // 透明度 (0 完全透明, 1 完全不透明)
});
...
...
@@ -244,7 +254,7 @@ const rotateMap = (deltaAngle) => {
const onZoomChange = (value) => { // 调整地图图层
map.value.setZoom(value);
//
map.value.setZoom(value);
}
const onLBRangeBlur = () => {
...
...
@@ -267,6 +277,34 @@ const onCenterBlur = () => {
const formattedArray = str.split(',').map(Number);
map.value.setCenter(formattedArray);
}
const showInfoClick = (e) => {
var text =
e.lnglat.getLng() +
"," +
e.lnglat.getLat()
console.log(text);
log_lnglat.value = text;
}
const copyText = (text) => {
navigator.clipboard.writeText(text)
.then(() => {
ElMessage({
message: '复制成功',
type: 'success',
plain: true,
})
})
.catch(err => {
ElMessage({
message: '复制失败',
type: 'warning',
plain: true,
})
console.error('复制失败:', err);
});
}
</script>
<style>
...
...
Please
register
or
login
to post a comment