Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
f26abe98
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f26abe98
编写于
9月 27, 2024
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update:适配腾讯地图App端
上级
f9d00337
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
180 deletion
+87
-180
pages.json
pages.json
+1
-1
pages/component/map/map.uvue
pages/component/map/map.uvue
+86
-179
未找到文件。
pages.json
浏览文件 @
f26abe98
...
@@ -437,7 +437,7 @@
...
@@ -437,7 +437,7 @@
}
}
},
},
//
#endif
//
#endif
//
#ifdef
WEB
//
#ifdef
WEB
||
APP
{
{
"path"
:
"pages/component/map/map"
,
"path"
:
"pages/component/map/map"
,
"group"
:
"0,6"
,
"group"
:
"0,6"
,
...
...
pages/component/map/map.uvue
浏览文件 @
f26abe98
...
@@ -18,9 +18,11 @@
...
@@ -18,9 +18,11 @@
<button class="button" @click="addControls">控件</button>
<button class="button" @click="addControls">控件</button>
<button class="button" @click="addMarkers">添加标记点</button>
<button class="button" @click="addMarkers">添加标记点</button>
<button class="button" @click="addMarkersLabel">为标记点旁边增加标签</button>
<!-- #ifdef WEB -->
<button class="button" @click="deleteMarker">移除ID为4的标记点和标签</button>
<button class="button" @click="addMarkersLabel">为标记点旁边增加标签</button>
<!-- #endif -->
<button class="button" @click="removeMarker">移除ID为4的标记点和标签</button>
<button class="button" @click="addPolyline">添加路线</button>
<button class="button" @click="addPolyline">添加路线</button>
<button class="button" @click="removePolyline">移除一条路线</button>
<button class="button" @click="removePolyline">移除一条路线</button>
<button class="button" @click="addPolygons">添加多边形</button>
<button class="button" @click="addPolygons">添加多边形</button>
...
@@ -42,113 +44,21 @@
...
@@ -42,113 +44,21 @@
</template>
</template>
<script setup lang="uts">
<script setup lang="uts">
type Anchor = {
x : number,
y : number
}
type Callout = {
content : string,
color : string,
fontSize : number,
borderRadius : number,
borderWidth : number,
borderColor : string,
bgColor : string,
padding : number,
display : string
}
type Label = {
content : string,
color : string,
fontSize : number,
x : number,
y : number,
borderColor : string
borderWidth : number,
borderRadius : number,
bgColor : string,
padding : number
}
type Markers = {
id : number,
latitude : number,
longitude : number,
title ?: string,
iconPath : string,
zIndex ?: string,
rotate ?: number,
width ?: number,
height ?: number,
label ?: Label,
anchor ?: Anchor,
callout ?: Callout
}
type Points = {
latitude : number,
longitude : number
}
type Polyline = {
points : Points[],
color : string,
width : number,
dottedLine : boolean,
arrowLine : boolean,
borderColor : string,
borderWidth : number
}
type Polygons = {
points : Points[];
fillColor : string;
strokeWidth : number;
strokeColor : string;
zIndex : number;
}
type Circles = {
latitude : number;
longitude : number;
radius : number;
strokeWidth : number;
color : string;
fillColor : string;
}
type PositionType = {
left : number,
top : number,
width : number,
height : number
}
type ControlsType = {
id ?: number;
position : PositionType;
iconPath : string;
clickable ?: boolean;
}
type TypeJestResult = {
type TypeJestResult = {
translateMarkerMsg : string,
translateMarkerMsg : string,
animationEnd : boolean,
animationEnd : boolean,
centerPoints :
Points
,
centerPoints :
LocationObject
,
southwest :
Points
,
southwest :
LocationObject
,
northeast :
Points
,
northeast :
LocationObject
,
moveToLocationMsg : string,
moveToLocationMsg : string,
scale : number
scale : number
}
}
const testMarkers = [{
const testMarkers
:Marker[]
= [{
id: 0,
id: 0,
latitude: 39.989631,
latitude: 39.989631,
longitude: 116.481018,
longitude: 116.481018,
title: '方恒国际 阜通东大街6号',
title: '方恒国际 阜通东大街6号',
zIndex: '1',
iconPath: '../../../static/location.png',
iconPath: '../../../static/location.png',
rotate: 0,
rotate: 0,
width: 20,
width: 20,
...
@@ -156,7 +66,7 @@
...
@@ -156,7 +66,7 @@
anchor: {
anchor: {
x: 0.5,
x: 0.5,
y: 1
y: 1
},
}
,
callout: {
callout: {
content: '方恒国际 阜通东大街6号',
content: '方恒国际 阜通东大街6号',
color: '#00BFFF',
color: '#00BFFF',
...
@@ -167,14 +77,14 @@
...
@@ -167,14 +77,14 @@
bgColor: '#CCFF99',
bgColor: '#CCFF99',
padding: 5,
padding: 5,
display: 'ALWAYS'
display: 'ALWAYS'
}
}
as MapMarkerCallout
},
},
{
{
id: 1,
id: 1,
latitude: 39.9086920000,
latitude: 39.9086920000,
longitude: 116.3974770000,
longitude: 116.3974770000,
title: '天安门',
title: '天安门',
zIndex: '1',
//
zIndex: '1',
iconPath: '../../../static/location.png',
iconPath: '../../../static/location.png',
width: 40,
width: 40,
height: 40,
height: 40,
...
@@ -192,14 +102,13 @@
...
@@ -192,14 +102,13 @@
bgColor: '#CCFF11',
bgColor: '#CCFF11',
padding: 5,
padding: 5,
display: 'ALWAYS'
display: 'ALWAYS'
}
}
as MapMarkerCallout
},
},
{
{
id: 2,
id: 2,
latitude: 39.894793,
latitude: 39.894793,
longitude: 116.321592,
longitude: 116.321592,
title: '北京西站',
title: '北京西站',
zIndex: '1',
iconPath: '../../../static/location.png',
iconPath: '../../../static/location.png',
width: 40,
width: 40,
height: 40,
height: 40,
...
@@ -217,14 +126,13 @@
...
@@ -217,14 +126,13 @@
bgColor: '#ff5500',
bgColor: '#ff5500',
padding: 5,
padding: 5,
display: 'ALWAYS'
display: 'ALWAYS'
}
}
as MapMarkerCallout
},
},
{
{
id: 3,
id: 3,
latitude: 39.902344,
latitude: 39.902344,
longitude: 116.484822,
longitude: 116.484822,
title: '北京东站',
title: '北京东站',
zIndex: '1',
iconPath: '../../../static/location.png',
iconPath: '../../../static/location.png',
width: 20,
width: 20,
height: 20,
height: 20,
...
@@ -242,14 +150,13 @@
...
@@ -242,14 +150,13 @@
bgColor: '#ff5500',
bgColor: '#ff5500',
padding: 5,
padding: 5,
display: 'ALWAYS'
display: 'ALWAYS'
}
}
as MapMarkerCallout
},
},
{
{
id: 4,
id: 4,
latitude: 39.865011,
latitude: 39.865011,
longitude: 116.379007,
longitude: 116.379007,
title: '北京南站',
title: '北京南站',
zIndex: '1',
iconPath: '../../../static/location.png',
iconPath: '../../../static/location.png',
width: 40,
width: 40,
height: 40,
height: 40,
...
@@ -267,12 +174,12 @@
...
@@ -267,12 +174,12 @@
bgColor: '#00aa00',
bgColor: '#00aa00',
padding: 5,
padding: 5,
display: 'ALWAYS'
display: 'ALWAYS'
}
}
as MapMarkerCallout
},
},
];
];
const testPolyline = [{
const testPolyline
: Polyline[]
= [{
points: [{
points: [{
latitude: 39.925539,
latitude: 39.925539,
longitude: 116.279037
longitude: 116.279037
...
@@ -318,7 +225,7 @@
...
@@ -318,7 +225,7 @@
}
}
];
];
const testPolygons = [{
const testPolygons
: Polygon[]
= [{
points: [{
points: [{
latitude: 39.781892,
latitude: 39.781892,
longitude: 116.293413
longitude: 116.293413
...
@@ -365,7 +272,7 @@
...
@@ -365,7 +272,7 @@
}
}
];
];
const testCircles = [{
const testCircles
: Circle[]
= [{
latitude: 39.996441,
latitude: 39.996441,
longitude: 116.411146,
longitude: 116.411146,
radius: 15000,
radius: 15000,
...
@@ -391,7 +298,7 @@
...
@@ -391,7 +298,7 @@
}
}
];
];
const testIncludePoints = [{
const testIncludePoints
:LocationObject[]
= [{
latitude: 39.989631,
latitude: 39.989631,
longitude: 116.481018,
longitude: 116.481018,
},
},
...
@@ -402,8 +309,8 @@
...
@@ -402,8 +309,8 @@
];
];
const map = ref(null as MapContext | null);
const map
Context
= ref(null as MapContext | null);
const location = ref({ longitude: 116.39742, latitude: 39.909 });
const location = ref({ longitude: 116.39742, latitude: 39.909 }
as LocationObject
);
const rotate = ref(0);
const rotate = ref(0);
const skew = ref(0);
const skew = ref(0);
// 自动化测试
// 自动化测试
...
@@ -434,7 +341,7 @@
...
@@ -434,7 +341,7 @@
onReady(() => {
onReady(() => {
map.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
map
Context
.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
});
});
const scale = ref(13);
const scale = ref(13);
...
@@ -442,19 +349,19 @@
...
@@ -442,19 +349,19 @@
scale.value = value
scale.value = value
};
};
const controls = ref([] as Control
sType
[]);
const controls = ref([] as Control[]);
const addControls = () => {
const addControls = () => {
controls.value
.push(
{
controls.value
= [
{
id: 1,
id: 1,
position: {
position: {
left: 5,
left: 5,
top: 180,
top: 180,
width: 30,
width: 30,
height: 30
height: 30
},
}
as ControlPosition
,
iconPath: '../../../static/uni.png',
iconPath: '../../../static/uni.png',
clickable: true
clickable: true
}
)
}
as Control]
}
}
const showLocation = ref(false);
const showLocation = ref(false);
...
@@ -462,31 +369,34 @@
...
@@ -462,31 +369,34 @@
showLocation.value = checked
showLocation.value = checked
}
}
const includePoints = ref([] as
Points
[]);
const includePoints = ref([] as
LocationObject
[]);
const includePoint = () => {
const includePoint = () => {
includePoints.value = testIncludePoints;
includePoints.value = testIncludePoints;
};
};
const markers = reactive([] as Markers
[]);
let markers = ref([] as Marker
[]);
const addMarkers = () => {
const addMarkers = () => {
scale.value = 11
scale.value = 11
markers.push(...testMarkers);
const temp = JSON.parse<Marker[]>(JSON.stringify(testMarkers))!
markers.value = temp
};
};
const removeMarker = () => {
const removeMarker = () => {
const index = markers.findIndex(marker => marker.id === 4);
const index = markers.value.findIndex((marker: Marker):boolean=>{
if (index !== -1) {
return marker.id == 4
delete markers[index].label;
});
markers.splice(index, 1);
if (index != -1) {
}else{
mapContext.value?.removeMarkers({markerIds:[4]})
uni.showToast({
} else {
title: '未找到该标记点',
uni.showToast({
icon: 'none'
title: '未找到该标记点',
});
icon: 'none'
});
}
}
};
};
// #ifdef WEB
const addMarkersLabel = () => {
const addMarkersLabel = () => {
markers.forEach((marker, index) => {
markers.forEach((marker, index) => {
marker.label = {
marker.label = {
...
@@ -502,41 +412,42 @@
...
@@ -502,41 +412,42 @@
padding: 10
padding: 10
};
};
});
});
};
};
// #endif
const polyline = ref([] as Polyline[]);
const polyline = ref([] as Polyline[]);
const addPolyline = () => {
const addPolyline = () => {
scale.value = 11;
scale.value = 11;
polyline.value =
testPolyline
;
polyline.value =
JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!
;
};
};
const removePolyline = () => {
const removePolyline = () => {
if (polyline.value.length > 1) {
if (polyline.value.length > 1) {
polyline.value.splice(0, 1);
polyline.value
= JSON.parse<Polyline[]>(JSON.stringify(testPolyline))!
.splice(0, 1);
}
}
};
};
const polygons = ref([] as Polygon
s
[]);
const polygons = ref([] as Polygon[]);
const addPolygons = () => {
const addPolygons = () => {
scale.value = 10;
scale.value = 10;
polygons.value =
testPolygons
;
polygons.value =
JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!
;
};
};
const removePolygon = () => {
const removePolygon = () => {
if (polygons.value.length > 1) {
if (polygons.value.length > 1) {
polygons.value.splice(0, 1);
polygons.value
= JSON.parse<Polygon[]>(JSON.stringify(testPolygons))!
.splice(0, 1);
}
}
};
};
const circles = ref([] as Circle
s
[]);
const circles = ref([] as Circle[]);
const addCircles = () => {
const addCircles = () => {
scale.value = 10;
scale.value = 10;
circles.value =
testCircles
;
circles.value =
JSON.parse<Circle[]>(JSON.stringify(testCircles))!
;
};
};
const removeCircle = () => {
const removeCircle = () => {
if (circles.value.length > 1) {
if (circles.value.length > 1) {
circles.value.splice(0, 1);
circles.value
= JSON.parse<Circle[]>(JSON.stringify(testCircles))!
.splice(0, 1);
}
}
};
};
...
@@ -582,8 +493,7 @@
...
@@ -582,8 +493,7 @@
const handleGetCenterLocation = () => {
const handleGetCenterLocation = () => {
if (map.value) {
mapContext.value?.getCenterLocation({
map.value.getCenterLocation({
success: ret => {
success: ret => {
// console.log('getCenterLocation',ret);
// console.log('getCenterLocation',ret);
jestResult.centerPoints = ret;
jestResult.centerPoints = ret;
...
@@ -594,12 +504,10 @@
...
@@ -594,12 +504,10 @@
}
}
}
}
});
});
}
};
};
const handleGetRegion = () => {
const handleGetRegion = () => {
if (map.value) {
mapContext.value?.getRegion({
map.value.getRegion({
success: ret => {
success: ret => {
// console.log('getRegion',JSON.stringify(ret));
// console.log('getRegion',JSON.stringify(ret));
jestResult.southwest = ret.southwest;
jestResult.southwest = ret.southwest;
...
@@ -611,34 +519,34 @@
...
@@ -611,34 +519,34 @@
}
}
}
}
});
});
}
};
};
const handleTranslateMarker = () => {
const handleTranslateMarker = () => {
if (map.value) {
mapContext.value?.translateMarker({
map.value.translateMarker({
markerId: 1,
markerId: 1,
destination: {
destination: {
latitude: 39.989631,
latitude: 39.989631,
longitude: 116.481018
longitude: 116.481018
},
},
autoRotate: true,
autoRotate: true,
rotate: 10,
rotate: 10,
duration: 2000,
duration: 2000,
animationEnd: () => {
moveWithRotate: true,
// console.log('动画结束');
// animationEnd: () => {
jestResult.animationEnd = true;
// // console.log('动画结束');
},
// jestResult.animationEnd = true;
// },
success: ret => {
success: ret => {
// console.log('handleTranslateMarker',JSON.stringify(ret));
console.log('handleTranslateMarker',JSON.stringify(ret));
jestResult.translateMarkerMsg = ret.errMsg;
const result = ret as UTSJSONObject
jestResult.translateMarkerMsg = result["errMsg"] as string;
},
},
fail: error => {
fail: error => {
console.log(error)
console.log(error)
}
}
});
});
map
.value
.translateMarker({
map
Context.value?
.translateMarker({
markerId: 2,
markerId: 2,
destination: {
destination: {
latitude: 39.902344,
latitude: 39.902344,
...
@@ -648,19 +556,17 @@
...
@@ -648,19 +556,17 @@
rotate: 0,
rotate: 0,
duration: 2000,
duration: 2000,
success: ret => {
success: ret => {
console.log('handleTranslateMarker',JSON.stringify(ret));
console.log('handleTranslateMarker',
JSON.stringify(ret));
},
},
fail: error => {
fail: error => {
console.log(error)
console.log(error)
}
}
});
});
}
};
};
const handleGetScale = () => {
const handleGetScale = () => {
if (map.value) {
mapContext.value?.getScale({
map.value.getScale({
success: res => {
success: res => {
// console.log('getScale',res);
// console.log('getScale',res);
scale.value = res.scale
scale.value = res.scale
...
@@ -675,17 +581,17 @@
...
@@ -675,17 +581,17 @@
console.log(error)
console.log(error)
},
},
});
});
}
};
};
const handleMoveToLocation = () => {
const handleMoveToLocation = () => {
if (map.value) {
mapContext.value?.moveToLocation({
map.value.moveToLocation({
latitude: 39.909,
latitude: 39.909,
longitude: 116.39742,
longitude: 116.39742,
success: res => {
success: res => {
// console.log('moveToLocation',res);
console.log('moveToLocation',res);
jestResult.moveToLocationMsg = res.errMsg;
const result = res as UTSJSONObject
jestResult.moveToLocationMsg = result["errMsg"] as string;
if (!autoTest.value) {
if (!autoTest.value) {
uni.showModal({
uni.showModal({
content: JSON.stringify(res)
content: JSON.stringify(res)
...
@@ -696,24 +602,23 @@
...
@@ -696,24 +602,23 @@
console.log(error)
console.log(error)
}
}
});
});
}
};
};
const maptap = (e : UniEvent) => {
const maptap = (e : Uni
MapUpdated
Event) => {
// console.log('点击地图时触发',e)
// console.log('点击地图时触发',e)
uni.showModal({
uni.showModal({
content: JSON.stringify(e)
content: JSON.stringify(e)
});
});
};
};
const onmarkertap = (e : UniEvent) => {
const onmarkertap = (e : Uni
MapMarkerTap
Event) => {
// console.log('点击标记点时触发',e)
// console.log('点击标记点时触发',e)
uni.showModal({
uni.showModal({
content: JSON.stringify(e)
content: JSON.stringify(e)
});
});
};
};
const oncontroltap = (e : UniEvent) => {
const oncontroltap = (e : Uni
MapControlTap
Event) => {
// console.log('点击控件时触发',e)
// console.log('点击控件时触发',e)
uni.showModal({
uni.showModal({
content: JSON.stringify(e)
content: JSON.stringify(e)
...
@@ -727,15 +632,15 @@
...
@@ -727,15 +632,15 @@
});
});
};
};
const onupdated = (e : UniEvent) => {
const onupdated = (e : Uni
MapUpdated
Event) => {
console.log('在地图渲染更新完成时触发', e)
console.log('在地图渲染更新完成时触发', e)
};
};
const onregionchange = (e : UniEvent) => {
const onregionchange = (e : Uni
MapRegionChange
Event) => {
console.log('视野发生变化时触发', e)
console.log('视野发生变化时触发', e)
};
};
const onpoitap = (e : UniEvent) => {
const onpoitap = (e : Uni
MapPoiTap
Event) => {
// console.log('点击地图poi点时触发',e)
// console.log('点击地图poi点时触发',e)
uni.showModal({
uni.showModal({
content: JSON.stringify(e)
content: JSON.stringify(e)
...
@@ -747,8 +652,10 @@
...
@@ -747,8 +652,10 @@
autoTest,
autoTest,
updateAutoTest,
updateAutoTest,
addControls,
addControls,
addMarkers,
addMarkers,
addMarkersLabel,
// #ifdef WEB
addMarkersLabel,
// #endif
removeMarker,
removeMarker,
addPolyline,
addPolyline,
removePolyline,
removePolyline,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录