Multipart polygon

1809
4
Jump to solution
03-07-2012 08:28 PM
MuzammilAK
New Contributor
I have 3 polygons(rectangles) touching each other. Please see attached image.

I need to make them behave as one polygon so that I can rotate or move(drag) them together. Please suggest me some pointers.

1. First Method which I tried.
-----------------------------------
Created custom fill symbol as shown below:

<esriSym:SimpleFillSymbol x:Name="sfsRect2" BorderBrush="Black" BorderThickness="3" Fill="Transparent">
                <esriSym:SimpleFillSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Grid>
                            <Grid.RenderTransform>
                                <RotateTransform Angle="{Binding Path=Attributes[Angle]}" />
                            </Grid.RenderTransform>
                            <StackPanel Orientation="Vertical">
                                <StackPanel Orientation="Horizontal">
                                    <Rectangle Width="{Binding Path=Attributes[PITWIDTH]}" Height="{Binding Attributes[PITHEIGHT]}" Fill="Transparent" Stroke="Aqua" StrokeThickness="3"/>
                                    <Rectangle Width="{Binding Path=Attributes[PARKWIDTH]}" Height="{Binding Attributes[PARKHEIGHT]}" Fill="Transparent" Stroke="Aqua" StrokeThickness="3"/>
                                </StackPanel>
                                <Rectangle Width="{Binding Path=Attributes[TEMPWIDTH]}" Height="{Binding Path=Attributes[TEMPHEIGHT]}" Fill="Transparent" Stroke="Aqua" StrokeThickness="3"/>
                            </StackPanel>
                        </Grid>
                      </ControlTemplate>
                </esriSym:SimpleFillSymbol.ControlTemplate>
            </esriSym:SimpleFillSymbol>

Created geometry and bound the variables

                Graphic gg = new Graphic() { Geometry = env, Symbol = sfsRect2 };
                gg.Attributes.Add("Angle", csNB.Value.ToString());
                gg.Attributes.Add("TEMPWIDTH", env.Width);
                gg.Attributes.Add("TEMPHEIGHT", env.Height);
                and so on......

Output:
-------
I am able to see the conjoined rectangles, but the dimensions are inconsistent/varying. The more I zoom into the map, the smaller they (rectangle graphics) become.


2. Second method that I tried.
-----------------------------------------------------------------

Draw the three polygons(rectangles) normally. And manage the mouse events for moving them collectively.
But when I rotate (programmatically using binding), the 3 rectangles rotate independently. And moreover, the center of rotation is top left vertex of each rectangle. And hence the collective shape is dis-arranged.
[ATTACH=CONFIG]12508[/ATTACH]
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
You can create a graphic with a multi rings geometry.   During the edition the rings will be manipulated as a whole.

Example of code merging all polygons of a graphics layer to one multi rings graphic:

private void MergePolygonGraphics(GraphicsLayer graphicsLayer) {     var graphics = graphicsLayer.Graphics.Where(g => g.Geometry is Polygon).ToList();     var geometry = graphics.First().Geometry as Polygon;     foreach (var gra in graphics.Skip(1))     {         foreach(var ring in ((Polygon)gra.Geometry).Rings)             geometry.Rings.Add(ring);         graphicsLayer.Graphics.Remove(gra);     }     graphics.First().Geometry = geometry; }

View solution in original post

0 Kudos
4 Replies
MuzammilAK
New Contributor
Re-posting..........
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You can create a graphic with a multi rings geometry.   During the edition the rings will be manipulated as a whole.

Example of code merging all polygons of a graphics layer to one multi rings graphic:

private void MergePolygonGraphics(GraphicsLayer graphicsLayer) {     var graphics = graphicsLayer.Graphics.Where(g => g.Geometry is Polygon).ToList();     var geometry = graphics.First().Geometry as Polygon;     foreach (var gra in graphics.Skip(1))     {         foreach(var ring in ((Polygon)gra.Geometry).Rings)             geometry.Rings.Add(ring);         graphicsLayer.Graphics.Remove(gra);     }     graphics.First().Geometry = geometry; }
0 Kudos
DarinaTchountcheva
Occasional Contributor II
Muzammil,

See this sample:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Union

Good Luck!

Edit: Now that I see Dominique's response, I realize that you probably want to keep the polygons separate, so Union is probably not what you need.
0 Kudos
MuzammilAK
New Contributor
Thanks Dominique and darina.

@Dominique,

Many thanks.
I concurred the same idea after seeing the json response of multipart polygon (created in arcmap, and published).

Thank you.
0 Kudos