首页 / 浏览问题 / 三维GIS / 问题详情
在发布出来的三维场景里面的建筑物点击出现弹出气泡
84EXP 2017年09月07日
在浏览器中加载出来的三维图,点击建筑物怎样能和案例那样出现一个气泡,为什么我一直没有气泡

1个回答

您好,对照下范例,检查您的代码。或者 您发下 我可以帮您看下
11EXP 2017年09月08日
var sceneControl = null;
var scene = null;
var htmlUrl = document.location.host;
var layer3D = null;
var infoPage = "noInfo.htm";
var bubble = null;
//判断网页的打开方式是本地打开还是通过网络打开
//不同的打开方式url赋值不同
if(htmlUrl == "")
{
    htmlUrl = "http://localhost:8090";
}
else
{
    htmlUrl = "http://" + htmlUrl;
}
function onPageLoad()
{
    //初始化三维场景控件
    try
    {
       //初始化三维场景控件实例,参数为包含控件的HTML元素
        sceneControl = new SuperMap.Web.UI.Controls.SceneControl($get("ControlDiv"), initCallback, failedCallback);    
    }
    catch(e)
    {   
        //若没有安装插件,则抛出该异常
        if (e.name == SuperMap.Web.Realspace.ExceptionName.PlugInNotInstalled)
        {
            var url = htmlUrl + "/iserver/iClient/for3D/plugin/Setup.exe";
            document.write(" <a href='"+url+"'>未检测到 SuperMap iClient3D for  Plugin 插件,请单击此处下载并安装插件。 </a>");
            return;
        }
        //若使用非IE浏览器,则抛出该异常
        else if (e.name == SuperMap.Web.Realspace.ExceptionName.BrowserNotSupport)
        {
            document.write(" <p>SuperMap iClient3D for  Plugin 目前仅支持 InternetExplorer 浏览器,请更换浏览器后重新尝试加载本页面。 </p>");
            return;
        }
        //抛出其他异常
        else
        {
            alert(e.message);
        }    
    }               
}

//控件初始化完成后的回调函数,初始化完成之后才能进行数据加载
function initCallback() {
    
    //获取Realspace控件的场景,控件和场景是一对一的捆绑关系
    scene = sceneControl.get_scene("http://192.168.1.131:8090/iserver/services/3D-beijing3D/rest/realspace/scenes");
    var isOpen = scene.open("http://192.168.1.131:8090/iserver/services/3D-beijing3D/rest/realspace","BeiJing3D");
    var layer3d1 = new SuperMap.Web.Realspace.Layer3D("http://192.168.1.131:8090/iserver/services/3D-beijing3D/rest/realspace","Build@3D_BeiJing","Build",SuperMap.Web.Realspace.Layer3DType.VECTOR);
    screenLayer = scene.get_screenLayer3D();
    //设置三维图层的可选状态
           layer3d1.set_isSelectable (true);
    //设置三维图层的可见状态
           layer3d1.set_isVisible (true);
           layer3d1.updateData();
           sceneControl.addEvent("objectSelected",objectSelected);
           sceneControl.addEvent("bubbleInitialize",bubbleInitialize);
           sceneControl.addEvent("bubbleResize",bubbleResize);
           sceneControl.addEvent("bubbleClose",bubbleClose);
         //添加屏幕图层文本
            try{
                var anchorPoint = new SuperMap.Web.Core.Point3D(510791.54,312097.98,36);
                var txtPart3D = new SuperMap.Web.Core.TextPart3D("设置气泡任一属性后,需要关闭当前气泡,选择模型对象,弹出新气泡,修改属性生效", anchorPoint);   
                var textArray = [txtPart3D];
                var text3D = new SuperMap.Web.Core.GeoText3D(textArray);
                
                var feature3D = new SuperMap.Web.Core.Feature3D();
                feature3D.set_geometry(text3D);
                
                var textStyle = new SuperMap.Web.Core.TextStyle3D();
                textStyle.set_foreColor(new SuperMap.Web.Core.Color(255,0,0,255));
                textStyle.set_backColor(new SuperMap.Web.Core.Color(0,0,0,255));
                textStyle.set_outline(true);
                textStyle.set_fontName("微软雅黑");
                textStyle.set_fontScale(0.8);
                feature3D.set_textStyle3D(textStyle);
                
                scene.get_screenLayer3D().add(feature3D,"Text");
                scene.get_screenLayer3D().set_isVisible(true);
                
            }
            catch(e){
                alert("屏幕图层添加文字失败");
            }
        }
