Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in / Register
Toggle navigation
A
amap-road-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-road-edit
Commits
f7ee02a5
Commit
f7ee02a5
authored
Jul 09, 2019
by
aoobao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add map init plugin
parent
5d4ca1d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
4 deletions
+81
-4
src/components/map-template.vue
src/components/map-template.vue
+21
-0
src/components/map/AMap.vue
src/components/map/AMap.vue
+14
-4
src/components/map/Register.vue
src/components/map/Register.vue
+46
-0
No files found.
src/components/map-template.vue
0 → 100644
View file @
f7ee02a5
<
script
>
import
register
from
'
@/components/map/Register
'
// import { mapGetters } from 'vuex'
// import { getDateString } from '@/assets/js/utils'
// import AMapUtils from 'amap-utils'
export
default
{
mixins
:
[
register
],
methods
:
{
// 组件入口 不需要写在create中
init
()
{
},
// 销毁组件调用.
destroy
()
{
}
}
}
</
script
>
src/components/map/AMap.vue
View file @
f7ee02a5
<
template
>
<
template
>
<div
class=
"map"
ref=
"map"
>
<div
class=
"map"
ref=
"map"
>
<slot></slot>
<slot
v-if=
"isCreated"
></slot>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
...
@@ -13,7 +13,7 @@ export default {
...
@@ -13,7 +13,7 @@ export default {
default
()
{
default
()
{
return
{
return
{
zoom
:
8
,
//级别
zoom
:
8
,
//级别
viewMode
:
'
2D
'
//使用3D视图
viewMode
:
'
2D
'
}
}
}
}
}
}
...
@@ -21,7 +21,8 @@ export default {
...
@@ -21,7 +21,8 @@ export default {
data
()
{
data
()
{
let
amap
=
{}
let
amap
=
{}
return
{
return
{
amap
amap
,
isCreated
:
false
}
}
},
},
provide
()
{
provide
()
{
...
@@ -48,11 +49,20 @@ export default {
...
@@ -48,11 +49,20 @@ export default {
...
this
.
opts
...
this
.
opts
})
})
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
$emit
(
'
created
'
)
this
.
isCreated
=
true
this
.
$emit
(
'
created
'
,
this
.
getMap
())
},
1
);
},
1
);
},
},
getMap
()
{
getMap
()
{
return
this
.
amap
.
$map
||
null
return
this
.
amap
.
$map
||
null
},
applyMethod
(
methodName
,
...
params
)
{
let
map
=
this
.
getMap
()
if
(
!
map
)
{
console
.
warn
(
'
not ready
'
)
return
}
return
map
[
methodName
](...
params
)
}
}
}
}
}
}
...
...
src/components/map/Register.vue
0 → 100644
View file @
f7ee02a5
<
script
>
// 高德地图注册事件(所有地图组件mixins)
// 所有地图组件实现init 方法,初始化结束后会自动调用init
// 组件销毁时会自动调用destroy方法,
// 如果实例下绑定有$object(this.$object),会在地图中移除
export
default
{
render
()
{
return
null
},
inject
:
[
'
amap
'
],
created
()
{
let
map
=
this
.
getMap
()
typeof
this
.
init
===
'
function
'
&&
this
.
init
(
map
)
},
beforeDestroy
()
{
typeof
this
.
destroy
===
'
function
'
&&
this
.
destroy
()
this
.
destroyObject
()
},
methods
:
{
// 通用方法 TODO
getObject
()
{
return
this
.
$object
||
null
},
setObject
(
object
)
{
this
.
destroyObject
()
this
.
$object
=
object
},
getMap
()
{
return
this
.
amap
.
$map
||
null
},
destroyObject
()
{
if
(
this
.
$object
)
{
if
(
typeof
this
.
$object
===
'
object
'
)
{
if
(
typeof
this
.
$object
.
setMap
===
'
function
'
)
{
this
.
$object
.
setMap
(
null
)
}
if
(
typeof
this
.
$object
.
destroy
===
'
function
'
)
{
this
.
$object
.
destroy
()
}
this
.
$object
=
null
}
else
{
console
.
warn
(
'
$object is not object
'
)
}
}
}
}
}
</
script
>
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