terraExplorer 6.6 for javascript 获取地理要素上的坐标值,通过图层设置标注(作为上一篇的补充)

来源:互联网 发布:milogs工作日志软件 编辑:程序博客网 时间:2024/05/27 12:22
/** * 给要素创建label * @param dxCoord * @param dYCoord * @param text 标签名 */function CreateTextLabel(dxCoord,dYCoord,text,layerName) {try {// B. Create position for label// B1. Set position input parameters (San Fransico shore)var dXCoord = dxCoord;var dYCoord = dYCoord;var dAltitude = 100.0;var eAltitudeTypeCode = 0; // AltitudeTypeCode.ATC_TERRAIN_RELATIVE;var dYaw = 0.0;var dPitch = 0.0;var dRoll = 0.0;var dDistance = 500;// B2. Create Positionvar cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude,eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);//// C. Create label style for label//// C1. Create label sylecLabelStyle = sgworld.Creator.CreateLabelStyle();// C2. Change label style settingsvar nBGRValue = 0xFF0000; // Bluevar dAlpha = 0.5; // 50% opacityvar cBackgroundColor = cLabelStyle.BackgroundColor; // Get label// style// background// colorcBackgroundColor.FromBGRColor(nBGRValue); // Set background to// bluecBackgroundColor.SetAlpha(dAlpha); // Set transparency to 50%cLabelStyle.BackgroundColor = cBackgroundColor; // Set label// style// background// colorcLabelStyle.FontName = "Arial"; // Set font name to ArialcLabelStyle.Italic = true; // Set label style font to italiccLabelStyle.Scale = 3; // Set label style scale//// D. Create text label using label style//// D1. Set label style paramsvar tText = text;// D2. Create label stylevar parentGroup=sgworld.ProjectTree.FindItem(layerName);var groupID = sgworld.ProjectTree.CreateGroup(layerName,parentGroup);var cTextLabel = sgworld.Creator.CreateTextLabel(cPos, tText,cLabelStyle, groupID, "TextLabel");//// E. FlyTo text label//var cFlyToPos = cPos.Copy();cFlyToPos.Pitch = -89.0; // Set camera to look downward on text// labelsgworld.Navigate.FlyTo(cFlyToPos);}catch (e){alert("Unexpected error: " + e.description);}}/** * 获取每个feature的坐标值 *  * @param feature */function getXYCoordfromFeat(feature){//var geometry=feature.Geometry;var geometry="";//(feature.Geometry)?geometry=feature.Geometry:geometry=feature.Item(0);if(!feature.Geometry){geometry=feature.Item(0);}else{geometry=feature.Geometry;}var x="",y="";console.log("type:"+geometry.GeometryType);if (geometry.GeometryType=="0"){// ipointx=geometry.X;y=geometry.Y;}else if (geometry.GeometryType=="1"){//lineStringx=geometry.StartPoint.X;y=geometry.StartPoint.Y;}else if (geometry.GeometryType=="2"||geometry.GeometryType=="3"){//polygon,lineAring  (geometry.GeometryType=2||3)x=geometry.Centroid.X;y=geometry.Centroid.Y;}else {//3 linearRing (geometry.GeometryType=="5"||6)getXYCoordfromFeat(geometry);}return{"x":x,"y":y};}

阅读全文
0 0
原创粉丝点击