Runtime Environment: Development Environment: 64bit, visualstudio2008 with SP1, arcengine10.0, netframework4.0, iis7, and C # development languages for Windows 7 flagship edition.
Problem description: In the past, the section analysis function of CS was to draw the broken parts on the IMAP, and then display the axmapcontrol. Now we need to transplant it to WebService, and naturally there is no control to display it, therefore, you can export the elements drawn in IMAP as images directly. However, during image export, the exported regions are not the regions where the elements are drawn, therefore, you must first obtain the region range of the elements you have drawn.
The following is a method to obtain the public external rectangle of the elements to be drawn. You only need to obtain the public external rectangle after the painting is complete, and then export the region as an image.
1: // obtain the overall scope of the painting Element
2: IEnumElement pEnumElem;
3: IGraphicsContainer graphicsContainer = pMap as IGraphicsContainer;
4: IGraphicsContainerSelect pGraphicsContainerSelect = pMap as IGraphicsContainerSelect;
5: pGraphicsContainerSelect.SelectAllElements();
6: pEnumElem = pGraphicsContainerSelect.SelectedElements;
7: IElement ele = pEnumElem.Next();
8: IEnvelope env = new EnvelopeClass();
9: while (ele != null)
10: {
11: IGeometry geo = ele.Geometry;
12: ele = pEnumElem.Next();
13: env.Union(geo.Envelope);
14: }
15: pActiveView.Extent = env;
16: pGraphicsContainerSelect.UnselectAllElements();
The last obtained env is the required public external rectangle.
Note: In this process, the envelop of text elements is processed as vertices. Therefore, if a text element exists on the periphery, you need to adjust the position based on the actual situation. Alternatively, you can obtain the external rectangle of the text for calculation, which is more accurate.