Пример #1
0
        async override public Task <bool> RefreshMap(DrawPhase phase, ICancelTracker cancelTracker)
        {
            base.ResetRequestExceptions();

            if (_canvas != null && phase == DrawPhase.Graphics)
            {
                return(true);
            }

            this.ZoomTo(m_actMinX, m_actMinY, m_actMaxX, m_actMaxY);

            if (cancelTracker == null)
            {
                cancelTracker = new CancelTracker();
            }

            using (var datasetCachingContext = new DatasetCachingContext(this))
                using (var geoTransformer = GeometricTransformerFactory.Create())
                {
                    //geoTransformer.ToSpatialReference = this.SpatialReference;

                    if (_bitmap == null)
                    {
                        _bitmap = Current.Engine.CreateBitmap(iWidth, iHeight, PixelFormat.Rgba32);
                    }

                    _canvas = _bitmap.CreateCanvas();
                    //_canvas.CompositingMode = CompositingMode.SourceCopy;
                    //this.dpi = _canvas.DpiX * this.ScaleSymbolFactor;

                    if (BackgroundColor.A != 0 && !Display.MakeTransparent)
                    {
                        using (var brush = Current.Engine.CreateSolidBrush(BackgroundColor))
                        {
                            _canvas.FillRectangle(brush, new CanvasRectangle(0, 0, _bitmap.Width, _bitmap.Height));
                        }
                    }

                    if (phase == DrawPhase.All || phase == DrawPhase.Geography)
                    {
                        this.GeometricTransformer = geoTransformer;

                        // Thread für MapServer Datasets starten...

                        #region WebServiceLayer
                        List <IWebServiceLayer> webServices;
                        if (this.TOC != null)
                        {
                            webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers);
                        }
                        else
                        {
                            webServices = new List <IWebServiceLayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is IWebServiceLayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    webServices.Add((IWebServiceLayer)layer);
                                }
                            }
                        }
                        int webServiceOrder = 0, webServiceOrder2 = 1;
                        foreach (IWebServiceLayer element in webServices)
                        {
                            if (!element.Visible)
                            {
                                continue;
                            }

                            IWebServiceLayer wsLayer = LayerFactory.Create(element.WebServiceClass.Clone() as IClass, element) as IWebServiceLayer;

                            if (wsLayer == null || wsLayer.WebServiceClass == null)
                            {
                                continue;
                            }

                            wsLayer.WebServiceClass.SpatialReference = this.SpatialReference;

                            List <IWebServiceClass> additionalWebServices = new List <IWebServiceClass>();
                            if (BeforeRenderLayers != null)
                            {
                                List <ILayer> modLayers = new List <ILayer>();
                                foreach (IWebServiceTheme theme in wsLayer.WebServiceClass.Themes)
                                {
                                    if (theme is ILayer)
                                    {
                                        modLayers.Add(theme);
                                    }
                                }
                                BeforeRenderLayers(this, modLayers);

                                foreach (ILayer additionalLayer in MapServerHelper.FindAdditionalWebServiceLayers(wsLayer.WebServiceClass, modLayers))
                                {
                                    IWebServiceClass additionalWebService = MapServerHelper.CloneNonVisibleWebServiceClass(wsLayer.WebServiceClass);
                                    MapServerHelper.CopyWebThemeProperties(additionalWebService, additionalLayer);

                                    if (MapServerHelper.HasVisibleThemes(additionalWebService))
                                    {
                                        additionalWebServices.Add(additionalWebService);
                                    }
                                }
                            }


                            var srt = new RenderServiceRequest(this, wsLayer, webServiceOrder++);
                            srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished);
                            //Thread thread = new Thread(new ThreadStart(srt.ImageRequest));
                            m_imageMerger.max++;
                            //thread.Start();
                            var task = srt.ImageRequest(); // start Task and continue...


                            foreach (IWebServiceClass additionalWebService in additionalWebServices)
                            {
                                wsLayer = LayerFactory.Create(additionalWebService, element) as IWebServiceLayer;
                                if (wsLayer == null || wsLayer.WebServiceClass == null)
                                {
                                    continue;
                                }

                                wsLayer.WebServiceClass.SpatialReference = this.SpatialReference;

                                srt         = new RenderServiceRequest(this, wsLayer, (++webServiceOrder2) + webServices.Count);
                                srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished);
                                //thread = new Thread(new ThreadStart(srt.ImageRequest));
                                m_imageMerger.max++;
                                //thread.Start();
                                var additionalTask = srt.ImageRequest(); // start task and continue...
                            }
                        }
                        #endregion

                        List <ILayer> layers = new List <ILayer>();
                        if (this.TOC != null)
                        {
                            if (this.GetType().Equals(typeof(ServiceMap)))
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.Layers);
                            }
                            else
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers);
                            }
                        }
                        else
                        {
                            layers = new List <ILayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is ILayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    layers.Add((ILayer)layer);
                                }
                            }
                        }

                        if (BeforeRenderLayers != null)
                        {
                            //
                            // Kopie der Original Layer erstellen
                            // ACHTUNG: Renderer werden nicht kopiert!
                            // dürfen in BeforeRenderLayers nicht verändert werden...
                            // Eine zuweisung eines neuen Renderers ist jedoch legitim.
                            //
                            List <ILayer> modLayers = new List <ILayer>();
                            foreach (IDatasetElement element in layers)
                            {
                                if (!(element is ILayer) || element is IWebServiceTheme)
                                {
                                    continue;
                                }

                                ILayer layer = (ILayer)element;
                                if (layer.MinimumScale > 1 && layer.MinimumScale > this.mapScale)
                                {
                                    continue;
                                }

                                if (layer.MaximumScale > 1 && layer.MaximumScale < this.mapScale)
                                {
                                    continue;
                                }

                                modLayers.Add(LayerFactory.Create(layer.Class, layer));
                            }
                            BeforeRenderLayers(this, modLayers);
                            layers = modLayers;
                        }
                        //layers = ModifyLayerList(layers);
                        List <IFeatureLayer> labelLayers = this.OrderedLabelLayers(layers);

                        LabelEngine.Init(this.Display, false);
                        foreach (IDatasetElement element in layers)
                        {
                            if (!cancelTracker.Continue)
                            {
                                break;
                            }

                            if (!(element is ILayer))
                            {
                                continue;
                            }

                            ILayer layer = (ILayer)element;

                            //if (_ceckLayerVisibilityBeforeDrawing)
                            //{
                            //    if (!LayerIsVisible(layer)) continue;
                            //}
                            if (!layer.Visible)
                            {
                                continue;
                            }

                            if (!layer.RenderInScale(this))
                            {
                                continue;
                            }
#if (DEBUG)
                            //Logger.LogDebug("Drawing Layer:" + element.Title);
#endif
                            SetGeotransformer((ILayer)element, geoTransformer);

                            if (layer is IFeatureLayer)
                            {
                                if (layer.Class?.Dataset is IFeatureCacheDataset)
                                {
                                    await((IFeatureCacheDataset)layer.Class.Dataset).InitFeatureCache(datasetCachingContext);
                                }

                                IFeatureLayer fLayer = (IFeatureLayer)layer;
                                if (fLayer.FeatureRenderer == null &&
                                    (
                                        fLayer.LabelRenderer == null ||
                                        (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode != LabelRenderMode.RenderWithFeature)
                                    ))
                                {
                                    //continue;
                                }
                                else
                                {
                                    RenderFeatureLayer rlt = new RenderFeatureLayer(this, datasetCachingContext, fLayer, cancelTracker, new FeatureCounter());
                                    if (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode == LabelRenderMode.RenderWithFeature)
                                    {
                                        rlt.UseLabelRenderer = true;
                                    }
                                    else
                                    {
                                        rlt.UseLabelRenderer = labelLayers.IndexOf(fLayer) == 0; // letzten Layer gleich mitlabeln
                                    }

                                    if (rlt.UseLabelRenderer)
                                    {
                                        labelLayers.Remove(fLayer);
                                    }

                                    await rlt.Render();
                                }
                                //thread = new Thread(new ThreadStart(rlt.Render));
                                //thread.Start();
                            }
                            if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null)
                            {
                                IRasterLayer rLayer = (IRasterLayer)layer;
                                if (rLayer.RasterClass.Polygon == null)
                                {
                                    continue;
                                }

                                IEnvelope dispEnvelope = this.Envelope;
                                if (Display.GeometricTransformer != null)
                                {
                                    dispEnvelope = ((IGeometry)Display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
                                }

                                if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(rLayer.RasterClass.Polygon, dispEnvelope))
                                {
                                    if (rLayer.Class is IParentRasterLayer)
                                    {
                                        await DrawRasterParentLayer((IParentRasterLayer)rLayer.Class, cancelTracker, rLayer);
                                    }
                                    else
                                    {
                                        RenderRasterLayer rlt = new RenderRasterLayer(this, rLayer, rLayer, cancelTracker);
                                        await rlt.Render();

                                        //thread = new Thread(new ThreadStart(rlt.Render));
                                        //thread.Start();
                                    }
                                }
                            }
                            // Andere Layer (zB IRasterLayer)

#if (DEBUG)
                            //Logger.LogDebug("Finished drawing layer: " + element.Title);
#endif
                        }

                        // Label Features
                        if (labelLayers.Count != 0)
                        {
                            foreach (IFeatureLayer fLayer in labelLayers)
                            {
                                this.SetGeotransformer(fLayer, geoTransformer);

                                if (!fLayer.Visible)
                                {
                                    continue;
                                }

                                RenderLabel rlt = new RenderLabel(this, fLayer, cancelTracker, new FeatureCounter());
                                await rlt.Render();
                            }
                        }

                        LabelEngine.Draw(this.Display, cancelTracker);
                        LabelEngine.Release();

                        if (cancelTracker.Continue)
                        {
                            while (m_imageMerger.Count < m_imageMerger.max)
                            {
                                await Task.Delay(10);
                            }
                        }
                        if (_drawScaleBar)
                        {
                            m_imageMerger.mapScale = this.mapScale;
                            m_imageMerger.dpi      = this.dpi;
                        }
#if (DEBUG)
                        //Logger.LogDebug("Merge Images");
#endif
                        m_imageMerger.Merge(_bitmap, this.Display);
                        m_imageMerger.Clear();
#if (DEBUG)
                        //Logger.LogDebug("Merge Images Finished");
#endif
                    }

                    if (phase == DrawPhase.All || phase == DrawPhase.Graphics)
                    {
                        foreach (IGraphicElement grElement in Display.GraphicsContainer.Elements)
                        {
                            grElement.Draw(Display);
                        }
                    }

                    base.AppendRequestExceptionsToImage();

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

                    _canvas = null;

                    this.GeometricTransformer = null;
                }

            return(this.HasRequestExceptions == false);
        }
Пример #2
0
        async override public Task <bool> RefreshMap(DrawPhase phase, ICancelTracker cancelTracker)
        {
            base.ResetRequestExceptions();
            bool printerMap = (this.GetType() == typeof(PrinterMap));

            try
            {
                _original.FireStartRefreshMap();

                using (var datasetCachingContext = new DatasetCachingContext(this))
                {
                    this.IsRefreshing = true;

                    _lastException = null;

                    if (_canvas != null && phase == DrawPhase.Graphics)
                    {
                        return(true);
                    }

                    #region Start Drawing/Initialisierung

                    this.ZoomTo(m_actMinX, m_actMinY, m_actMaxX, m_actMaxY);

                    if (cancelTracker == null)
                    {
                        cancelTracker = new CancelTracker();
                    }

                    IGeometricTransformer geoTransformer = GeometricTransformerFactory.Create();

                    //geoTransformer.ToSpatialReference = this.SpatialReference;
                    if (!printerMap)
                    {
                        if (phase == DrawPhase.All)
                        {
                            DisposeStreams();
                        }

                        if (_bitmap != null && (_bitmap.Width != iWidth || _bitmap.Height != iHeight))
                        {
                            if (!DisposeImage())
                            {
                                return(false);
                            }
                        }

                        if (_bitmap == null)
                        {
                            //DisposeStreams();
                            _bitmap = GraphicsEngine.Current.Engine.CreateBitmap(iWidth, iHeight, GraphicsEngine.PixelFormat.Rgba32);
                            //if (NewBitmap != null && cancelTracker.Continue) NewBitmap(_image);
                        }

                        _canvas = _bitmap.CreateCanvas();
                        //this.dpi = /*96f*/ /* _canvas.DpiX*/ GraphicsEngine.Current.Engine.ScreenDpi;

                        // NewBitmap immer aufrufen, da sonst neuer DataView nix mitbekommt
                        if (NewBitmap != null && cancelTracker.Continue)
                        {
                            NewBitmap?.BeginInvoke(_bitmap, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                        }

                        using (var brush = GraphicsEngine.Current.Engine.CreateSolidBrush(_backgroundColor))
                        {
                            _canvas.FillRectangle(brush, new GraphicsEngine.CanvasRectangle(0, 0, iWidth, iHeight));
                        }
                    }

                    #endregion

                    #region Geometry

                    if (Bit.Has(phase, DrawPhase.Geography))
                    //if (phase == DrawPhase.All || phase == DrawPhase.Geography)
                    {
                        LabelEngine.Init(this.Display, printerMap);

                        this.GeometricTransformer = geoTransformer;

                        // Thread für MapServer Datasets starten...
                        #region WebServiceLayer
                        List <IWebServiceLayer> webServices;
                        if (this.TOC != null)
                        {
                            webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers);
                        }
                        else
                        {
                            webServices = new List <IWebServiceLayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is IWebServiceLayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    webServices.Add((IWebServiceLayer)layer);
                                }
                            }
                        }
                        int webServiceOrder = 0;
                        foreach (IWebServiceLayer element in webServices)
                        {
                            if (!element.Visible)
                            {
                                continue;
                            }

                            RenderServiceRequest srt = new RenderServiceRequest(this, element, webServiceOrder++);
                            srt.finish += new RenderServiceRequest.RequestThreadFinished(MapRequestThread_finished);
                            //Thread thread = new Thread(new ThreadStart(srt.ImageRequest));
                            m_imageMerger.max++;
                            //thread.Start();
                            var task = srt.ImageRequest();  // start the task...
                        }
                        #endregion

                        #region Layerlisten erstellen
                        List <ILayer> layers;
                        if (this.TOC != null)
                        {
                            if (this.ToString() == "gView.MapServer.Instance.ServiceMap")
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.Layers);
                            }
                            else
                            {
                                layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers);
                            }
                        }
                        else
                        {
                            layers = new List <ILayer>();
                            foreach (IDatasetElement layer in this.MapElements)
                            {
                                if (!(layer is ILayer))
                                {
                                    continue;
                                }

                                if (((ILayer)layer).Visible)
                                {
                                    layers.Add((ILayer)layer);
                                }
                            }
                        }

                        List <IFeatureLayer> labelLayers = this.OrderedLabelLayers(layers);

                        #endregion

                        #region Renderer Features

                        foreach (ILayer layer in layers)
                        {
                            if (!cancelTracker.Continue)
                            {
                                break;
                            }

                            if (!layer.RenderInScale(this))
                            {
                                continue;
                            }

                            SetGeotransformer(layer, geoTransformer);

                            DateTime startTime = DateTime.Now;

                            FeatureCounter fCounter = new FeatureCounter();
                            if (layer is IFeatureLayer)
                            {
                                if (layer.Class?.Dataset is IFeatureCacheDataset)
                                {
                                    await((IFeatureCacheDataset)layer.Class.Dataset).InitFeatureCache(datasetCachingContext);
                                }

                                IFeatureLayer fLayer = (IFeatureLayer)layer;
                                if (fLayer.FeatureRenderer == null &&
                                    (
                                        fLayer.LabelRenderer == null ||
                                        (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode != LabelRenderMode.RenderWithFeature)
                                    ))
                                {
                                    //continue;
                                }
                                else
                                {
                                    RenderFeatureLayer rlt = new RenderFeatureLayer(this, datasetCachingContext, fLayer, cancelTracker, fCounter);
                                    if (fLayer.LabelRenderer != null && fLayer.LabelRenderer.RenderMode == LabelRenderMode.RenderWithFeature)
                                    {
                                        rlt.UseLabelRenderer = true;
                                    }
                                    else
                                    {
                                        rlt.UseLabelRenderer = labelLayers.IndexOf(fLayer) == 0;  // letzten Layer gleich mitlabeln
                                    }

                                    if (rlt.UseLabelRenderer)
                                    {
                                        labelLayers.Remove(fLayer);
                                    }

                                    if (cancelTracker.Continue)
                                    {
                                        DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                    }

                                    await rlt.Render();
                                }
                            }
                            if (layer is IRasterLayer && ((IRasterLayer)layer).RasterClass != null)
                            {
                                IRasterLayer rLayer = (IRasterLayer)layer;
                                if (rLayer.RasterClass.Polygon == null)
                                {
                                    continue;
                                }

                                IEnvelope dispEnvelope = this.DisplayTransformation.TransformedBounds(this); //this.Envelope;
                                if (Display.GeometricTransformer != null)
                                {
                                    dispEnvelope = ((IGeometry)Display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
                                }

                                if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(rLayer.RasterClass.Polygon, dispEnvelope))
                                {
                                    if (rLayer.Class is IParentRasterLayer)
                                    {
                                        if (cancelTracker.Continue)
                                        {
                                            DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                        }

                                        await DrawRasterParentLayer((IParentRasterLayer)rLayer.Class, cancelTracker, rLayer);
                                    }
                                    else
                                    {
                                        RenderRasterLayer rlt = new RenderRasterLayer(this, rLayer, rLayer, cancelTracker);

                                        if (cancelTracker.Continue)
                                        {
                                            DrawingLayer?.BeginInvoke(layer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                        }

                                        await rlt.Render();
                                    }
                                }
                            }
                            // Andere Layer (zB IRasterLayer)

                            _original.FireDrawingLayerFinished(new gView.Framework.system.TimeEvent("Drawing: " + layer.Title, startTime, DateTime.Now, fCounter.Counter));

                            FireRefreshMapView(1000);
                        }
                        #endregion

                        #region Label Features

                        if (labelLayers.Count != 0)
                        {
                            StreamImage(ref _msGeometry, _bitmap);
                            foreach (IFeatureLayer fLayer in labelLayers)
                            {
                                this.SetGeotransformer(fLayer, geoTransformer);

                                FeatureCounter fCounter  = new FeatureCounter();
                                DateTime       startTime = DateTime.Now;

                                RenderLabel rlt = new RenderLabel(this, fLayer, cancelTracker, fCounter);

                                if (cancelTracker.Continue)
                                {
                                    DrawingLayer?.BeginInvoke(fLayer.Title, new AsyncCallback(AsyncInvoke.RunAndForget), null);
                                }

                                await rlt.Render();

                                _original.FireDrawingLayerFinished(new gView.Framework.system.TimeEvent("Labelling: " + fLayer.Title, startTime, DateTime.Now, fCounter.Counter));
                            }

                            DrawStream(_canvas, _msGeometry);
                        }

                        if (!printerMap)
                        {
                            LabelEngine.Draw(this.Display, cancelTracker);
                        }

                        LabelEngine.Release();

                        #endregion

                        #region Waiting for Webservices

                        if (cancelTracker.Continue)
                        {
                            if (webServices != null && webServices.Count != 0)
                            {
                                DrawingLayer?.BeginInvoke("...Waiting for WebServices...", new AsyncCallback(AsyncInvoke.RunAndForget), null);
                            }

                            while (m_imageMerger.Count < m_imageMerger.max)
                            {
                                await Task.Delay(100);
                            }
                        }
                        if (_drawScaleBar)
                        {
                            m_imageMerger.mapScale = this.mapScale;
                            m_imageMerger.dpi      = this.dpi;
                        }
                        if (m_imageMerger.Count > 0)
                        {
                            var clonedBitmap = _bitmap.Clone(GraphicsEngine.PixelFormat.Rgba32);
                            clonedBitmap.MakeTransparent(_backgroundColor);
                            m_imageMerger.Add(new GeorefBitmap(clonedBitmap), 999);

                            if (!m_imageMerger.Merge(_bitmap, this.Display) &&
                                (this is IServiceMap) &&
                                ((IServiceMap)this).MapServer != null)
                            {
                                await((IServiceMap)this).MapServer.LogAsync(
                                    this.Name,
                                    "Image Merger:",
                                    loggingMethod.error,
                                    m_imageMerger.LastErrorMessage);
                            }
                            m_imageMerger.Clear();
                        }

                        StreamImage(ref _msGeometry, _bitmap);

                        #endregion
                    }
                    #endregion

                    #region Draw Selection

                    if (Bit.Has(phase, DrawPhase.Selection))
                    {
                        if (phase != DrawPhase.All)
                        {
                            DrawStream(_canvas, _msGeometry);
                        }

                        foreach (IDatasetElement layer in this.MapElements)
                        {
                            if (!cancelTracker.Continue)
                            {
                                break;
                            }

                            if (!(layer is ILayer))
                            {
                                continue;
                            }

                            if (layer is IFeatureLayer &&
                                layer is IFeatureSelection &&
                                ((IFeatureSelection)layer).SelectionSet != null &&
                                ((IFeatureSelection)layer).SelectionSet.Count > 0)
                            {
                                SetGeotransformer((ILayer)layer, geoTransformer);
                                await RenderSelection(layer as IFeatureLayer, cancelTracker);
                            } // Andere Layer (zB IRasterLayer)
                            else if (layer is IWebServiceLayer)
                            {
                                IWebServiceLayer wLayer = (IWebServiceLayer)layer;
                                if (wLayer.WebServiceClass == null)
                                {
                                    continue;
                                }

                                foreach (IWebServiceTheme theme in wLayer.WebServiceClass.Themes)
                                {
                                    if (theme is IFeatureLayer &&
                                        theme.SelectionRenderer != null &&
                                        theme is IFeatureSelection &&
                                        ((IFeatureSelection)theme).SelectionSet != null &&
                                        ((IFeatureSelection)theme).SelectionSet.Count > 0)
                                    {
                                        SetGeotransformer(theme, geoTransformer);
                                        await RenderSelection(theme as IFeatureLayer, cancelTracker);
                                    }
                                }
                            }
                        }

                        StreamImage(ref _msSelection, _bitmap);
                    }

                    #endregion

                    #region Graphics

                    if (Bit.Has(phase, DrawPhase.Graphics))
                    //if (phase == DrawPhase.All || phase == DrawPhase.Graphics)
                    {
                        if (phase != DrawPhase.All)
                        {
                            DrawStream(_canvas, (_msSelection != null) ? _msSelection : _msGeometry);
                        }

                        foreach (IGraphicElement grElement in Display.GraphicsContainer.Elements)
                        {
                            grElement.Draw(Display);
                        }
                        foreach (IGraphicElement grElement in Display.GraphicsContainer.SelectedElements)
                        {
                            if (grElement is IGraphicElement2)
                            {
                                if (((IGraphicElement2)grElement).Ghost != null)
                                {
                                    ((IGraphicElement2)grElement).Ghost.Draw(Display);
                                }
                                ((IGraphicElement2)grElement).DrawGrabbers(Display);
                            }
                        }
                    }

                    #endregion

                    #region Cleanup

                    if (geoTransformer != null)
                    {
                        this.GeometricTransformer = null;
                        geoTransformer.Release();
                        geoTransformer = null;
                    }

                    #endregion

                    #region Send Events

                    // Überprüfen, ob sich Extent seit dem letztem Zeichnen geändert hat...
                    if (cancelTracker.Continue)
                    {
                        if (_lastRenderExtent == null)
                        {
                            _lastRenderExtent = new Envelope();
                        }

                        if (NewExtentRendered != null)
                        {
                            if (!_lastRenderExtent.Equals(Display.Envelope))
                            {
                                NewExtentRendered(this, Display.Envelope);
                            }
                        }
                        _lastRenderExtent.minx = Display.Envelope.minx;
                        _lastRenderExtent.miny = Display.Envelope.miny;
                        _lastRenderExtent.maxx = Display.Envelope.maxx;
                        _lastRenderExtent.maxy = Display.Envelope.maxy;
                    }

                    #endregion

                    return(true);
                }
            }
            catch (Exception ex)
            {
                _lastException = ex;
                AddRequestException(ex);
                //System.Windows.Forms.MessageBox.Show(ex.Message+"\n"+ex.InnerException+"\n"+ex.Source);
                return(false);
            }
            finally
            {
                AppendRequestExceptionsToImage();

                if (!printerMap)
                {
                    if (_canvas != null)
                    {
                        _canvas.Dispose();
                    }

                    _canvas = null;
                }

                this.IsRefreshing = false;
            }
        }
