Skyline 实现代码长度量算

对距离的量算基本都会默认调用量算ICommend的方法,这个方法比较封闭特殊化要求是无法实现的。通过画线方法和
sgworld.CoordServices.GetDistanc接口用模拟了距离量算。

注意:请用IE内核浏览器查看运行结果(Result)。  经测试 运行无问题。DOME

Skyline 实现代码长度量算_第1张图片

/*
展示 skyline的距离计算,自定画线方式画线。 
*/

var sgworld;

function init() {
    var flypath = "http://bcs.duapp.com/wordprees-bk/fly/wp0.FLY";
    sgworld = document.getElementById("SGWorldLeft");
    sgworld.Project.Open(flypath);
    // 绑定
}

function CreatePolyLine() {
    sgworld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown);
    sgworld.AttachEvent("OnRButtonUp", EndPolyLine);
    sgworld.Window.SetInputMode(1);
}

function EndPolyLine() {
    sgworld.ProjectTree.DeleteItem(sgworld.ProjectTree.FindItem("线"));
    sgworld.DetachEvent("OnLButtonDown", DrawPolyLButtonDown);
    sgworld.DetachEvent("OnRButtonUp", EndPolyLine);
    verticesArray = null;
    PolyLine = null;
    Frist = true;
    sgworld.Window.SetInputMode(0);
}

var PolyLine = null;
var Frist = true;
var verticesArray = null;

function DrawPolyLButtonDown(Flags, X, Y) {
    var linecolor = sgworld.Creator.CreateColor(255, 0, 0, 125);
    try {
        var cpos = sgworld.Window.pixelToWorld(X, Y);
        if (cpos == null) return false;
        var pos = cpos.Position;
        if (!PolyLine && Frist) {
            Frist = false;
            verticesArray = [pos.X, pos.Y, 0, pos.X, pos.Y, 0];
            var geometry = sgworld.Creator.GeometryCreator.CreateLineStringGeometry(verticesArray);
            PolyLine = sgworld.Creator.CreatePolyline(geometry, linecolor, 2, 0, "线");

        } else {
            verticesArray.push(pos.X);
            verticesArray.push(pos.Y);
            verticesArray.push(0);
            var geometry = sgworld.Creator.GeometryCreator.CreateLineStringGeometry(verticesArray);
            sgworld.ProjectTree.DeleteItem(sgworld.ProjectTree.FindItem("线"));
            PolyLine = sgworld.Creator.CreatePolyline(geometry, linecolor, 2, 0, "线");
            CreatLabel(verticesArray[verticesArray.length-6],verticesArray[verticesArray.length-5],pos.X,pos.Y);
         }
    } catch (e) {
        alert(e.description);
    }
}


function ExecuteCommand(command) {
    switch (command) {
        case "HorizontalDist":
            sgworld.Command.Execute(1034, 0);
            break;
        case "AerialDist":
            sgworld.Command.Execute(1035, 0);
            break;
        case "VerticalDist":
            sgworld.Command.Execute(1036, 0);
            break;
        case "Area":
            sgworld.Command.Execute(1037, 0);
            break;
    }
}

function CreatLabel(x1,y1,x2,y2) {
  try {
         {
             var dXCoord = (x1+x2)/2;
             var dYCoord = (y1+y2)/2;
             var dAltitude = 100.0;
             var eAltitudeTypeCode = 0; // AltitudeTypeCode.ATC_TERRAIN_RELATIVE;
             var dYaw = 0.0;
             var dPitch = -89;
             var dRoll = 0.0;
             var dDistance = 10000;
             var cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
         } {
             var tText = sgworld.CoordServices.GetDistance(x1,y1,x2,y2);
             var cLabelStyle = sgworld.Creator.CreateLabelStyle();
             cLabelStyle.Scale = 10000;
             
             var cTextLabel = sgworld.Creator.CreateTextLabel(cPos, parseInt(tText)+"M", cLabelStyle, 0, dXCoord+"-"+dYCoord);
//            sgworld.Navigate.FlyTo(cPos);
         }
     } catch (e) {
         alert("Unexpected error: " + e.description);
     }

}


你可能感兴趣的:(Skyline综合)