Hi all,
I'm playing around with PrintPreviewSample to print a map on paper.
I have changed the sample code to read a shape file which is at different projection (EPSG 31467).
MapUnit is Meter.
I get the program running, but the map doesn't show the shape layer.
What to do? How to zoom to a layer which is added to the mapPrinterLayer?
Here is my code:
private void AddMapLayer()
{
// Create the MapPrinterLayer and set the position
MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();
mapPrinterLayer.MapUnit = GeographyUnit.Meter;
mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1));
mapPrinterLayer.Open();
// Set the maps position slightly below the pages center and 8 inches wide and 7 inches tall
RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Meter);
mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Meter);
// Setup the intial extent and ensure they snap to the default ZoomLevel
ZoomLevelSet zoomLevelSet = new ZoomLevelSet();
//mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(zoomLevelSet.ZoomLevel03.Scale, new RectangleShape(-180, 90, 180, -90), mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height);
// Setup the Countries mapping layer
ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"\\192.168.178.31\hybrid\sulingen kirche\daten\referenzen\Vermessung\sulingen.shp", ShapeFileReadWriteMode.ReadOnly);
shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Highway1;
Proj4Projection BaseProjection = new Proj4Projection();
BaseProjection.ExternalProjectionParametersString = Proj4Projection.GetSphericalMercatorParametersString();
BaseProjection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(31467);
BaseProjection.Open();
shapefileFeatureLayer.FeatureSource.Projection = BaseProjection;
// Add the new country layer to the MapPrinterLayer
mapPrinterLayer.Layers.Add(shapefileFeatureLayer);
// Add the MapPrinterLayer to the PrinterInteractiveOverlay
PrinterInteractiveOverLay printerInteractiveOverLay = (PrinterInteractiveOverLay)winformsMap1.InteractiveOverlays["PrintPreviewOverlay"];
printerInteractiveOverLay.PrinterLayers.Add("MapLayer", mapPrinterLayer);
}
What to do?
Regards
Hardy