Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
1f13d7d5
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1f13d7d5
编写于
3月 24, 2022
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: app-vue3 map 组件新增支持 polygons
上级
c7fdc6fc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
68 addition
and
2 deletion
+68
-2
packages/uni-app-plus/src/view/components/map/index.tsx
packages/uni-app-plus/src/view/components/map/index.tsx
+68
-2
未找到文件。
packages/uni-app-plus/src/view/components/map/index.tsx
浏览文件 @
1f13d7d5
...
...
@@ -73,9 +73,16 @@ interface Circle extends PlusMapsCircle, Coordinate {
fillColor
?:
string
strokeWidth
?:
number
}
interface
Polygon
extends
PlusMapsPolygon
,
Coordinate
{
points
:
Array
<
Coordinate
>
fillColor
?:
string
strokeColor
?:
string
strokeWidth
?:
number
}
type
Markers
=
Array
<
Marker
>
type
Lines
=
Array
<
Line
>
type
Circles
=
Array
<
Circle
>
type
Polygons
=
Array
<
Polygon
>
type
Control
=
{
id
?:
number
position
:
Data
...
...
@@ -86,6 +93,7 @@ interface Map extends PlusMapsMap {
__markers__
:
Markers
__lines__
:
Lines
__circles__
:
Circles
__polygons__
:
Polygons
}
const
props
=
{
...
...
@@ -123,6 +131,12 @@ const props = {
return
[]
},
},
polygons
:
{
type
:
Array
,
default
()
{
return
[]
},
},
controls
:
{
type
:
Array
,
default
()
{
...
...
@@ -145,8 +159,13 @@ export default /*#__PURE__*/ defineBuiltInComponent({
let
map
:
Map
|
undefined
const
{
_addMarkers
,
_addMapLines
,
_addMapCircles
,
_setMap
}
=
useMapMethods
(
props
,
trigger
)
const
{
_addMarkers
,
_addMapLines
,
_addMapCircles
,
_addMapPolygons
,
_setMap
,
}
=
useMapMethods
(
props
,
trigger
)
onParentReady
(()
=>
{
map
=
extend
(
...
...
@@ -172,6 +191,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
__markers__
:
[],
__lines__
:
[],
__circles__
:
[],
__polygons__
:
[],
}
)
map
.
setZoom
(
parseInt
(
String
(
props
.
scale
)))
...
...
@@ -189,6 +209,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
_addMarkers
(
props
.
markers
as
Markers
)
_addMapLines
(
props
.
polyline
as
Lines
)
_addMapCircles
(
props
.
circles
as
Circles
)
_addMapPolygons
(
props
.
polygons
as
Polygons
)
watch
(
()
=>
attrs
.
value
,
...
...
@@ -239,6 +260,13 @@ export default /*#__PURE__*/ defineBuiltInComponent({
},
{
deep
:
true
}
)
watch
(
()
=>
props
.
polygons
,
(
val
)
=>
{
_addMapPolygons
(
val
as
Polygons
)
},
{
deep
:
true
}
)
})
const
mapControls
=
computed
(()
=>
...
...
@@ -475,6 +503,43 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
map
.
__circles__
.
push
(
nativeCircle
)
})
}
function
_addMapPolygons
(
polygons
:
Polygons
)
{
if
(
!
map
)
return
const
nativeMapPolygons
=
map
.
__polygons__
nativeMapPolygons
.
forEach
((
polygon
)
=>
{
map
?.
removeOverlay
(
polygon
as
unknown
as
PlusMapsOverlay
)
})
nativeMapPolygons
.
length
=
0
polygons
.
forEach
((
polygon
)
=>
{
const
{
points
,
strokeWidth
,
strokeColor
,
fillColor
}
=
polygon
const
plusPoints
:
Array
<
PlusMapsPoint
>
=
[]
if
(
points
)
{
points
.
forEach
((
coordinate
:
Coordinate
)
=>
{
plusPoints
.
push
(
new
plus
.
maps
.
Point
!
(
coordinate
.
longitude
,
coordinate
.
latitude
)
)
})
}
const
nativePolygon
=
new
plus
.
maps
.
Polygon
!
(
plusPoints
)
if
(
strokeColor
)
{
const
strokeStyle
=
parseHex
(
strokeColor
)
nativePolygon
.
setStrokeColor
(
strokeStyle
.
color
)
nativePolygon
.
setStrokeOpacity
(
strokeStyle
.
opacity
)
}
if
(
fillColor
)
{
const
fillStyle
=
parseHex
(
fillColor
)
nativePolygon
.
setFillColor
(
fillStyle
.
color
)
nativePolygon
.
setFillOpacity
(
fillStyle
.
opacity
)
}
if
(
strokeWidth
)
{
nativePolygon
.
setLineWidth
(
strokeWidth
)
}
map
?.
addOverlay
(
nativePolygon
as
unknown
as
PlusMapsOverlay
)
nativeMapPolygons
.
push
(
nativePolygon
as
unknown
as
Polygon
)
})
}
const
methods
=
{
moveToLocation
,
...
...
@@ -496,6 +561,7 @@ function useMapMethods(props: Props, trigger: CustomEventTrigger) {
_addMarkers
,
_addMapLines
,
_addMapCircles
,
_addMapPolygons
,
_setMap
(
_map
:
Map
|
null
)
{
map
=
_map
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录