运行范例

描述

该范例展示如何批量隐藏模型

SceneControl是对应的三维控件,可根据该控件获取场景Scene

代码 (文件格式为 UTF-8)


<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>三维场景浏览</title>
		<script type="text/javascript" src="SuperMap.Include.js" ></script>
		<script type="text/javascript">
			var sceneControl = null;
			var scene = null;
			var htmlUrl = document.location.host;
			//判断网页的打开方式是本地打开还是通过网络打开
			//不同的打开方式url赋值不同
			if(htmlUrl == "")
			{
				htmlUrl = "http://localhost:8090";
			}
			else
			{
				htmlUrl = "http://" + htmlUrl;
			}
            var strServerUrl = htmlUrl + "/iserver/services/3D-sample/rest/realspace";
			
			function onPageLoad() 
			{
				//初始化三维场景控件
				try
				{
					//初始化三维场景控件实例,参数为包含控件的HTML元素
					sceneControl = new SuperMap.Web.UI.Controls.SceneControl($get("sceneControlDiv"), 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() 
			{
			   //获取地球控件场景,控件和场景是一对一的捆绑关系
				scene = sceneControl.get_scene();
				layer3DServicesList = sceneControl.get_layer3DServicesList();
				var layer3Ds = scene.get_layer3Ds()
				
				var bLoad = layer3DServicesList.load(strServerUrl, "scene");
				
				if(!bLoad)
				{
					alert("获取图层服务信息失败!");
					return;
				}
	
				//获取指定的图层信息,包括图层名称、数据名称、图层类型
				var layer3DServiceInfo = layer3DServicesList.get_item("Building@OlympicGreen");
				var layerName = layer3DServiceInfo.get_name();
				var dataName = layer3DServiceInfo.get_dataName();
				var layer3DType = layer3DServiceInfo.get_type();
				
				layer3Ds.add(strServerUrl, layerName, dataName, layer3DType, false);
				var geobound = layer3Ds.get_item(layerName).get_bounds();
				scene.get_flyingOperator().flyToBounds(geobound);
			}

			//控件初始化失败后的回调函数
			function failedCallback() 
			{
				alert("Realspace initialized failed!");
			}
			
			function setObjVisble(isVisi)
			{
				var arrIds=[156,17,154,155,211,160];
				var isVisi;
				if(ObjVisble[0].checked){
					isVisi = true;
				}else if(ObjVisble[1].checked){
					isVisi = false;
				}
				var layer = scene.get_layer3Ds().get_item("Building@OlympicGreen");
				layer.setObjectVisible(arrIds,isVisi);
			}
			
			function setAllObjVis()
			{
				var arrIds=[];
				var layer = scene.get_layer3Ds().get_item("Building@OlympicGreen");
				layer.setObjectVisible(arrIds,false);
			}
            
		</script>
	</head>

	<body onLoad="onPageLoad()" style="width:800px; height:500px">
		<div id="toolSet" style="height: 6%; width: 100%; float: left"> 
<input type="radio" name="ObjVisble" value="radiobutton" onClick="setObjVisble()">仅主要模型可见
<input type="radio" name="ObjVisble" value="radiobutton" onClick="setObjVisble()">仅主要模型不可见
<input type="button" name="back" value="所有对象可见" onClick="setAllObjVis()"/>
</div>
<div id="sceneControlDiv" style="height: 93%; width: 100%; float: left;">
</div></body> </html>