/**
* 给要素创建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 Position
var cPos = sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude,
eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
//
// C. Create label style for label
//
// C1. Create label syle
cLabelStyle = sgworld.Creator.CreateLabelStyle();
// C2. Change label style settings
var nBGRValue = 0xFF0000; // Blue
var dAlpha = 0.5; // 50% opacity
var cBackgroundColor = cLabelStyle.BackgroundColor; // Get label
// style
// background
// color
cBackgroundColor.FromBGRColor(nBGRValue); // Set background to
// blue
cBackgroundColor.SetAlpha(dAlpha); // Set transparency to 50%
cLabelStyle.BackgroundColor = cBackgroundColor; // Set label
// style
// background
// color
cLabelStyle.FontName = "Arial"; // Set font name to Arial
cLabelStyle.Italic = true; // Set label style font to italic
cLabelStyle.Scale = 3; // Set label style scale
//
// D. Create text label using label style
//
// D1. Set label style params
var tText = text;
// D2. Create label style
var 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
// label
sgworld.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"){// ipoint
x=geometry.X;
y=geometry.Y;
}else if (geometry.GeometryType=="1"){//lineString
x=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};
}
terraExplorer 6.6 for javascript 获取地理要素上的坐标值,通过图层设置标注(作为上一篇的补充)
最新推荐文章于 2018-05-16 15:13:55 发布