百度智能小程序組件 地圖

2020-08-28 15:36 更新

map


解釋?zhuān)旱貓D

屬性說(shuō)明:
屬性名 類(lèi)型 默認(rèn)值 說(shuō)明
longitude Number 中心經(jīng)度
latitude Number 中心緯度
scale Number 16 縮放級(jí)別,取值范圍為4-21
markers Array 標(biāo)記點(diǎn)
polyline Array 路線
circles Array
controls Array 控件
include-points Array 縮放視野以包含所有給定的坐標(biāo)點(diǎn)
show-location Boolean 顯示帶有方向的當(dāng)前定位點(diǎn)
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ā)
markers
標(biāo)記點(diǎn)用于在地圖上顯示標(biāo)記的位置屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型 必填 備注
id 標(biāo)記點(diǎn)id Number marker點(diǎn)擊事件回調(diào)會(huì)返回此id。建議為每個(gè)marker設(shè)置上Number類(lèi)型id,保證更新marker時(shí)有更好的性能。
latitude 緯度 Number 浮點(diǎn)數(shù),范圍 -90 ~ 90
longitude 經(jīng)度 Number 浮點(diǎn)數(shù),范圍 -180 ~ 180
title 標(biāo)注點(diǎn)名 String
iconPath 顯示的圖標(biāo) String 項(xiàng)目目錄下的圖片路徑,支持相對(duì)路徑寫(xiě)法,以’/‘開(kāi)頭則表示相對(duì)智能小程序根目錄;也支持臨時(shí)路徑
rotate 旋轉(zhuǎn)角度 Number 順時(shí)針旋轉(zhuǎn)的角度,范圍 0 ~ 360,默認(rèn)為 0
alpha 標(biāo)注的透明度 Number 默認(rèn)1,無(wú)透明
width 標(biāo)注圖標(biāo)寬度 Number 默認(rèn)為圖片實(shí)際寬度
height 標(biāo)注圖標(biāo)高度 Number 默認(rèn)為圖片實(shí)際高度
callout 自定義標(biāo)記點(diǎn)上方的氣泡窗口 Object 支持的屬性見(jiàn)下表,可識(shí)別換行符。
label 為標(biāo)記點(diǎn)旁邊增加標(biāo)簽 Object 支持的屬性見(jiàn)下表,可識(shí)別換行符。
anchor 經(jīng)緯度在標(biāo)注圖標(biāo)的錨點(diǎn),默認(rèn)底邊中點(diǎn) Object {x, y},x表示橫向(0-1),y表示豎向(0-1)。{x: .5, y: 1} 表示底邊中點(diǎn)
marker 上的氣泡 callout屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型
content 文本 String
color 文本顏色 String
fontSize 文字大小 Number
borderRadius callout邊框圓角 Number
bgColor 背景色 String
padding 文本邊緣留白 Number
display ‘BYCLICK’:點(diǎn)擊顯示; ‘ALWAYS’:常顯 String
textAlign 文本對(duì)齊方式。有效值: left, right, center String
marker 上的氣泡 label屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型
content 文本 String
color 文本顏色 String
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
borderRadius 邊框圓角 Number
bgColor 背景色 String
padding 文本邊緣留白 Number
textAlign 文本對(duì)齊方式。有效值: left, right, center String

polyline


指定一系列坐標(biāo)點(diǎn),從數(shù)組第一項(xiàng)連線至最后一項(xiàng)屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型 必填 備注
points 經(jīng)緯度數(shù)組 Array [{latitude: 0, longitude: 0}]
color 線的顏色 String 8位十六進(jìn)制表示,后兩位表示alpha值,如:#000000AA
width 線的寬度 Number
dottedLine 是否虛線 Boolean 默認(rèn)false
arrowLine 帶箭頭的線 Boolean 默認(rèn)false,開(kāi)發(fā)者工具暫不支持該屬性
arrowIconPath 更換箭頭圖標(biāo) String 在arrowLine為true時(shí)生效
borderColor 線的邊框顏色 String
borderWidth 線的厚度 Number

