Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in / Register
Toggle navigation
A
amap-line-edit
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
feng
amap-line-edit
Commits
7b74ae8f
Commit
7b74ae8f
authored
Apr 25, 2019
by
aoobao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加绘制线段功能
parent
9f2cc5eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
190 additions
and
99 deletions
+190
-99
src/assets/MouseTool.js
src/assets/MouseTool.js
+50
-0
src/components/DrawLine.vue
src/components/DrawLine.vue
+24
-2
src/components/LineView.vue
src/components/LineView.vue
+91
-88
src/views/Home.vue
src/views/Home.vue
+25
-9
No files found.
src/assets/MouseTool.js
0 → 100644
View file @
7b74ae8f
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
src/components/DrawLine.vue
View file @
7b74ae8f
<
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
:
{
...
...
src/components/LineView.vue
View file @
7b74ae8f
<
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>
<el-button
@
click=
"remove"
type=
"danger"
icon=
"el-icon-delete"
size=
"mini"
circle
></el-button>
<el-button
@
click=
"remove"
type=
"danger"
icon=
"el-icon-delete"
size=
"mini"
circle
></el-button>
<el-button
type=
"primary"
size=
"mini"
@
click=
"copyLine"
>
导出
</el-button>
<el-button
type=
"primary"
size=
"mini"
@
click=
"copyLine"
>
导出
</el-button>
<el-switch
:value=
"data.lock"
size=
"mini"
style=
"margin-left:5px;"
@
input=
"changeLock"
></el-switch>
<el-switch
:value=
"data.lock"
size=
"mini"
style=
"margin-left:5px;"
@
input=
"changeLock"
></el-switch>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
export
default
{
export
default
{
props
:
{
props
:
{
data
:
{
data
:
{
type
:
Object
,
type
:
Object
,
required
:
true
required
:
true
}
}
},
},
computed
:
{
computed
:
{
name
()
{
name
()
{
if
(
this
.
data
)
{
if
(
this
.
data
)
{
return
this
.
data
.
name
return
this
.
data
.
name
}
}
return
'
无
'
return
'
无
'
},
},
startPoint
()
{
startPoint
()
{
if
(
this
.
data
)
{
if
(
this
.
data
)
{
let
list
=
this
.
data
.
line
let
list
=
this
.
data
.
line
if
(
list
&&
list
.
length
>
0
)
{
if
(
list
&&
list
.
length
>
0
)
{
return
list
[
0
]
return
list
[
0
]
}
}
}
}
return
null
return
null
},
},
// startPointName () {
// startPointName () {
// if (this.startPoint) {
// if (this.startPoint) {
// return `${this.startPoint[0].toFixed(3)},${this.startPoint[1].toFixed(3)}...`
// return `${this.startPoint[0].toFixed(3)},${this.startPoint[1].toFixed(3)}...`
// }
// }
// return ''
// return ''
// }
// }
},
},
methods
:
{
methods
:
{
changeName
(
val
)
{
changeName
(
val
)
{
this
.
$emit
(
'
input
'
,
val
)
this
.
$emit
(
'
input
'
,
val
)
},
},
changeLock
()
{
changeLock
()
{
this
.
$emit
(
'
lock
'
)
this
.
$emit
(
'
lock
'
)
},
},
remove
()
{
remove
()
{
this
.
$emit
(
'
remove
'
)
this
.
$emit
(
'
remove
'
)
},
},
reverse
()
{
reverse
()
{
this
.
$emit
(
'
reverse
'
)
this
.
$emit
(
'
reverse
'
)
},
},
mouseout
()
{
mouseout
()
{
this
.
$emit
(
'
mouseout
'
)
this
.
$emit
(
'
mouseout
'
)
},
},
mouseover
()
{
mouseover
()
{
this
.
$emit
(
'
mouseover
'
)
this
.
$emit
(
'
mouseover
'
)
},
},
copyLine
()
{
copyLine
()
{
this
.
$emit
(
'
copyLine
'
)
this
.
$emit
(
'
copyLine
'
)
}
}
}
}
}
}
</
script
>
</
script
>
<
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
;
.name
{
&
:hover
{
// color: #fff;
background-color
:
aquamarine
;
}
margin-left
:
10px
;
.name
{
margin-right
:
10px
;
// color: #fff;
}
}
margin-left
:
10px
;
</
style
>
margin-right
:
10px
;
}
}
</
style
>
src/views/Home.vue
View file @
7b74ae8f
...
@@ -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;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment