W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋:地圖,客戶端創(chuàng)建的 原生組件,使用時請注意相關(guān)限制。
屬性名 | 類型 | 默認值 | 必填 | 說明 | 最低版本 | Web 態(tài)說明 |
---|---|---|---|---|---|---|
longitude | Number | 是 | gcj02 坐標系中心經(jīng)度 | - | - | |
latitude | Number | 是 | gcj02 坐標系中心緯度 | - | - | |
scale | Number | 16 | 否 | 縮放級別,取值范圍為 4-21 。 | - | - |
markers | Array.<marker> | 否 | 標記點 | - | - | |
polyline | Array.<polyline> | 否 | 路線 | - | - | |
polygons | Array.<polygon> | 否 | 多邊形(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
- | |
circles | Array.<circle> | 否 | 圓 | - | - | |
controls | Array.<control> | 否 | 控件 | - | - | |
include-points | Array.<point> | 否 | 縮放視野以包含所有給定的坐標點 | - | - | |
show-location | Boolean | false | 否 | 顯示帶有方向的當前定位點 | - | 暫時不能顯示方向 |
enable-3D | Boolean | false | 否 | 顯示 3D 樓塊(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
暫不支持 |
show-compass | Boolean | false | 否 | 顯示指南針(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
暫不支持 |
enable-overlooking | Boolean | false | 否 | 開啟俯視(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
暫不支持 |
enable-zoom | Boolean | true | 否 | 是否支持縮放(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
- |
enable-scroll | Boolean | true | 否 | 是否支持拖動(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
- |
enable-rotate | Boolean | false | 否 | 是否支持旋轉(zhuǎn)(工具暫不支持) | 2.0.13
低版本請做兼容性處理 |
暫不支持 |
bindmarkertap | EventHandle | 否 | 點擊標記點時觸發(fā) | - | - | |
bindcallouttap | EventHandle | 否 | 點擊標記點對應的氣泡時觸發(fā) | - | - | |
bindcontroltap | EventHandle | 否 | 點擊控件時觸發(fā) | - | - | |
bindregionchange | EventHandle | 否 | 視野發(fā)生變化時觸發(fā) | - | - | |
bindtap | EventHandle | 否 | 點擊地圖時觸發(fā) | - | - | |
bindupdated | EventHandle | 否 | 在地圖渲染更新完成時觸發(fā) | - | - | |
bindpoitap | EventHandle | 否 | 點擊地圖 poi 點時觸發(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">支持拖動</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: '西山壹號院'
}
}],
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);
}
});
解釋:標記點,用于在地圖上顯示標記的位置。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
markerId | 標記點 id | Number | 否 | marker 點擊事件回調(diào)會返回此 id。建議為每個 marker 設置 Number 類型的 id,保證更新 marker 時有更好的性能。 |
latitude | 緯度 | Number | 是 | 浮點數(shù),范圍 -90 ~ 90 。 |
longitude | 經(jīng)度 | Number | 是 | 浮點數(shù),范圍 -180 ~ 180 。 |
zIndex | 顯示層級 | Number | 否 | |
iconPath | 顯示的圖標 | String | 是 | 項目目錄下的圖片路徑,支持網(wǎng)絡路徑、本地路徑(相對和絕對路徑寫法),工具暫不支持絕對路徑寫法。 |
rotate | 旋轉(zhuǎn)角度 | Number | 否 | 默認為 0,順時針旋轉(zhuǎn)的角度,范圍 0 ~ 360 。 |
alpha | 標注的透明度 | Number | 否 | 默認為 1,無透明,范圍 0 ~ 1 。 |
width | 標注圖標寬度 | Number | 否 | 默認為圖片實際寬度 |
height | 標注圖標高度 | Number | 否 | 默認為圖片實際高度 |
callout | 自定義標記點上方的氣泡窗口 | Object | 否 | 支持的屬性見下表,可識別換行符。 |
label | 為標記點旁邊增加標簽 | Object | 否 | 支持的屬性見下表,可識別換行符。 |
anchor | 經(jīng)緯度在標注圖標的錨點 | Object | 否 | 默認底邊中點,{x, y},x 表示橫向(0-1),y 表示豎向(0-1)。{x: .5, y: 1} 表示底邊中點。 |
屬性名 | 說明 | 類型 | 備注 |
---|---|---|---|
content | 文本 | String | |
color | 文本顏色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
fontSize | 文字大小 | Number | |
borderWidth | 邊框?qū)挾?/td> | Number | |
borderColor | 邊框顏色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
borderRadius | callout 邊框圓角 | Number | |
bgColor | 背景色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
padding | 文本邊緣留白 | Number | |
display | ‘BYCLICK’:點擊顯示; ‘ALWAYS’:常顯 | String | 默認為常顯 |
textAlign | 文本對齊方式。有效值: left , right , center 。 | String | 默認為居中對齊 |
屬性名 | 說明 | 類型 | 備注 |
---|---|---|---|
content | 文本 | String | |
color | 文本顏色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
fontSize | 文字大小 | Number | |
x | label 的坐標,原點是 marker 對應的經(jīng)緯度 | Number | |
y | label 的坐標,原點是 marker 對應的經(jīng)緯度 | Number | |
borderWidth | 邊框?qū)挾?/td> | Number | |
borderColor | 邊框顏色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
borderRadius | 邊框圓角 | Number | |
bgColor | 背景色 | String | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
padding | 文本邊緣留白 | Number | |
textAlign | 文本對齊方式。有效值: left , right , center 。 | String | 默認為居中對齊 |
圖片示例
<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: '西山壹號院',
color: '#FFF',
fontSize: '16',
borderRadius: 50,
bgColor: '#5B9FFF',
padding: 2,
textAlign: 'center'
}
}]
},
bindmarkertap() {
swan.showToast({
title: '點擊標記啦',
icon: 'none'
});
},
bindcallouttap() {
swan.showToast({
title: '點擊標記上方氣泡啦',
icon: 'none'
});
}
});
解釋:指定一系列坐標點,從數(shù)組第一項連線至最后一項。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
points | 經(jīng)緯度數(shù)組 | Array | 是 | [{latitude: 0, longitude: 0}] |
color | 線的顏色 | String | 否 | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
width | 線的寬度 | Number | 否 | |
dottedLine | 是否虛線 | Boolean | 否 | 默認 false |
arrowLine | 帶箭頭的線 | Boolean | 否 | 默認 false |
arrowIconPath | 更換箭頭圖標 | String | 否 | 在 arrowLine 為 true 時生效 |
borderColor | 線的邊框顏色 | String | 否 | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
borderWidth | 線的厚度 | Number | 否 |
圖片示例
<view class="wrap">
<map
style="width: 100%; height: 300px;"
longitude="{{longitude}}"
latitude="{{latitude}}"
polyline="{{polyline}}">
</map>
</view>
解釋:指定一系列坐標點,根據(jù) points 坐標數(shù)據(jù)生成閉合多邊形。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
points | 經(jīng)緯度數(shù)組 | Array | 是 | [{latitude: 0, longitude: 0}] |
strokeWidth | 描邊的寬度 | Number | 否 | |
strokeColor | 描邊的顏色 | String | 否 | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
fillColor | 填充顏色 | String | 否 | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
zIndex | 設置多邊形 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 | 是 | 浮點數(shù),范圍 -90 ~ 90 。 |
longitude | 經(jīng)度 | Number | 是 | 浮點數(shù),范圍 -180 ~ 180 。 |
color | 描邊的顏色 | String | 否 | 8 位十六進制表示,最后 2 位表示 alpha 值(可省略)。 |
fillColor | 填充顏色 | String | 否 | 8 位十六進制表示,最后 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
}]
}
});
解釋:在地圖上顯示控件,控件不隨著地圖移動。
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
controlId | 控件 id | Number | 否 | 在控件點擊事件回調(diào)會返回此 id |
position | 控件在地圖的位置 | Object | 是 | 控件相對地圖位置 |
iconPath | 顯示的圖標 | String | 是 | 項目目錄下的圖片路徑,支持網(wǎng)絡路徑、本地路徑(相對和絕對路徑寫法),工具暫不支持絕對路徑寫法。 |
clickable | 是否可點擊 | Boolean | 否 | 默認不可點擊 |
屬性名 | 說明 | 類型 | 必填 | 備注 |
---|---|---|---|---|
left | 距離地圖的左邊界多遠 | Number | 否 | 默認為 0 |
top | 距離地圖的上邊界多遠 | Number | 否 | 默認為 0 |
width | 控件寬度 | Number | 否 | 默認為圖片寬度 |
height | 控件高度 | Number | 否 | 默認為圖片高度 |
圖片示例
<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: '點擊控件',
icon: 'none'
})
}
});
代碼示例 - 錯誤用法:原生組件設置 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號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: