function GridAnalysis(option) {
|
this.gridView = []// 网格
|
this.textView = []//文本
|
this.opacity = 0.8//图形默认透明度
|
}
|
|
GridAnalysis.prototype = {
|
/**
|
* 绘制网格
|
* @param points 网格线段坐标点组
|
*/
|
drawGrid: function (points) {
|
this.gridView = [];
|
points.forEach((p) => {
|
let line = MapUtil.parse2LngLat(p);
|
var polyline = new AMap.Polyline({
|
path: line,
|
strokeStyle: 'solid',
|
isOutline: false,
|
borderWeight: 0,
|
outlineColor: 'white',
|
strokeWeight: 2, // 线条宽度,默认为 1
|
strokeColor: '#CC0000', // 线条颜色
|
lineJoin: 'round', // 折线拐点连接处样式
|
showDir: true,
|
});
|
this.gridView.push(polyline);
|
});
|
MapUtil._map.add(this.gridView);
|
},
|
|
/**
|
* 绘制网格风险图
|
* @param {*} points
|
*/
|
drawRectangle: function (points) {
|
var that = this
|
this.clear()
|
|
var gpsList = []
|
points.forEach((p) => {
|
gpsList.push(p.lb, p.rt, p.c)
|
})
|
MapUtil.convertFromGPS(gpsList, function (gd) {
|
for (let i = 0; i < points.length; i++) {
|
const p = points[i];
|
var lb = gd[i * 3]
|
var rt = gd[i * 3 + 1]
|
var c = gd[i * 3 + 2]
|
|
var color = '#990D0D';
|
switch (p.level) {
|
case 0:
|
color = '#990D0D';
|
break;
|
case 1:
|
color = '#DBB70D';
|
break;
|
case 2:
|
color = '#0DE707';
|
break;
|
default:
|
color = '#0DE707';
|
break;
|
}
|
|
let pList = MapUtil.parse2LngLat([lb, rt]);
|
var bounds = new AMap.Bounds(...pList);
|
var rectangle = new AMap.Rectangle({
|
bounds: bounds,
|
// strokeColor: '#ffffffff',
|
strokeWeight: 0,
|
strokeOpacity: 0,
|
// strokeStyle还支持 solid
|
strokeStyle: 'solid',
|
fillColor: color,
|
fillOpacity: that.opacity,
|
cursor: 'pointer',
|
zIndex: 50,
|
});
|
|
var text = new AMap.Text({
|
text: p.value,
|
anchor: 'center', // 设置文本标记锚点
|
draggable: false,
|
style: {
|
'background-color': 'transparent',
|
'border-width': 0,
|
'text-align': 'center',
|
'font-size': '12px',
|
'color': 'white'
|
},
|
position: c
|
});
|
that.gridView.push(rectangle);
|
that.textView.push(text);
|
}
|
MapUtil._map.add(that.gridView);
|
that.toggleText(that.show)
|
})
|
},
|
|
/**
|
* 调整图形透明度
|
* @param show 图形透明度调整
|
*/
|
changeOpacity (show) {
|
|
if (show) {
|
this.opacity = 0.8
|
} else {
|
this.opacity = 0.3
|
}
|
this.gridView.forEach(g => {
|
g.setOptions({
|
fillOpacity: this.opacity,
|
})
|
});
|
},
|
|
/**
|
* 切换文本显示
|
*/
|
toggleText (show) {
|
if (show) {
|
this.show = true
|
MapUtil._map.add(this.textView);
|
} else {
|
this.show = false
|
MapUtil.removeViews(this.textView);
|
}
|
},
|
|
clear() {
|
MapUtil.removeViews(this.gridView);
|
MapUtil.removeViews(this.textView);
|
this.gridView = [];
|
this.textView = [];
|
},
|
};
|