circles


在地圖上顯示圓屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型 必填 備注
latitude 緯度 Number 浮點(diǎn)數(shù),范圍 -90 ~ 90
longitude 經(jīng)度 Number 浮點(diǎn)數(shù),范圍 -180 ~ 180
color 描邊的顏色 String 8位十六進(jìn)制表示,后兩位表示alpha值,如:#000000AA
fillColor 填充顏色 String 8位十六進(jìn)制表示,后兩位表示alpha值,如:#000000AA
radius 半徑 Number
strokeWidth 描邊的寬度 Number

controls


在地圖上顯示控件,控件不隨著地圖移動(dòng)屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型 必填 備注
id 控件id Number 在控件點(diǎn)擊事件回調(diào)會(huì)返回此id
position 控件在地圖的位置 Object 控件相對(duì)地圖位置
iconPath 顯示的圖標(biāo) String 項(xiàng)目目錄下的圖片路徑,支持相對(duì)路徑寫(xiě)法,以’/‘開(kāi)頭則表示相對(duì)智能小程序根目錄;也支持臨時(shí)路徑
clickable 是否可點(diǎn)擊 Boolean 默認(rèn)不可點(diǎn)擊

position


屬性說(shuō)明:
屬性名 說(shuō)明 類(lèi)型 必填 備注
left 距離地圖的左邊界多遠(yuǎn) Number 默認(rèn)為0
top 距離地圖的上邊界多遠(yuǎn) Number 默認(rèn)為0
width 控件寬度 Number 默認(rèn)為圖片寬度
height 控件高度 Number 默認(rèn)為圖片高度
地圖組件的經(jīng)緯度必填, 如果不填經(jīng)緯度則默認(rèn)值是北京的經(jīng)緯度。  示例:
<!-- map.swan -->
<map id="myMap"
     style="width: 100%"
     scale="{{scale}}"
     longitude="{{longitude}}"
     latitude="{{latitude}}"
     markers="{{markers}}"
     position="{{position}}"
     showLocation="{{showLocation}}"
     polyline="{{polyline}}"
     controls="{{controls}}"
     circles="{{circles}}"
     bindmarkertap="onMarkertap" bindcallouttap="onCallouttap" bindcontroltap="onControltap" bindregionchange="onRegionchange" bindtap="onTap" bindupdated="onUpdated"></map>
Page({
    data: {
        scale: 16,
        latitude: '40.048828',
        longitude: '116.280412',
        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)院'
            }
        }],
        showLocation: '1',
        polyline: [{
            points: [{
                longitude: 116.278796,
                latitude: 40.048828
            }, {
                longitude: 116.27505,
                latitude: 40.049655
            }],
            color: '#FF5F41FF',
            width: 2,
            dottedLine: true
        }],
        controls: [{
            controlId: 1,
            iconPath: '/images/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'
        }]
    },
    onReady() {
        console.log('map ready');
        this.mapContext = swan.createMapContext('myMap');
    },
    onMarkertap(e) {
        console.log('onMarkertap callback:');
        console.log(e);
    },
    onCallouttap(e) {
        console.log('onCallouttap callback:');
        console.log(e);
    },
    onControltap(e) {
        console.log('onControltap callback:');
        console.log(e);
    },
    onRegionchange(e) {
        console.log('onRegionchange callback:');
        console.log(e);
    },
    onTap(e) {
        console.log('onTap callback:');
        console.log(e);
    },
    onUpdated(e) {
        console.log('onUpdated callback::');
        console.log(e);
    }
}
Tips:

1、map 組件是由客戶(hù)端創(chuàng)建的原生組件,它的層級(jí)是最高的,不能通過(guò) z-index 控制層級(jí)

2、請(qǐng)勿在 scroll-view、swiper、picker-view、movable-view 中使用 map 組件

3、CSS 動(dòng)畫(huà)對(duì) map 組件無(wú)效

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)