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 ICreator61 (CreatePolygon, CreateColor, GeometryCreator), IPosition61 (Distance, Pitch) and INavigate61 (FlyTo) properties and methods.
function ComplexPolygon()
{
try
{
// Create polygon with hole geometry from well-known-text
var complexGeometry1 = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-80.900091 26.739261,-80.906338 26.840896,-80.591731 26.951601,-80.809248 26.716679,-80.900091 26.739261),(-80.873569 26.819371,-80.81616 26.772908,-80.811242 26.846308,-80.873569 26.819371))");
// 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*/, 0, "Polygon with hole");
// create multipolygon from array of x,y,z 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([-80.593456, 26.692189, 1000, -80.569379, 26.654723, 2000, -80.482195, 1000, 26.724591, -80.55208, 26.771137, 1000]);
var interiorRing1 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-80.577327, 26.713192, 1000, -80.567401, 26.726351, 1000, -80.569138, 26.705869, 1000 ]);
var interiorRing2 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-80.55315, 26.691784, 2000, -80.555867, 26.673088, 2000, -80.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 */, 0, "Polygon with 2 holes");
polygon2.Position.Distance = 80000;
polygon2.Position.Pitch = -45;
sgworld.Navigate.FlyTo(polygon2.Position);
}
catch(e)
{
alert("Unexpected error:" + ex.description);
}
}