uniapp地图 多边形使用
export default {
data() {
return {
"longitude": 100.789761,
"latitude": 22.022137,
screenHeight: '600px',
markerList: [],
polygons: [{
//多边形的坐标数组
points: [{
"longitude": 100.789761,
"latitude": 22.022137
}, {
"longitude": 100.789833,
"latitude": 22.022136
}, {
"longitude": 100.790838,
"latitude": 22.019582
}, {
"longitude": 100.794509,
"latitude": 22.020163
}, {
"longitude": 100.792928,
"latitude": 22.022182
}, {
"longitude": 100.789761,
"latitude": 22.022137
}],
fillColor: "#55888888", //填充颜色
strokeColor: "#22FF00", //描边颜色
strokeWidth: 2, //描边宽度
zIndex: 1, //层级
}]
}
},
methods: {
mapTap(e) {
console.log(JSON.stringify(e))
console.log('当前位置的经度:' + e.detail.longitude);
console.log('当前位置的纬度:' + e.detail.latitude);
this.markerList.push({
latitude: e.detail.latitude,
longitude: e.detail.longitude,
iconPath: '../../static/'
});
this.markerList = JSON.parse(JSON.stringify(this.markerList));
var poly = [{
points: this.markerList,
fillColor: "#55888888", //填充颜色
strokeColor: "#22FF00", //描边颜色
strokeWidth: 2, //描边宽度
zIndex: 1, //层级
}];
this.polygons = poly;
}
},
onLoad() {
// = ().windowHeight;
uni.getLocation({
type: 'gcj02',
success: res => {
// = ;
// = ;
},
fail: (res) => {
console.log('错误:' + JSON.stringify(res));
}
});
},
onReady() {}
}