运行范例

描述

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

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

代码 (文件格式为 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 trackingLayer = null;
        var profile;
		 var temp=new Array();

        //判断网页的打开方式是本地打开还是通过网络打开
        //不同的打开方式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() { //获取地球控件场景,控件和场景是一对一的捆绑关系 scene = sceneControl.get_scene(); trackingLayer = scene.get_trackingLayer3D(); var layer3DServicesList = sceneControl.get_layer3DServicesList(); var layer3Ds = scene.get_layer3Ds(); var bLoad = layer3DServicesList.load(sceneUrl, "scene"); if(bLoad){ var lyr3d = layer3Ds.add(sceneUrl, "Building@OlympicGreen", "Building@OlympicGreen", SuperMap.Web.Realspace.Layer3DType.VECTOR, false); var geobound = layer3Ds.get_item(0).get_bounds(); scene.get_flyingOperator().flyToBounds(geobound); } profile = new SuperMap.Web.Realspace.Profile(); } //控件初始化失败后的回调函数 function failedCallback() { alert("Realspace initialized failed!"); } function drawProLine() { sceneControl.set_sceneAction(null); var newAction = new SuperMap.Web.UI.Action3Ds.DrawLine(sceneControl,profile); sceneControl.set_sceneAction(newAction); profile.build(); } SuperMap.Web.UI.Action3Ds.DrawLine = function (sceneControl,profile) { SuperMap.Web.UI.Action3Ds.DrawLine.initializeBase(this); this._name = "DrawLine"; this._profile = profile; this._sceneControl = sceneControl; this._points = new SuperMap.Web.Core.Point3Ds(); this._geoLine = null; this._point = null;; this._type = SuperMap.Web.UI.Action3Ds.SceneActionType.POINTSELECT; this._id1 = -1;//记录静态id this._id2 = -1;//记录动态id }; SuperMap.Web.UI.Action3Ds.DrawLine.prototype = { dispose: function () { this._sceneControl = null; }, onMouseDown: function (e) { if (e.get_flagType() % 2 == 1) { var curPt = new SuperMap.Web.Core.Point3D(e.get_longitude(), e.get_latitude(), e.get_altitude()); if (this._point == null) { this._point = curPt; this._points.add(curPt); this._profile.set_startPoint(this._point); } else { this._points.add(curPt); this._profile.set_endPoint(curPt); this._geoLine = new SuperMap.Web.Core.GeoLine3D([this._points]); var feature3D = new SuperMap.Web.Core.Feature3D(); var style = new SuperMap.Web.Core.Style3D(); style.set_lineColor(new SuperMap.Web.Core.Color(255,0,0,255)); feature3D.set_style3D(style); feature3D.set_geometry(this._geoLine); var trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); trackingLayer.set_isVisible(true); trackingLayer.removeAt(this._id2); trackingLayer.removeAt(this._id1); this._id2 = null; this._id1 = trackingLayer.add(feature3D, "line1"); var panAction = new SuperMap.Web.UI.Action3Ds.Pan(this._sceneControl); this._sceneControl.set_sceneAction(panAction); probuild(); } } }, onMouseMove: function (e) { if (this._point != null) { var points = new SuperMap.Web.Core.Point3Ds(); points.add(this._point) var temppoint = new SuperMap.Web.Core.Point3D(e.get_longitude(), e.get_latitude(), e.get_altitude()); 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_fillForeColor(new SuperMap.Web.Core.Color(255,0,0,255)); feature3D.set_style3D(style); feature3D.set_geometry(line); var trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); trackingLayer.removeAt(this._id2); this._id2 = trackingLayer.add(feature3D, "line2"); } } }; SuperMap.Web.UI.Action3Ds.DrawLine.registerClass('SuperMap.Web.UI.Action3Ds.DrawLine', SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable); function probuild() { profile.outputProfileToBitMap("C:/profile.png", SuperMap.Web.Realspace.ImageType.PNG); var test=profile.getLeftTopPosition(); var test2=profile.getRightBottomPosition(); var str=profile.outputProfileToJPG(); //var temp=new Array(); temp.push(str); //window.showModalDialog("pop.html",temp); var temppage=window.open("pop.html"); } function clearAnalysis(){ trackingLayer.removeAll(); profile.clear(); temp=[]; } </script> </head> <body onLoad="onPageLoad()"> <div style="position:absolute;left:5px;top:5px;right:5px;float:left"> <input id="drowline" type="button" value="绘制剖面线" onClick="return drawProLine()"/> <input id="clearAll" type="button" value="清除分析结果" onClick="return clearAnalysis()"/> </div> <div id="sceneControlDiv" style="position:absolute;left:5px;top:35px;bottom:5px;right:5px"> </div> </body> </html>