Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
20岁爱吃必胜客
uni-app
提交
0fc59ce1
U
uni-app
项目概览
20岁爱吃必胜客
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
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,发现更多精彩内容 >>
提交
0fc59ce1
编写于
8月 02, 2022
作者:
DCloud-WZF
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(h5 map): 优化是否高德地图判断
上级
5de87940
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
51 deletion
+35
-51
src/platforms/h5/helpers/location.js
src/platforms/h5/helpers/location.js
+2
-0
src/platforms/h5/view/components/map/index.vue
src/platforms/h5/view/components/map/index.vue
+14
-17
src/platforms/h5/view/components/map/map-marker.js
src/platforms/h5/view/components/map/map-marker.js
+7
-14
src/platforms/h5/view/components/map/map-polygon.js
src/platforms/h5/view/components/map/map-polygon.js
+3
-6
src/platforms/h5/view/components/map/maps/callout.js
src/platforms/h5/view/components/map/maps/callout.js
+4
-9
src/platforms/h5/view/components/map/maps/index.js
src/platforms/h5/view/components/map/maps/index.js
+5
-5
未找到文件。
src/platforms/h5/helpers/location.js
浏览文件 @
0fc59ce1
...
...
@@ -36,3 +36,5 @@ export function getMapInfo () {
key
:
''
}
}
export
const
IS_AMAP
=
getMapInfo
().
type
===
MapType
.
AMAP
src/platforms/h5/view/components/map/index.vue
浏览文件 @
0fc59ce1
...
...
@@ -48,10 +48,7 @@ import {
import
mapMarker
from
'
./map-marker
'
import
mapPolygon
from
'
./map-polygon
'
import
{
ICON_PATH_ORIGIN
,
MapType
,
getMapInfo
}
from
'
../../../helpers/location
'
const
mapInfo
=
getMapInfo
()
const
ISAMAP
=
mapInfo
.
type
===
MapType
.
AMAP
import
{
ICON_PATH_ORIGIN
,
IS_AMAP
}
from
'
../../../helpers/location
'
function
getAMapPosition
(
maps
,
latitude
,
longitude
)
{
return
new
maps
.
LngLat
(
longitude
,
latitude
)
...
...
@@ -60,7 +57,7 @@ function getGoogleQQMapPosition (maps, latitude, longitude) {
return
new
maps
.
LatLng
(
latitude
,
longitude
)
}
function
getMapPosition
(
maps
,
latitude
,
longitude
)
{
return
ISAMAP
?
getAMapPosition
(
maps
,
latitude
,
longitude
)
:
getGoogleQQMapPosition
(
maps
,
latitude
,
longitude
)
return
IS
_
AMAP
?
getAMapPosition
(
maps
,
latitude
,
longitude
)
:
getGoogleQQMapPosition
(
maps
,
latitude
,
longitude
)
}
function
getLat
(
latLng
)
{
...
...
@@ -231,7 +228,7 @@ export default {
},
methods
:
{
handleAMapClick
(
e
)
{
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
const
{
pageX
,
pageY
}
=
e
.
changedTouches
[
0
]
this
.
$trigger
(
'
click
'
,
{
x
:
pageX
,
y
:
pageY
},
{})
this
.
$trigger
(
'
tap
'
,
{
x
:
pageX
,
y
:
pageY
},
{})
...
...
@@ -370,7 +367,7 @@ export default {
}
})
})
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
this
.
isBoundsReady
=
true
this
.
$emit
(
'
boundsready
'
)
}
...
...
@@ -492,7 +489,7 @@ export default {
const
path
=
[]
option
.
points
.
forEach
(
point
=>
{
const
pointPosition
=
ISAMAP
?
[
point
.
longitude
,
point
.
latitude
]
:
getGoogleQQMapPosition
(
maps
,
point
.
latitude
,
point
.
longitude
)
const
pointPosition
=
IS
_
AMAP
?
[
point
.
longitude
,
point
.
latitude
]
:
getGoogleQQMapPosition
(
maps
,
point
.
latitude
,
point
.
longitude
)
path
.
push
(
pointPosition
)
})
...
...
@@ -507,7 +504,7 @@ export default {
strokeDashStyle
:
option
.
dottedLine
?
'
dash
'
:
'
solid
'
}
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
polylineOptions
.
strokeColor
=
option
.
strokeColor
polylineOptions
.
strokeStyle
=
option
.
dottedLine
?
'
dashed
'
:
'
solid
'
polylineOptions
.
isOutline
=
!!
option
.
borderWidth
...
...
@@ -535,7 +532,7 @@ export default {
polyline
.
push
(
new
maps
.
Polyline
(
polylineBorderOptions
))
}
const
_polyline
=
new
maps
.
Polyline
(
polylineOptions
)
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
map
.
add
(
_polyline
)
}
polyline
.
push
(
_polyline
)
...
...
@@ -554,7 +551,7 @@ export default {
const
circles
=
this
.
circlesSync
this
.
removeCircles
()
this
.
circles
.
forEach
(
option
=>
{
const
center
=
ISAMAP
?
[
option
.
longitude
,
option
.
latitude
]
:
getGoogleQQMapPosition
(
maps
,
option
.
latitude
,
option
.
longitude
)
const
center
=
IS
_
AMAP
?
[
option
.
longitude
,
option
.
latitude
]
:
getGoogleQQMapPosition
(
maps
,
option
.
latitude
,
option
.
longitude
)
const
circleOptions
=
{
map
,
center
,
...
...
@@ -564,7 +561,7 @@ export default {
strokeDashStyle
:
'
solid
'
}
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
circleOptions
.
strokeColor
=
option
.
color
circleOptions
.
fillColor
=
option
.
fillColor
||
'
#000
'
}
else
{
...
...
@@ -584,7 +581,7 @@ export default {
}
const
circle
=
new
maps
.
Circle
(
circleOptions
)
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
map
.
add
(
circle
)
}
circles
.
push
(
circle
)
...
...
@@ -636,7 +633,7 @@ export default {
}
$event
.
stopPropagation
()
}
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
this
.
$refs
.
mapContainer
.
appendChild
(
control
)
}
else
{
map
.
controls
[
maps
.
ControlPosition
.
TOP_LEFT
].
push
(
control
)
...
...
@@ -665,7 +662,7 @@ export default {
return
}
const
position
=
getMapPosition
(
maps
,
res
.
latitude
,
res
.
longitude
)
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
location
=
new
maps
.
Marker
({
position
,
map
,
...
...
@@ -736,7 +733,7 @@ export default {
this
.
boundsReady
(()
=>
{
const
map
=
this
.
_map
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
const
_points
=
[]
points
.
forEach
(
point
=>
{
_points
.
push
([
point
.
longitude
,
point
.
latitude
])
...
...
@@ -759,7 +756,7 @@ export default {
}
})
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
this
.
isBoundsReady
=
true
this
.
$emit
(
'
boundsready
'
)
}
...
...
src/platforms/h5/view/components/map/map-marker.js
浏览文件 @
0fc59ce1
import
{
MapType
,
getMapInfo
}
from
'
../../../helpers/location
'
import
{
mapInfo
,
MapType
,
IS_AMAP
}
from
'
../../../helpers/location
'
import
getRealPath
from
'
uni-platform/helpers/get-real-path
'
const
mapInfo
=
getMapInfo
()
const
ISAMAP
=
mapInfo
.
type
===
MapType
.
AMAP
export
default
{
props
:
{
id
:
{
...
...
@@ -105,7 +99,7 @@ export default {
maps
.
event
.
addListener
(
marker
,
'
click
'
,
(
e
)
=>
{
const
callout
=
marker
.
callout
if
(
callout
&&
!
callout
.
alwaysVisible
)
{
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
callout
.
visible
=
!
callout
.
visible
if
(
callout
.
visible
)
{
marker
.
callout
.
createAMapText
()
...
...
@@ -140,7 +134,7 @@ export default {
const
maps
=
this
.
_maps
const
marker
=
this
.
_marker
const
title
=
option
.
title
const
position
=
ISAMAP
?
new
maps
.
LngLat
(
option
.
longitude
,
option
.
latitude
)
:
new
maps
.
LatLng
(
option
.
latitude
,
option
.
longitude
)
const
position
=
IS
_
AMAP
?
new
maps
.
LngLat
(
option
.
longitude
,
option
.
latitude
)
:
new
maps
.
LatLng
(
option
.
latitude
,
option
.
longitude
)
const
img
=
new
Image
()
img
.
onload
=
()
=>
{
const
anchor
=
option
.
anchor
||
{}
...
...
@@ -216,8 +210,7 @@ export default {
})
marker
.
label
=
label
}
else
if
(
'
setLabel
'
in
marker
)
{
// 高德
if
(
ISAMAP
)
{
if
(
IS_AMAP
)
{
const
content
=
`<div style="
margin-left:
${
labelStyle
.
marginLeft
}
;
...
...
@@ -280,7 +273,7 @@ export default {
if
(
callout
)
{
callout
.
setOption
(
calloutStyle
)
}
else
{
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
const
callback
=
(
self
)
=>
{
if
(
self
.
idString
)
{
self
.
$parent
.
$trigger
(
'
callouttap
'
,
{},
{
...
...
@@ -342,7 +335,7 @@ export default {
let
latitude
let
longitude
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
latitude
=
e
.
lnglat
.
lat
longitude
=
e
.
lnglat
.
lng
}
else
if
(
mapInfo
.
type
===
MapType
.
QQ
)
{
...
...
@@ -369,7 +362,7 @@ export default {
this
.
_marker
=
null
},
removeMarkerCallout
(
callout
)
{
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
callout
.
removeAMapText
()
}
else
{
callout
.
setMap
(
null
)
...
...
src/platforms/h5/view/components/map/map-polygon.js
浏览文件 @
0fc59ce1
import
{
hexToRgba
}
from
'
uni-shared
'
import
{
MapType
,
getMapInfo
}
from
'
../../../helpers/location
'
const
mapInfo
=
getMapInfo
()
const
ISAMAP
=
mapInfo
.
type
===
MapType
.
AMAP
import
{
IS_AMAP
}
from
'
../../../helpers/location
'
export
default
{
props
:
{
// 边框虚线,腾讯地图支持,google 地图不支持,默认值为[0, 0] 为实线,非 [0, 0] 为虚线,H5 端无法像微信小程序一样控制虚线的间隔像素大小
// 边框虚线,腾讯地图支持,google
高德
地图不支持,默认值为[0, 0] 为实线,非 [0, 0] 为虚线,H5 端无法像微信小程序一样控制虚线的间隔像素大小
dashArray
:
{
type
:
Array
,
default
:
()
=>
[
0
,
0
]
...
...
@@ -69,7 +66,7 @@ export default {
const
path
=
points
.
map
(
item
=>
{
const
{
latitude
,
longitude
}
=
item
return
ISAMAP
?
[
longitude
,
latitude
]
:
new
_maps
.
LatLng
(
latitude
,
longitude
)
return
IS
_
AMAP
?
[
longitude
,
latitude
]
:
new
_maps
.
LatLng
(
latitude
,
longitude
)
})
const
{
r
:
fcR
,
g
:
fcG
,
b
:
fcB
,
a
:
fcA
}
=
hexToRgba
(
fillColor
)
...
...
src/platforms/h5/view/components/map/maps/callout.js
浏览文件 @
0fc59ce1
import
{
MapType
,
getMapInfo
}
from
'
../../../../helpers/location
'
const
mapInfo
=
getMapInfo
()
const
ISAMAP
=
mapInfo
.
type
===
MapType
.
AMAP
import
{
IS_AMAP
}
from
'
../../../../helpers/location
'
export
function
createCallout
(
maps
)
{
function
onAdd
()
{
...
...
@@ -75,7 +70,7 @@ export function createCallout (maps) {
constructor
(
option
=
{},
callback
,
parent
)
{
this
.
option
=
option
||
{}
this
.
visible
=
this
.
alwaysVisible
=
option
.
display
===
'
ALWAYS
'
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
this
.
callback
=
callback
this
.
parent
=
parent
if
(
this
.
visible
)
{
...
...
@@ -118,7 +113,7 @@ export function createCallout (maps) {
}
else
{
this
.
alwaysVisible
=
false
}
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
if
(
this
.
visible
)
{
this
.
createAMapText
()
}
...
...
@@ -167,7 +162,7 @@ export function createCallout (maps) {
destroy
=
onRemove
}
if
(
!
ISAMAP
)
{
if
(
!
IS
_
AMAP
)
{
const
prototype
=
Callout
.
prototype
const
overlay
=
new
(
maps
.
OverlayView
||
maps
.
Overlay
)()
for
(
const
key
in
overlay
)
{
...
...
src/platforms/h5/view/components/map/maps/index.js
浏览文件 @
0fc59ce1
import
{
MapType
,
getMapInfo
getMapInfo
,
IS_AMAP
}
from
'
../../../../helpers/location
'
import
{
createCallout
}
from
'
./callout
'
...
...
@@ -10,7 +11,6 @@ const GOOGLE_MAP_CALLBACKNAME = '__map_callback__'
export
function
loadMaps
(
libraries
,
callback
)
{
const
mapInfo
=
getMapInfo
()
const
ISAMAP
=
mapInfo
.
type
===
MapType
.
AMAP
if
(
!
mapInfo
.
key
)
{
console
.
error
(
'
Map key not configured.
'
)
return
...
...
@@ -22,7 +22,7 @@ export function loadMaps (libraries, callback) {
window
[
mapInfo
.
type
]
&&
window
[
mapInfo
.
type
].
maps
)
{
maps
=
ISAMAP
?
window
[
mapInfo
.
type
]
:
window
[
mapInfo
.
type
].
maps
maps
=
IS
_
AMAP
?
window
[
mapInfo
.
type
]
:
window
[
mapInfo
.
type
].
maps
maps
.
Callout
=
maps
.
Callout
||
createCallout
(
maps
)
callback
(
maps
)
}
else
if
(
callbacks
.
length
)
{
...
...
@@ -33,7 +33,7 @@ export function loadMaps (libraries, callback) {
const
callbackName
=
GOOGLE_MAP_CALLBACKNAME
+
mapInfo
.
type
globalExt
[
callbackName
]
=
function
()
{
delete
globalExt
[
callbackName
]
maps
=
ISAMAP
?
window
[
mapInfo
.
type
]
:
window
[
mapInfo
.
type
].
maps
maps
=
IS
_
AMAP
?
window
[
mapInfo
.
type
]
:
window
[
mapInfo
.
type
].
maps
maps
.
Callout
=
createCallout
(
maps
)
callbacks
.
forEach
((
callback
)
=>
callback
(
maps
))
callbacks
.
length
=
0
...
...
@@ -48,7 +48,7 @@ export function loadMaps (libraries, callback) {
src
+=
`libraries=
${
libraries
.
join
(
'
%2C
'
)}
&`
}
if
(
ISAMAP
)
{
if
(
IS
_
AMAP
)
{
handleAMapSecurityPolicy
(
mapInfo
)
}
script
.
src
=
`
${
src
}
key=
${
mapInfo
.
key
}
&callback=
${
callbackName
}
`
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录