Commit 7b74ae8f authored by aoobao's avatar aoobao

增加绘制线段功能

parent 9f2cc5eb
export default class MouseTool {
constructor(map, opt) {
this._initialize(map, opt || {})
}
_initialize(map, opt) {
this._map = map
this._drawEvent = opt.drawEvent
this._fillColor = opt.fillColor || '#ffecb3'
this._fillOpacity = opt.fillOpacity || 0.4
this._strokeColor = opt.strokeColor || '#ffecb3'
this._strokeOpacity = opt.strokeOpacity || 1
this._callback = opt.callback
// this._drawType = opt.drawType || 'polyline'
}
startDraw() {
if (!this._mouseTool) {
this._mouseTool = new AMap.MouseTool(this._map)
this._mouseTool.polyline({
fillColor: this._fillColor,
fillOpacity: this._fillOpacity,
strokeColor: this._strokeColor,
strokeOpacity: this._strokeOpacity
})
this._mouseTool.on('draw', e => {
// console.log(e)
let lineObj = e.obj
lineObj.setMap(null)
typeof this._callback && this._callback(e)
})
}
// this._map.setDefaultCursor('crosshair')
}
endDraw() {
if (this._mouseTool) {
this._mouseTool.close()
this._mouseTool.setMap(null)
this._mouseTool = null
}
}
destory() {
this.endDraw()
}
}
\ No newline at end of file
<script> <script>
// 线段编辑 // 线段编辑
import MouseTool from '@/assets/MouseTool'
export default { export default {
render () { return null }, render () { return null },
props: { props: {
draw: { draw: {
type: Boolean, type: Boolean,
default: false default: false
},
map: {
type: Object,
required: true
} }
}, },
mounted () { mounted () {
this.$mouseTool = new MouseTool(this.map, {
strokeColor: 'red',
callback: this.drawCallback.bind(this)
})
if (this.draw) { if (this.draw) {
this.initDraw() this.initDraw()
} }
}, },
beforeDestroy () { beforeDestroy () {
if (this.draw) this.destory() if (this.draw) this.destory()
this.$mouseTool.destory()
this.$mouseTool = null
}, },
methods: { methods: {
drawCallback (e) {
// console.log(e, this)
let lineObj = e.obj
let path = lineObj.getPath()
let list = path.map(t => {
return [t.getLng(), t.getLat()]
})
this.$emit('draw', list)
},
initDraw () { initDraw () {
this.$mouseTool.startDraw()
}, },
destory () { destory () {
if (this.$mouseTool) {
this.$mouseTool.endDraw()
}
} }
}, },
watch: { watch: {
......
<template> <template>
<div class="line-container" @mouseout="mouseout" @mouseover="mouseover"> <div class="line-container" @mouseout="mouseout" @mouseover="mouseover">
<!-- <span class="name">{{name}} {{startPointName}}</span> --> <!-- <span class="name">{{name}} {{startPointName}}</span> -->
<div style="width:150px;margin-right:5px;" class="input-container"> <div style="width:150px;margin-right:5px;margin-left:5px;" class="input-container">
<el-input :value="name" @input="changeName"></el-input> <el-input size="mini" :value="name" @input="changeName"></el-input>
</div> </div>
<el-button type="success" size="mini" @click="reverse">反转</el-button> <el-button type="success" size="mini" @click="reverse">反转</el-button>
...@@ -72,12 +72,15 @@ export default { ...@@ -72,12 +72,15 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.line-container { .line-container {
width: 400px; width: 400px;
height: 30px; height: 40px;
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
margin-left: 10px; // margin-left: 10px;
margin-top: 15px; margin-top: 10px;
&:hover {
background-color: aquamarine;
}
.name { .name {
// color: #fff; // color: #fff;
......
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
<div class="map-container" @mousemove="mapMouseMove" @mouseout="mapMouseOut"> <div class="map-container" @mousemove="mapMouseMove" @mouseout="mapMouseOut">
<div class="map" ref="map"></div> <div class="map" ref="map"></div>
<LineManagerView v-if="map" :map="map" :data="lineList" ref="lineManager" :status="status" :x="x" :y="y" :clearWidth="clearNumber" /> <LineManagerView v-if="map" :map="map" :data="lineList" ref="lineManager" :status="status" :x="x" :y="y" :clearWidth="clearNumber" />
<DrawLine :draw="isDrawLine" @createLine="createLine" /> <DrawLine v-if="map" :map="map" :draw="isDrawLine" @draw="createLine" />
</div> </div>
<div class="control"> <div class="control">
<div class="button-control"> <div class="button-control">
<label>{{statusName}}</label> <!-- <label>{{statusName}}</label> -->
<el-button v-if="!exportVisible && !isDrawLine && statusName === '查看'" style="margin-left:5px;" type="primary" @click="showAdd">新增</el-button> <el-button v-if="!exportVisible && !isDrawLine && statusName === '查看'" style="margin-left:5px;" type="primary" @click="showAdd">新增</el-button>
<el-button v-if="!exportVisible && !isDrawLine" style="margin-left:5px;" type="warning" @click="clearModel">{{statusName == '擦除' ? '取消擦除' : '擦除'}}</el-button> <el-button v-if="!exportVisible && !isDrawLine" style="margin-left:5px;" type="warning" @click="clearModel">{{statusName == '擦除' ? '取消擦除' : '擦除'}}</el-button>
<el-button v-if="!exportVisible && !isDrawLine && statusName === '查看'" style="margin-left:5px;" type="success" @click="merge">合并</el-button> <el-button v-if="!exportVisible && !isDrawLine && statusName === '查看'" style="margin-left:5px;" type="success" @click="merge">合并</el-button>
<el-button style="margin-left:5px;" @click="exportAll">{{exportVisible ? '关闭导出' : '导出'}}</el-button> <el-button style="margin-left:5px;" @click="exportAll">{{exportVisible ? '关闭导出' : '导出'}}</el-button>
<el-button v-if="!exportVisible && statusName === '查看'" @click="drawLine" style="margin-left:5px;">{{isDrawLine ? '关闭绘制' : '绘制线'}}</el-button>
</div> </div>
<div class="line-control"> <div class="line-control">
<template v-if="statusName == '查看'"> <template v-if="statusName == '查看'">
...@@ -72,7 +73,8 @@ export default { ...@@ -72,7 +73,8 @@ export default {
remark: null, remark: null,
imgBase64: null, imgBase64: null,
exportVisible: false, exportVisible: false,
isDrawLine: false isDrawLine: false,
drawIndex: 0
} }
}, },
computed: { computed: {
...@@ -121,9 +123,7 @@ export default { ...@@ -121,9 +123,7 @@ export default {
}, },
methods: { methods: {
createLine (line) {
console.log(line)
},
copyLine (lineObj) { copyLine (lineObj) {
let line = lineObj.line let line = lineObj.line
let st = LineToString(line) let st = LineToString(line)
...@@ -134,6 +134,9 @@ export default { ...@@ -134,6 +134,9 @@ export default {
exportAll () { exportAll () {
this.exportVisible = !this.exportVisible this.exportVisible = !this.exportVisible
}, },
drawLine () {
this.isDrawLine = !this.isDrawLine
},
// 合并 // 合并
merge () { merge () {
if (this.status == LineManager.VIEW) { if (this.status == LineManager.VIEW) {
...@@ -199,6 +202,19 @@ export default { ...@@ -199,6 +202,19 @@ export default {
})] })]
}, },
createLine (line) {
// console.log(line)
this.drawIndex++
let name = '自定义线段' + this.drawIndex
let o = {
line: line,
id: ++__id,
name: name,
color: 'blue',
lock: false
}
this.lineList.unshift(o)
},
addLine (obj) { addLine (obj) {
// console.log(str) // console.log(str)
...@@ -324,7 +340,7 @@ export default { ...@@ -324,7 +340,7 @@ export default {
.line-control { .line-control {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: aqua; // background-color: aqua;
overflow-y: auto; overflow-y: auto;
// display: flex; // display: flex;
// flex-flow: row wrap; // flex-flow: row wrap;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment