Ejemplo n.º 1
0
        public void DrawOverlay(IGraphicsContainer container, bool clearOld)
        {
            if (RenderOverlayImage == null || _canvas != null)
            {
                return;
            }

            if (container == null)
            {
                ClearOverlay();
            }

            GraphicsEngine.Abstraction.IBitmap bm = null;
            try
            {
                bm = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight);
                bm.MakeTransparent();

                _canvas = bm.CreateCanvas();
                foreach (IGraphicElement element in container.Elements)
                {
                    element.Draw(this);
                }

                RenderOverlayImage(bm, clearOld);
            }
            catch
            {
            }
            finally
            {
                if (_canvas != null)
                {
                    _canvas.Dispose();
                }

                _canvas = null;
                if (bm != null)
                {
                    bm.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public bool Create(GraphicsEngine.Abstraction.IBitmap bitmap, int a, int y)
        {
            double dpm = _dpi / 0.0256;
            double pix = _scale / dpm;
            double bl  = pix * (200 * (_dpi / 96)) / 5.0;
            float  fac = (float)_dpi / 96;

            if (bl > 1000000)
            {
                bl = Math.Round((int)(bl / 100000) * 100000.0, 0);
            }
            else if (bl > 100000)
            {
                bl = Math.Round((int)(bl / 10000) * 10000.0, 0);
            }
            else if (bl > 10000)
            {
                bl = Math.Round((int)(bl / 5000) * 5000.0, 0);
            }
            else if (bl > 1000)
            {
                bl = Math.Round((int)(bl / 500) * 500.0, 0);
            }
            else if (bl > 100)
            {
                bl = Math.Round((int)(bl / 100) * 100.0, 0);
            }
            else if (bl > 10)
            {
                bl = Math.Round((int)(bl / 10) * 10.0, 0);
            }

            int bm_bl = (int)(bl / pix);

            using (var canvas = bitmap.CreateCanvas())
                using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.FromArgb(155, 149, 149)))
                    using (var brush2 = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.White))
                        using (var brush3 = GraphicsEngine.Current.Engine.CreateSolidBrush(GraphicsEngine.ArgbColor.White))
                            using (var pen = GraphicsEngine.Current.Engine.CreatePen(GraphicsEngine.ArgbColor.Black, 1f))
                                using (var font = GraphicsEngine.Current.Engine.CreateFont("Verdana", 7 * fac, GraphicsEngine.FontStyle.Bold))
                                {
                                    int dist = (int)Math.Round(bl * 5, 0);

                                    // Hintergrund und Rahmen zeichnen
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 0, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 2 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangleF(a + 4 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));

                                    canvas.FillRectangle(brush2, new GraphicsEngine.CanvasRectangleF(a + 1 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));
                                    canvas.FillRectangle(brush2, new GraphicsEngine.CanvasRectangleF(a + 3 * bm_bl, 15 * fac + y, bm_bl, 5 * fac));

                                    canvas.DrawRectangle(pen, new GraphicsEngine.CanvasRectangleF(a + 0, 14 * fac + y, bm_bl * 5 - 1, 5 * fac));
                                    canvas.DrawLine(pen, a, 12 * fac + y, a, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 5 - 1, 12 * fac + y, a + bm_bl * 5 - 1, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl, 14 * fac + y, a + bm_bl, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 2, 14 * fac + y, a + bm_bl * 2, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 3, 14 * fac + y, a + bm_bl * 3, 19 * fac + y);
                                    canvas.DrawLine(pen, a + bm_bl * 4, 14 * fac + y, a + bm_bl * 4, 19 * fac + y);

                                    string text = Math.Round(_scale, 0).ToString(), t = "";
                                    int    counter = 1;
                                    // Tausenderpunkte
                                    for (int i = text.Length - 1; i > 0; i--)
                                    {
                                        t = text[i] + t;
                                        if ((counter++ % 3) == 0)
                                        {
                                            t = "." + t;
                                        }
                                    }
                                    t    = text[0] + t;
                                    text = "M 1:" + t;
                                    drawString(canvas, font, text, (float)(a + (bm_bl * 5 - canvas.MeasureText(text, font).Width) / 2), y);
                                    drawString(canvas, font, "0", a - 4, y);

                                    if (dist > 1000)
                                    {
                                        float x = dist / (float)1000;
                                        text = x.ToString() + " km";
                                    }
                                    else
                                    {
                                        text = dist.ToString() + " m";
                                    }
                                    drawString(canvas, font, text, (float)(a + bm_bl * 5 - 5 * fac), y);
                                }
            return(true);
        }
