运行范例

描述

该范例展示如何进行通视分析及其相关参数设置。

了解微软脚本库的更多信息请参见微软官方帮助文档. 微软官方帮助文档.

代码 (文件格式为 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 scene = null;
var sceneControl = null;
var firstgeopoint;
var otherpoints=new  Array();
var firstpoint;
var Sightline;
var trackingLayer=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("未检测到 SuperMap iClient3D for  Plugin 插件,请单击此处下载并安装插件。");
            return;
        }
        //若使用非IE浏览器,则抛出该异常
        else if (e.name == SuperMap.Web.Realspace.ExceptionName.BrowserNotSupport)
        {
            document.write("

SuperMap iClient3D for Plugin 目前仅支持 InternetExplorer 浏览器,请更换浏览器后重新尝试加载本页面。

"); return; } //抛出其他异常 else { alert(e.message); } } } //控件初始化完成后的回调函数,初始化完成之后才能进行数据加载 function initCallback() { //获取Realspace控件的场景,控件和场景是一对一的捆绑关系 scene = sceneControl.get_scene(); scene.open(sceneUrl,"scene_olympicgreen"); var layer3D = scene.get_layer3Ds().get_item(0); if (layer3D != null) { //获取图层的地理范围,并飞行到该范围 var geobound = layer3D.get_bounds(); scene.get_flyingOperator().flyToBounds(geobound); } } //控件初始化失败后的回调函数 function failedCallback() { alert("Realspace initialized failed!"); } function SceneLoad() { //指定场景的服务器地址 var sceneAddress = sceneUrl; //指定图层名称 var sceneName = "scene"; //打开场景 scene.open(sceneAddress, sceneName); //获取场景中的图层 var layer3D = scene.get_layer3Ds().get_item("Ground@OlympicGreen"); if (layer3D != null) { //获取图层的地理范围,并飞行到该范围 var geobound = layer3D.get_bounds(); scene.get_flyingOperator().flyToBounds(geobound); } } function drawvisibipoint(){ sceneControl.set_sceneAction(null); var newpointAction = new SuperMap.Web.UI.Action3Ds.DrawVisibiPoint(sceneControl); sceneControl.set_sceneAction(newpointAction); } //继承自SuperMap.Web.UI.Action3Ds.SceneAction类扩展一个SuperMap.Web.UI.Action3Ds.DrawVisibiPoint SuperMap.Web.UI.Action3Ds.DrawVisibiPoint = function (sceneControl) { SuperMap.Web.UI.Action3Ds.DrawVisibiPoint.initializeBase(this); this._name = "DrawVisibiPoint"; this._sceneControl = sceneControl; this._points = new SuperMap.Web.Core.Point3Ds(); this._point; this._type = SuperMap.Web.UI.Action3Ds.SceneActionType.POINTSELECT; this._id1;//记录静态id this._id2;//记录动态id }; SuperMap.Web.UI.Action3Ds.DrawVisibiPoint.prototype = { dispose: function () { this._sceneControl = null; }, onMouseDown: function (e) { if(e.get_flagType()%2 == 1) { if(this._point == null) { var pt = new SuperMap.Pixel(e.get_clientX(), e.get_clientY()); this._point = this._sceneControl.pixelToGlobe(pt, SuperMap.Web.Realspace.PixelToGlobeMode.TerrainAndModel); firstpoint=this._point; firstgeopoint=new SuperMap.Web.Core.GeoPoint3D(this._point); var firstfeature3D = new SuperMap.Web.Core.Feature3D(); //设置feature3D中的style3D属性 var firststyle = new SuperMap.Web.Core.Style3D(); firststyle.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.ABSOLUTE); firststyle.set_markerSize(3); firststyle.set_markerColor(new SuperMap.Web.Core.Color(255, 0, 0, 255)); firstfeature3D.set_style3D(firststyle); firstfeature3D.set_geometry(firstgeopoint); trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); //设置跟踪图层为可见 trackingLayer.set_isVisible(true); trackingLayer.add(firstfeature3D, "firstpoint"); }else { var pt = new SuperMap.Pixel(e.get_clientX(), e.get_clientY()); this._point = this._sceneControl.pixelToGlobe(pt, SuperMap.Web.Realspace.PixelToGlobeMode.TerrainAndModel); this._points.add(this._point); otherpoints.push(this._point); var geopoint=new SuperMap.Web.Core.GeoPoint3D(this._point); var feature3D = new SuperMap.Web.Core.Feature3D(); var style = new SuperMap.Web.Core.Style3D(); style.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.ABSOLUTE); style.set_markerColor(new SuperMap.Web.Core.Color(255,0,0,255)) style.set_markerSize(3); feature3D.set_style3D(style); feature3D.set_geometry(geopoint); var trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); trackingLayer.set_isVisible(true); trackingLayer.add(feature3D, "point"); } }else { trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); trackingLayer.removeAt(this._id2); this._point = null; this._id1 = null; this._id2 = null; this._points = new SuperMap.Web.Core.Point3Ds(); var panAction = new SuperMap.Web.UI.Action3Ds.Pan(sceneControl); sceneControl.set_sceneAction(panAction); Sightline=new SuperMap.Web.Realspace.Sightline(); Sightline.set_viewerPosition(firstpoint); var pointlength=otherpoints.length; for(i=0;i <pointlength;i++){ var otherpoint=otherpoints[i]; Sightline.addTargetPoint(otherpoint); } Sightline.build(); } }, onMouseMove: function(e) { if(this._point != null) { var points = new SuperMap.Web.Core.Point3Ds(); points.add(firstpoint); //var temppoint = new SuperMap.Web.Core.Point3D(e.get_longitude(),e.get_latitude(),e.get_altitude()); var pt = new SuperMap.Pixel(e.get_clientX(), e.get_clientY()); var temppoint = this._sceneControl.pixelToGlobe(pt, SuperMap.Web.Realspace.PixelToGlobeMode.TerrainAndModel); points.add(temppoint); var line = new SuperMap.Web.Core.GeoLine3D([points]); var feature3D = new SuperMap.Web.Core.Feature3D(); var style = new SuperMap.Web.Core.Style3D(); style.set_lineWidth(1); style.set_altitudeMode(SuperMap.Web.Realspace.AltitudeMode.ABSOLUTE); feature3D.set_style3D(style); feature3D.set_geometry(line); trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); trackingLayer.set_isVisible(true); trackingLayer.removeAt(this._id2); this._id2 = trackingLayer.add(feature3D, "line2"); } } }; SuperMap.Web.UI.Action3Ds.DrawVisibiPoint.registerClass('SuperMap.Web.UI.Action3Ds.DrawVisibiPoint', SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable); function visibili(){ sceneControl.set_sceneAction(null); var newAction = new SuperMap.Web.UI.Action3Ds.DrawVisibiPoint(sceneControl); sceneControl.set_sceneAction(newAction); } function clearvisib(){ trackingLayer.removeAll(); firstgeopoint=null; firstpoint=null; otherpoints=[]; var panAction = new SuperMap.Web.UI.Action3Ds.Pan(sceneControl); sceneControl.set_sceneAction(panAction); Sightline.clear(); } </script > </head > <body onLoad="onPageLoad()" > <div id="toolSet" style="position:absolute;top:5px;float:left;" > <!--分析-- > <input id="visib" type="button" value="开始分析" onClick="return visibili()" / > <input id="clearvisib" type="button" value="清除结果" onClick="return clearvisib()" / > </div > <div id="sceneControlDiv" style="position:absolute;top:35px;bottom:5px;left:5px;right:5px" > </div > </body > </html >