I am writing a console application using ArcGIS (engine or desktop). I'm trying to rotate and scale a map based on a polygon, and I'm not having any luck at all. With some tinkering, I can usually do one or the other but not both.Anybody have any suggestions? I feel as though I've tried every variation in terms of rotating the map and adjusting the scale either using the Imap interface, or the IActiveView interface.
Private Sub Zoom2AndExportJpgs(mapDocument As IMapDocument, imagePath As String)
'Get the relevant strip maps for the route
Dim map As IMap = mapDocument.Map(0) '(assumed that there is only one map in the mxd)
Dim pageLayout As IPageLayout = mapDocument.PageLayout
Dim pageAV As IActiveView = pageLayout
Dim mapAV As IActiveView = map
Try
'get a list of strip map objects... EF object containing a list of the 4 corners of a polygon
Dim stripmaps As List(Of MRLAStripMapExtent) = getStripMaps()
Dim filename As String = ""
'get all the associated stripmaps for the route for each scale
If Not stripmaps Is Nothing Then
For i = 0 To stripmaps.Count - 1
Dim pgon As IPolygon = geometryHelper.CreatePGON(stripmaps(i).RectLowerLeftX, stripmaps(i).RectLowerLeftY, _
stripmaps(i).RectLowerRightX, stripmaps(i).RectLowerRightY, _
stripmaps(i).RectUpperLeftX, stripmaps(i).RectUpperLeftY, _
stripmaps(i).RectUpperRightX, stripmaps(i).RectUpperRightY)
filename = imagePath & stripmaps(i).ZoomScale & stripmaps(i).PageNumber & ".jpg"
CreateJpgFile(filename, mapAV, pageAV, pgon, stripmaps(i).ANGLE, stripmaps(i).ZoomScale)
Next i
End If
Catch ex As Exception
publishError.PublishError(publishError.ErrorSeverity.majorStopRouteProcessing, ex)
End Try
End Sub
Private Sub CreateJpgFile(ByVal sFilename As String, ByVal pAV As ESRI.ArcGIS.Carto.IActiveView, _
ByVal pPageActiveView As ESRI.ArcGIS.Carto.IActiveView, _
ByVal pgon As IPolygon,
rotationAngle As Double, _
mapScale As Double)
Dim pExport As ESRI.ArcGIS.Output.IExport
pExport = New ESRI.ArcGIS.Output.ExportJPEG
pAV.Extent = pgon.Envelope
pAV.ScreenDisplay.DisplayTransformation.ScaleRatio = mapScale
pAV.ScreenDisplay.DisplayTransformation.Rotation = rotationAngle '0
pAV.Refresh()
'Export Image....
pExport.ExportFileName = sFilename
pExport.Resolution = 96
Dim exportRECT As ESRI.ArcGIS.esriSystem.tagRECT
exportRECT = pPageActiveView.ExportFrame
Dim pPixelBoundsEnv As ESRI.ArcGIS.Geometry.IEnvelope
pPixelBoundsEnv = New ESRI.ArcGIS.Geometry.Envelope
pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.bottom, exportRECT.right, exportRECT.top)
pExport.PixelBounds = pPixelBoundsEnv
Dim hDC As Integer
hDC = pExport.StartExporting
pPageActiveView.Output(hDC, pExport.Resolution, exportRECT, Nothing, Nothing)
'Finish writing the export file and cleanup any intermediate files.
pExport.FinishExporting()
pExport.Cleanup()
End Sub