Ejemplo n.º 3
0
        public bool Merge(GraphicsEngine.Abstraction.IBitmap bitmap, IDisplay display)
        {
            try
            {
                int iWidth  = bitmap.Width;
                int iHeight = bitmap.Height;

                using (var canvas = bitmap.CreateCanvas())
                {
                    canvas.CompositingMode = GraphicsEngine.CompositingMode.SourceOver;

                    foreach (GeorefBitmap geoBmp in _picList)
                    {
                        if (geoBmp == null || geoBmp.Bitmap == null)
                        {
                            continue;
                        }

                        if (bitmap != geoBmp.Bitmap)
                        {
                            if (geoBmp.Envelope != null)
                            {
                                double x0, y0, x1, y1, x2, y2;
                                gView.Framework.Geometry.IGeometry geom = gView.Framework.Geometry.GeometricTransformerFactory.Transform2D(geoBmp.Envelope, geoBmp.SpatialReference, display.SpatialReference);
                                if (geom is gView.Framework.Geometry.IPolygon)
                                {
                                    gView.Framework.Geometry.IRing ring = ((gView.Framework.Geometry.IPolygon)geom)[0];

                                    x0 = ring[1].X; y0 = ring[1].Y;
                                    x1 = ring[2].X; y1 = ring[2].Y;
                                    x2 = ring[0].X; y2 = ring[0].Y;

                                    /////////////////////////////////////////////////////////
                                    Display d = new Display(display.Map, false);
                                    d.Limit            = d.Envelope = geoBmp.Envelope;
                                    d.iWidth           = geoBmp.Bitmap.Width;
                                    d.iHeight          = geoBmp.Bitmap.Height;
                                    d.SpatialReference = geoBmp.SpatialReference;
                                    Resample(bitmap, display, geoBmp.Bitmap, d);
                                    continue;
                                }
                                else
                                {
                                    x0 = geoBmp.Envelope.minx; y0 = geoBmp.Envelope.maxy;
                                    x1 = geoBmp.Envelope.maxx; y1 = geoBmp.Envelope.maxy;
                                    x2 = geoBmp.Envelope.minx; y2 = geoBmp.Envelope.miny;
                                }

                                display.World2Image(ref x0, ref y0);
                                display.World2Image(ref x1, ref y1);
                                display.World2Image(ref x2, ref y2);

                                GraphicsEngine.CanvasPointF[] points =
                                {
                                    new GraphicsEngine.CanvasPointF((float)x0, (float)y0),
                                    new GraphicsEngine.CanvasPointF((float)x1, (float)y1),
                                    new GraphicsEngine.CanvasPointF((float)x2, (float)y2)
                                };

                                canvas.DrawBitmap(geoBmp.Bitmap,
                                                  points,
                                                  new GraphicsEngine.CanvasRectangleF(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                  opacity: geoBmp.Opacity);
                            }
                            else
                            {
                                canvas.DrawBitmap(geoBmp.Bitmap,
                                                  new GraphicsEngine.CanvasRectangle(0, 0, iWidth, iHeight),
                                                  new GraphicsEngine.CanvasRectangle(0, 0, geoBmp.Bitmap.Width, geoBmp.Bitmap.Height),
                                                  opacity: geoBmp.Opacity);
                            }
                        }
                    }
                }

                if (_scale > 0)
                {
                    Scalebar bar = new Scalebar(_scale, m_dpi);
                    bar.Create(bitmap, bitmap.Width - (int)(50 * m_dpi / 96.0) - bar.ScaleBarWidth, bitmap.Height - (int)(32 * m_dpi / 96.0));
                }
                return(true);
            }
            catch (Exception ex)
            {
                _errMsg = ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace;
                return(false);
            }
        }
Ejemplo n.º 4
0
        async private Task Render(IFeatureLayer layer)
        {
            IFeatureRenderer clonedFeatureRenderer = null;
            ILabelRenderer   clonedLabelRenderer   = null;

            GraphicsEngine.Abstraction.IBitmap compositionModeCopyBitmap = null;
            GraphicsEngine.Abstraction.ICanvas compositionModeCopyCanvas = null, originalCanvas = null;

            try
            {
                _map.FireOnUserInterface(true);
                if ((
                        layer.FeatureRenderer == null ||
                        layer.FeatureRenderer.HasEffect(layer, _map) == false)
                    &&
                    (
                        layer.LabelRenderer == null ||
                        _useLabelRenderer == false
                    ))
                {
                    return;
                }

                IFeatureClass fClass = layer.FeatureClass;
                if (fClass == null)
                {
                    return;
                }

                //IDataset dataset = (IDataset)_map[layer];
                //if (dataset == null) return;

                //if (!(dataset is IFeatureDataset)) return;

                IGeometry filterGeom = _map.Display.DisplayTransformation.TransformedBounds(_map.Display); //_map.Display.Envelope;

                if (_map.Display.GeometricTransformer != null)
                {
                    filterGeom = MapHelper.Project(fClass, _map.Display);
                }

                gView.Framework.Data.SpatialFilter filter = new gView.Framework.Data.SpatialFilter();
                filter.DatasetCachingContext = _datasetCachingContext;
                filter.Geometry = filterGeom;
                filter.AddField(fClass.ShapeFieldName);
                //filter.FuzzyQuery = true;
                filter.SpatialRelation = spatialRelation.SpatialRelationMapEnvelopeIntersects;
                filter.MapScale        = _map.Display.mapScale;
                filter.CancelTracker   = _cancelTracker;

                if (layer.FilterQuery != null)
                {
                    filter.WhereClause = layer.FilterQuery.WhereClause;
                    if (layer.FilterQuery is IBufferQueryFilter)
                    {
                        ISpatialFilter sFilter = await BufferQueryFilter.ConvertToSpatialFilter(layer.FilterQuery as IBufferQueryFilter);

                        if (sFilter == null)
                        {
                            return;
                        }
                        filter.SpatialRelation = spatialRelation.SpatialRelationIntersects;
                        filter.Geometry        = sFilter.Geometry;
                    }
                    if (layer.FilterQuery is ISpatialFilter)
                    {
                        //filter.FuzzyQuery = ((ISpatialFilter)layer.FilterQuery).FuzzyQuery;
                        filter.SpatialRelation = ((ISpatialFilter)layer.FilterQuery).SpatialRelation;
                        filter.Geometry        = ((ISpatialFilter)layer.FilterQuery).Geometry;
                    }
                }

                // Erst nach dem Clonen anwenden!!!
                //if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                //{
                //    layer.FeatureRenderer.PrepareQueryFilter(layer, filter);
                //}
                //if (layer.LabelRenderer != null && _useLabelRenderer)
                //{
                //    layer.LabelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                //}

                IDisplay display  = _map;
                double   refScale = display.refScale;

                #region Layer Clonen

                IFeatureRenderer renderer      = null;
                ILabelRenderer   labelRenderer = null;

                lock (lockThis)
                {
                    // Beim Clonen sprerren...
                    // Da sonst bei der Servicemap bei gleichzeitigen Requests
                    // Exception "Objekt wird bereits an anderer Stelle verwendet" auftreten kann!
                    if (layer.FeatureRenderer != null && layer.FeatureRenderer.HasEffect(layer, _map))
                    {
                        if (layer.RequiresFeatureRendererClone(display))
                        {
                            renderer = clonedFeatureRenderer = (IFeatureRenderer)layer.FeatureRenderer.Clone(
                                new CloneOptions(display,
                                                 layer.UseWithRefScale(display),
                                                 maxRefScaleFactor: layer.MaxRefScaleFactor));
                        }
                        else
                        {
                            renderer = layer.FeatureRenderer;
                        }
                    }
                    if (layer.LabelRenderer != null && _useLabelRenderer)
                    {
                        if (layer.RequiresLabelRendererClone(display))
                        {
                            labelRenderer = clonedLabelRenderer =
                                (ILabelRenderer)layer.LabelRenderer.Clone(new CloneOptions(display,
                                                                                           layer.UseLabelsWithRefScale(display),
                                                                                           maxLabelRefscaleFactor: layer.MaxLabelRefScaleFactor));
                        }
                        else  // Clone with null => simple clone
                        {
                            //display.refScale = 0;
                            labelRenderer = clonedLabelRenderer = (ILabelRenderer)layer.LabelRenderer.Clone(null);
                            //display.refScale = refScale;
                        }
                    }
                }

                #endregion

                #region Prepare filter

                // Prepare erst auf geclonte renderer anwenden!! (Threadsafe)
                if (renderer != null && renderer.HasEffect(layer, _map))
                {
                    renderer.PrepareQueryFilter(layer, filter);
                }
                if (labelRenderer != null && _useLabelRenderer)
                {
                    labelRenderer.PrepareQueryFilter(_map.Display, layer, filter);
                }

                #endregion

                using (IFeatureCursor fCursor = await fClass.GetFeatures(MapHelper.MapQueryFilter(filter)))
                {
                    _map.FireOnUserInterface(false);

                    if (fCursor != null)
                    {
                        IFeature feature;

                        if (renderer != null)
                        {
                            renderer.StartDrawing(_map);

                            bool useCompostionModeCopy = layer is IFeatureLayerComposition &&
                                                         ((IFeatureLayerComposition)layer).CompositionMode == FeatureLayerCompositionMode.Copy;

                            if (useCompostionModeCopy)
                            {
                                originalCanvas            = _map.Display.Canvas;
                                compositionModeCopyBitmap = GraphicsEngine.Current.Engine.CreateBitmap(_map.Display.Bitmap.Width, _map.Display.Bitmap.Height, GraphicsEngine.PixelFormat.Rgba32);
                                compositionModeCopyCanvas = compositionModeCopyBitmap.CreateCanvas();

                                compositionModeCopyBitmap.MakeTransparent();
                                compositionModeCopyBitmap.SetResolution(_map.Display.Bitmap.DpiX,
                                                                        _map.Display.Bitmap.DpiY);

                                ((Display)_map.Display).Canvas = compositionModeCopyCanvas;
                            }

                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                renderer.Draw(_map, feature);

                                if (labelRenderer != null)
                                {
                                    labelRenderer.Draw(_map, feature);
                                }

                                _counter.Counter++;

                                if (_isServiceMap == false)
                                {
                                    if (_counter.Counter % 100 == 0)
                                    {
                                        _map.FireRefreshMapView();
                                    }
                                }
                            }
                        }
                        else if (labelRenderer != null && _cancelTracker.Continue)
                        {
                            while ((feature = await fCursor.NextFeature()) != null)
                            {
                                if (_cancelTracker != null)
                                {
                                    if (!_cancelTracker.Continue)
                                    {
                                        break;
                                    }
                                }

                                labelRenderer.Draw(_map, feature);
                                _counter.Counter++;
                            }
                        }

                        if (labelRenderer != null)
                        {
                            labelRenderer.Release();
                        }

                        if (renderer != null)
                        {
                            renderer.FinishDrawing(_map, _cancelTracker);
                        }

                        if (compositionModeCopyCanvas != null && compositionModeCopyBitmap != null)
                        {
                            originalCanvas.DrawBitmap(compositionModeCopyBitmap,
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      new GraphicsEngine.CanvasRectangle(0, 0, compositionModeCopyBitmap.Width, compositionModeCopyBitmap.Height),
                                                      opacity: (float)Math.Min(1, (100f - ((IFeatureLayerComposition)layer).CompositionModeCopyTransparency) / 100));
                        }
                    }
                    else
                    {
                        if (fClass is IDebugging && ((IDebugging)fClass).LastException != null)
                        {
                            throw ((IDebugging)fClass).LastException;
                        }

                        throw new Exception("Can't query feature class. Unknown error");
                    }
                }
            }
            catch (Exception ex)
            {
                if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null)
                {
                    await((IServiceMap)_map).MapServer.LogAsync(
                        ((IServiceMap)_map).Name,
                        "RenderFeatureLayer: " + ((layer != null) ? layer.Title : String.Empty),
                        loggingMethod.error,
                        ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                }
                if (_map != null)
                {
                    _map.AddRequestException(new Exception("RenderFeatureLayerThread: " + ((layer != null) ? layer.Title : String.Empty) + "\n" + ex.Message, ex));
                }
            }
            finally
            {
                if (clonedFeatureRenderer != null)
                {
                    clonedFeatureRenderer.Release();
                }

                if (clonedLabelRenderer != null)
                {
                    clonedLabelRenderer.Release();
                }

                if (originalCanvas != null)
                {
                    ((Display)_map.Display).Canvas = originalCanvas;
                }

                if (compositionModeCopyCanvas != null)
                {
                    compositionModeCopyCanvas.Dispose();
                    compositionModeCopyCanvas = null;
                }

                if (compositionModeCopyBitmap != null)
                {
                    compositionModeCopyBitmap.Dispose();
                    compositionModeCopyBitmap = null;
                }

                _map.FireOnUserInterface(false);
            }
        }