Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
fba86962
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5977
Star
89
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fba86962
编写于
7月 16, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
map页面改成组合式
上级
ebf1766b
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
229 addition
and
178 deletion
+229
-178
pages/component/map/map.uvue
pages/component/map/map.uvue
+229
-178
未找到文件。
pages/component/map/map.uvue
浏览文件 @
fba86962
<template>
<view class="content">
<map class="map" id="map1" ref="map1" :controls="controls" :scale="scale" :longitude="location.longitude"
<map class="map" id="map1" ref="map1" :controls="controls" :scale="scale"
min-scale="3" max-scale="20"
:longitude="location.longitude"
:latitude="location.latitude" :show-location="showLocation" :enable-3D="enable3D" :rotate="rotate" :skew="skew"
:show-compass="showCompass" :enable-overlooking="enableOverlooking" :enable-zoom="enableZoom"
:enable-scroll="enableScroll" :enable-rotate="enableRotate" :enable-satellite="enableSatellite"
...
...
@@ -8,22 +8,29 @@
:include-points="includePoints" @tap="maptap" @controltap="oncontroltap" @markertap="onmarkertap"
@callouttap="oncallouttap" @poitap="onpoitap" @updated="onupdated" @regionchange="onregionchange"></map>
<scroll-view class="scrollview" scroll-y="true">
<view class="uni-title">
<text class="uni-title-text">属性示例</text>
</View>
<input-data defaultValue="13" title="scale: 缩放级别,取值范围为3-20" type="number" @confirm="confirm_scale_input"></input-data>
<boolean-data :defaultValue="showLocation" title="开启显示带有方向的当前定位点" @change="change_show_location"></boolean-data>
<button class="button" @click="changeScale">changeScale</button>
<button class="button" @click="addMarkers">addMarkers</button>
<button class="button" @click="addPolyline">addPolyline</button>
<button class="button" @click="addPolygons">addPolygons</button>
<button class="button" @click="addCircles">addCircles</button>
<button class="button" @click="includePoint">includePoints</button>
<button class="button" @click="handleGetCenterLocation">getCenterLocation</button>
<button class="button" @click="handleGetRegion">getRegion</button>
<button class="button" @click="handleTranslateMarker">translateMarker</button>
<button class="button" @click="addControls">控件</button>
<button class="button" @click="addMarkers">标记点</button>
<button class="button" @click="addPolyline">路线</button>
<button class="button" @click="addPolygons">多边形</button>
<button class="button" @click="addCircles">圆</button>
<button class="button" @click="includePoint">缩放视野以包含所有给定的坐标点</button>
<view class="uni-title">
<text class="uni-title-text">方法示例</text>
</View>
<button class="button" @click="handleGetCenterLocation">获取当前地图中心的经纬度</button>
<button class="button" @click="handleGetRegion">获取当前地图的视野范围</button>
<button class="button" @click="handleTranslateMarker">平移marker,带动画</button>
</scroll-view>
</view>
</template>
<script lang="uts">
<script
setup
lang="uts">
type Anchor = {
x : number,
y : number
...
...
@@ -42,17 +49,17 @@
}
type Markers = {
id :
string |
number,
id : number,
latitude : number,
longitude : number,
title : string
zIndex : string,
title
?
: string
zIndex
?
: string,
iconPath : string,
rotate ?: number,
width : number,
height : number,
anchor : Anchor,
callout : Callout
width
?
: number,
height
?
: number,
anchor
?
: Anchor,
callout
?
: Callout
}
type Points = {
...
...
@@ -269,14 +276,50 @@
}
];
export default {
data() {
return {
location: {
longitude: 116.3974770000,
latitude: 39.9086920000
},
controls: [{
type ControlsType = {
id?: number;
position: PositionType;
iconPath:string;
clickable?: boolean;
}
type PositionType = {
left: number,
top: number,
width: number,
height: number
}
const location = ref({ longitude: 116.39742, latitude: 39.909 });
const controls = ref( []as ControlsType[]);
const showLocation = ref(false);
const scale = ref(13);
const showCompass = ref(true);
const enable3D = ref(true);
const enableOverlooking = ref(true);
const enableZoom = ref(true);
const enableScroll = ref(true);
const enableRotate = ref(true);
const enableSatellite = ref(false);
const enableTraffic = ref(false);
const polyline = ref([] as Polyline[]);
const markers = ref([] as Markers[]);
const polygons = ref([] as Polygons[]);
const circles = ref([] as Circles[]);
const includePoints = ref([] as Points[]);
const rotate = ref(0);
const skew = ref(0);
const map = ref(null as MapContext | null);
const autoTest = ref(false);
const getCenterLocationTest = ref({});
const getRegionTest = ref({});
onReady(() => {
map.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
});
const addControls = () => {
controls.value = [{
id: 1,
position: {
left: 5,
...
...
@@ -286,152 +329,160 @@
},
iconPath: '../../../static/uni.png',
clickable: true
}],
showLocation: false,
scale: 13,
showCompass: true,
enable3D: true,
enableOverlooking: true,
enableZoom: true,
enableScroll: true,
enableRotate: true,
enableSatellite: false,
enableTraffic: false,
polyline: [] as Polyline[],
markers: [] as Markers[],
polygons: [] as Polygons[],
circles: [] as Circles[],
includePoints: [] as Points[],
rotate: 0,
skew: 0,
map: null as MapContext | null,
// 自动化测试
autoTest: false,
getCenterLocationTest:{},
getRegionTest:{},
}]
}
},
onReady() {
this.map = uni.createMapContext("map1", this);
},
methods: {
changeScale() {
this.scale = this.scale == 9 ? 15 : 9;
},
enableThreeD(e) {
this.enable3D = e.detail.value;
},
changeShowCompass(e) {
this.showCompass = e.detail.value;
},
changeEnableOverlooking(e) {
this.enableOverlooking = e.detail.value;
},
changeEnableZoom(e) {
this.enableZoom = e.detail.value;
},
changeEnableScroll(e) {
this.enableScroll = e.detail.value;
},
changeEnableRotate(e) {
this.enableRotate = e.detail.value;
},
changeEnableSatellite(e) {
this.enableSatellite = e.detail.value;
},
changeEnableTraffic(e) {
this.enableTraffic = e.detail.value;
},
addMarkers() {
this.markers = testMarkers;
},
addPolyline() {
this.polyline = testPolyline;
},
const confirm_scale_input = (value: number) => {
scale.value = value
};
addPolygons()
{
this.polygons = testPolygons;
},
const change_show_location = (checked : boolean)=>
{
showLocation.value = checked
}
addCircles() {
this.circles = testCircles;
},
includePoint() {
this.includePoints = testIncludePoints;
},
handleGetCenterLocation() {
this.map!.getCenterLocation({
const enableThreeD = (e)=>{
enable3D.value = e.detail.value;
}
const changeShowCompass = (e)=>{
showCompass.value = e.detail.value;
}
const changeEnableOverlooking = (e) => {
enableOverlooking.value = e.detail.value;
};
const changeEnableZoom = (e) => {
enableZoom.value = e.detail.value;
};
const changeEnableScroll = (e) => {
enableScroll.value = e.detail.value;
};
const changeEnableRotate = (e) => {
enableRotate.value = e.detail.value;
};
const changeEnableSatellite = (e) => {
enableSatellite.value = e.detail.value;
};
const changeEnableTraffic = (e) => {
enableTraffic.value = e.detail.value;
};
const addMarkers = () => {
markers.value = testMarkers;
};
const addPolygons = () => {
polygons.value = testPolygons;
};
const addPolyline = () => {
polyline.value = testPolyline;
};
const addCircles = () => {
circles.value = testCircles;
};
const includePoint = () => {
includePoints.value = testIncludePoints;
};
const handleGetCenterLocation = () => {
if (map.value) {
map.value.getCenterLocation({
success: ret => {
console.log(JSON.stringify(ret)
);
this.getCenterLocationTest = ret
if(!this.autoTest){
console.log('getCenterLocation',ret
);
// console.log(JSON.stringify(ret));
getCenterLocationTest.value = ret;
uni.showModal({
content: JSON.stringify(ret)
})
});
}
});
}
})
},
handleGetRegion() {
this.map!.getRegion({
};
const handleGetRegion = () => {
if (map.value) {
map.value.getRegion({
success: ret => {
console.log(JSON.stringify(ret));
this.getRegionTest = ret
if(!this.autoTest){
getRegionTest.value = ret;
uni.showModal({
content: JSON.stringify(ret)
})
});
}
});
}
})
},
};
handleTranslateMarker() {
this.map!.translateMarker({
const handleTranslateMarker = () => {
if (map.value) {
map.value.translateMarker({
markerId: 1,
destination: {
latitude: 39.989631,
longitude: 116.481018
},
autoRotate:true,
rotate:10,
duration: 2000,
animationEnd: () => {
console.log('动画结束');
},
success: ret => {
console.log(JSON.stringify(ret));
console.log('handleTranslateMarker',JSON.stringify(ret));
},
fail: ret => {
console.log('handleTranslateMarker',JSON.stringify(ret));
}
});
},
maptap(e) {
}
};
const maptap = (e) => {
uni.showModal({
content: JSON.stringify(e)
})
},
onmarkertap(e) {
});
};
const onmarkertap = (e:UniEvent) => {
console.log('点击标记点时触发',e)
uni.showModal({
content: JSON.stringify(e)
})
},
oncontroltap(e) {
});
};
const oncontroltap = (e:UniEvent) => {
console.log('点击控件时触发',e)
uni.showModal({
content: JSON.stringify(e)
})
},
oncallouttap(e) {
});
};
const oncallouttap = (e:UniEvent) => {
console.log('点击标记点对应的气泡时触发',e)
uni.showModal({
content: JSON.stringify(e)
})
},
onupdated(e) {
console.log(JSON.stringify(e))
},
onregionchange(e) {
console.log(JSON.stringify(e));
},
onpoitap(e) {
});
};
const onupdated = (e:UniEvent) => {
console.log('在地图渲染更新完成时触发',e)
};
const onregionchange = (e:UniEvent) => {
console.log('视野发生变化时触发',e)
};
const onpoitap = (e) => {
uni.showModal({
content: JSON.stringify(e)
})
}
}
}
});
};
</script>
<style>
...
...
@@ -441,7 +492,7 @@
.map {
width: 100%;
height:
25
0px;
height:
30
0px;
background-color: #f0f0f0;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录