zoukankan      html  css  js  c++  java
  • 三维叠加标签代码

     function addLabelEntity(data) {
        
        // viewer.entities.removeAll();
        for (var i = 0; i < data.length; i++) {
            var text;
            if (data[i].NAME) {
                text = data[i].NAME;
            }
    
            var x = parseFloat(data[i].SMX);
            var y = parseFloat(data[i].SMY);
            var z = parseFloat(data[i].HEIGHT);
            var img = document.getElementById("building");
            // var img = new Image()
            // img.src = "../images/menu-bg.png"
            // img.onload = function(){
            // }
            var wWidth = img.width;
            var wHeight = img.height;
            var canvas = document.createElement("canvas");
            if (canvas == null)
                return false;
            canvas.width = wWidth;
            canvas.height = wHeight;
            //canvas.style.letterSpacing = '30px';
            //获取上下文
            var ctx = canvas.getContext('2d');
    
            // ctx.drawImage(img, 0, 0);
            ctx.drawImage(img, 0, 0, wWidth, wHeight, 0, 0, wWidth, wHeight);
            // 设置字体
            if(text.length>8){
                ctx.font = "55px bold 微软雅黑";
            }else{
                ctx.font = "60px bold 微软雅黑";
            }
            // 设置颜色
            ctx.fillStyle = "#fff";
            // 设置水平对齐方式
            ctx.textAlign = "center";
            // 设置垂直对齐方式
            ctx.textBaseline = "middle";
            
            
            var _w = ctx.measureText(text).width;
            var _h = ctx.measureText(text).height;
            // 绘制文字(参数:要写的字,x坐标,y坐标)
            ctx.fillText(text, wWidth / 2, 70);
            //console.log(ctx);
            var entity = viewer.entities.add({
                name: "theme",
                description: null,
                position: Cesium.Cartesian3.fromDegrees(x, y, z),
                billboard: {
                    image: canvas.toDataURL(),
                    horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    scaleByDistance: new Cesium.NearFarScalar(500, 0.5, 10000, 0.0),
                    //  32, // default: undefined
                    // height: 32, // default: undefined
                    // pixelOffset: new Cesium.Cartesian2(0.0, -10.0),
                    // pixelOffsetScaleByDistance: new Cesium.NearFarScalar(100, 15, 5000, 0.0),
                    // color: Cesium.Color.WHITE,
                    // disableDepthTestDistance: Number.POSITIVE_INFINITY//返回正无穷大
                }
            });
        }
    }
  • 相关阅读:
    hdu 2444 交叉染色判断二分图+二分最大匹配
    uva 交叉染色法10004
    poj 3177&&3352 求边双联通分量,先求桥,然后求分量( 临界表代码)
    poj 3177&&poj 3352加边构双联通(有重边)用tarjan 模板求的
    poj 3006水题打素数表
    POJ 3352 无向图边双连通分量,缩点,无重边
    hdu 1430 魔板 康托展开 + 很好的映射
    D. Artsem and Saunders 数学题
    vijos P1412多人背包 DP的前k优解
    1475 建设国家 DP
  • 原文地址:https://www.cnblogs.com/wanlige/p/13260133.html
Copyright © 2011-2022 走看看