运行范例

描述

该范例展示如何使用场景的set_terrainExaggeration接口来按照给定的拉伸系数拉伸地形

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


<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=8" />	
		<meta http-equiv="Content-Type" content="text/html; UTF-8" />
		<title>地形拉伸</title>
		<script type="text/javascript" src="SuperMap.Include.js" ></script>
		<script type="text/javascript">
			var scene = null;
			var sceneControl = null;
			var htmlUrl = document.location.host;
			//判断网页的打开方式是本地打开还是通过网络打开
			//不同的打开方式url赋值不同
			if(htmlUrl == "")
			{
				htmlUrl = "http://localhost:8090";
			}
			else
			{
				htmlUrl = "http://" + htmlUrl;
			}
			var sceneUrl = 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();

				//指定场景的服务器地址
				var sceneAddress = sceneUrl;

				//指定场景名字
				var sceneName = "scene";

				//打开场景
				var bSceneOpen = scene.open(sceneAddress, sceneName);

				//获取场景中的地形图层
				var terrainLayer = scene.get_terrainLayers().get_item("Beijing@RealspaceSample_Terrain");

				if (terrainLayer != null) 
				{
					//获取图层的地理范围,并飞行到该范围
					var geobound = terrainLayer.get_bounds();
					scene.get_flyingOperator().flyToBounds(geobound);
				}	
			}

			//控件初始化失败后的回调函数
			function failedCallback() 
			{
				alert("Realspace initialized failed!");
			}
			
			function TerrainExaggeration()
			{
				//从页面获取地形拉伸系数拉伸地形
				var exaVal = document.getElementById("ExaVal").value;
				scene.set_terrainExaggeration(exaVal);
			}
		</script>

	</head>
	<body onLoad="onPageLoad()">
		<div id="toolSet" style="position:absolute;left:5px;top:5px;bottom:5px;right:5px;float:left;">
			拉伸系数:
			<input id="ExaVal" name="ExaVal" type="text"/>
			<input id="TerrainExaggeration" type="button" value="地形拉伸" onClick="TerrainExaggeration()" />
		</div>
		<div id="sceneControlDiv" style="position:absolute;left:5px;top:35px;bottom:5px;right:5px">
		</div>
	</body>
</html>