地块绘制组件

master
贾肃 5 months ago
parent 2464fbc9de
commit f5a4eae842
  1. 31
      src/utils/ruoyi.js
  2. 2
      src/views/system/base/mapMarkers.vue
  3. 123
      src/views/system/base/massifMap.vue

@ -1,5 +1,3 @@
/** /**
* 通用js方法封装处理 * 通用js方法封装处理
* Copyright (c) 2019 ruoyi * Copyright (c) 2019 ruoyi
@ -37,7 +35,9 @@ export function parseTime(time, pattern) {
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key] let value = formatObj[key]
// Note: getDay() returns 0 on Sunday // Note: getDay() returns 0 on Sunday
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) { if (result.length > 0 && value < 10) {
value = '0' + value value = '0' + value
} }
@ -198,6 +198,7 @@ export function handleTree(data, id, parentId, children) {
} }
} }
} }
return tree; return tree;
} }
@ -232,7 +233,8 @@ export function tansParams(params) {
export function getNormalPath(p) { export function getNormalPath(p) {
if (p.length === 0 || !p || p == 'undefined') { if (p.length === 0 || !p || p == 'undefined') {
return p return p
}; }
;
let res = p.replace('//', '/') let res = p.replace('//', '/')
if (res[res.length - 1] === '/') { if (res[res.length - 1] === '/') {
return res.slice(0, res.length - 1) return res.slice(0, res.length - 1)
@ -244,6 +246,7 @@ export function getNormalPath(p) {
export function blobValidate(data) { export function blobValidate(data) {
return data.type !== 'application/json' return data.type !== 'application/json'
} }
/** /**
* 转换字体颜色 * 转换字体颜色
* *
@ -299,3 +302,23 @@ export function findTextColor(colorValue) {
return false; return false;
} }
} }
/**
* 面积转换
* @param value 单位面积
* @param from 从那个单位
* @param arrive 转换到那个单位
* @returns {number}
*/
export function areaConversion(value, from = '平方米', arrive = '亩') {
//10000平米 = 15亩 = 1公顷
var fRate = {//换算率
'公顷': {'亩': 15, '平方米': 10000},
'亩': {'平方米': 10000 / 15, '公顷': 1 / 15},
'平方米': {'亩': 15 / 10000, '公顷': 1 / 10000}
};
var v = parseFloat(value);//得到原来的值
//执行换算注意fRate的取值得到上一次的单位节点再取当前单位的换算率
var rst = (v * fRate[from][arrive]).toFixed(4);//保留4位小数
return parseFloat(rst)
}

@ -108,5 +108,7 @@ const selectPoi = ({poi}) => {
border: none; border: none;
border-radius: 5px; border-radius: 5px;
padding: 5px 10px; padding: 5px 10px;
//
cursor: pointer;
} }
</style> </style>

@ -2,13 +2,63 @@
<script setup> <script setup>
import {ElAmap, useGeolocation, lazyAMapApiLoaderInstance} from "@vuemap/vue-amap"; import {ElAmap, useGeolocation, lazyAMapApiLoaderInstance} from "@vuemap/vue-amap";
import BaseRightControl from "@/views/system/base/baseRightControl.vue"; import BaseRightControl from "@/views/system/base/baseRightControl.vue";
import {areaConversion} from "@/utils/ruoyi.js";
import {ElMessageBox} from "element-plus";
const polygonRef = ref(null)
const router = useRouter() const router = useRouter()
const route = useRoute(); const route = useRoute();
// ()
const floorSpace = ref(0)
const maxHeight = ref(window.innerHeight - 100); const maxHeight = ref(window.innerHeight - 100);
const zoom = ref(13); const zoom = ref(13);
onMounted(()=>{ //
console.log(route.params); const protract = ref(false)
//
const createdMouse = ref(false)
// id
const baseId = Number(route.params.baseId)
//
const polygonList = reactive([])
const polygonTemp = ref(null)
//
const draw = (value) => {
// polygonList.push({
// edit: false,
// path: value
// })
polygonTemp.value = value
computeArea(value)
createdMouse.value = false
}
const computeArea = (value) => {
lazyAMapApiLoaderInstance.then(() => {
//
let number = Math.round(AMap.GeometryUtil.ringArea(value));
//
floorSpace.value = areaConversion(number)
}) })
}
//
const updateMassif = (value) => {
//
let newPath = polygonRef.value.$$getInstance().getPath().map(item =>item.toArray())
polygonTemp.value = newPath
computeArea(newPath)
}
//
const addMassif = () => {
createdMouse.value = true
polygonTemp.value = undefined
protract.value = true
floorSpace.value = 0
}
//
const cancelMassif = () => {
polygonTemp.value = undefined
protract.value = false
createdMouse.value = false
}
//
const center = ref([ const center = ref([
116.338461, 116.338461,
39.97947 39.97947
@ -17,6 +67,22 @@ const center = ref([
const selectPoi = ({poi}) => { const selectPoi = ({poi}) => {
center.value = poi.location.toArray() center.value = poi.location.toArray()
} }
const resetMassif = () => {
ElMessageBox.confirm(
'重置后本次绘制内容将会被清空,是否确认重置?重置后可重新绘制',
'重置地块',
{
confirmButtonText: '不,我再想想',
cancelButtonText: '确认重置',
customClass:'message-box'
}
)
.then(() => {
addMassif()
})
.catch(() => {
})
}
</script> </script>
<template> <template>
@ -39,8 +105,40 @@ const selectPoi = ({poi}) => {
:debounce="1000" :debounce="1000"
@select="selectPoi" @select="selectPoi"
/> />
<!--鼠标工具-->
<el-amap-mouse-tool
v-if="createdMouse"
type="polyline"
:auto-clear="true"
@draw="draw"
/>
<!--多边形-->
<el-amap-polygon
v-for="(polygon, index) in polygonList"
:path="polygon.path"
:visible="true"
:editable="polygon.edit"
/>
<!--多边形-->
<el-amap-polygon
ref="polygonRef"
v-if="!!polygonTemp"
:path="polygonTemp"
@addnode="updateMassif"
@removenode="updateMassif"
@adjust="updateMassif"
:visible="true"
:editable="true"
/>
<div class="top-block"> <div class="top-block">
<base-right-control /> <el-button v-if="!protract" class="operate" @click="addMassif"></el-button>
<base-right-control v-if="!protract"/>
<!--绘制操作区-->
<div v-if="protract" class="protract-control operate">
<el-button type="primary" :disabled="createdMouse">确认({{ floorSpace }})</el-button>
<el-button @click="resetMassif" :disabled="createdMouse">重置</el-button>
<el-button @click="cancelMassif"></el-button>
</div>
</div> </div>
</el-amap> </el-amap>
</div> </div>
@ -58,13 +156,32 @@ const selectPoi = ({poi}) => {
pointer-events: all; pointer-events: all;
} }
} }
.local-icon { .local-icon {
width: 30px; width: 30px;
height: 30px; height: 30px;
} }
:deep(.amap-marker-label) { :deep(.amap-marker-label) {
border: none; border: none;
border-radius: 5px; border-radius: 5px;
padding: 5px 10px; padding: 5px 10px;
} }
.protract-control {
position: absolute;
right: 20px;
top: 10px;
}
</style>
<style lang="scss">
.message-box{
--el-messagebox-width: 450px;
padding: 20px;
.el-message-box__btns{
justify-content: center;
}
.el-button{
border-radius: 20px;
}
}
</style> </style>
Loading…
Cancel
Save