在skyline中没有交互式的画线方法,下面的代码完成了一个简单的画线操作逻辑。 在左键下压事件中绑定画线方法,在获取鼠标坐标后增加线的节点来完成画线操作。
注意:请用IE内核浏览器查看运行结果(Result)。 经测试<IE10> 运行无问题。DOME
function CreatePolyLine() {
sgworld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown);
sgworld.Window.SetInputMode(1);
}
function EndPolyLine() {
sgworld.ProjectTree.DeleteItem(sgworld.ProjectTree.FindItem("线"));
sgworld.DetachEvent("OnLButtonDown", DrawPolyLButtonDown);
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, "线");
}
} catch (e) {
alert(e.description);
}
}