W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋:地圖,客戶端創(chuàng)建的 原生組件,使用時(shí)請(qǐng)注意相關(guān)限制。
屬性名 | 類型 | 默認(rèn)值 | 必填 | 說明 | 最低版本 | Web 態(tài)說明 |
---|---|---|---|---|---|---|
longitude | Number | 是 | gcj02 坐標(biāo)系中心經(jīng)度 | - | - | |
latitude | Number | 是 | gcj02 坐標(biāo)系中心緯度 | - | - | |
scale | Number | 16 | 否 | 縮放級(jí)別,取值范圍為 4-21 。 | - | - |
markers | Array.<marker> | 否 | 標(biāo)記點(diǎn) | - | - | |
polyline | Array.<polyline> | 否 | 路線 | - | - | |
polygons | Array.<polygon> | 否 | 多邊形(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
- | |
circles | Array.<circle> | 否 | 圓 | - | - | |
controls | Array.<control> | 否 | 控件 | - | - | |
include-points | Array.<point> | 否 | 縮放視野以包含所有給定的坐標(biāo)點(diǎn) | - | - | |
show-location | Boolean | false | 否 | 顯示帶有方向的當(dāng)前定位點(diǎn) | - | 暫時(shí)不能顯示方向 |
enable-3D | Boolean | false | 否 | 顯示 3D 樓塊(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
暫不支持 |
show-compass | Boolean | false | 否 | 顯示指南針(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
暫不支持 |
enable-overlooking | Boolean | false | 否 | 開啟俯視(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
暫不支持 |
enable-zoom | Boolean | true | 否 | 是否支持縮放(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
- |
enable-scroll | Boolean | true | 否 | 是否支持拖動(dòng)(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
- |
enable-rotate | Boolean | false | 否 | 是否支持旋轉(zhuǎn)(工具暫不支持) | 2.0.13
低版本請(qǐng)做兼容性處理 |
暫不支持 |
bindmarkertap | EventHandle | 否 | 點(diǎn)擊標(biāo)記點(diǎn)時(shí)觸發(fā) | - | - | |
bindcallouttap | EventHandle | 否 | 點(diǎn)擊標(biāo)記點(diǎn)對(duì)應(yīng)的氣泡時(shí)觸發(fā) | - | - | |
bindcontroltap | EventHandle | 否 | 點(diǎn)擊控件時(shí)觸發(fā) | - | - | |
bindregionchange | EventHandle | 否 | 視野發(fā)生變化時(shí)觸發(fā) | - | - | |
bindtap | EventHandle | 否 | 點(diǎn)擊地圖時(shí)觸發(fā) | - | - | |
bindupdated | EventHandle | 否 | 在地圖渲染更新完成時(shí)觸發(fā) | - | - | |
bindpoitap | EventHandle | 否 | 點(diǎn)擊地圖 poi 點(diǎn)時(shí)觸發(fā) | - | 暫不支持 |
代碼示例
<view class="wrap">
<view class="card-area">
<map class="map"
longitude="{{longitude}}"
latitude="{{latitude}}"
scale="{{scale}}"
markers="{{markers}}"
polyline="{{polyline}}"
polygons="{{drawPolygon ? polygons : []}}"
circles="{{circles}}"
controls="{{controls}}"
show-location="{{showLocation}}"
include-points="{{includePoints}}"
enable-3D="{{enable3d}}"
show-compass="{{showCompass}}"
enable-overlooking="{{enableOverlooking}}"
enable-zoom="{{enableZoom}}"
enable-scroll="{{enableScroll}}"
enable-rotate="{{enableRotate}}"
bindmarkertap="onMarkertap"
bindcallouttap="onCallouttap"
bindcontroltap="onControltap"
bindregionchange="onRegionchange"
bindtap="onTap"
bindupdated="onUpdated"
bindpoitap="onPoitap">
</map>
<view class="item-scroll block border-bottom">
<text class="switch-text">支持縮放</text>
<switch bindchange="toggleZoom" checked></switch>
</view>
<view class="item-scroll block border-bottom">
<text class="switch-text">支持拖動(dòng)</text>
<switch bindchange="toggleScroll" checked></switch>
</view>
<view class="item-scroll block border-bottom" s-if="{{!isWeb}}">
<text class="switch-text">支持旋轉(zhuǎn)</text>
<switch bindchange="toggleRotate" checked></switch>
</view>
</view>
<view class="tip-week">工具暫不支持手勢控制</view>
</view>
Page({
data: {
latitude: '40.048828',
longitude: '116.280412',
scale: 16,
polygons: [],
drawPolygon: false,
includePoints: [],
showLocation: true,
enable3d: false,
showCompass: false,
enableOverlooking: false,
enableZoom: true,
enableScroll: true,
enableRotate: true,
markers: [{
markerId: '1',
latitude: '40.052751',
longitude: '116.278796'
}, {
markerId: '2',
latitude: '40.048828',
longitude: '116.280412',
callout: {
display: 'ALWAYS',
content: '百度科技園'
}
}, {
markerId: '3',
latitude: '40.049655',
longitude: '116.27505',
callout: {
display: 'ALWAYS',
content: '西山壹號(hào)院'
}
}],
polyline: [{
points: [{
longitude: 116.278796,
latitude: 40.048828
}, {
longitude: 116.27505,
latitude: 40.049655
}],
color: '#FF5F41FF',
width: 2,
dottedLine: true
}],
controls: [{
controlId: 1,
iconPath: 'https://b.bdstatic.com/searchbox/icms/searchbox/img/api_logo.png',
position: {
left: 0,
top: 100,
width: 50,
height: 50
},
clickable: true
}],
circles: [{
latitude: '40.052751',
longitude: '116.278796',
color: '#FF5F41FF',
fillColor: '#21FFFFFF',
radius: '200',
strokeWidth: '2'
}]
},
showLocation() {
this.setData({
showLocation: !this.data.showLocation
});
},
toggle3d() {
this.setData({
enable3d: !this.data.enable3d
});
},
toggleShowCompass() {
this.setData({
showCompass: !this.data.showCompass
});
},
toggleOverlooking() {
this.setData({
enableOverlooking: !this.data.enableOverlooking
});
},
toggleZoom() {
this.setData({
enableZoom: !this.data.enableZoom
});
},
toggleScroll() {
this.setData({
enableScroll: !this.data.enableScroll
});
},
toggleRotate() {
this.setData({
enableRotate: !this.data.enableRotate
});
},
togglePolygon() {
this.setData({
drawPolygon: !this.data.drawPolygon
});
},
onMarkertap(e) {
console.log('onMarkertap callback:', e);
},
onCallouttap(e) {
console.log('onCallouttap callback:', e);
},
onControltap(e) {
console.log('onControltap callback:', e);
},
onRegionchange(e) {
console.log('onRegionchange callback:', e);
},
onTap(e) {
console.log('onTap callback:', e);
},
onUpdated(e) {
console.log('onUpdated callback:', e);
},
onPoitap(e) {
console.log('onPoitap callback:', e);
}
});
解釋:標(biāo)記點(diǎn),用于在地圖上顯示標(biāo)記的位置。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
markerId | 標(biāo)記點(diǎn) id | Number | 否 | marker 點(diǎn)擊事件回調(diào)會(huì)返回此 id。建議為每個(gè) marker 設(shè)置 Number 類型的 id,保證更新 marker 時(shí)有更好的性能。 |
latitude | 緯度 | Number | 是 | 浮點(diǎn)數(shù),范圍 -90 ~ 90 。 |
longitude | 經(jīng)度 | Number | 是 | 浮點(diǎn)數(shù),范圍 -180 ~ 180 。 |
zIndex | 顯示層級(jí) | Number | 否 | |
iconPath | 顯示的圖標(biāo) | String | 是 | 項(xiàng)目目錄下的圖片路徑,支持網(wǎng)絡(luò)路徑、本地路徑(相對(duì)和絕對(duì)路徑寫法),工具暫不支持絕對(duì)路徑寫法。 |
rotate | 旋轉(zhuǎn)角度 | Number | 否 | 默認(rèn)為 0,順時(shí)針旋轉(zhuǎn)的角度,范圍 0 ~ 360 。 |
alpha | 標(biāo)注的透明度 | Number | 否 | 默認(rèn)為 1,無透明,范圍 0 ~ 1 。 |
width | 標(biāo)注圖標(biāo)寬度 | Number | 否 | 默認(rèn)為圖片實(shí)際寬度 |
height | 標(biāo)注圖標(biāo)高度 | Number | 否 | 默認(rèn)為圖片實(shí)際高度 |
callout | 自定義標(biāo)記點(diǎn)上方的氣泡窗口 | Object | 否 | 支持的屬性見下表,可識(shí)別換行符。 |
label | 為標(biāo)記點(diǎn)旁邊增加標(biāo)簽 | Object | 否 | 支持的屬性見下表,可識(shí)別換行符。 |
anchor | 經(jīng)緯度在標(biāo)注圖標(biāo)的錨點(diǎn) | Object | 否 | 默認(rèn)底邊中點(diǎn),{x, y},x 表示橫向(0-1),y 表示豎向(0-1)。{x: .5, y: 1} 表示底邊中點(diǎn)。 |
屬性名 | 說明 | 類型 | 備注 |
---|---|---|---|
content | 文本 | String | |
color | 文本顏色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
fontSize | 文字大小 | Number | |
borderWidth | 邊框?qū)挾?/td> | Number | |
borderColor | 邊框顏色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
borderRadius | callout 邊框圓角 | Number | |
bgColor | 背景色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
padding | 文本邊緣留白 | Number | |
display | ‘BYCLICK’:點(diǎn)擊顯示; ‘ALWAYS’:常顯 | String | 默認(rèn)為常顯 |
textAlign | 文本對(duì)齊方式。有效值: left , right , center 。 | String | 默認(rèn)為居中對(duì)齊 |
屬性名 | 說明 | 類型 | 備注 |
---|---|---|---|
content | 文本 | String | |
color | 文本顏色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
fontSize | 文字大小 | Number | |
x | label 的坐標(biāo),原點(diǎn)是 marker 對(duì)應(yīng)的經(jīng)緯度 | Number | |
y | label 的坐標(biāo),原點(diǎn)是 marker 對(duì)應(yīng)的經(jīng)緯度 | Number | |
borderWidth | 邊框?qū)挾?/td> | Number | |
borderColor | 邊框顏色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
borderRadius | 邊框圓角 | Number | |
bgColor | 背景色 | String | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
padding | 文本邊緣留白 | Number | |
textAlign | 文本對(duì)齊方式。有效值: left , right , center 。 | String | 默認(rèn)為居中對(duì)齊 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
markers="{{markers}}"
bindmarkertap="bindmarkertap"
bindcallouttap="bindcallouttap">
</map>
</view>
Page({
data: {
latitude: 40.048828,
longitude: 116.280412,
markers: [{
markerId: 1,
latitude: 40.048828,
longitude: 116.280412,
title: 'markerId: 1',
zIndex: 100,
iconPath: '../images/location.png',
rotate: 90,
callout: {
display: 'ALWAYS',
content: '百度科技園',
color: '#000',
fontSize: '16',
borderRadius: 50,
bgColor: '#5B9FFF',
padding: 2,
textAlign: 'center'
}
}, {
markerId: 2,
latitude: 40.049655,
longitude: 116.27505,
title: 'markerId: 2',
zIndex: 100,
rotate: 90,
alpha: 0.5,
width: 30,
height: 50,
label: {
'content': 'label',
'color': '#7B68EE',
'fontSize': 16,
'borderWidth': 1,
'borderColor': '#5B9FFF',
'borderRadius': 50,
'bgColor': '#ADCFFF',
'padding': 5,
'textAlign': 'center'
},
anchor: {x: .5, y: 1},
callout: {
display: 'BYCLICK',
content: '西山壹號(hào)院',
color: '#FFF',
fontSize: '16',
borderRadius: 50,
bgColor: '#5B9FFF',
padding: 2,
textAlign: 'center'
}
}]
},
bindmarkertap() {
swan.showToast({
title: '點(diǎn)擊標(biāo)記啦',
icon: 'none'
});
},
bindcallouttap() {
swan.showToast({
title: '點(diǎn)擊標(biāo)記上方氣泡啦',
icon: 'none'
});
}
});
解釋:指定一系列坐標(biāo)點(diǎn),從數(shù)組第一項(xiàng)連線至最后一項(xiàng)。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
points | 經(jīng)緯度數(shù)組 | Array | 是 | [{latitude: 0, longitude: 0}] |
color | 線的顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
width | 線的寬度 | Number | 否 | |
dottedLine | 是否虛線 | Boolean | 否 | 默認(rèn) false |
arrowLine | 帶箭頭的線 | Boolean | 否 | 默認(rèn) false |
arrowIconPath | 更換箭頭圖標(biāo) | String | 否 | 在 arrowLine 為 true 時(shí)生效 |
borderColor | 線的邊框顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
borderWidth | 線的厚度 | Number | 否 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
polyline="{{polyline}}">
</map>
</view>
解釋:指定一系列坐標(biāo)點(diǎn),根據(jù) points 坐標(biāo)數(shù)據(jù)生成閉合多邊形。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
points | 經(jīng)緯度數(shù)組 | Array | 是 | [{latitude: 0, longitude: 0}] |
strokeWidth | 描邊的寬度 | Number | 否 | |
strokeColor | 描邊的顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
fillColor | 填充顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
zIndex | 設(shè)置多邊形 Z 軸數(shù)值 | Number | 否 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
polygons="{{polygons}}">
</map>
</view>
Page({
data: {
latitude: 40.048828,
longitude: 116.280412,
polygons: [{
points: [{
longitude: 116.278796,
latitude: 40.048828
}, {
longitude: 116.27505,
latitude: 40.049655
},{
longitude: 116.27305,
latitude: 40.050655
},{
longitude: 116.27105,
latitude: 40.051655
}],
strokeWidth: 1,
strokeColor: '#000000AA',
fillColor: '#000000AA',
zIndex: 20
}]
}
});
解釋:在地圖上顯示圓
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
latitude | 緯度 | Number | 是 | 浮點(diǎn)數(shù),范圍 -90 ~ 90 。 |
longitude | 經(jīng)度 | Number | 是 | 浮點(diǎn)數(shù),范圍 -180 ~ 180 。 |
color | 描邊的顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
fillColor | 填充顏色 | String | 否 | 8 位十六進(jìn)制表示,最后 2 位表示 alpha 值(可省略)。 |
radius | 半徑 | Number | 是 | |
strokeWidth | 描邊的寬度 | Number | 否 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
circles="{{circles}}">
</map>
</view>
Page({
data: {
scale: 16,
latitude: 40.048828,
longitude: 116.280412,
circles: [{
latitude: 40.052751,
longitude: 116.278796,
color: '#FF5F41FF',
fillColor: '#FF5F41FF',
radius: 200,
strokeWidth: 2
}]
}
});
解釋:在地圖上顯示控件,控件不隨著地圖移動(dòng)。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
controlId | 控件 id | Number | 否 | 在控件點(diǎn)擊事件回調(diào)會(huì)返回此 id |
position | 控件在地圖的位置 | Object | 是 | 控件相對(duì)地圖位置 |
iconPath | 顯示的圖標(biāo) | String | 是 | 項(xiàng)目目錄下的圖片路徑,支持網(wǎng)絡(luò)路徑、本地路徑(相對(duì)和絕對(duì)路徑寫法),工具暫不支持絕對(duì)路徑寫法。 |
clickable | 是否可點(diǎn)擊 | Boolean | 否 | 默認(rèn)不可點(diǎn)擊 |
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
left | 距離地圖的左邊界多遠(yuǎn) | Number | 否 | 默認(rèn)為 0 |
top | 距離地圖的上邊界多遠(yuǎn) | Number | 否 | 默認(rèn)為 0 |
width | 控件寬度 | Number | 否 | 默認(rèn)為圖片寬度 |
height | 控件高度 | Number | 否 | 默認(rèn)為圖片高度 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
controls="{{controls}}"
bindcontroltap="bindcontroltap"
>
</map>
</view>
Page({
data: {
latitude: 40.048828,
longitude: 116.280412,
controls: [{
controlId: 1,
iconPath: '/images/navigate.png',
position: {
left: 0,
top: 100,
width: 50,
height: 50
},
clickable: true
}]
},
bindcontroltap() {
swan.showToast({
title: '點(diǎn)擊控件',
icon: 'none'
})
}
});
代碼示例 - 錯(cuò)誤用法:原生組件設(shè)置 border 無效,也不可用 cover-view 覆蓋為圓角
<view class="wrap">
<cover-view class="card-area">
<map
longitude="{{longitude}}"
latitude="{{latitude}}">
</map>
</cover-view>
</view>
.card-area {
width: 3.88rem;
height: 2.18rem;
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: