var ThermalMap = { toMaterial:function(option,side){ // create svg element var svgtemp = document.getElementById('svgtemp' + side); if (!svgtemp) { svgtemp = document.createElement('svgtemp' + side); document.body.appendChild(svgtemp); } //generate themal map this.create('#svgtemp' + side,option); //convert svg to image var img = document.getElementById('imgsvg' + side); if (!img){ img = new Image(); img.setAttribute("id", "imgsvg" + side); document.body.appendChild(img); } var serializer = new XMLSerializer(); var svgStr = serializer.serializeToString(svgtemp.lastChild); //console.log(svgStr); img.src = 'data:image/svg+xml;base64,'+window.btoa(svgStr); //img.style.visibility = 'hidden'; img.style.display = 'none'; //generate texture var canvas = document.getElementById('canvas' + side); if (!canvas) { canvas = document.createElement('canvas'); canvas.setAttribute("id", 'canvas' + side); document.body.appendChild(canvas); } //canvas.style.visibility = 'hidden'; canvas.style.display = 'none'; //var canvas = document.createElement('canvas'); var context = canvas.getContext("2d"); canvas.width = option.panel.width; canvas.height = option.panel.height; context.drawImage(img,0,0,canvas.width,canvas.height); //img.style.visibility = 'hidden'; img.style.display = 'none'; var texture = new THREE.Texture(canvas); texture.needsUpdate = true; var material = new THREE.MeshBasicMaterial( { map: texture, side: THREE.DoubleSide, transparent: true, opacity: 0.7,depthWrite:false} ); material.needsUpdate = true; //var material = new THREE.MeshBasicMaterial( {color: 0xffff00, side: THREE.DoubleSide} ); //param.shininess = 100; //param.envMap = reflectionCube; return material; }, create:function(id,option){ var tm = {}; var span = 3;//颗粒度,这是测试过没有颗粒感的最佳效果,如果小了CPU和内存受不了 tm.init = function(id, option,span){ // var tooltip = d3.select("body") // .append("div") // .style("position", "absolute") // .style("z-index", "10") // .style("visibility", "hidden") // .text("a simple tooltip"); // 颜色Array(255,0,255)格式转为#FF00FF function rgb2color(rgb) { var s = "#"; for (var i = 0; i < 3; i++) { var c = Math.round(rgb[i]).toString(16); if (c.length == 1) c = '0' + c; s += c; } return s.toUpperCase(); } function getHeatMapColor(value) { var resultColor = []; var color = [ [0,0,1], [0,1,0], [1,1,0], [1,0,0] ]; var idx1; // |-- Our desired color will be between these two indexes in "color". var idx2; // | var fractBetween = 0; // Fraction between "idx1" and "idx2" where our value is. if(value <= 0) { idx1 = idx2 = 0; } // accounts for an input <=0 else if(value >= 1) { idx1 = idx2 = 3; } // accounts for an input >=0 else { value = value * 3; // Will multiply value by 3. idx1 = Math.floor(value); // Our desired color will be after this index. idx2 = idx1+1; // ... and before this index (inclusive). fractBetween = value - idx1; // Distance between the two indexes (0-1). } resultColor.push(((color[idx2][2] - color[idx1][2])*fractBetween + color[idx1][2]) * 255);//blue resultColor.push(((color[idx2][1] - color[idx1][1])*fractBetween + color[idx1][1]) * 255);//green resultColor.push(((color[idx2][0] - color[idx1][0])*fractBetween + color[idx1][0]) * 255);//red return resultColor } //任一点与指定的几个点的距离是d1,d2,d3等。 //指定点的温度是t1,t2,t3, //那么任一点的温度可以通过公式(t1/d1+t2/d2+t3/d3)/(1/d1+1/d2+1/d3)得到 var pickPointColor = function(x,y,sensors){ var distances = []; var res ={}; for(var i=0;i