private void TextElementEntity_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (withPreview && e.PropertyName != "Preview" && !string.IsNullOrEmpty(text.Trim())) { LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer(); labelPrinterLayer.LoadFromViewModel(this); using (Bitmap bitmap = new Bitmap(250, 100)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter); labelPrinterLayer.SafeProcess(() => { labelPrinterLayer.Draw(canvas, new Collection <SimpleCandidate>()); }); //labelPrinterLayer.Open(); //labelPrinterLayer.Draw(canvas, new System.Collections.ObjectModel.Collection<SimpleCandidate>()); //labelPrinterLayer.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; RaisePropertyChanged(() => Preview); } } }
public static BitmapImage GetImageSource(GeoBrush geoBrush) { BitmapImage result = null; System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(16, 16); PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); RectangleShape area = new RectangleShape(-90, 90, 90, -90); geoCanvas.BeginDrawing(nativeImage, area, GeographyUnit.DecimalDegree); try { geoCanvas.DrawArea(area, geoBrush, DrawingLevel.LevelOne); geoCanvas.EndDrawing(); MemoryStream streamSource = new MemoryStream(); nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png); result = new BitmapImage(); result.BeginInit(); result.StreamSource = streamSource; result.EndInit(); result.Freeze(); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { nativeImage.Dispose(); } return(result); }
private void ScaleBarViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "Preview") { ScaleBarPrinterLayer scaleBarPrinterLayer = new ScaleBarPrinterLayer(MapPrinterLayer); scaleBarPrinterLayer.BackgroundMask = Background as AreaStyle; scaleBarPrinterLayer.BarBrush = Color; scaleBarPrinterLayer.AlternateBarBrush = AlternatingColor; scaleBarPrinterLayer.TextStyle.NumericFormat = NumericFormatString; scaleBarPrinterLayer.UnitFamily = SelectedUnitSystem; scaleBarPrinterLayer.DragMode = DragMode; scaleBarPrinterLayer.ResizeMode = ResizeMode; scaleBarPrinterLayer.Open(); scaleBarPrinterLayer.MapUnit = MapPrinterLayer.MapUnit; scaleBarPrinterLayer.SetPosition(1.25, .25, -3.25, -2.25, PrintingUnit.Inch); var boundingBox = scaleBarPrinterLayer.GetBoundingBox(); //using (Bitmap bitmap = new Bitmap((int)boundingBox.Width, (int)boundingBox.Height)) using (Bitmap bitmap = new Bitmap(210, 56)) { var ms = new MemoryStream(); var gdiPlusGeoCanvas = new PlatformGeoCanvas(); gdiPlusGeoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Feet); scaleBarPrinterLayer.Draw(gdiPlusGeoCanvas, new Collection <SimpleCandidate>()); gdiPlusGeoCanvas.EndDrawing(); bitmap.Save(ms, ImageFormat.Png); BitmapImage previewImage = new BitmapImage(); previewImage.BeginInit(); previewImage.StreamSource = ms; previewImage.EndInit(); Preview = previewImage; } } }
/// <summary> /// This method overrides from its base class TileOverlay. /// It actually requests image for the passed tile with the passed world extent. /// </summary> /// <param name="tile">A tile object that creating by the GetTileCore method. It's the tile which needs to be draw in this mehtod.</param> /// <param name="targetExtent">A world extent that to draw the passed tile object.</param> protected override void DrawTileCore(Wpf.Tile tile, RectangleShape targetExtent) { LayerTile layerTile = tile as LayerTile; if (layerTile != null) { layerTile.TileCache = TileCache; layerTile.DrawingLayers.Clear(); layerTile.DrawingLayers.Add(wktLayer); Bitmap nativeImage = new Bitmap((int)tile.Width, (int)tile.Height); PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); geoCanvas.BeginDrawing(nativeImage, targetExtent, MapArguments.MapUnit); if (tile.IsAsync) { layerTile.DrawAsync(geoCanvas); } else { layerTile.Draw(geoCanvas); geoCanvas.EndDrawing(); layerTile.CommitDrawing(geoCanvas, MapUtils.GetImageSourceFromNativeImage(nativeImage)); } } }
public HttpResponseMessage GetTile(string layerId, string accessId, int z, int x, int y) { // Create the LayerOverlay for displaying the map. LayerOverlay layerOverlay; // The FilterStyle overlay is not stored in CachedOverlay. if (layerId == "FilterStyle") { layerOverlay = GetFilterStyleOverlay(accessId); } else { layerOverlay = cachedOverlays[layerId]; } // Draw the map and return the image back to client in an HttpResponseMessage. using (Bitmap bitmap = new Bitmap(256, 256)) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); RectangleShape boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter); geoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Meter); layerOverlay.Draw(geoCanvas); geoCanvas.EndDrawing(); MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, ImageFormat.Png); HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.OK); responseMessage.Content = new ByteArrayContent(memoryStream.ToArray()); responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return(responseMessage); } }
private void DataGridViewModelPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "FontPreview" || e.PropertyName == "AddingColumnName" || e.PropertyName == "RemovingColumnName") { return; } LabelPrinterLayer labelPrinterLayer = GetLabelPrinterLayer(); using (Bitmap bitmap = new Bitmap(311, 60)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter); labelPrinterLayer.SafeProcess(() => { labelPrinterLayer.Draw(canvas, new System.Collections.ObjectModel.Collection <SimpleCandidate>()); }); canvas.EndDrawing(); MemoryStream ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.EndInit(); FontPreview = bitmapImage; } }
private void RefreshPreview(string propertyName) { if (propertyName != "Preview" && !string.IsNullOrEmpty(selectedFormat.Trim())) { DatePrinterLayer datePrinterLayer = new DatePrinterLayer(); datePrinterLayer.LoadFromViewModel(this); using (Bitmap bitmap = new Bitmap(460, 50)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.Meter); datePrinterLayer.SafeProcess(() => { datePrinterLayer.Draw(canvas, new Collection <SimpleCandidate>()); }); canvas.EndDrawing(); MemoryStream ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = ms; bitmapImage.EndInit(); preview = bitmapImage; RaisePropertyChanged(() => Preview); } } }
protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(new Bitmap((int)virtualMapWidth, (int)virtualMapHeight), virtualWorldExtent, MapUnit); return(canvas.MeasureText(text, font)); }
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)); } }
public void DrawSample(Stream stream, double imageWidth, double imageHeight) { TextStyle textStyle = GetTextStyle(); PlatformGeoCanvas canvas = new PlatformGeoCanvas(); using (Bitmap bitmap = new Bitmap((int)imageWidth, (int)imageHeight)) { canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.DecimalDegree); textStyle.DrawSample(canvas, new DrawingRectangleF((float)(imageWidth * 0.5), (float)(imageHeight * 0.5), (float)imageWidth, (float)imageHeight)); canvas.EndDrawing(); bitmap.Save(stream, ImageFormat.Png); } }
public static Bitmap GetPreviewBitmap(GisEditorWpfMap printMap) { var printerOverlay = printMap.InteractiveOverlays.OfType <PrinterInteractiveOverlay>().FirstOrDefault(); var pagePrinterLayer = printerOverlay.PrinterLayers.OfType <PagePrinterLayer>().FirstOrDefault(); RectangleShape pageBoundingBox = pagePrinterLayer.GetBoundingBox(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)pageBoundingBox.Width, (int)pageBoundingBox.Height); PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.ClippingArea = pageBoundingBox; canvas.BeginDrawing(bitmap, pageBoundingBox, printMap.MapUnit); try { SetLegendIsPrinting(true, printerOverlay); SetDescriptionLabelVisible(false, printerOverlay); printerOverlay.PrinterLayers.OfType <GisEditorLegendPrinterLayer>().ForEach(l => l.IsPrinting = true); Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>(); foreach (var printerLayer in printerOverlay.PrinterLayers.Where(l => !(l is PagePrinterLayer))) { if (printerLayer is SimplifyMapPrinterLayer) { (printerLayer as SimplifyMapPrinterLayer).DrawingMode = MapPrinterDrawingMode.Vector; } printerLayer.IsDrawing = !(printerLayer is SimplifyMapPrinterLayer); if (!printerLayer.IsOpen) { printerLayer.Open(); } printerLayer.Draw(canvas, labelsInAllLayers); } canvas.EndDrawing(); foreach (var mapPrinterLayer in printerOverlay.PrinterLayers.Where(l => l.GetType() == typeof(SimplifyMapPrinterLayer)).OfType <SimplifyMapPrinterLayer>()) { mapPrinterLayer.DrawingMode = MapPrinterDrawingMode.Raster; mapPrinterLayer.DrawDescription = true; } return(bitmap); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); return(bitmap); } finally { SetLegendIsPrinting(false, printerOverlay); SetDescriptionLabelVisible(true, printerOverlay); } }
private static void DrawPolygon(PolygonShape p, string f) { Bitmap bmp = new Bitmap(256, 256); PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bmp, new RectangleShape(-30, 30, 30, -30), GeographyUnit.DecimalDegree); canvas.DrawArea(p, GeoBrushes.Blue, DrawingLevel.LabelLevel); canvas.EndDrawing(); string resultFilePath = f; bmp.Save(resultFilePath); Process.Start(resultFilePath); }
public static byte[] GetPreviewBinary(this Style style, int width = 23, int height = 23) { using (var bitmap = new Bitmap(width, height)) { var canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-10, 10, 10, -10), GeographyUnit.DecimalDegree); DrawStyleSamples(style, width, height, canvas); canvas.EndDrawing(); using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, ImageFormat.Png); return(memoryStream.ToArray()); } } }
private GeoImage GetCacheImage(PageGeoCanvas pageGeoCanvas, GeographyUnit geographyUnit, RectangleShape adjustedWorldExtent, Collection <SimpleCandidate> labelsInAllLayers, double width, double height) { RectangleShape currentBoundingBox = GetBoundingBox(); if (mapImageCache == null && Layers.Count > 0) { Bitmap bitmap = null; MemoryStream memoryStream = null; try { bitmap = new Bitmap((int)width, (int)height); PlatformGeoCanvas tmpCanvas = new PlatformGeoCanvas(); tmpCanvas.DrawingQuality = DrawingQuality.HighSpeed; tmpCanvas.BeginDrawing(bitmap, currentBoundingBox, geographyUnit); pageGeoCanvas.BeginDrawing(tmpCanvas, adjustedWorldExtent, MapUnit); lock (Layers) { foreach (Layer layer in Layers) { if (!layer.IsOpen) { layer.Open(); } pageGeoCanvas.Flush(); layer.Draw(pageGeoCanvas, labelsInAllLayers); } } pageGeoCanvas.EndDrawing(); tmpCanvas.EndDrawing(); IsDrawing = false; memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); mapImageCache = new GeoImage(memoryStream); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { bitmap?.Dispose(); } } return(mapImageCache); }
private BitmapImage GetImageSource() { MemoryStream streamSource = null; if (Width != 0 && Height != 0) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas { CompositingQuality = CompositingQuality.HighSpeed, SmoothingMode = SmoothingMode.HighSpeed, DrawingQuality = DrawingQuality.CanvasSettings, }; SizeF measuredSize = Measure(geoCanvas); Bitmap nativeImage = new Bitmap((int)(measuredSize.Width + LeftPadding + RightPadding + 1), (int)(measuredSize.Height + TopPadding + BottomPadding + 1)); geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-10, 10, 10, -10), GeographyUnit.Meter); simpleCandidates.Clear(); LegendItem newLegendItem = ToLegendItem(); newLegendItem.Width = measuredSize.Width; newLegendItem.Height = measuredSize.Height; //newLegendItem.Draw(0, 0, 100, geoCanvas, simpleCandidates); newLegendItem.Draw(geoCanvas, simpleCandidates, new LegendDrawingParameters { XOffset = 0, YOffset = 0 }); geoCanvas.EndDrawing(); streamSource = new MemoryStream(); nativeImage.Save(streamSource, ImageFormat.Png); } BitmapImage previewSource = new BitmapImage(); if (streamSource != null) { previewSource.BeginInit(); previewSource.StreamSource = streamSource; previewSource.EndInit(); previewSource.Freeze(); } return(previewSource); }
private HttpResponseMessage DrawTileImage(LayerOverlay layerOverlay, int z, int x, int y) { using (Bitmap bitmap = new Bitmap(256, 256)) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); RectangleShape boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter); geoCanvas.BeginDrawing(bitmap, boundingBox, GeographyUnit.Meter); layerOverlay.Draw(geoCanvas); geoCanvas.EndDrawing(); MemoryStream ms = new MemoryStream(); bitmap.Save(ms, ImageFormat.Png); HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.OK); msg.Content = new ByteArrayContent(ms.ToArray()); msg.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return(msg); } }
private void ConvertTextToAnnotation(string valueStyleMatchColumnName, TextStyle textStyle, Feature feature, string annotationText) { PlatformGeoCanvas canvas = new PlatformGeoCanvas { CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed, DrawingQuality = DrawingQuality.HighSpeed, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed }; double width = GisEditor.ActiveMap.ActualWidth; double height = GisEditor.ActiveMap.ActualHeight; Bitmap nativeImage = new Bitmap((int)width, (int)height); canvas.BeginDrawing(nativeImage, GisEditor.ActiveMap.CurrentExtent, GisEditor.ActiveMap.MapUnit); DrawingRectangleF rectangle = canvas.MeasureText(annotationText, textStyle.Font); Type type = textStyle.GetType(); MethodInfo method = type.GetMethod("GetLabelingCandidates", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { Collection <LabelingCandidate> candidates = method.Invoke(textStyle, new object[] { feature, canvas }) as Collection <LabelingCandidate>; if (candidates != null) { foreach (var candidate in candidates) { foreach (var labelInfo in candidate.LabelInformation) { ScreenPointF point = new ScreenPointF((float)labelInfo.PositionInScreenCoordinates.X + rectangle.Width / 2 + 3, (float)labelInfo.PositionInScreenCoordinates.Y - rectangle.Height / 2); PointShape pointShape = ExtentHelper.ToWorldCoordinate(GisEditor.ActiveMap.CurrentExtent, point, (float)width, (float)height); Feature pointFeature = new Feature(pointShape); pointFeature.Id = pointShape.Id; pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.valueStyleMatchColumnName] = valueStyleMatchColumnName; pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName] = annotationText; CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures[pointShape.Id] = pointFeature; } } } } }
private void RefreshHighlightTile(RectangleShape targetExtent) { highlightTile.TargetExtent = targetExtent; highlightTile.DrawingLayers.Clear(); highlightTile.DrawingLayers.Add(highlightFeatureLayer); highlightTile.DrawingLayers.Add(standOutHighlightFeatureLayer); if (MapArguments != null) { highlightTile.Width = MapArguments.ActualWidth; highlightTile.Height = MapArguments.ActualHeight; highlightTile.ZoomLevelIndex = MapArguments.GetSnappedZoomLevelIndex(targetExtent); using (System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap((int)highlightTile.Width, (int)highlightTile.Height)) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); geoCanvas.BeginDrawing(nativeImage, targetExtent, MapArguments.MapUnit); highlightTile.Draw(geoCanvas); geoCanvas.EndDrawing(); highlightTile.CommitDrawing(geoCanvas, GetImageSourceFromNativeImage(nativeImage)); } } }
private MemoryStream GetImageStream(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers, RectangleShape adjustedWorldExtent, RectangleShape boundingBox) { using (Bitmap bitmap = new Bitmap((int)boundingBox.Width, (int)boundingBox.Height)) { MemoryStream ms = new MemoryStream(); PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas(); gdiPlusGeoCanvas.DrawingQuality = DrawingQuality.HighQuality; gdiPlusGeoCanvas.BeginDrawing(bitmap, adjustedWorldExtent, MapUnit); foreach (Layer layer in Layers) { gdiPlusGeoCanvas.Flush(); layer.SafeProcess(() => { layer.Draw(gdiPlusGeoCanvas, labelsInAllLayers); }); } gdiPlusGeoCanvas.EndDrawing(); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); return(ms); } }
private BitmapImage GetImageSource() { MemoryStream streamSource = null; if (PreviewWidth != 0 && PreviewHeight != 0 && Width != 0 && Height != 0 && LegendItems.Count > 0) { Bitmap nativeImage = new Bitmap(PreviewWidth, PreviewHeight); PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas { CompositingQuality = CompositingQuality.HighSpeed, SmoothingMode = SmoothingMode.HighSpeed, DrawingQuality = DrawingQuality.CanvasSettings, }; LegendAdornmentLayer tmpLegendAdornmentLayer = ToLegendAdornmentLayer(); double left = -tmpLegendAdornmentLayer.Width * .5; double top = tmpLegendAdornmentLayer.Height * .5; double right = left + tmpLegendAdornmentLayer.Width; double bottom = top - tmpLegendAdornmentLayer.Height; geoCanvas.BeginDrawing(nativeImage, new RectangleShape(left, top, right, bottom), GeographyUnit.Meter); simpleCandidates.Clear(); tmpLegendAdornmentLayer.Draw(geoCanvas, simpleCandidates); geoCanvas.EndDrawing(); streamSource = new MemoryStream(); nativeImage.Save(streamSource, ImageFormat.Png); } BitmapImage previewSource = new BitmapImage(); if (streamSource != null) { previewSource.BeginInit(); previewSource.StreamSource = streamSource; previewSource.EndInit(); previewSource.Freeze(); } return(previewSource); }
private static byte[] GetComplicatedStyleSampleImageBinary(IEnumerable <Style> styles, int width, int height) { int loopCount = styles.Count() > 4 ? 4 : styles.Count(); using (Bitmap bitmap = new Bitmap(width, height)) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(bitmap, new RectangleShape(-180, 90, 180, -90), GeographyUnit.DecimalDegree); Collection <Tuple <int, int> > tuples = new Collection <Tuple <int, int> >() { new Tuple <int, int>(1, 1), new Tuple <int, int>(3, 1), new Tuple <int, int>(1, 3), new Tuple <int, int>(3, 3) }; float tileWidth = width * 0.5f; float tileHeight = height * 0.5f; float centerXParameter = tileWidth * 0.5f; float centerYParameter = tileHeight * 0.5f; for (int i = 0; i < loopCount; i++) { Style customStyle = styles.ElementAt(i); float centerX = tuples[i].Item1 * centerXParameter; float centerY = tuples[i].Item2 * centerYParameter; if (customStyle != null) { customStyle.DrawSample(canvas, new DrawingRectangleF(centerX, centerY, tileWidth, tileHeight)); } } canvas.EndDrawing(); using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Save(memoryStream, ImageFormat.Png); return(memoryStream.ToArray()); } } }
private ImageSource GetPreviewSourceFromStyle(Style style) { if (style != null) { System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(20, 20); MemoryStream streamSource = new MemoryStream(); try { var geoCanvas = new PlatformGeoCanvas(); geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-10, 10, 10, -10), GeographyUnit.DecimalDegree); geoCanvas.Clear(new GeoSolidBrush(GeoColor.StandardColors.White)); style.DrawSample(geoCanvas); geoCanvas.EndDrawing(); nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png); BitmapImage imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = streamSource; imageSource.EndInit(); return(imageSource); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); return(new BitmapImage()); } finally { nativeImage.Dispose(); } } else { return(null); } }
private static void PreviewImageChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { FontPicker currentInstance = (FontPicker)sender; int selectedCharIndex = currentInstance.SelectedCharacterIndex; PointStyle pointStyle = new PointStyle( new GeoFont(currentInstance.SelectedFontFamily.Source, defaultFontSize, currentInstance.SelectedFontStyle), currentInstance.SelectedCharacterIndex, new GeoSolidBrush(GeoColor.StandardColors.Black)); System.Drawing.Bitmap nativeImage = new System.Drawing.Bitmap(defaultPreviewSize, defaultPreviewSize); var geoCanvas = new PlatformGeoCanvas(); try { geoCanvas.BeginDrawing(nativeImage, new RectangleShape(-90, 90, 90, -90), GeographyUnit.DecimalDegree); pointStyle.DrawSample(geoCanvas); geoCanvas.EndDrawing(); MemoryStream streamSource = new MemoryStream(); nativeImage.Save(streamSource, System.Drawing.Imaging.ImageFormat.Png); BitmapImage imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = streamSource; imageSource.EndInit(); currentInstance.PreviewImage = imageSource; } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { nativeImage.Dispose(); } }
private LayerTile DrawHighlightTile(RectangleShape targetExtent, LayerTile tile) { tile.DrawingLayers.Clear(); if (highlightFeatureLayer.InternalFeatures.Count > 0) { tile.DrawingLayers.Add(highlightFeatureLayer); } GeoCanvas geoCanvas = new PlatformGeoCanvas() { CompositingQuality = CompositingQuality.HighSpeed, DrawingQuality = DrawingQuality.HighSpeed, SmoothingMode = SmoothingMode.HighSpeed }; Bitmap bitmap = new Bitmap((int)tile.Width, (int)tile.Height); geoCanvas.BeginDrawing(bitmap, targetExtent, MapArguments.MapUnit); tile.Draw(geoCanvas); geoCanvas.EndDrawing(); tile.CommitDrawing(geoCanvas, MapSuiteSampleHelper.GetImageSourceFromNativeImage(bitmap)); return(tile); }
public GeoImage ToGeoImage(RectangleShape worldExtent, GeographyUnit drawingMapUnit) { // only support SingleTile mode, otherwise return the background image directly if (TileType != TileType.SingleTile) { if (BackgroundImage == null) { return(null); } else { return(new GeoImage(BackgroundImage.GetImageStream())); } } // find any layer tiles in this overlay var layerTiles = new List <LayerTile>(); foreach (var overlayUIElement in OverlayCanvas.Children) { if (overlayUIElement is Canvas) { foreach (var canvasUIElement in (overlayUIElement as Canvas).Children) { if (canvasUIElement is LayerTile) { layerTiles.Add(canvasUIElement as LayerTile); } } } } GeoImage geoImage = null; if (layerTiles.Count > 0) { int width = Convert.ToInt32(layerTiles.First().ActualWidth); int height = Convert.ToInt32(layerTiles.First().ActualHeight); if (width > 0 && height > 0) { // initialize geoCanvas by using current BackgroundImage var geoCanvas = new PlatformGeoCanvas(); if (BackgroundImage == null) { geoImage = new GeoImage(width, height); geoCanvas.BeginDrawing(geoImage, worldExtent, drawingMapUnit); geoCanvas.Clear(new GeoSolidBrush(GeoColors.Transparent)); } else { geoImage = new GeoImage(BackgroundImage.GetImageStream()); geoCanvas.BeginDrawing(geoImage, worldExtent, drawingMapUnit); } // draw each layer tiles foreach (var layerTile in layerTiles) { layerTile.Draw(geoCanvas); } geoCanvas.EndDrawing(); } } return(geoImage); }
public static void SaveToKmlMenuitemClick(object sender, RoutedEventArgs e) { Collection <Feature> features = GisEditor.SelectionManager.GetSelectedFeatures(); if (features.All(i => !GisEditor.ActiveMap.CurrentExtent.Intersects(i))) { ShowOptionsIfNoSelectedFeatureInCurrentExtent(features); return; } Collection <FeatureLayer> featureLayers = new Collection <FeatureLayer>(); var featuresGroup = GisEditor.SelectionManager.GetSelectionOverlay().GetSelectedFeaturesGroup(); Proj4Projection tempProjection = new Proj4Projection(); tempProjection.InternalProjectionParametersString = GisEditor.ActiveMap.DisplayProjectionParameters; tempProjection.ExternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString(); tempProjection.SyncProjectionParametersString(); try { tempProjection.Open(); foreach (var item in featuresGroup) { if (item.Value.Count > 0) { InMemoryFeatureLayer layer = new InMemoryFeatureLayer(); ZoomLevelSet sourceZoomLevelSet = item.Key.ZoomLevelSet; try { string tempXml = GisEditor.Serializer.Serialize(sourceZoomLevelSet); ZoomLevelSet targetZoomLevelSet = (ZoomLevelSet)GisEditor.Serializer.Deserialize(tempXml); layer.ZoomLevelSet = targetZoomLevelSet; layer.Open(); layer.EditTools.BeginTransaction(); foreach (var feature in item.Value) { Feature newFeature = tempProjection.ConvertToExternalProjection(feature); layer.EditTools.Add(newFeature); } layer.EditTools.CommitTransaction(); if (!item.Key.IsOpen) { item.Key.Open(); } foreach (var column in item.Key.QueryTools.GetColumns()) { layer.Columns.Add(column); } featureLayers.Add(layer); } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } } } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); } finally { tempProjection.Close(); } KmlParameter parameter = GetKmlParameter(); //System.Windows.Forms.SaveFileDialog sf = new System.Windows.Forms.SaveFileDialog(); //sf.Filter = "(*.kml)|*.kml|(*.kmz)|*.kmz"; //sf.FileName = string.Format("{0}-{1}", "KmlExportFile", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); if (parameter != null) { if (Path.GetExtension(parameter.PathFileName).ToUpper() == ".KML") { SaveKmlData(featureLayers, parameter); } else if (Path.GetExtension(parameter.PathFileName).ToUpper() == ".KMZ") { StringBuilder builder = GetKmlDataBuilder(featureLayers); PlatformGeoCanvas canvas = new PlatformGeoCanvas(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)GisEditor.ActiveMap.ActualWidth, (int)GisEditor.ActiveMap.ActualHeight); RectangleShape drawingExtent = GetDrawingExtentInWgs84(); canvas.BeginDrawing(bitmap, drawingExtent, GeographyUnit.DecimalDegree); featureLayers.ForEach(l => { Proj4ProjectionInfo projectionInfo = l.GetProj4ProjectionInfo(); if (projectionInfo != null) { projectionInfo.ExternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString(); projectionInfo.SyncProjectionParametersString(); } l.Open(); l.Draw(canvas, new Collection <SimpleCandidate>()); }); canvas.EndDrawing(); string kmlPath = Path.ChangeExtension(parameter.PathFileName, ".kml"); string pngPath = Path.ChangeExtension(parameter.PathFileName, ".png"); if (File.Exists(kmlPath)) { File.Delete(kmlPath); } if (File.Exists(pngPath)) { File.Delete(pngPath); } MemoryStream stream = new MemoryStream(); bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png); byte[] bitmapArray = stream.GetBuffer(); File.WriteAllText(kmlPath, builder.ToString()); File.WriteAllBytes(pngPath, bitmapArray); var zipFileAdapter = ZipFileAdapterManager.CreateInstance(); zipFileAdapter.AddFileToZipFile(kmlPath, ""); zipFileAdapter.AddFileToZipFile(pngPath, ""); zipFileAdapter.Save(Path.ChangeExtension(parameter.PathFileName, ".kmz")); File.Delete(kmlPath); File.Delete(pngPath); } string mentionedString = GisEditor.LanguageManager.GetStringResource("KMLFileHasSavedSuccessText"); if (MessageBox.Show(mentionedString, "Open in Google Earth", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { string proInstalledPath = GetGoogleEarthProInstalledPath(); OpenKmlFileWithGoogleEarth(string.IsNullOrEmpty(proInstalledPath) ? GetGoogleEarthInstalledPath() : proInstalledPath , parameter.PathFileName); } } }
private IEnumerable <LegendImporterItemViewModel> GenerateStyleItems(Styles.Style style, int level) { if (style is AreaStyle || style is PointStyle || style is LineStyle) { LegendImporterItemViewModel styleLegendItem = new LegendImporterItemViewModel { Text = style.Name, CheckBoxVisibility = Visibility.Visible, Level = level, LeftPaddingLevel = level, Style = style }; using (Bitmap nativeImage = new Bitmap(iconSize, iconSize)) { var geoCanvas = new PlatformGeoCanvas(); var drawingShape = new RectangleShape(-10, 10, 10, -10); geoCanvas.BeginDrawing(nativeImage, drawingShape, GeographyUnit.Meter); style.DrawSample(geoCanvas, new DrawingRectangleF(geoCanvas.Width * .5f, geoCanvas.Height * .5f, geoCanvas.Width, geoCanvas.Height)); geoCanvas.EndDrawing(); var streamSource = new MemoryStream(); nativeImage.Save(streamSource, ImageFormat.Png); var imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = streamSource; imageSource.EndInit(); imageSource.Freeze(); styleLegendItem.IconSource = imageSource; } yield return(styleLegendItem); } else if (style is ClassBreakStyle || style is RegexStyle || style is ValueStyle || style is FilterStyle) { var clonedStyle = style.CloneDeep(); var classBreakStyle = clonedStyle as ClassBreakStyle; var regexStyle = clonedStyle as RegexStyle; var valueStyle = clonedStyle as ValueStyle; var filterStyle = clonedStyle as FilterStyle; IEnumerable <Styles.Style> subStyles = new Collection <Styles.Style>(); if (classBreakStyle != null) { subStyles = classBreakStyle.ClassBreaks.SelectMany(classBreakItem => { foreach (var item in classBreakItem.CustomStyles) { item.Name = ClassBreakSubItem.GetClassBreakStyleName(classBreakItem.Value); } return(classBreakItem.CustomStyles); }); } else if (regexStyle != null) { subStyles = regexStyle.RegexItems.SelectMany(regexItem => regexItem.CustomStyles); } else if (filterStyle != null) { subStyles = new Collection <Styles.Style>();//filterStyle.Styles; } else { subStyles = valueStyle.ValueItems.SelectMany(valueItem => { foreach (var item in valueItem.CustomStyles) { item.Name = valueItem.Value; } return(valueItem.CustomStyles); }); } LegendImporterItemViewModel styleLegendItem = new LegendImporterItemViewModel { Text = style.Name, CheckBoxVisibility = Visibility.Visible, Level = level, Style = style }; styleLegendItem.PropertyChanged += LayerLegendImporterItemPropertyChanged; using (Bitmap nativeImage = new Bitmap(iconSize, iconSize)) { var geoCanvas = new PlatformGeoCanvas(); var drawingShape = new RectangleShape(-10, 10, 10, -10); geoCanvas.BeginDrawing(nativeImage, drawingShape, GeographyUnit.Meter); style.DrawSample(geoCanvas, new DrawingRectangleF(geoCanvas.Width * .5f, geoCanvas.Height * .5f, geoCanvas.Width, geoCanvas.Height)); geoCanvas.EndDrawing(); var streamSource = new MemoryStream(); nativeImage.Save(streamSource, ImageFormat.Png); BitmapImage imageSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = streamSource; imageSource.EndInit(); imageSource.Freeze(); styleLegendItem.IconSource = imageSource; } yield return(styleLegendItem); foreach (var itemStyle in subStyles) { foreach (var tmpItem in GenerateStyleItems(itemStyle, level + 3)) { yield return(tmpItem); } } } else { var componentStyle = style as CompositeStyle; if (componentStyle != null) { if (componentStyle.Styles.Count > 1) { LegendImporterItemViewModel styleLegendItem = new LegendImporterItemViewModel { Text = style.Name, CheckBoxVisibility = Visibility.Visible, Level = level, IconSource = new BitmapImage() }; yield return(styleLegendItem); foreach (var innerStyle in componentStyle.Styles.Reverse()) { foreach (var tmpItem in GenerateStyleItems(innerStyle, level + 3)) { yield return(tmpItem); } } } else { foreach (var tmpItem in GenerateStyleItems(componentStyle.Styles.FirstOrDefault(), level)) { yield return(tmpItem); } } } else { LegendImporterItemViewModel styleLegendItem = new LegendImporterItemViewModel { Text = style.Name, CheckBoxVisibility = Visibility.Collapsed, Level = level, IconSource = new BitmapImage() }; yield return(styleLegendItem); } } }