Creating a Complex Polygon
This example demonstrates how to create a polygon based on a multipolygon geometry and set its properties. This example uses the IGeometryCreator (CreateGeometryFromWKT, CreateLinearRingGeometry, CreatePolygonGeometry) and ICreator (CreatePolygon, CreateColor, GeometryCreator), IPosition (Distance, Pitch) and INavigate (FlyTo) properties and methods.
function ComplexPolygon()
{
try
{
// Create polygon with hole geometry from well-known-text
var complexGeometry1 = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-.900091 26.739261,-.906338 26.840896,-.591731 26.951601,-.9248 26.717179,-.900091 26.739261),(-.873569 26.9371,-.616 26.772908,-.1242 26.846308,-.873569 26.9371))");
// Create polygon
// Create line color using creator by specifying red,green,blue,alpha values
var lineColor1 = sgworld.Creator.CreateColor(255, 0, 0, 0);
var fillColor1 = "#00ff00"; // we can also specify color using HTML notation
var polygon1 = sgworld.Creator.CreatePolygon(complexGeometry1, lineColor1, fillColor1, 2 /*AltitudeTypeCode.ATC_ON_TERRAIN*/, "", "Polygon with hole");
// create multipolygon from array of x,z,y points
// Polygon geometry consists of LinearRing that specifies exterior ring and array of LinearRing geometries that specify interior rings
// create exterior ring using array of coordinates
var exteriorRing = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-.593456, 26.692189, 1000, -.569379, 26.654723, 2000, -.482195, 26.724591, 1000, -.55208, 26.771137, 1000]);
var interiorRing1 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-.577327, 26.713192, 1000, -.5601, 26.726351, 1000, -.569138, 26.715869, 1000]);
var interiorRing2 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-.55315, 26.691784, 2000, -.555867, 26.673088, 2000, -.5252610, 26.688447, 2000]);
var complexGeometry2 = sgworld.Creator.GeometryCreator.CreatePolygonGeometry(exteriorRing, [interiorRing1,interiorRing2 ] );
var fillColor2 = "#0000ff";
var lineColor2 = "#00ff00";
// Create polygon
var polygon2 = sgworld.Creator.CreatePolygon(complexGeometry2, lineColor2, fillColor2, 3 /* AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE */, "", "Polygon with 2 holes");
polygon2.Position.Distance = 000;
polygon2.Position.Pitch = -45;
sgworld.Navigate.FlyTo(polygon2.Position);
}
catch(e)
{
alert("Unexpected error:" + ex.description);
}
}