Sure here is the entire Method Code (BTW, I’ve just adapted the Sample, so pretty much everything else is the same as the Sample)
private void AddMapLayer()
{
// Create the MapPrinterLayer and set the position
MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();
mapPrinterLayer.MapUnit = GeographyUnit.DecimalDegree;
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.Inch);
mapPrinterLayer.SetPosition(8, 10, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);
// Setup the intial extent and ensure they snap to the default ZoomLevel
ZoomLevelSet zoomLevelSet = new ZoomLevelSet();
mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(zoomLevelSet.ZoomLevel03.Scale, CurrentExtent,
mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height);
// Add the World Map Kit layer as the background
WorldMapKitLayer worldMapKitLayer = new WorldMapKitLayer();
worldMapKitLayer.Projection = WorldMapKitProjection.DecimalDegrees;
mapPrinterLayer.Layers.Add(worldMapKitLayer);
if (Physicians != null) //Physicians DataTable
{
InMemoryFeatureLayer physicianLayer = new InMemoryFeatureLayer();
foreach (DataRow row in Physicians.Rows)
{
PointShape point = new PointShape(Convert.ToDouble(row["longitude"]), Convert.ToDouble(row["latitude"]));
ShapeValidationResult result = point.Validate(ShapeValidationMode.Simple);
if (result.IsValid)
{
point.Id = bc.Getkey();
Feature feature = point.GetFeature();
physicianLayer.InternalFeatures.Add(feature);
}
}
MemoryStream stream = new MemoryStream();
Marketware.Resource1.doctor16.Save(stream, ImageFormat.Png);
GeoImage geoImage = new GeoImage(stream);
PointStyle hStyle = new PointStyle();
hStyle.Image = geoImage;
physicianLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(hStyle);
mapPrinterLayer.Layers.Add(physicianLayer);
}
if (Hospitals != null) //Hospitals DataTable
{
InMemoryFeatureLayer hospitalLayer = new InMemoryFeatureLayer();
foreach (DataRow row in Hospitals.Rows)
{
PointShape point = new PointShape(Convert.ToDouble(row["longitude"]), Convert.ToDouble(row["latitude"]));
ShapeValidationResult result = point.Validate(ShapeValidationMode.Simple);
if (result.IsValid)
{
point.Id = bc.Getkey();
Feature feature = point.GetFeature();
hospitalLayer.InternalFeatures.Add(feature);
}
}
MemoryStream stream = new MemoryStream();
Marketware.Resource1.Hospital16.Save(stream, ImageFormat.Png); //Original Image is PNG
GeoImage geoImage = new GeoImage(stream);
PointStyle hStyle = new PointStyle();
hStyle.Image = geoImage;
hospitalLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(hStyle);
hospitalLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapPrinterLayer.Layers.Add(hospitalLayer);
}
//Now Add our Detail (Polygon) Layer
if (DetailLayer != null)
{
mapPrinterLayer.Layers.Add(DetailLayer);
}
// Add the MapPrinterLayer to the PrinterInteractiveOverlay
mapPrinterLayer.MapExtent = CurrentExtent; //The original Extent of the MapControl before the PrintPreview window is called;
PrinterInteractiveOverLay printerInteractiveOverLay = (PrinterInteractiveOverLay)MapControl.InteractiveOverlays["PrintPreviewOverlay"];
printerInteractiveOverLay.PrinterLayers.Add("MapLayer", mapPrinterLayer);
}