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
1e290eb3
Commit
1e290eb3
authored
Aug 09, 2021
by
郭铭瑶
🤘
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
约束初始化参数
parent
57e6f3fa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
102 additions
and
77 deletions
+102
-77
main.vue
src/components/main.vue
+0
-1
ai-map.ts
src/map/ai-map.ts
+13
-11
index.ts
src/map/index.ts
+20
-3
s-map.ts
src/map/s-map.ts
+37
-36
types.ts
src/map/types.ts
+32
-26
No files found.
src/components/main.vue
View file @
1e290eb3
...
@@ -17,7 +17,6 @@ let map: MyMap
...
@@ -17,7 +17,6 @@ let map: MyMap
onMounted
(
async
()
=>
{
onMounted
(
async
()
=>
{
await
nextTick
()
await
nextTick
()
map
=
useMap
(
'SMap'
).
with
({
map
=
useMap
(
'SMap'
).
with
({
el
:
'container'
,
el
:
'container'
,
center
:
[
0
,
0
],
center
:
[
0
,
0
],
...
...
src/map/ai-map.ts
View file @
1e290eb3
...
@@ -8,6 +8,8 @@ import {
...
@@ -8,6 +8,8 @@ import {
FocusOptions
,
FocusOptions
,
Location
,
Location
,
ClickCallBack
,
ClickCallBack
,
Controls
,
AIMapConfig
,
}
from
'./types'
}
from
'./types'
declare
const
aimap
:
{
declare
const
aimap
:
{
...
@@ -20,7 +22,7 @@ declare const aimap: {
...
@@ -20,7 +22,7 @@ declare const aimap: {
}
}
export
default
class
AI_Map
extends
MyMap
{
export
default
class
AI_Map
extends
MyMap
{
constructor
(
config
:
MapConfig
)
{
constructor
(
config
:
MapConfig
<
AIMapConfig
>
)
{
if
(
!
config
.
appKey
)
{
if
(
!
config
.
appKey
)
{
throw
new
Error
(
'AIMap需要设置appKey参数!'
)
throw
new
Error
(
'AIMap需要设置appKey参数!'
)
}
}
...
@@ -89,27 +91,27 @@ export default class AI_Map extends MyMap {
...
@@ -89,27 +91,27 @@ export default class AI_Map extends MyMap {
}
}
private
_setControls
()
{
private
_setControls
()
{
const
_controls
=
{
const
_controls
:
Partial
<
Controls
>
=
{
compass
:
(
options
:
ControlOptions
)
=>
{
compass
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
new
aimap
.
CompassControl
(),
options
.
position
)
this
.
map
.
addControl
(
new
aimap
.
CompassControl
(),
options
?
.
position
)
},
},
zoom
:
(
options
:
ControlOptions
)
=>
{
zoom
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
aimap
.
NavigationControl
({
new
aimap
.
NavigationControl
({
showZoom
:
options
.
show
,
showZoom
:
options
?
.
show
,
showCompass
:
false
,
showCompass
:
false
,
visualizePitch
:
false
,
visualizePitch
:
false
,
}),
}),
options
.
position
,
options
?
.
position
,
)
)
},
},
scale
:
(
options
:
ControlOptions
)
=>
{
scale
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
aimap
.
ScaleControl
({
new
aimap
.
ScaleControl
({
maxWidth
:
options
.
maxWidth
||
80
,
maxWidth
:
options
?
.
maxWidth
||
80
,
unit
:
options
.
unit
||
'metric'
,
unit
:
options
?
.
unit
||
'metric'
,
}),
}),
options
.
position
,
options
?
.
position
,
)
)
},
},
}
}
...
...
src/map/index.ts
View file @
1e290eb3
import
{
MapConfig
}
from
'./types'
import
{
AIMapConfig
,
MapConfig
,
S
MapConfig
}
from
'./types'
import
S_Map
from
'./s-map'
import
S_Map
from
'./s-map'
import
AI_Map
from
'./ai-map'
import
AI_Map
from
'./ai-map'
const
whichMap
=
{
const
whichMap
=
{
SMap
:
{
SMap
:
{
with
:
(
config
:
MapConfig
)
=>
new
S_Map
(
config
),
/**
* 使用配置初始化地图
* @param config 地图配置
*/
with
:
(
config
:
MapConfig
<
SMapConfig
>
)
=>
new
S_Map
(
config
),
},
},
AIMap
:
{
AIMap
:
{
with
:
(
config
:
MapConfig
)
=>
new
AI_Map
(
config
),
/**
* 使用配置初始化地图
* @param config 地图配置
*/
with
:
(
config
:
MapConfig
<
AIMapConfig
>
)
=>
new
AI_Map
(
config
),
},
},
}
}
/**
* 创建地图
* @param key 地图关键字:
*
* 'SMap': 测绘院地图
*
* 'AIMap': 维智地图
*
*/
export
default
function
useMap
<
K
extends
keyof
typeof
whichMap
>
(
key
:
K
)
{
export
default
function
useMap
<
K
extends
keyof
typeof
whichMap
>
(
key
:
K
)
{
return
whichMap
[
key
]
return
whichMap
[
key
]
}
}
src/map/s-map.ts
View file @
1e290eb3
...
@@ -4,9 +4,10 @@ import {
...
@@ -4,9 +4,10 @@ import {
MapConfig
,
MapConfig
,
Listeners
,
Listeners
,
ControlOptions
,
ControlOptions
,
ZoomOptions
,
Location
,
Location
,
FocusOptions
,
FocusOptions
,
Controls
,
SMapConfig
,
}
from
'./types'
}
from
'./types'
declare
const
SMap
:
{
declare
const
SMap
:
{
...
@@ -34,7 +35,7 @@ declare const Plugins: {
...
@@ -34,7 +35,7 @@ declare const Plugins: {
}
}
export
default
class
S_Map
extends
MyMap
{
export
default
class
S_Map
extends
MyMap
{
constructor
(
config
:
MapConfig
)
{
constructor
(
config
:
MapConfig
<
SMapConfig
>
)
{
if
(
!
config
.
netType
)
{
if
(
!
config
.
netType
)
{
throw
new
Error
(
'SMap需要设置netType参数!'
)
throw
new
Error
(
'SMap需要设置netType参数!'
)
}
}
...
@@ -116,92 +117,92 @@ export default class S_Map extends MyMap {
...
@@ -116,92 +117,92 @@ export default class S_Map extends MyMap {
}
}
private
_setControls
()
{
private
_setControls
()
{
const
_controls
=
{
const
_controls
:
Partial
<
Controls
>
=
{
home
:
(
options
:
ControlOptions
)
=>
{
home
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
Home
({
new
SMap
.
Home
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
compass
:
(
options
:
ControlOptions
)
=>
{
compass
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
Compass
({
new
SMap
.
Compass
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
zoom
:
(
options
:
ControlOptions
)
=>
{
zoom
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
Zoom
({
new
SMap
.
Zoom
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
fullScreen
:
(
options
:
ControlOptions
)
=>
{
fullScreen
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
Fullscreen
({
new
SMap
.
Fullscreen
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
layerList
:
(
options
:
ControlOptions
)
=>
{
layerList
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
LayerListControl
({
new
SMap
.
LayerListControl
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
measureLine
:
(
options
:
ControlOptions
)
=>
{
measureLine
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
MeasureLine
({
new
SMap
.
MeasureLine
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
measureArea
:
(
options
:
ControlOptions
)
=>
{
measureArea
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
MeasureArea
({
new
SMap
.
MeasureArea
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
basemapToggle
:
(
options
:
ControlOptions
)
=>
{
basemapToggle
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
BasemapToggle
({
new
SMap
.
BasemapToggle
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
underguroundSwitch
:
(
options
:
ControlOptions
)
=>
{
underguroundSwitch
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
UndergroundSwitch
({
new
SMap
.
UndergroundSwitch
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
bMapGallery
:
(
options
:
ControlOptions
)
=>
{
bMapGallery
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
BMapGallery
({
new
SMap
.
BMapGallery
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
bMapGalleryexpand
:
(
options
:
ControlOptions
)
=>
{
bMapGalleryexpand
:
(
options
?
:
ControlOptions
)
=>
{
this
.
map
.
addControl
(
this
.
map
.
addControl
(
new
SMap
.
BMapGalleryExpand
({
new
SMap
.
BMapGalleryExpand
({
visible
:
options
.
show
,
visible
:
options
?
.
show
,
position
:
options
.
position
,
position
:
options
?
.
position
,
}),
}),
)
)
},
},
...
...
src/map/types.ts
View file @
1e290eb3
/**
/**
* 地图配置
* 地图配置
*/
*/
export
type
MapConfig
=
Partial
<
{
export
type
MapConfig
<
T
>
=
T
&
{
/** 地图容器(需要有宽高) */
/** 地图容器(需要有宽高) */
el
:
string
el
:
string
/**
* 在SMap中作为appKey使用
* 在AIMap中作为accessToken使用
*/
appKey
:
string
}
&
Partial
<
{
/** 地图模式 */
mode
:
'2D'
|
'3D'
/** 地图初始中心点位 */
center
:
Location
/** 地图初始zoom等级 */
zoom
:
number
/** 地图zoom允许范围 */
zooms
:
[
number
,
number
]
/** 地图初始旋转角度 */
bearing
:
number
/** 地图初始仰角(3D用) */
pitch
:
number
/** 地图仰角允许范围 */
pitchs
:
[
number
,
number
]
/** 地图样式 */
style
:
string
showBuildingBlock
:
boolean
rotateEnable
:
boolean
family
:
string
}
>
export
type
SMapConfig
=
{
/**
/**
* SMap 地图专用
* SMap 地图专用
* @param internet 表示互联网2D
* @param internet 表示互联网2D
...
@@ -13,32 +41,10 @@ export type MapConfig = Partial<{
...
@@ -13,32 +41,10 @@ export type MapConfig = Partial<{
* @param njdl 表示南京东路政务网3D
* @param njdl 表示南京东路政务网3D
*/
*/
netType
:
'internet'
|
'affairs'
|
'local3D'
|
'affairs3D'
|
'njdl'
netType
:
'internet'
|
'affairs'
|
'local3D'
|
'affairs3D'
|
'njdl'
/** 地图模式 */
}
mode
:
'2D'
|
'3D'
export
type
AIMapConfig
=
{
/** 地图初始中心点位 */
center
:
Location
/** 地图初始zoom等级 */
zoom
:
number
/** 地图zoom允许范围 */
zooms
:
[
number
,
number
]
/** 地图初始旋转角度 */
bearing
:
number
/** 地图初始仰角(3D用) */
pitch
:
number
/** 地图仰角允许范围 */
pitchs
:
[
number
,
number
]
/** 地图样式 */
style
:
string
/**
* 在SMap中作为appKey使用
* 在AIMap中作为accessToken使用
*/
appKey
:
string
showBuildingBlock
:
boolean
rotateEnable
:
boolean
baseApiUrl
:
string
baseApiUrl
:
string
family
:
string
}
}
>
export
type
Location
=
[
number
,
number
]
|
[
number
,
number
,
number
]
export
type
Location
=
[
number
,
number
]
|
[
number
,
number
,
number
]
...
...
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