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

/**
 * 给要素创建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};
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值