private void ScaleLineElementEntity_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Preview" || (MapPrinterLayer.MapUnit == GeographyUnit.DecimalDegree && !PrinterLayerHelper.CheckDecimalDegreeIsInRange(MapPrinterLayer.MapExtent))) { return; } if (!MapPrinterLayer.IsOpen) { MapPrinterLayer.Open(); } try { ScaleLinePrinterLayer scaleLinePrinterLayer = new ScaleLinePrinterLayer(MapPrinterLayer); scaleLinePrinterLayer.BackgroundMask = BackgroundStyle as AreaStyle; scaleLinePrinterLayer.MapUnit = MapPrinterLayer.MapUnit; scaleLinePrinterLayer.UnitSystem = SelectedUnitSystem; var boundingBox = MapPrinterLayer.GetBoundingBox(); var pageCenter = boundingBox.GetCenterPoint(); scaleLinePrinterLayer.SetPosition(1.25, .25, -3.25, -2.25, PrintingUnit.Inch); using (Bitmap bitmap = new Bitmap(220, 60)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); scaleLinePrinterLayer.SafeProcess(() => { var scaleLineBoundingBox = scaleLinePrinterLayer.GetBoundingBox(); canvas.BeginDrawing(bitmap, scaleLineBoundingBox, GeographyUnit.Meter); scaleLinePrinterLayer.Draw(canvas, new Collection <SimpleCandidate>()); }); //scaleLinePrinterLayer.Open(); //var scaleLineBoundingBox = scaleLinePrinterLayer.GetBoundingBox(); //canvas.BeginDrawing(bitmap, scaleLineBoundingBox, GeographyUnit.Meter); //scaleLinePrinterLayer.Draw(canvas, new Collection<SimpleCandidate>()); //scaleLinePrinterLayer.Close(); canvas.EndDrawing(); MemoryStream ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.EndInit(); Preview = bitmapImage; } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } }
private void AddMapLayer() { // Create the MapPrinterLayer and set the position MapPrinterLayer mapPrinterLayer = new MapPrinterLayer(); mapPrinterLayer.MapUnit = GeographyUnit.Meter; mapPrinterLayer.MapExtent = new RectangleShape(-20026376.39, 20048966.10, 20026376.39, -20048966.10); mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColors.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, 7, 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 = MapUtil.ZoomToScale(zoomLevelSet.ZoomLevel03.Scale, new RectangleShape(-20026376.39, 20048966.10, 20026376.39, -20048966.10), mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height); // This ThinkGeo Cloud test key is exclusively for demonstration purposes and is limited to requesting base map // tiles only. Do not use it in your own applications, as it may be restricted or disabled without prior notice. // Please visit https://cloud.thinkgeo.com to create a free key for your own use. //ThinkGeoCloudRasterMapsLayer worldMapKitLayer = new ThinkGeoCloudRasterMapsLayer("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~"); //worldMapKitLayer.TileCache = null; //mapPrinterLayer.Layers.Add(worldMapKitLayer); ShapeFileFeatureLayer backgroundLayer = new ShapeFileFeatureLayer(@"data/Countries02_3857.shp", FileAccess.Read); backgroundLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; backgroundLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyle.CreateSimpleAreaStyle(GeoColors.White, GeoColors.Black); mapPrinterLayer.Layers.Add(backgroundLayer); // Setup the Countries mapping layer ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"data/Countries02_3857.shp", FileAccess.Read); shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Create the class break style for countries less than 70 million ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP_CNTRY"); // Create the style and class break for countries with greater and 70 million AreaStyle hatchAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(100, GeoColors.Green))); classBreakStyle.ClassBreaks.Add(new ClassBreak(70000000, hatchAreaStyle)); // Add the class break style to the layer shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); // Add the new country layer to the MapPrinterLayer mapPrinterLayer.Layers.Add(shapefileFeatureLayer); // Add the MapPrinterLayer to the PrinterInteractiveOverlay PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"]; printerInteractiveOverlay.PrinterLayers.Add("MapLayer", mapPrinterLayer); }
private void btnZoomOut_Click(object sender, RoutedEventArgs e) { // Grab the MapPrinterLayer and adjust the extent PrinterInteractiveOverlay printerOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"]; MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerOverlay.PrinterLayers["MapLayer"])); // Here we snap the current scale to the default zoomLevelSet when we zoom in ZoomLevelSet zoomLevelSet = new ZoomLevelSet(); double newScale = ZoomLevelSet.GetHigherZoomLevelScale(MapUtil.GetScale(mapPrinterLayer.MapExtent, (float)mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.MapUnit), zoomLevelSet); mapPrinterLayer.MapExtent = MapUtil.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height); Map1.Refresh(); }