根据城市名称来下载离线地图包
[!TIP|labelVisibility:hidden|iconVisibility:hidden] downloadOfflineMapWithCityName(list, onlyWifiDownload, resultCallback)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
list | StringArray | 是 | 城市名称数组 |
onlyWifiDownload | Boolean | 否 | 仅WiFi下下载 |
resultCallback | Function | 是 | 回调函数 |
list
为字符串数组StringArray
,数组里是要下载的离线城市的名称
onlyWifiDownload
默认为true
设置是否仅在WiFi
环境下下载离线地图
true
-- 仅在WiFi
环境下下载离线地图,当网络环境切换为非WiFi
环境时会,自动暂停下载,再切换回WiFi
环境时会继续下载。false
-- 在非WiFi
环境下会弹出提示框(当前为非Wi-Fi
网络,下载离线数据将产生流量费用,是否继续下载)点击继续则开始下载,点击取消则取消此次下载。网络环境的切换不会暂停下载。
resultCallback
函数会返回一个对象,其属性包含以下一项或多项:
success
(Boolean)true
-- 成功false
-- 失败
data
(对象数组ObjectArray
) -- 数据对象数组,数组中的对象属性包含以下几项:status
(Int)-- 下载任务当前状态- 100-- 已插入队列,等待中
- 101-- 开始下载
- 102-- 下载中
- 103-- 下载成功
- 104-- 暂停
- 105-- 解压缩中
- 106-- 完成
- 107-- 发生错误
cityName
(String) -- 城市名称provinceName
(String) -- 省份名称cityCode
(String) -- 城市编码progress
(Int) -- 下载进度,范围 [0, 100]
message
(String) -- 成功或者失败的相关信息
示例代码
<template>
<div class="wrapper">
<hcm-amap class="map" ref="map"
:zoomLevel="map.zoomLevel"
:showScale="map.showScale"
:center="map.center"
:showPositioning="map.showPositioning"
:showUserLocation="true">
</hcm-amap>
<text class="close" @click="close">关闭</text>
</div>
</template>
<script>
const modal = weex.requireModule('modal')
const amap = weex.requireModule('amap')
const offline = weex.requireModule('amap-offline')
export default {
data () {
return {
map: {
zoomLevel: 16,
showScale: false,
showPositioning: true,
showUserLocation: false,
center: {
latitude: 30.238753,
longitude: 120.145336
}
}
}
},
mounted () {
offline.downloadOfflineMapWithCityName(['杭州市', '北京市'], true, function (res) {
if (res.success) {
modal.toast({
message: JSON.stringify(res)
})
} else {
modal.alert({
message: res.message
})
}
})
},
methods: {
close () {
amap.close()
}
}
}
</script>
<style scoped>
.wrapper {
flex: 1;
}
.map {
flex: 1;
}
.close {
position: absolute;
top: 40px;
right: 30px;
width: 88px;
height: 88px;
background-color: white;
text-align: center;
line-height: 88px;
font-size: 30px;
border-radius: 44px;
}
</style>