• 三维叠加标签代码


     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//返回正无穷大
                }
            });
        }
    }
  • 相关阅读:
    systemctl无法停掉keepalived
    python小工具
    python pip
    linux下安装python3
    python process
    python socket模块
    python logging日志模块
    板邓:C#的声明数组和赋值
    板邓:解决jquery中全选点击第二次不生效的问题
    板邓:php+mayql分页原理及案例
  • 原文地址:https://www.cnblogs.com/wanlige/p/13260133.html
Copyright © 2020-2023  润新知