完成大屏地图功能

This commit is contained in:
liub
2025-09-28 15:37:15 +08:00
parent 81df83be26
commit e8b19513b4
5 changed files with 338 additions and 2 deletions

View File

@ -0,0 +1,184 @@
import { fa } from "element-plus/es/locale/index.mjs";
var map = null;
function initMap(click) {
// let key = '90bc158992feb8ccd0145e168cab1307';
let init = function () {
map = new AMap.Map("map", {
viewMode: '2D', //默认使用 2D 模式
zoom: 11, //地图级别
center: [114.420739, 30.487514], //地图中心点
mapStyle: "amap://styles/8c3efc37298895fd78e6aa0e799e78ce"
});
map.on('click', function (evt) {
// alert('您点击的位置:'+evt.lnglat.longitude+' , '+ evt.lnglat.latitude);
if (click) {
click(evt.lnglat);
}
});
}
return new Promise((resolve, reject) => {
if (map) {
resolve(200);
return;
}
if (window.AMap) {
init();
resolve(200);
return;
}
reject({ code: 500, msg: '高德地图未能初始化成功' });
});
}
//添加一个点
function AddPoint(point, index, dragEnd, click, iconImg) {
return new Promise((resolve, reject) => {
try {
let center = point ? new AMap.LngLat(point.longitude, point.latitude) : map.getCenter();
let icon = new AMap.Icon({
size: new AMap.Size(45, 45), //图标尺寸
image: iconImg, //Icon 的图像
imageSize: new AMap.Size(45, 45), //根据所设置的大小拉伸或压缩图片
});
let marker = new AMap.Marker({
icon: icon,
position: center,
offset: new AMap.Pixel(-15, -24),
draggable: dragEnd ? true : false,
cursor: 'point',
title: point.isAlarming ? '正在报警:' + point.deviceName : point.deviceName,
text: index,
class: 'point',
extData: point
});
marker.setMap(map);
let lays = map.getAllOverlays('text');
for (let i = 0; i < lays.length; i++) {
const element = lays[i];
let cls = element.getOptions();
if (cls.class) {
element.dom.classList.add(cls.class);
}
}
resolve(center);
} catch (ex) {
reject(ex)
}
});
}
function getCenter() {
var center = map.getCenter().toJSON();
return center;
}
function setCenter(lon, latitude) {
var position = new AMap.LngLat(lon, latitude); //传入经纬度
map.setCenter(position); //简写 设置地图中心点
}
//画多边形
function DrawPoy(points) {
if (!map) {
return;
}
if (!points) {
return;
}
let path = [];
let path1 = [];
setTimeout(() => {
points.coordinates.filter(v => {
path.push(new AMap.LngLat(v.longitude, v.latitude));
path1.push(new AMap.LngLat(v.longitude * 0.5, v.latitude * 0.5));
return true;
});
let polygon = new AMap.Polygon({
path: path,
fillColor: '#F00C0C',
fillOpacity: 0.03,
strokeOpacity: 0.1,
strokeColor: '#F00C0C',
strokeWeight: 3,
strokeStyle: 'dashed',
// strokeDasharray: [50,50,50],
extData: points
});
map.add(polygon);
}, 0);
}
//画圆形
function DrawCicle(points, raduis, dragEnd) {
if (!map) {
return;
}
let circle = new AMap.Circle({
center: [points.coordinates[0].longitude, points.coordinates[0].latitude],
radius: raduis ? raduis : 1000, //半径
borderWeight: 3,
strokeColor: "#F00C0C",
strokeWeight: 1,
strokeOpacity: 0.2,
fillOpacity: 0.4,
strokeStyle: 'dashed',
strokeDasharray: [10, 10],
// 线样式还支持 'dashed'
fillColor: '#1791fc',
zIndex: 50,
})
map.add(circle);
// 缩放地图到合适的视野级别
}
//清除所有
function clearOverLays() {
map && map.clearMap();
}
function removeOverLay(lay) {
map && map.remove(lay);
}
function setFitView() {
if (map) { map.setFitView(); }
}
export default {
gdMap: map,
initMap: initMap,
AddPoint: AddPoint,
getCenter: getCenter,
DrawPoy: DrawPoy,
DrawCicle: DrawCicle,
clearOverLays: clearOverLays,
removeOverLay: removeOverLay,
setFitView: setFitView
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -83,13 +83,14 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="经纬度" align="center" prop="id"> <!-- <el-table-column label="经纬度" align="center" prop="id">
<template #default="scope"> <template #default="scope">
<span style="margin-right: 15px">{{ scope.row.longitude }}</span <span style="margin-right: 15px">{{ scope.row.longitude }}</span
><span>{{ scope.row.latitude }}</span> ><span>{{ scope.row.latitude }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="精度" align="userName" prop="accuracy"> </el-table-column> <el-table-column label="精度" align="userName" prop="accuracy"> </el-table-column> -->
<el-table-column label="事件地址" align="left" prop="eventAddress"> </el-table-column>
<el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width"> <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
<template #default="scope"> <template #default="scope">

View File

@ -0,0 +1,151 @@
<template>
<div class="content">
<div class="map" id="map"></div>
<div class="topTool">
<div class="form">
<el-select v-model="search.deviceType" placeholder="Select" style="width: 240px">
<el-option v-for="item in dic.types" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-select v-model="value" placeholder="Select" style="width: 240px">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import common from '@/utils/common';
import map from '@/api/largeScreen/mapOpt';
import request from '@/utils/request';
var dic = reactive({
groups: [],
types: [],
imeis: []
});
var search = ref({
groupId: '',
deviceType: '',
deviceImei: ''
});
var points = ref([]);
var fens = ref([]);
function getPoints() {
let promise = request({
url: '/api/largeScreen/getDeviceLocationInfo',
method: 'get',
params: search
});
promise.then((res) => {
if (res) {
if (res.code && res.code == 200) {
var array = res.data;
for (let i = 0; i < array.length; i++) {
let v = array[i];
let json={
deviceId: v.deviceId,
deviceName: v.deviceName,
longitude: v.longitude,
latitude: v.latitude,
fenceId: null
};
if (v.fenceInfo) {
fens.value.find((item) => {
return item.id == v.fenceInfo.id;
});
json.fenceId=v.fenceInfo.id;
fens.value.push(v.fenceInfo);
}
points.value.push(json);
}
} else {
console.error('接口getDeviceLocationInfo出现了未知的异常', res);
}
} else {
console.error('接口getDeviceLocationInfo出现了未知的异常', res);
}
});
}
function getTypes(){
let promise = request({
url: '/api/deviceType/all',
method: 'get'
});
promise.then(res=>{
if(res && res.code && res.code==200){
dic.types=res.data.map(v=>{
return {
value:v.id,
label:v.typeName
}
});
}
});
}
function getGroups(){
let promise = request({
url: '/api/device/group/list',
method: 'get',
params:{
status:1,
isDeleted:0,
pageNum:1,
pageSize:9999
}
});
promise.then(res=>{
if(res && res.code && res.code==200){
dic.groups=res.data;
}
});
}
onMounted(() => {
debugger;
map.initMap();
getTypes();
getGroups();
});
</script>
<style lang="scss" scoped>
.content {
width: 100vw;
height: 100vh;
}
.map {
width: 100%;
height: 100%;
}
.topTool {
position: absolute;
width: 33%;
height: 200px;
z-index: 9999999999999999;
left: 50%;
background: #e2e2e2;
top: 100px;
}
</style>