//控件初始化失败后的回调函数
function failedCallback() {
    alert("Realspace initialized failed!");
}
function objectSelected(selected3d){
        console.log(selected3d);
        var objId = selected3d[0].get_item(0);
        var objInLayer3D = selected3d[0].get_layer3D();
        var featrue3D = objInLayer3D.findFeature3DByID(objId);
        var point3D = null;
        if (featrue3D) {
            point3D = featrue3D.get_geometry().get_position();
        }
        
        var featureName = featrue3D.get_name();
        switch(objId){
            case 206:
                infoPage = "Info_1.htm";
                break;
            case 156:
                infoPage = "Info_3.htm";
                break;
            case 17:
                infoPage = "Info_2.htm";
                break;
            default:
                infoPage = "noInfo.htm";
                break;
        }
        createBubble(point3D);
    }
function createBubble(pos){
    try{
            bubble = new SuperMap.Web.Realspace.Bubble();
            bubble.set_pointer(pos);

            var textStyle3D = new SuperMap.Web.Core.TextStyle3D();
            //设置气泡标题内容
            var title = textStyle3D.set_fontName("你好");
            if (title != null) {
                bubble.set_title(title);
            }
            bubble.set_titleTextStyle3D(textStyle3D);                      
            bubble.set_frameColor(new SuperMap.Web.Core.Color(255,255,255,255));    
            bubble.set_height(400);
            bubble.set_width(500);
            sceneControl.get_bubbles().removeAll();
            sceneControl.get_bubbles().add(bubble);
        }
    catch(e){
        alert("创建气泡失败");
    }   
}

function bubbleInitialize(bubble){
    try
    {
        var frameInfo = document.getElementById("infoWindow");
        frameInfo.style.display = "block";
        frameInfo.src = infoPage;            
        
        frameInfo.frameborder = 0;
        frameInfo.style.marginwidth = 0;
        frameInfo.style.marginheight = 0;
        
        frameInfo.style.width = bubble.get_clientWidth()+"px";
        frameInfo.style.height = bubble.get_clientHeight()+"px";
        frameInfo.style.left = bubble.get_clientLeft() + sceneControl.get_controlOffsetX()+"px";
        frameInfo.style.top = bubble.get_clientTop() + sceneControl.get_controlOffsetY()+"px";
    }
    catch(e){
        alert("Faile to initialize bubble");
    }
}

function bubbleResize(bubble){
    try
    {
        var frameInfo = document.getElementById("infoWindow");
        frameInfo.style.display = "block";
        frameInfo.src = infoPage;
                
        frameInfo.style.width = bubble.get_clientWidth()+"px";
        frameInfo.style.height = bubble.get_clientHeight()+"px";
        frameInfo.style.left = bubble.get_clientLeft() + sceneControl.get_controlOffsetX()+"px";
        frameInfo.style.top = bubble.get_clientTop() + sceneControl.get_controlOffsetY()+"px";
    }
    catch(e)
    {
        alert("Failed to resize bubble");
    }
}

//关闭气泡
function bubbleClose(bubble){
    try
    {
        var frameInfo = document.getElementById("infoWindow");
        frameInfo.style.display = "none";
        
        var selection3Ds = scene.findSelection3Ds(true);
        if (selection3Ds.length > 0) {
            for(var i = 0; i <= selection3Ds.length - 1; i++){
                selection3Ds[i].removeAll();
            }
        }
    }
    catch(e){
        alert("Failed to close bubble");
    }
}
...