微信小程序地图多边形绘制功能示例 - 详细代码教程
{"pages": ["pages/index/index"], "window": {"backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "多边形绘制", "navigationBarTextStyle": "black"}} {"data": {"points": [], "polygon": []}, "onReady": function () {this.mapCtx = wx.createMapContext('map');}, "handleTap": function (e) {const { points, polygon } = this.data; const latitude = e.detail.latitude; const longitude = e.detail.longitude; points.push({ latitude, longitude }); const polygonPoints = points.map(point => ({ latitude: point.latitude, longitude: point.longitude })); polygonPoints.push(polygonPoints[0]); this.setData({ points, polygon: [{ points: polygonPoints, strokeWidth: 2, strokeColor: '#FF0000', fillColor: '#FFD70033' }] }); this.mapCtx.includePoints({ padding: [50], points: points });}} points 数组中,并根据 points 数组绘制多边形。同时,地图会自动缩放以包含所有点击的点。
原文地址: https://www.cveoy.top/t/topic/qBRn 著作权归作者所有。请勿转载和采集!