Пример #3
0
        async public Task <IBitmap> Legend()
        {
            ITOC toc = _toc.Clone(this) as ITOC;

            #region WebServiceLayer
            List <IWebServiceLayer> webServices;
            if (this.TOC != null)
            {
                webServices = ListOperations <IWebServiceLayer> .Swap(this.TOC.VisibleWebServiceLayers);
            }
            else
            {
                webServices = new List <IWebServiceLayer>();
                foreach (IDatasetElement layer in this.MapElements)
                {
                    if (!(layer is IWebServiceLayer))
                    {
                        continue;
                    }

                    if (((ILayer)layer).Visible)
                    {
                        webServices.Add((IWebServiceLayer)layer);
                    }
                }
            }
            foreach (IWebServiceLayer element in webServices)
            {
                if (!(element is ILayer))
                {
                    continue;
                }

                if (!element.Visible)
                {
                    continue;
                }

                IWebServiceLayer wsLayer = LayerFactory.Create(element.WebServiceClass.Clone() as IClass, element) as IWebServiceLayer;
                if (wsLayer == null || wsLayer.WebServiceClass == null)
                {
                    continue;
                }

                if (BeforeRenderLayers != null)
                {
                    // layer im geklonten TOC austauschen...
                    // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                    // verwendet werden kann zB bei gesplitteten Layern...
                    //ITOCElement tocElement = toc.GetTOCElement(element.Class);
                    ITOCElement tocElement = toc.GetTOCElement(element);
                    tocElement.RemoveLayer(element);
                    tocElement.AddLayer(wsLayer);

                    List <ILayer> modLayers = new List <ILayer>();
                    foreach (IWebServiceTheme theme in wsLayer.WebServiceClass.Themes)
                    {
                        if (theme is ILayer)
                        {
                            modLayers.Add(theme);
                        }
                    }
                    BeforeRenderLayers(this, modLayers);
                }
            }
            #endregion

            List <ILayer> layers = new List <ILayer>();
            if (this.TOC != null)
            {
                if (this.GetType().Equals(typeof(ServiceMap)))
                {
                    layers = ListOperations <ILayer> .Swap(this.TOC.Layers);
                }
                else
                {
                    layers = ListOperations <ILayer> .Swap(this.TOC.VisibleLayers);
                }
            }
            else
            {
                layers = new List <ILayer>();
                foreach (IDatasetElement layer in this.MapElements)
                {
                    if (!(layer is ILayer))
                    {
                        continue;
                    }

                    if (((ILayer)layer).Visible)
                    {
                        layers.Add((ILayer)layer);
                    }
                }
            }

            if (BeforeRenderLayers != null)
            {
                //
                // Kopie der Original Layer erstellen
                // ACHTUNG: Renderer werden nicht kopiert!
                // dürfen in BeforeRenderLayers nicht verändert werden...
                // Eine zuweisung eines neuen Renderers ist jedoch legitim.
                //
                List <ILayer> modLayers = new List <ILayer>();
                foreach (IDatasetElement element in layers)
                {
                    if (!(element is ILayer) || element is IWebServiceTheme)
                    {
                        continue;
                    }

                    ILayer layer = (ILayer)element;
                    if (layer.MinimumScale > 1 && layer.MinimumScale > this.mapScale)
                    {
                        continue;
                    }

                    if (layer.MaximumScale > 1 && layer.MaximumScale < this.mapScale)
                    {
                        continue;
                    }

                    ILayer newLayer = null;
                    modLayers.Add(newLayer = LayerFactory.Create(layer.Class, layer));

                    // layer im geklonten TOC austauschen...
                    if (element is ILayer && newLayer != null)
                    {
                        // Besser layer als layer.Class verwendenden, weil Class von mehrerenen Layern
                        // verwendet werden kann zB bei gesplitteten Layern...
                        //ITOCElement tocElement = toc.GetTOCElement(layer.Class);
                        ITOCElement tocElement = toc.GetTOCElement(layer);
                        tocElement.RemoveLayer(element as ILayer);
                        tocElement.AddLayer(newLayer);
                    }
                }
                BeforeRenderLayers(this, modLayers);
                layers = modLayers;
            }

            return(await toc.Legend());
        }
Пример #4
0
 public RenderServiceRequest(Map map, IWebServiceLayer layer, int order)
 {
     _map   = map;
     _layer = layer;
     _order = order;
 }