地块左侧地块列表完成

master
贾肃 5 months ago
parent 1a624e005e
commit 9f85f98957
  1. 7
      src/main.js
  2. 284
      src/views/system/base/massifMap.vue

@ -5,7 +5,8 @@ import Cookies from 'js-cookie'
import ElementPlus from 'element-plus' import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css' import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn' import locale from 'element-plus/es/locale/lang/zh-cn'
// fade/zoom
import 'element-plus/theme-chalk/base.css'
import '@/assets/styles/index.scss' // global css import '@/assets/styles/index.scss' // global css
// iconpark样式 // iconpark样式
import {install} from '@icon-park/vue-next/es/all'; import {install} from '@icon-park/vue-next/es/all';
@ -52,6 +53,8 @@ import VueAMap, {initAMapApiLoader} from '@vuemap/vue-amap';
// import VueAMapLoca from '@vuemap/vue-amap-loca'; // import VueAMapLoca from '@vuemap/vue-amap-loca';
// import VueAMapExtra from '@vuemap/vue-amap-extra'; // import VueAMapExtra from '@vuemap/vue-amap-extra';
import '@vuemap/vue-amap/dist/style.css' import '@vuemap/vue-amap/dist/style.css'
// collapse
import { ElCollapseTransition } from 'element-plus'
const app = createApp(App) const app = createApp(App)
initAMapApiLoader({ initAMapApiLoader({
key: '62c3411d6528d67db00ad510a7ee5fb9', key: '62c3411d6528d67db00ad510a7ee5fb9',
@ -82,7 +85,7 @@ app.component('ImagePreview', ImagePreview)
app.component('RightToolbar', RightToolbar) app.component('RightToolbar', RightToolbar)
app.component('Editor', Editor) app.component('Editor', Editor)
app.component('LeftDrawer', LeftDrawer) app.component('LeftDrawer', LeftDrawer)
app.component(ElCollapseTransition.name, ElCollapseTransition)
app.use(VueAMap) app.use(VueAMap)
app.use(router) app.use(router)
app.use(store) app.use(store)

@ -6,30 +6,41 @@ import {areaConversion, calculateCenter, drawGridLines} from "@/utils/ruoyi.js";
import {ElMessage, ElMessageBox} from "element-plus"; import {ElMessage, ElMessageBox} from "element-plus";
import useSettingsStore from "@/store/modules/settings.js"; import useSettingsStore from "@/store/modules/settings.js";
import * as turf from '@turf/turf' import * as turf from '@turf/turf'
const polygonRef = ref(null) const polygonRef = ref(null)
const settingsStore = useSettingsStore() const settingsStore = useSettingsStore()
const theme = computed(()=>settingsStore.theme)
//
const showMassifList = ref(true)
// //
const currentMassif = ref(null) const currentMassif = ref(null)
const router = useRouter()
const route = useRoute();
// id
const baseId = Number(route.params.baseId)
const baseInfo = ref({
baseId: baseId,
baseName: '测试基地1',
area: 1232.45
})
const control = reactive({ const control = reactive({
// //
dataType: 1, dataType: 1,
// //
massifLabel: true, massifLabel: true,
// //
massifGrid: false, massifGrid: false,
// //
showRidge: false, showRidge: false,
// //
ridgeLabel: false, ridgeLabel: false,
// //
showPlant: false, showPlant: false,
// //
plantLabel: false, plantLabel: false,
}) })
// ref // ref
const mouseToolRef = ref(null) const mouseToolRef = ref(null)
const router = useRouter()
const route = useRoute();
// () // ()
const floorSpace = ref(0) const floorSpace = ref(0)
const maxHeight = ref(window.innerHeight - 100); const maxHeight = ref(window.innerHeight - 100);
@ -38,8 +49,7 @@ const zoom = ref(17);
const protract = ref(false) const protract = ref(false)
// //
const createdMouse = ref(false) const createdMouse = ref(false)
// id
const baseId = Number(route.params.baseId)
// //
const componentText = ref([]) const componentText = ref([])
// 线 // 线
@ -49,7 +59,8 @@ const polygonList = reactive([
{ {
id: 1, id: 1,
title: '测试地块1', title: '测试地块1',
path:[ cropType: '甘蔗',
path: [
[ [
116.337325, 116.337325,
39.979046 39.979046
@ -71,12 +82,13 @@ const polygonList = reactive([
39.97906 39.97906
] ]
], ],
fillColor:'#09a882' fillColor: undefined
}, },
{ {
id:2, id: 2,
title:'测试地块2', title: '测试地块2',
path:[ cropType: '甘蔗',
path: [
[ [
116.338296, 116.338296,
39.978921 39.978921
@ -93,7 +105,8 @@ const polygonList = reactive([
116.33859, 116.33859,
39.978905 39.978905
] ]
] ],
fillColor:undefined
} }
]) ])
const polygonTemp = ref(null) const polygonTemp = ref(null)
@ -118,7 +131,7 @@ const computeArea = (value) => {
// //
const updateMassif = (value) => { const updateMassif = (value) => {
// //
let newPath = polygonRef.value.$$getInstance().getPath().map(item =>item.toArray()) let newPath = polygonRef.value.$$getInstance().getPath().map(item => item.toArray())
polygonTemp.value = newPath polygonTemp.value = newPath
computeArea(newPath) computeArea(newPath)
} }
@ -151,11 +164,11 @@ const resetMassif = () => {
{ {
confirmButtonText: '确认重置', confirmButtonText: '确认重置',
cancelButtonText: '不,我再想想', cancelButtonText: '不,我再想想',
customClass:'message-box' customClass: 'message-box'
} }
) )
.then(() => { .then(() => {
if (mouseToolRef.value){ if (mouseToolRef.value) {
mouseToolRef.value.$$close(true) mouseToolRef.value.$$close(true)
mouseToolRef.value.$$open() mouseToolRef.value.$$open()
} }
@ -167,43 +180,65 @@ const resetMassif = () => {
// //
const submitMassif = () => { const submitMassif = () => {
lazyAMapApiLoaderInstance.then(() => { lazyAMapApiLoaderInstance.then(() => {
if (polygonTemp.value.length<3){ if (polygonTemp.value.length < 3) {
ElMessage.error('地块至少需要三个点') ElMessage.error('地块至少需要三个点')
return return
} }
for (let item of polygonList) { for (let item of polygonList) {
if (AMap.GeometryUtil.doesRingRingIntersect(polygonTemp.value,item.path) || AMap.GeometryUtil.isRingInRing(polygonTemp.value,item.path) || AMap.GeometryUtil.isRingInRing(item.path,polygonTemp.value)){ if (AMap.GeometryUtil.doesRingRingIntersect(polygonTemp.value, item.path) || AMap.GeometryUtil.isRingInRing(polygonTemp.value, item.path) || AMap.GeometryUtil.isRingInRing(item.path, polygonTemp.value)) {
ElMessage.error('当前地块与已有地块边界重合,请修改后再确认') ElMessage.error('当前地块与已有地块边界重合,请修改后再确认')
return return
} }
} }
polygonList.push({path:polygonTemp.value,edit:false}) polygonList.push({path: polygonTemp.value, edit: false})
polygonTemp.value = undefined polygonTemp.value = undefined
createdMouse.value = false createdMouse.value = false
protract.value = false protract.value = false
}) })
} }
watch(()=>polygonList,(value)=>{ watch(() => polygonList, (value) => {
componentText.value = [] componentText.value = []
value.forEach(item=>{ let sumArea = 0
let points = turf.points(item.path); value.forEach(item => {
// let points = turf.points(item.path);
componentText.value.push({text:item.title,position:turf.center(points).geometry.coordinates}) //
// 线 componentText.value.push({text: item.title, position: turf.center(points).geometry.coordinates})
// gridLines.value.push(drawGridLines(item.path)) // 线
var bbox = turf.bbox(turf.lineString(item.path)); // gridLines.value.push(drawGridLines(item.path))
// km var bbox = turf.bbox(turf.lineString(item.path));
var cellSide = 0.01; // km
var options = {units: 'kilometers'}; var cellSide = 0.01;
var squareGrid = turf.squareGrid(bbox, cellSide, options); var options = {units: 'kilometers'};
let newList = [] var squareGrid = turf.squareGrid(bbox, cellSide, options);
squareGrid.features.map(item => item.geometry.coordinates).forEach(item =>{ let newList = []
newList.push(...item) squareGrid.features.map(item => item.geometry.coordinates).forEach(item => {
}) newList.push(...item)
gridLines.value.push(newList) })
gridLines.value.push(newList)
//
lazyAMapApiLoaderInstance.then(() => {
//
let number = Math.round(AMap.GeometryUtil.ringArea(item.path));
let number1 = areaConversion(number);
item.area = parseFloat(number1.toFixed(2))
//
sumArea += number1
baseInfo.value.area = parseFloat(sumArea.toFixed(2))
}) })
},{deep:true,immediate:true}) })
}, {deep: true, immediate: true})
//
const clickCurrentMassif = (item) => {
currentMassif.value = item
let points = turf.points(item.path);
polygonList.forEach(polygon =>{
polygon.fillColor = '#00B2D5'
})
item.fillColor = theme.value
//
center.value = turf.center(points).geometry.coordinates
}
</script> </script>
<template> <template>
@ -241,6 +276,7 @@ watch(()=>polygonList,(value)=>{
:visible="true" :visible="true"
:fillColor="polygon.fillColor" :fillColor="polygon.fillColor"
:editable="false" :editable="false"
@mousedown="clickCurrentMassif(polygon)"
/> />
<!--多边形--> <!--多边形-->
<el-amap-polygon <el-amap-polygon
@ -272,7 +308,56 @@ watch(()=>polygonList,(value)=>{
<base-right-control v-if="!protract" v-model="control"/> <base-right-control v-if="!protract" v-model="control"/>
<!--左侧操作区--> <!--左侧操作区-->
<div v-if="!protract" class="operate map-left"> <div v-if="!protract" class="operate map-left">
<el-button @click="addMassif"></el-button> <div class="massif-head">
<div class="title">{{ baseInfo.baseName }}</div>
<div class="all-area">{{ baseInfo.area }}</div>
</div>
<div class="massif-control">
<el-button @click="addMassif" type="primary" plain icon="Plus">
添加地块
</el-button>
<div class="show-massif" @click="showMassifList = !showMassifList">
{{ showMassifList ? '收起' : '展开' }}地块
<i-down v-if="!showMassifList" theme="outline" size="20" fill="#5c5e5d"/>
<i-up v-if="showMassifList" theme="outline" size="20" fill="#5c5e5d"/>
</div>
</div>
<el-collapse-transition>
<div class="massif-list" v-show="showMassifList">
<div class="massif-item" :class="{'massif-item-click':item.id === currentMassif?.id}" v-for="(item,index) in polygonList" @click="clickCurrentMassif(item)">
<el-row>
<el-col :span="12">
<div class="title">
<div class="title-icon" :style="{background:theme}">
<i-more-app theme="outline" size="24" fill="#FFFFFF"/>
</div>
<div class="title-text">
{{ item.title || '' }}
<div class="crop">
{{ item.cropType || '' }}
</div>
</div>
</div>
</el-col>
<el-col :span="12">
<div class="massif-item-right">
<div class="area">
{{ item.area || 0 }}
</div>
|
<div class="enabled">
{{ item.enabled ? '启用' : '禁用' }}
</div>
<div class="more">
<i-more theme="outline" size="24" fill="#5c5e5d"/>
</div>
</div>
</el-col>
</el-row>
</div>
</div>
</el-collapse-transition>
</div> </div>
<!--绘制操作区--> <!--绘制操作区-->
<div v-if="protract" class="protract-control operate"> <div v-if="protract" class="protract-control operate">
@ -298,45 +383,128 @@ watch(()=>polygonList,(value)=>{
pointer-events: all; pointer-events: all;
} }
} }
// //
.map-left{ .map-left {
background: #FFFFFF; background: #FFFFFF;
width: 350px; width: 350px;
border-radius: 5px; border-radius: 5px;
padding: 10px; padding: 15px;
position: absolute; position: absolute;
left: 10px; left: 10px;
top: 20px; top: 20px;
// //
opacity:0.9; opacity: 0.9;
.massif-head {
display: flex;
justify-content: space-between;
align-items: center;
height: 40px;
.title {
font-size: 18px;
font-weight: 700;
}
.all-area {
font-size: 14px;
color: #5c5e5d;
}
}
.massif-control {
display: flex;
justify-content: space-between;
align-items: center;
margin: 10px 0;
.show-massif {
font-size: 14px;
align-items: center;
color: #5c5e5d;
display: flex;
//
cursor: pointer;
}
}
//
.massif-list {
.title-icon {
padding: 6px 5px 4px 5px;
display: inline-block;
border-radius: 5px;
float: left;
}
.title-text{
margin-left: 10px;
float: left;
font-size: 16px;
.crop{
font-size: 12px;
margin-top: 2px;
}
}
.massif-item-click{
border: 1px solid v-bind(theme) !important;
}
.massif-item {
border-radius: 5px;
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
padding: 10px;
margin: 0 -5px;
.massif-item-right{
display: flex;
justify-content: flex-end;
align-items: center;
font-size: 14px;
color: #5c5e5d;
div{
margin: 0 3px;
}
.more{
//
cursor: pointer;
}
}
}
}
} }
// //
.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;
background: none;
color: #FFFFFF;
} }
// //
.protract-control { .protract-control {
position: absolute; position: absolute;
right: 20px; right: 30px;
top: 10px; top: 50px;
} }
</style> </style>
<style lang="scss"> <style lang="scss">
// //
.message-box{ .message-box {
--el-messagebox-width: 450px; --el-messagebox-width: 450px;
padding: 20px; padding: 20px;
.el-message-box__btns{
.el-message-box__btns {
justify-content: center; justify-content: center;
} }
.el-button{
.el-button {
border-radius: 20px; border-radius: 20px;
} }
} }

Loading…
Cancel
Save