Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my-map
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
郭铭瑶
my-map
Commits
57e6f3fa
Commit
57e6f3fa
authored
Aug 04, 2021
by
郭铭瑶
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
点击事件回调参数统一化
parent
38273348
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
38 deletions
+75
-38
main.vue
src/components/main.vue
+16
-16
ai-map.ts
src/map/ai-map.ts
+17
-7
s-map.ts
src/map/s-map.ts
+22
-14
types.ts
src/map/types.ts
+20
-1
No files found.
src/components/main.vue
View file @
57e6f3fa
...
@@ -18,27 +18,27 @@ let map: MyMap
...
@@ -18,27 +18,27 @@ let map: MyMap
onMounted
(
async
()
=>
{
onMounted
(
async
()
=>
{
await
nextTick
()
await
nextTick
()
// map = useMap('SMap').with({
map
=
useMap
(
'SMap'
).
with
({
// el: 'container',
// center: [0, 0],
// zoom: 5,
// style: 'smap://styles/dark',
// appKey: 'ACF69EDK17LON63GHPF081',
// netType: 'internet',
// })
map
=
useMap
(
'AIMap'
).
with
({
el
:
'container'
,
el
:
'container'
,
center
:
[
121.612846
,
31.205494
],
center
:
[
0
,
0
],
zoom
:
13
,
zoom
:
5
,
style
:
'
aimap://styles/aimap/darkblue-v4
'
,
style
:
'
smap://styles/dark
'
,
appKey
:
'
gt8XidVe5upHf7cirkJwwXTCWj20zfu3
'
,
appKey
:
'
ACF69EDK17LON63GHPF081
'
,
baseApiUrl
:
'https://location-dev.newayz.com
'
,
netType
:
'internet
'
,
})
})
// map = useMap('AIMap').with({
// el: 'container',
// center: [121.612846, 31.205494],
// zoom: 13,
// style: 'aimap://styles/aimap/darkblue-v4',
// appKey: 'gt8XidVe5upHf7cirkJwwXTCWj20zfu3',
// baseApiUrl: 'https://location-dev.newayz.com',
// })
map
map
.
on
(
'load'
,
addControls
)
.
on
(
'load'
,
addControls
)
.
on
(
'click'
,
(
a
,
b
)
=>
console
.
log
(
'click'
,
a
,
b
,
map
))
.
on
(
'click'
,
(
a
,
b
)
=>
console
.
log
(
'click'
,
a
,
b
))
.
on
(
'zoom'
,
(
e
)
=>
console
.
log
(
'zoom: '
,
e
))
.
on
(
'zoom'
,
(
e
)
=>
console
.
log
(
'zoom: '
,
e
))
.
on
(
'move'
,
(
e
)
=>
console
.
log
(
'move: '
,
e
))
.
on
(
'move'
,
(
e
)
=>
console
.
log
(
'move: '
,
e
))
.
on
(
'blur'
,
(
e
)
=>
console
.
log
(
'blur: '
,
e
))
.
on
(
'blur'
,
(
e
)
=>
console
.
log
(
'blur: '
,
e
))
...
...
src/map/ai-map.ts
View file @
57e6f3fa
...
@@ -7,6 +7,7 @@ import {
...
@@ -7,6 +7,7 @@ import {
ZoomOptions
,
ZoomOptions
,
FocusOptions
,
FocusOptions
,
Location
,
Location
,
ClickCallBack
,
}
from
'./types'
}
from
'./types'
declare
const
aimap
:
{
declare
const
aimap
:
{
...
@@ -41,14 +42,13 @@ export default class AI_Map extends MyMap {
...
@@ -41,14 +42,13 @@ export default class AI_Map extends MyMap {
bearing
:
config
.
bearing
||
0
,
bearing
:
config
.
bearing
||
0
,
style
:
config
.
style
,
style
:
config
.
style
,
localIdeographFontFamily
:
config
.
family
,
localIdeographFontFamily
:
config
.
family
,
spatialReference
:
'cgcs2000'
,
})
})
super
(
instance
)
super
(
instance
)
this
.
setListeners
()
this
.
_
setListeners
()
this
.
setControls
()
this
.
_
setControls
()
}
}
private
setListeners
()
{
private
_
setListeners
()
{
const
_listeners
:
Partial
<
Listeners
>
=
{
const
_listeners
:
Partial
<
Listeners
>
=
{
load
:
(
cb
:
CallBack
)
=>
{
load
:
(
cb
:
CallBack
)
=>
{
this
.
map
.
on
(
'load'
,
cb
)
this
.
map
.
on
(
'load'
,
cb
)
...
@@ -71,14 +71,24 @@ export default class AI_Map extends MyMap {
...
@@ -71,14 +71,24 @@ export default class AI_Map extends MyMap {
resize
:
(
cb
:
CallBack
)
=>
{
resize
:
(
cb
:
CallBack
)
=>
{
this
.
map
.
on
(
'resize'
,
cb
)
this
.
map
.
on
(
'resize'
,
cb
)
},
},
click
:
(
cb
:
CallBack
)
=>
{
click
:
(
cb
:
ClickCallBack
)
=>
{
this
.
map
.
on
(
'click'
,
cb
)
this
.
map
.
on
(
'click'
,
(
e
:
any
)
=>
{
const
arg
=
{
type
:
e
.
type
,
center
:
[
e
.
lngLat
.
lng
,
e
.
lngLat
.
lat
],
event
:
e
.
originalEvent
,
clientX
:
e
.
point
.
x
,
clientY
:
e
.
point
.
y
,
originData
:
e
,
}
cb
(
arg
)
})
},
},
}
}
this
.
_listeners
=
Object
.
assign
(
this
.
_listeners
,
_listeners
)
this
.
_listeners
=
Object
.
assign
(
this
.
_listeners
,
_listeners
)
}
}
private
setControls
()
{
private
_
setControls
()
{
const
_controls
=
{
const
_controls
=
{
compass
:
(
options
:
ControlOptions
)
=>
{
compass
:
(
options
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
new
aimap
.
CompassControl
(),
options
.
position
)
this
.
map
.
addControl
(
new
aimap
.
CompassControl
(),
options
.
position
)
...
...
src/map/s-map.ts
View file @
57e6f3fa
...
@@ -51,19 +51,19 @@ export default class S_Map extends MyMap {
...
@@ -51,19 +51,19 @@ export default class S_Map extends MyMap {
rotateEnable
:
config
.
rotateEnable
,
rotateEnable
:
config
.
rotateEnable
,
})
})
super
(
instance
)
super
(
instance
)
this
.
setListeners
()
this
.
_
setListeners
()
this
.
setControls
()
this
.
_
setControls
()
this
.
on
(
'load'
,
this
.
clearFooter
)
this
.
on
(
'load'
,
this
.
_
clearFooter
)
}
}
private
clearFooter
()
{
private
_
clearFooter
()
{
const
footer
=
document
.
querySelector
(
const
footer
=
document
.
querySelector
(
'.esri-ui-manual-container>.esri-component'
,
'.esri-ui-manual-container>.esri-component'
,
)
)
footer
&&
((
footer
as
HTMLElement
).
style
.
display
=
'none'
)
footer
&&
((
footer
as
HTMLElement
).
style
.
display
=
'none'
)
}
}
private
setListeners
()
{
private
_
setListeners
()
{
const
_listeners
:
Partial
<
Listeners
>
=
{
const
_listeners
:
Partial
<
Listeners
>
=
{
load
:
(
cb
:
CallBack
)
=>
{
load
:
(
cb
:
CallBack
)
=>
{
this
.
map
.
on
(
SMap
.
MapEvent
.
maploaded
,
cb
)
this
.
map
.
on
(
SMap
.
MapEvent
.
maploaded
,
cb
)
...
@@ -81,33 +81,41 @@ export default class S_Map extends MyMap {
...
@@ -81,33 +81,41 @@ export default class S_Map extends MyMap {
this
.
map
.
on
(
SMap
.
MapEvent
.
focus
,
cb
)
this
.
map
.
on
(
SMap
.
MapEvent
.
focus
,
cb
)
},
},
drag
:
(
cb
:
CallBack
)
=>
{
drag
:
(
cb
:
CallBack
)
=>
{
this
.
map
.
on
(
SMap
.
MapEvent
.
drag
,
cb
)
this
.
_addEvent
(
SMap
.
MapEvent
.
drag
,
cb
)
},
},
resize
:
(
cb
:
CallBack
)
=>
{
resize
:
(
cb
:
CallBack
)
=>
{
this
.
map
.
on
(
SMap
.
MapEvent
.
resize
,
cb
)
this
.
map
.
on
(
SMap
.
MapEvent
.
resize
,
cb
)
},
},
click
:
(
cb
:
CallBack
)
=>
{
click
:
(
cb
:
CallBack
)
=>
{
this
.
e
vent
(
SMap
.
MapEvent
.
click
,
cb
)
this
.
_addE
vent
(
SMap
.
MapEvent
.
click
,
cb
)
},
},
dblclick
:
(
cb
:
CallBack
)
=>
{
dblclick
:
(
cb
:
CallBack
)
=>
{
this
.
e
vent
(
SMap
.
MapEvent
.
doubleclick
,
cb
)
this
.
_addE
vent
(
SMap
.
MapEvent
.
doubleclick
,
cb
)
},
},
mousewheel
:
(
cb
:
CallBack
)
=>
{
mousewheel
:
(
cb
:
CallBack
)
=>
{
this
.
e
vent
(
SMap
.
MapEvent
.
mousewheel
,
cb
)
this
.
_addE
vent
(
SMap
.
MapEvent
.
mousewheel
,
cb
)
},
},
}
}
this
.
_listeners
=
Object
.
assign
(
this
.
_listeners
,
_listeners
)
this
.
_listeners
=
Object
.
assign
(
this
.
_listeners
,
_listeners
)
}
}
private
event
(
event
:
unknown
,
cb
:
CallBack
)
{
private
_addEvent
(
event
:
unknown
,
cb
:
CallBack
)
{
this
.
map
.
on
(
event
,
(
view
:
any
,
eventParamter
:
any
)
=>
{
this
.
map
.
on
(
event
,
(
view
:
any
,
e
:
any
)
=>
{
view
.
hitTest
(
eventParamter
).
then
((
res
:
any
)
=>
{
const
arg
=
{
cb
(
res
.
results
,
eventParamter
.
mapPoint
)
type
:
e
.
type
,
center
:
[
e
.
mapPoint
?.
longitude
,
e
.
mapPoint
?.
latitude
],
event
:
e
.
native
,
clientX
:
e
.
x
,
clientY
:
e
.
y
,
originData
:
e
,
}
view
.
hitTest
(
e
).
then
((
res
:
any
)
=>
{
cb
(
arg
,
res
.
results
)
})
})
})
})
}
}
private
setControls
()
{
private
_
setControls
()
{
const
_controls
=
{
const
_controls
=
{
home
:
(
options
:
ControlOptions
)
=>
{
home
:
(
options
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
...
...
src/map/types.ts
View file @
57e6f3fa
...
@@ -47,6 +47,25 @@ export type Location = [number, number] | [number, number, number]
...
@@ -47,6 +47,25 @@ export type Location = [number, number] | [number, number, number]
*/
*/
export
type
CallBack
=
(
arg
:
any
,
oth
?:
any
)
=>
unknown
export
type
CallBack
=
(
arg
:
any
,
oth
?:
any
)
=>
unknown
/** 经过封装的返回统一参数的点击回调 */
export
type
ClickCallBack
=
(
arg
:
{
/** 事件类型 */
type
:
string
/** 地图初始中心点位 */
center
:
number
[]
/** 鼠标事件 */
event
:
PointerEvent
/** 触发时鼠标x位置 */
clientX
:
number
/** 触发时鼠标y位置 */
clientY
:
number
/** 地图触发事件的原始数据(即未经封装前的数据) */
originData
:
any
},
oth
?:
any
,
)
=>
unknown
/**
/**
* 监听事件
* 监听事件
*/
*/
...
@@ -66,7 +85,7 @@ export interface Listeners {
...
@@ -66,7 +85,7 @@ export interface Listeners {
/** 视图大小变化触发 */
/** 视图大小变化触发 */
resize
:
(
cb
:
CallBack
)
=>
unknown
resize
:
(
cb
:
CallBack
)
=>
unknown
/** 点击触发 */
/** 点击触发 */
click
:
(
cb
:
CallBack
)
=>
unknown
click
:
(
cb
:
C
lickC
allBack
)
=>
unknown
/** 双击触发 */
/** 双击触发 */
dblclick
:
(
cb
:
CallBack
)
=>
unknown
dblclick
:
(
cb
:
CallBack
)
=>
unknown
/** 滚轮触发 */
/** 滚轮触发 */
...
...
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