地图组件。
使用前,需参考开发准备完成基本准备工作。
如果需要在地图上显示用户位置,需要申请位置权限或是使用位置控件,申请方式请参考开启“我的位置”按钮 方式二。
起始版本:1.0.0
关联文档:has.createMapContext
名称 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
latitude | number | 39.9153935 | 是 | 中心纬度。默认为天安门的纬度。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
longitude | number | 116.4041457 | 是 | 中心经度。默认为天安门的经度。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
scale | number | 16 | 否 | 缩放级别,取值范围为2-20。 |
markers | Array<marker> | - | 否 | 标记点,详见Marker说明。 |
circles | Array<circle> | - | 否 | 圆。 |
polyline | Array<polyline> | - | 否 | 路线。 |
show-location | boolean | FALSE | 否 | 显示带有方向的当前定位点。 |
bindtap | event | - | 否 | 点击地图时触发。 |
bindmarkertap | event | - | 否 | 点击标记点时触发,e.detail = {markerId}。 |
bindupdated | event | - | 否 | 在地图渲染更新完成时触发。 |
名称 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
id | number | - | 是 | 标记点 id,marker 点击事件回调会返回此 id。 |
latitude | number | - | 是 | 纬度,浮点数,范围 -90 ~ 90。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
longitude | number | - | 是 | 经度,浮点数,范围 -180 ~ 180。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
title | string | - | 否 | 标注点名,点击时显示。 |
zIndex | number | - | 否 | 显示层级。 |
iconPath | string | - | 是 | 支持网络路径、本地路径、代码包路径。 |
rotate | number | 0 | 否 | 顺时针旋转的角度,范围 0 ~ 360,默认为 0。 |
alpha | number | 1 | 否 | 标注的透明度,默认 1,无透明,范围 0 ~ 1。 |
anchor | Object | - | 否 | 经纬度在标注图标的锚点,默认底边中点。{x, y},x 表示横向(0-1),y 表示竖向(0-1)。{x: .5, y: 1} 表示底边中点。 |
clickable | boolean | FALSE | 否 | 标记是否可以点击,默认值为false,异常值按默认值处理。true:可点击 false:不可点击。 |
名称 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
latitude | number | - | 是 | 纬度,浮点数,范围 -90 ~ 90。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
longitude | number | - | 是 | 经度,浮点数,范围 -180 ~ 180。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
color | string | #ff000000 | 否 | 描边的颜色。 |
fillColor | string | #00000000 | 否 | 填充颜色。 |
radius | number | - | 是 | 圆的半径,单位 “米”。 |
strokeWidth | number | 3 | 否 | 描边的宽度px。 |
zIndex | number | - | z轴排序,用于描述压盖关系。 |
名称 | 类型 | 默认值 | 必填 | 描述 |
|---|---|---|---|---|
points | array | - | 是 | [{latitude: 0, longitude: 0}]经纬度数组。 说明: 中国大陆及港澳地区,请使用 gcj02,其他地区请使用 wgs84。 |
color | Color | "#ff000000" | 否 | 线的颜色。 |
zIndex | number | - | 否 | z轴坐标。 |
hxml文件:
<view>
<map
id="map"
style="width: 100%; height: 100vh"
circles="{{circles}}"
latitude="{{latitude}}"
longitude="{{longitude}}"
markers="{{markers}}"
polyline="{{polyline}}"
scale="{{scale}}"
show-location="{{showLocation}}"
bindmarkertap="bindmarkertap"
bindtap="bindtap"
bindupdated="bindupdated"
/>
</view> js代码
Page({
data: {
_mapContext: null,
showLocation: true,
circles: [
{
latitude: 23.306574,
longitude: 113.324587,
radius: 1230,
fillColor: "#ffcd2222",
color: "#ff369b1d",
strokeWidth: 10,
zIndex: 15,
},
],
latitude: 23.106574,
//纬度
longitude: 113.324587,
//经度
scale: 10,
//缩放级别
markers: [
{
id: 0,
latitude: 23.13065, //纬度
longitude: 113.3274, //经度
clickable: true,
zIndex: 1,
//显示的图标
iconPath: "xxx/xxx.png", //显示的图标
rotate: 10, // 旋转度数
width: 20, //宽
height: 30, //高
title: "我在这里,0", //标注点名
alpha: 0.5, //透明度
anchor: { x: 0.5, y: 1 },
clickable: true,
},
{
id: 1234597,
latitude: 23.106574, //纬度
longitude: 113.324587, //经度
clickable: true,
zIndex: 1,
iconPath: "xxx/xxx.png", //显示的图标
rotate: 120, // 旋转度数
width: 20, //宽
height: 30, //高
title: "我在这里,1234597", //标注点名
alpha: 0.5, //透明度
anchor: { x: 0.5, y: 1 },
clickable: true,
},
],
polyline: [
{
// 折线坐标点,必传
points: [
{
latitude: 23.106574,
longitude: 113.324587,
},
{
latitude: 23.13065,
longitude: 113.3274,
},
],
color: "#ff369b1d",
zIndex: 0,
},
],
},
//地图点击事件
bindmarkertap: function bindmarkertap(e) {
console.log("markertap标记=", e);
},
//地图点击事件
bindtap: function bindtap(e) {
console.log("bindtap标记=", e);
},
//地图点击事件
bindupdated: function bindupdated(e) {
console.log("bindupdated标记=", e);
},
});