|
|
@@ -1,13 +1,5 @@
|
|
|
const { createCanvas, loadImage } = require('canvas');
|
|
|
|
|
|
-// // 模拟数据生成函数:根据 x, y, z 返回该瓦片内的温度数据(示例)
|
|
|
-// function generateTemperatureData(z, x, y) {
|
|
|
-// // 这里可以替换为数据库查询、API 调用等
|
|
|
-// const noise = Math.sin(x * 0.5) * Math.cos(y * 0.3) + Math.random() * 0.5;
|
|
|
-// const temp = 10 + 20 * (Math.sin(z) + noise); // 10~30°C 之间
|
|
|
-// return Array(256 * 256).fill().map(() => temp + (Math.random() - 0.5) * 5);
|
|
|
-// }
|
|
|
-
|
|
|
// 温度转颜色(蓝 -> 绿 -> 红)
|
|
|
function tempToColor(temp) {
|
|
|
let r, g, b;
|
|
|
@@ -28,50 +20,6 @@ function tempToColor(temp) {
|
|
|
return [r, g, b];
|
|
|
}
|
|
|
|
|
|
-// exports.tempapixyz = async (req, res) => {
|
|
|
-// const { z, x, y } = req.params;
|
|
|
-// const zoom = parseInt(z);
|
|
|
-// const tileX = parseInt(x);
|
|
|
-// const tileY = parseInt(y);
|
|
|
-
|
|
|
-// // 创建 256x256 画布(标准瓦片大小)
|
|
|
-// const canvas = createCanvas(256, 256);
|
|
|
-// const ctx = canvas.getContext('2d');
|
|
|
-
|
|
|
-// // 生成模拟数据(每个像素一个温度值)
|
|
|
-// const data = generateTemperatureData(zoom, tileX, tileY);
|
|
|
-
|
|
|
-// // 创建图像数据
|
|
|
-// const imageData = ctx.createImageData(256, 256);
|
|
|
-// const pixels = imageData.data;
|
|
|
-
|
|
|
-// for (let i = 0; i < 256; i++) {
|
|
|
-// for (let j = 0; j < 256; j++) {
|
|
|
-// const idx = (i * 256 + j);
|
|
|
-// const temp = data[idx];
|
|
|
-// const [r, g, b] = tempToColor(temp);
|
|
|
-
|
|
|
-// const pixelIdx = (j * 256 + i) * 4;
|
|
|
-// pixels[pixelIdx] = r; // R
|
|
|
-// pixels[pixelIdx + 1] = g; // G
|
|
|
-// pixels[pixelIdx + 2] = b; // B
|
|
|
-// pixels[pixelIdx + 3] = 200; // A (半透明)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// ctx.putImageData(imageData, 0, 0);
|
|
|
-
|
|
|
-// // 可选:添加网格线或边框
|
|
|
-// ctx.strokeStyle = 'rgba(255,255,255,0.2)';
|
|
|
-// ctx.strokeRect(0, 0, 256, 256);
|
|
|
-
|
|
|
-// // 输出 PNG
|
|
|
-// const buffer = canvas.toBuffer('image/png');
|
|
|
-// res.set('Content-Type', 'image/png');
|
|
|
-// res.set('Cache-Control', 'no-cache'); // 实时数据不缓存
|
|
|
-// res.send(buffer);
|
|
|
-// }
|
|
|
-
|
|
|
// 模拟数据集,实际应用中应替换为真实数据
|
|
|
const data = Array(256).fill().map((_, i) =>
|
|
|
Array(256).fill().map((_, j) => {
|