如何在小程序地图中绘制地块形状
步骤一.首先在小程序中引入map
map.wxml 文件
<map id="map" scale="{
{scale}}" longitude="{
{longitude}}" latitude="{
{latitude}}"
controls="{
{controls}}" bindcontroltap="controltap" markers="{
{markers}}" polygons="{
{polygons}}"
scale="{
{mapScale}}" bindcallouttap="markertap" bindregionchange="regionchange" show-location
style="width: 100%; height: 100vh;">
</map>
map.js 文件
onLoad: function (options) {
this.mapCtx = wx.createMapContext('map')
}
在页面加载时创建map对象
步骤二.获取当前地图视野范围
regionchange(e) {
console.log(e)
const now = new Date()
this.timeFlag = now
if(this.timeFlag===now){
let that = this
this.mapCtx = wx.createMapContext('map')
setTimeout(() => {
that.mapCtx.getRegion({
success: function (res) {
that.setData({
min_x: res.southwest.longitude,
max_x: res.northeast.longitude,
max_y: res.northeast.latitude,
min_y: res.southwest.latitude,
})
// 在这里请求数据,创建marker,polygon ,更新页面
that.testDebounce2()
},
fail: function (