运行范例

描述

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

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

代码 (文件格式为 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;
            var shadowQuery = null;

            //判断网页的打开方式是本地打开还是通过网络打开
            //不同的打开方式url赋值不同
            if (htmlUrl == "") {
                htmlUrl = "http://localhost:8090";
            }
            else {
                htmlUrl = "http://" + htmlUrl;
            }
            var sceneUrl = htmlUrl + "/iserver/services/3D-Sample/rest/realspace";
            function onPageLoad() {
                fillCombox("startTime",4);
                fillCombox("endTime",8);
                //初始化三维场景控件
                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 fillCombox(controlId,selectId){ var select = document.getElementById(controlId); for(var i=0;i<13;i++){ var time = i+6; select.options[i] = new Option(time+":00",i); } select.options[selectId].selected = "selected"; } //控件初始化完成后的回调函数,初始化完成之后才能进行数据加载 function initCallback() { //获取地球控件场景,控件和场景是一对一的捆绑关系 scene = sceneControl.get_scene(); //iServer服务地址 var sceneAddress = document.getElementById("ServerAddress").value; //场景名称 var sceneName = document.getElementById("SceneName").value; //打开场景 scene.open(sceneAddress, sceneName); var lyrCount = scene.get_layer3Ds().get_count(); for(var i=0; i<lyrCount; i++){ scene.get_layer3Ds().get_item(i).set_isVisible(false); } scene.get_layer3Ds().get_item(4).set_isVisible(true); scene.get_layer3Ds().get_item(4).set_isShadowEnable(true); } SuperMap.Web.UI.Action3Ds.Click = function (sceneControl) { SuperMap.Web.UI.Action3Ds.Click.initializeBase(this); this._name = "Click"; this._sceneControl = sceneControl; }; SuperMap.Web.UI.Action3Ds.Click.prototype = { dispose: function () { this._sceneControl = null; }, onMouseDown: function (e) { if(e.get_flagType()%2 == 1) { var pt = new SuperMap.Pixel(e.get_clientX(), e.get_clientY()); //new SuperMap.Web.Core.Point(e.get_clientX(), e.get_clientY()); this._point = this._sceneControl.pixelToGlobe(pt, SuperMap.Web.Realspace.PixelToGlobeMode.TerrainAndModel); //createBubble(this._point); var ratio = shadowQuery.getShadowRatio(pt); if(ratio != -1){ $("ratio").value = parseInt(ratio*100); }else{ $("ratio").value = "***" } } } }; SuperMap.Web.UI.Action3Ds.Click.registerClass('SuperMap.Web.UI.Action3Ds.Click', SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable); //控件初始化失败后的回调函数 function failedCallback() { alert("Realspace initialized failed!"); } function clickAction(){ sceneControl.set_sceneAction(null); var newAction = new SuperMap.Web.UI.Action3Ds.Click(sceneControl); sceneControl.set_sceneAction(newAction); } function drawRegionAction() { var measureAreaAction = new SuperMap.Web.UI.Action3Ds.MeasureArea(sceneControl); sceneControl.set_sceneAction(measureAreaAction); //给面积量算事件和量算结束事件注册回调函数 //sceneControl.addEvent("measureArea", areaHandler); sceneControl.addEvent("measureAreaFinished", Query); } function Query(dArea,region3d){ var panAction = new SuperMap.Web.UI.Action3Ds.Pan(sceneControl); sceneControl.set_sceneAction(panAction); StartShadowQuery(region3d); } function clearAll(){ scene.get_trackingLayer3D().removeAll(); shadowQuery.clear(); } function StartShadowQuery(geoRegion){ var dSpacing = Number($("spacing").value); var startControl = $('startTime'); var startHour = startControl.options[startControl.selectedIndex].text; var endControl = $('endTime'); var endHour = endControl.options[endControl.selectedIndex].text; var nInterval = Number($("interval").value); shadowQuery = new SuperMap.Web.Realspace.ShadowQuery(); var date = new Date(); date.setMinutes(0); date.setSeconds(0); date.setHours(parseInt(startHour)); shadowQuery.set_startTime(date); date.setHours(parseInt(endHour)); shadowQuery.set_endTime(date); shadowQuery.set_spacing(dSpacing); shadowQuery.set_timeInterval(nInterval); shadowQuery.set_queryRegion(geoRegion); var colors = new Array(); colors[0] = new SuperMap.Web.Core.Color(255,0,0,255); colors[1] =new SuperMap.Web.Core.Color(0,0,255,255); /* colors[2] = new SuperMap.Web.Core.Color(244,167,68,255); colors[3] = new SuperMap.Web.Core.Color(255,0,0,255);*/ shadowQuery.set_colorTable(colors); shadowQuery.build(); } function isShowShadowRatio(){ var bCheck = document.getElementById("isShowRatio").checked; if(bCheck){ sceneControl.set_sceneAction(null); var newAction = new SuperMap.Web.UI.Action3Ds.Click(sceneControl); sceneControl.set_sceneAction(newAction); }else{ sceneControl.set_sceneAction(SuperMap.Web.UI.Action3Ds.Pan(sceneControl)); } } </script> </head> <body onLoad="onPageLoad()"> <div id="control" style="position:absolute;top: 15px;left: 10px;width: 260px;bottom:10px;border: 2px solid #7F7F7F; padding: 10px">  间    隔:<input type="text" id="spacing" value="3" style="width: 100px"> 米<br/><br/>  开始时间:<select id="startTime" style="width: 100px"></select><br><br>  结束时间:<select id="endTime" style="width: 100px"></select><br><br>  时间间隔:<input type="text" name="interval" id="interval" value="15" style="width: 100px"/> 分<br/><br/> <input type="checkbox" id="isShowRatio" onchange="isShowShadowRatio()">阴影率:<input type="text" style="width: 100px" id="ratio"><br/><br/> <input type="button" id="draw" value="画面分析" style="width: 100px;height: 30px;" onclick="drawRegionAction()"/>   <input type="button" id="clear" value="清除" style="width: 100px;height: 30px;" onclick="clearAll()"/><br/><br/> </div> <div id="sceneControlDiv" style="position:absolute;left:315px;top:15px;bottom:5px;right:5px"> </div> </body> </html>