let construct3DRectangle = function (options) {
|
let dx = options.xMax - options.xMin;
|
let dy = options.yMax - options.yMin;
|
let width = options.width;
|
let height = options.height;
|
let gx = dx / width;
|
let gy = dy / height;
|
|
let wgwidth = width;
|
let wgheight = height + 1;
|
|
let positions = [];
|
let st = [];
|
let indexs = [];
|
|
//
|
for (let i = 0; i < wgheight; i++) {
|
for (let j = 0; j < wgwidth; j++) {
|
let degx = options.xMin + gx * j;
|
let degy = options.yMin + gy * i;
|
/**
|
* 计算结果
|
*/
|
let result = getValueFromDegrees({ lon: degx, lat: degy });
|
// if (!result.tooFar) {
|
let point = Cesium.Cartesian3.fromDegrees(
|
degx,
|
degy,
|
// (getValueFromDegrees({ lon: degx, lat: degy }) || 0) * options.scale + options.z
|
result.minDistanceHeight
|
);
|
|
positions.push(point.x, point.y, point.z);
|
|
st.push((gx * j) / dx, (gy * i) / dy);
|
|
if (i != 0 && j != 0) {
|
indexs.push(
|
(i - 1) * wgwidth + (j - 1),
|
(i - 1) * wgwidth + j,
|
i * wgwidth + j - 1
|
);
|
|
indexs.push(
|
(i - 1) * wgwidth + j,
|
i * wgwidth + j,
|
i * wgwidth + j - 1
|
)
|
}
|
// }
|
}
|
}
|
return {
|
positions,
|
st,
|
indexs,
|
};
|
};
|
let getValueFromDegrees = function (degrees) {
|
|
// return Math.random() * 10 + 340;
|
/**
|
* 测试 遍历最近点
|
*/
|
let minDistance = 9999999999999;
|
let minDistanceHeight = 0;
|
for (let k = 0; k < chunkedData.length; k++) {
|
let distance = Math.pow((degrees.lon - chunkedData[k][0]), 2) + Math.pow((degrees.lat - chunkedData[k][1]), 2);
|
if (distance < minDistance) {
|
minDistance = distance;
|
minDistanceHeight = chunkedData[k][2];
|
}
|
}
|
return { minDistanceHeight, tooFar: Boolean(minDistance > 0.05) };
|
|
|
// if (this.heatmapInstance && this.extent && degrees) {
|
// let x = (degrees.lon - this.extent.xMin) / (this.extent.xMax - this.extent.xMin) * this.heatmapcanvas.width;
|
// let y = (-(degrees.lat - this.extent.yMin) / (this.extent.yMax - this.extent.yMin) + 1) * this.heatmapcanvas.height;
|
// if (x <= this.heatmapcanvas.width && x >= 0 & y <= this.heatmapcanvas.height && y >= 0) {
|
// return this.heatmapInstance.getValueAt({
|
// x: Math.round(x),
|
// y: Math.round(y)
|
// });
|
// }
|
// }
|
}
|
// getHeatmapData = function (bounds, data, num = 600) {
|
// let heatmapData = [];
|
// for (let i = 0; i < num; i++) {
|
// let x = Math.random() * (bounds.east - bounds.west) + bounds.west;
|
// let y = Math.random() * (bounds.north - bounds.south) + bounds.south;
|
// let value = data.value || Math.random() * (data.max - data.min) + data.min;
|
// heatmapData.push({ x: x, y: y, value: value });
|
// }
|
// return heatmapData;
|
// }
|
let create3DGeometry = function (option) {
|
let rect = construct3DRectangle(option);
|
let geometry = new Cesium.Geometry({
|
attributes: {
|
position: new Cesium.GeometryAttribute({
|
componentDatatype: Cesium.ComponentDatatype.DOUBLE,
|
componentsPerAttribute: 3,
|
values: rect.positions,
|
}),
|
st: new Cesium.GeometryAttribute({
|
componentDatatype: Cesium.ComponentDatatype.FLOAT,
|
componentsPerAttribute: 2,
|
values: rect.st,
|
}),
|
},
|
//索引
|
indices: rect.indexs,
|
//绘制类型
|
primitiveType: option.grid ? Cesium.PrimitiveType.LINES : Cesium.PrimitiveType.TRIANGLES,
|
boundingSphere: Cesium.BoundingSphere.fromVertices(rect.positions),
|
});
|
return geometry;
|
};
|