运行范例

描述

该范例展示了如何使用粒子特效实现火焰的效果。

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


<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=8" />	
		<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 htmlUrl = document.location.host;
			var scene = null;
			var sceneControl = null;
			var trackingLayer = null;

			//判断网页的打开方式是本地打开还是通过网络打开
			//不同的打开方式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() 
			{

			    //获取Realspace控件的场景,控件和场景是一对一的捆绑关系
			    scene = sceneControl.get_scene();

				//改变当前操作为漫游状态
				sceneControl.set_sceneAction(new SuperMap.Web.UI.Action3Ds.Pan(sceneControl));

				//加载奥运场馆模型数据
				scene.open(sceneUrl,"scene_olympicgreen");
			
				//飞行到指定位置
				var camera = new SuperMap.Web.Realspace.Camera(116.3915,39.9889,300);
				camera.set_tilt(73.5);
				scene.get_flyingOperator().flyTo(camera, 10, SuperMap.Web.Realspace.FlyingMode.JUMP);
				
				//获取跟踪图层
				trackingLayer = scene.get_trackingLayer3D();

				//加载火焰效果
				displayFire();

				
			}

			function displayFire()
			{
				var particleStyle3D = new SuperMap.Web.Core.Style3D();
			    particleStyle3D.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.ABSOLUTE);

			    var geoPoint3D = new SuperMap.Web.Core.GeoPoint3D(new SuperMap.Web.Core.Point3D(116.390786, 39.991987, 88));

			    var fireParticle = new SuperMap.Web.Core.GeoParticle();
			    fireParticle.set_particleFilePath("fire.par");
			    fireParticle.makeWithGeometry(geoPoint3D);
			    fireParticle.set_scaleX(2.5);
			    fireParticle.set_scaleY(5);
			    fireParticle.set_scaleZ(2.5);

			    fireParticle.set_rotationX(-90);

			    var feature = new SuperMap.Web.Core.Feature3D();
			    feature.set_geometry(fireParticle);
			    feature.set_style3D(particleStyle3D);

			    trackingLayer.add(feature, "fireParticle");
			}

			//控件初始化失败后的回调函数
			function failedCallback() 
			{
			    alert("Realspace initialized failed!");
			}

	

			

			//获取数据信息
			function getDataName(strLayerName) 
			{
				var sceneservicelist = sceneControl .get_sceneServicesList();
				sceneservicelist.load(sceneUrl);
				var scenecount = sceneControl .get_sceneServicesList().get_count();

				for (var i = 0; i < scenecount; i++) 
				{
					//获取指定的场景信息
					var sceneinfor = sceneservicelist.get_item(i);
					var scenename = sceneinfor.get_name();

					layer3DServicesList = sceneControl .get_layer3DServicesList();
					layer3DServicesList.load(sceneUrl, scenename);

					var count = layer3DServicesList.get_count();
					for (var j = 0; j < count; j++) 
					{
						//获取指定的图层信息,包括图层名称、数据名称
						var layer3DServiceInfo = layer3DServicesList.get_item(j);
						var layerName = layer3DServiceInfo.get_name();
						var dataName = layer3DServiceInfo.get_dataName();
						if (layerName == strLayerName) 
						{
							return dataName;
						}
					}
				}
			}	

			</script>
	</head>

	<body onLoad="onPageLoad()">  	
		<div id="sceneControlDiv" style="position:absolute;top:5px;bottom:5px;left:5px;right:5px;"> 
		</div>
	</body>
</html>