public void MakeTransparent(GraphicsEngine.ArgbColor transColor) { if (Bitmap == null) { return; } try { var b = GraphicsEngine.Current.Engine.CreateBitmap(Bitmap.Width, Bitmap.Height, GraphicsEngine.PixelFormat.Rgba32); using (var g = b.CreateCanvas()) { g.DrawBitmap(Bitmap, new GraphicsEngine.CanvasPoint(0, 0)); } b.MakeTransparent(transColor); Bitmap.Dispose(); Bitmap = b; } catch { } }
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(); } } }
// Thread async public Task Render() { GraphicsEngine.Abstraction.IBitmap _filteredBitmap = null; try { if (_layer == null || _map == null || _cancelTracker == null) { return; } if (_layer.RasterClass.Polygon == null) { return; } IEnvelope env = _layer.RasterClass.Polygon.Envelope; double minx = env.minx, miny = env.miny, maxx = env.maxx, maxy = env.maxy; _map.World2Image(ref minx, ref miny); _map.World2Image(ref maxx, ref maxy); int iWidth = 0, iHeight = 0; int min_x = Math.Max(0, (int)Math.Min(minx, maxx) - 1); int min_y = Math.Max(0, (int)Math.Min(miny, maxy) - 1); int max_x = Math.Min(iWidth = _map.iWidth, (int)Math.Max(minx, maxx) + 1); int max_y = Math.Min(iHeight = _map.iHeight, (int)Math.Max(miny, maxy) + 1); using (var paintContext = await _layer.RasterClass.BeginPaint(_map.Display, _cancelTracker)) { if (_filter != FilterImplementations.Default) { _filteredBitmap = BaseFilter.ApplyFilter(paintContext.Bitmap, _filter); } if (paintContext.Bitmap == null && _filteredBitmap == null) { return; } //System.Windows.Forms.MessageBox.Show("begin"); double W = (_map.Envelope.maxx - _map.Envelope.minx); double H = (_map.Envelope.maxy - _map.Envelope.miny); double MinX = _map.Envelope.minx; double MinY = _map.Envelope.miny; //_lastRasterLayer = _layer; var canvas = _map.Display.Canvas; if (canvas == null) { return; } canvas.InterpolationMode = (GraphicsEngine.InterpolationMode)_interpolMethod; // Transformation berechnen GraphicsEngine.CanvasRectangleF rect; switch (canvas.InterpolationMode) { case GraphicsEngine.InterpolationMode.Bilinear: case GraphicsEngine.InterpolationMode.Bicubic: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width - 1f, paintContext.Bitmap.Height - 1f); break; case GraphicsEngine.InterpolationMode.NearestNeighbor: rect = new GraphicsEngine.CanvasRectangleF(-0.5f, -0.5f, paintContext.Bitmap.Width, paintContext.Bitmap.Height); //rect = new GraphicsEngine.CanvasRectangleF(0f, 0f, _layer.RasterClass.Bitmap.Width, _layer.RasterClass.Bitmap.Height); break; default: rect = new GraphicsEngine.CanvasRectangleF(0, 0, paintContext.Bitmap.Width, paintContext.Bitmap.Height); break; } var points = new GraphicsEngine.CanvasPointF[3]; if (_layer.RasterClass is IRasterClass2) { IPoint p1 = ((IRasterClass2)_layer.RasterClass).PicPoint1; IPoint p2 = ((IRasterClass2)_layer.RasterClass).PicPoint2; IPoint p3 = ((IRasterClass2)_layer.RasterClass).PicPoint3; if (_map.Display.GeometricTransformer != null) { p1 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p1); p2 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p2); p3 = (IPoint)_map.Display.GeometricTransformer.Transform2D(p3); } double X = p1.X, Y = p1.Y; _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p2.X; Y = p2.Y; _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = p3.X; Y = p3.Y; _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); RoundGraphicPixelPoints(points); } else { double X1 = _layer.RasterClass.oX - _layer.RasterClass.dx1 / 2.0 - _layer.RasterClass.dy1 / 2.0; double Y1 = _layer.RasterClass.oY - _layer.RasterClass.dx2 / 2.0 - _layer.RasterClass.dy2 / 2.0; double X = X1; double Y = Y1; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[0] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx1; Y = Y1 + (paintContext.Bitmap.Width) * _layer.RasterClass.dx2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[1] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); X = X1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy1; Y = Y1 + (paintContext.Bitmap.Height) * _layer.RasterClass.dy2; if (_map.Display.GeometricTransformer != null) { IPoint p = (IPoint)_map.Display.GeometricTransformer.Transform2D(new Point(X, Y)); X = p.X; Y = p.Y; } _map.Display.World2Image(ref X, ref Y); points[2] = new GraphicsEngine.CanvasPointF(ToPixelFloat(X), ToPixelFloat(Y)); } if (_transColor.ToArgb() != System.Drawing.Color.Transparent.ToArgb()) { try { // kann OutOfMemoryException auslösen... paintContext.Bitmap.MakeTransparent(_transColor); } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } } //var comQual = gr.CompositingQuality; //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; float opaque = 1.0f - _transparency; canvas.DrawBitmap(_filteredBitmap ?? paintContext.Bitmap, points, rect, opacity: opaque); _map.FireRefreshMapView(); } } catch (Exception ex) { if (_map is IServiceMap && ((IServiceMap)_map).MapServer != null) { await((IServiceMap)_map).MapServer.LogAsync( ((IServiceMap)_map).Name, "RenderRasterLayerThread:" + ((_layer != null) ? _layer.Title : String.Empty), loggingMethod.error, ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace); } if (_map != null) { if (_map != null) { _map.AddRequestException(new Exception("RenderRasterLayerThread: " + ((_layer != null) ? _layer.Title : String.Empty) + "\n" + ex.Message, ex)); } } } finally { if (_filteredBitmap != null) { _filteredBitmap.Dispose(); } } }
async public Task <bool> LegendRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null) { return(false); } List <IWebServiceTheme> themes = Themes; if (themes == null) { return(false); } #region Check for visible Layers bool visFound = false; foreach (IWebServiceTheme theme in themes) { if (!theme.Visible) { continue; } if (theme.MinimumScale > 1 && theme.MinimumScale > display.mapScale) { continue; } if (theme.MaximumScale > 1 && theme.MaximumScale < display.mapScale) { continue; } visFound = true; break; } if (!visFound) { if (_legend != null) { _legend.Dispose(); _legend = null; } return(true); } #endregion string server = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service"); string user = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd"); IServiceRequestContext context = display.Map as IServiceRequestContext; //if ((user == "#" || user == "$") && // context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) //{ // string roles = String.Empty; // if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) // { // foreach (string role in context.ServiceRequest.Identity.UserRoles) // { // if (String.IsNullOrEmpty(role)) continue; // roles += "|" + role; // } // } // user = context.ServiceRequest.Identity.UserName + roles; // pwd = context.ServiceRequest.Identity.HashedPassword; //} dotNETConnector connector = new dotNETConnector(); if (!String.IsNullOrEmpty(user) || !String.IsNullOrEmpty(pwd)) { connector.setAuthentification(user, pwd); } if (_dataset.State != DatasetState.opened) { if (!await _dataset.Open(context)) { return(false); } } try { StringBuilder sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='utf-8'?>"); sb.Append("<ARCXML version='1.1'>"); sb.Append("<REQUEST>"); sb.Append("<GET_IMAGE>"); sb.Append("<PROPERTIES>"); sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />"); sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />"); sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />"); sb.Append(_dataset._properties.PropertyString); sb.Append("<LAYERLIST>"); foreach (IWebServiceTheme theme in themes) { sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "'"); XmlNode xmlnode; if (LayerRenderer.TryGetValue(theme.LayerID, out xmlnode)) { sb.Append(">\n" + xmlnode.OuterXml + "\n</LAYERDEF>"); } else if (theme.FeatureRenderer != null) { string renderer = ObjectFromAXLFactory.ConvertToAXL(theme.FeatureRenderer); sb.Append(">\n" + renderer + "\n</LAYERDEF>"); } else { sb.Append("/>"); } } sb.Append("</LAYERLIST>"); sb.Append("<DRAW map=\"false\" />"); sb.Append("<LEGEND font=\"Arial\" autoextend=\"true\" columns=\"1\" width=\"165\" height=\"170\" backgroundcolor=\"255,255,255\" layerfontsize=\"11\" valuefontsize=\"10\">"); sb.Append("<LAYERS />"); sb.Append("</LEGEND>"); sb.Append("</PROPERTIES>"); foreach (XmlNode additional in this.AppendedLayers) { sb.Append(additional.OuterXml); } sb.Append("</GET_IMAGE>"); sb.Append("</REQUEST>"); sb.Append("</ARCXML>"); await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Request", server, service, sb); string resp = connector.SendRequest(sb, server, service); await ArcIMSClass.LogAsync(display as IServiceRequestContext, "GetLegend Response", server, service, resp); XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); XmlNode output = doc.SelectSingleNode("//LEGEND"); if (ModifyResponseOuput != null) { ModifyResponseOuput(this, new ModifyOutputEventArgs(output)); } if (_legend != null) { _legend.Dispose(); } _legend = WebFunctions.DownloadImage(output); return(true); } catch (Exception ex) { await ArcIMSClass.ErrorLog(context, "LegendRequest", server, service, ex); return(false); } }
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); } }