Hi, I want to create layer with polygon.
There is no error but, I can't see polygon UI
var gl_param = new GraphicsLayerCreationParams { Name = job_id };
QueuedTask.Run(() =>
{
var graphicsLayer = LayerFactory.Instance.CreateLayer<ArcGIS.Desktop.Mapping.GraphicsLayer>(gl_param, map);
double xMax, yMax, xMin, yMin;
(xMax, yMax) = (a, b);
(xMin, yMin) = (c, d);
List<Coordinate2D> plyCoords = new List<Coordinate2D>();
plyCoords.Add(new Coordinate2D(xMax, yMax));
plyCoords.Add(new Coordinate2D(xMax, yMin));
plyCoords.Add(new Coordinate2D(xMin, yMax));
plyCoords.Add(new Coordinate2D(xMin, yMin));
Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
var poly_symbol = SymbolFactory.Instance.ConstructLineSymbol(
SymbolFactory.Instance.ConstructStroke(
ColorFactory.Instance.RedRGB, 1.0, SimpleLineStyle.Solid));
var graphic = new CIMPolygonGraphic()
{
Symbol = poly_symbol.MakeSymbolReference(),
Polygon = poly,
};
graphicsLayer.AddElement(graphic);
});
Solved! Go to Solution.
To test your snippet i used the following code to define the envelope:
var env = MapView.Active.Extent;
(xMax, yMax) = (env.XMax, env.YMax);
(xMin, yMin) = (env.XMin, env.YMin);
This works for me, but the graphic i get is a bow tie.
Because you don't get a graphic at all, i assume that your projection for your a, b, c and d values needs to be defined. I don't know what your projection is, but you have to add it here:
Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords, map.SpatialReference);
Replace map.SpatialReference with the spatial reference for your corner coordinates. I.e. SpatialReferences.WGS84 if you are using lat/long.
To test your snippet i used the following code to define the envelope:
var env = MapView.Active.Extent;
(xMax, yMax) = (env.XMax, env.YMax);
(xMin, yMin) = (env.XMin, env.YMin);
This works for me, but the graphic i get is a bow tie.
Because you don't get a graphic at all, i assume that your projection for your a, b, c and d values needs to be defined. I don't know what your projection is, but you have to add it here:
Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords, map.SpatialReference);
Replace map.SpatialReference with the spatial reference for your corner coordinates. I.e. SpatialReferences.WGS84 if you are using lat/long.
Oh, I have wrong value.
I Solved it. Thanks! 😄