Exemple #1
0
        /// <summary>
        /// Method to render this layer to the map, applying <see cref="Style"/>.
        /// </summary>
        /// <param name="g">The graphics object</param>
        /// <param name="map">The map object</param>
        /// <param name="envelope">The envelope to render</param>
        protected void RenderInternal(Graphics g, MapViewport map, Envelope envelope)
        {
            //if style is not enabled, we don't need to render anything
            if (!Style.Enabled)
            {
                return;
            }

            IEnumerable <IStyle> stylesToRender = GetStylesToRender(Style);

            if (stylesToRender == null)
            {
                return;
            }

            var canvasArea   = RectangleF.Empty;
            var combinedArea = RectangleF.Empty;

            Collection <IGeometry> geoms = null;

            foreach (var style in stylesToRender)
            {
                if (!(style is VectorStyle) || !style.Enabled)
                {
                    continue;
                }
                using (var vStyle = (style as VectorStyle).Clone())
                {
                    if (vStyle != null)
                    {
                        if (geoms == null)
                        {
                            lock (_dataSource)
                            {
                                // Is datasource already open?
                                bool wasOpen = DataSource.IsOpen;
                                if (!wasOpen)
                                {
                                    DataSource.Open();
                                }

                                // Read data
                                geoms = DataSource.GetGeometriesInView(envelope);

                                if (!wasOpen)
                                {
                                    DataSource.Close();
                                }
                            }

                            if (_logger.IsDebugEnabled)
                            {
                                _logger.DebugFormat("Layer {0}, NumGeometries {1}", LayerName, geoms.Count);
                            }

                            // Transform geometries if necessary
                            if (CoordinateTransformation != null)
                            {
                                for (int i = 0; i < geoms.Count; i++)
                                {
                                    geoms[i] = ToTarget(geoms[i]);
                                }
                            }
                        }

                        if (vStyle.LineSymbolizer != null)
                        {
                            vStyle.LineSymbolizer.Begin(g, map, geoms.Count);
                        }
                        else
                        {
                            //Linestring outlines is drawn by drawing the layer once with a thicker line
                            //before drawing the "inline" on top.
                            if (vStyle.EnableOutline)
                            {
                                foreach (var geom in geoms)
                                {
                                    if (geom != null)
                                    {
                                        //Draw background of all line-outlines first
                                        if (geom is ILineString)
                                        {
                                            canvasArea = VectorRenderer.DrawLineStringEx(g, geom as ILineString, vStyle.Outline, map, vStyle.LineOffset);
                                        }
                                        else if (geom is IMultiLineString)
                                        {
                                            canvasArea = VectorRenderer.DrawMultiLineStringEx(g, geom as IMultiLineString, vStyle.Outline, map, vStyle.LineOffset);
                                        }
                                        combinedArea = canvasArea.ExpandToInclude(combinedArea);
                                    }
                                }
                            }
                        }

                        foreach (IGeometry geom in geoms)
                        {
                            if (geom != null)
                            {
                                canvasArea   = RenderGeometryEx(g, map, geom, vStyle);
                                combinedArea = canvasArea.ExpandToInclude(combinedArea);
                            }
                        }

                        if (vStyle.LineSymbolizer != null)
                        {
                            vStyle.LineSymbolizer.Symbolize(g, map);
                            vStyle.LineSymbolizer.End(g, map);
                        }
                    }
                }
            }

            CanvasArea = combinedArea;
        }
Exemple #2
0
        /// <summary>
        /// Function to render <paramref name="feature"/> using <paramref name="style"/> and returning the area covered.
        /// </summary>
        /// <param name="g">The graphics object</param>
        /// <param name="map">The map</param>
        /// <param name="feature">The feature's geometry</param>
        /// <param name="style">The style to apply</param>
        protected RectangleF RenderGeometryEx(Graphics g, MapViewport map, IGeometry feature, VectorStyle style)
        {
            if (feature == null)
            {
                return(RectangleF.Empty);
            }

            var geometryType = feature.OgcGeometryType;

            switch (geometryType)
            {
            case OgcGeometryType.Polygon:
                if (style.EnableOutline)
                {
                    return(VectorRenderer.DrawPolygonEx(g, (IPolygon)feature, style.Fill, style.Outline, _clippingEnabled,
                                                        map));
                }
                else
                {
                    return(VectorRenderer.DrawPolygonEx(g, (IPolygon)feature, style.Fill, null, _clippingEnabled, map));
                }

            case OgcGeometryType.MultiPolygon:
                if (style.EnableOutline)
                {
                    return(VectorRenderer.DrawMultiPolygonEx(g, (IMultiPolygon)feature, style.Fill, style.Outline, _clippingEnabled, map));
                }
                return(VectorRenderer.DrawMultiPolygonEx(g, (IMultiPolygon)feature, style.Fill, null, _clippingEnabled, map));

            case OgcGeometryType.LineString:
                if (style.LineSymbolizer != null)
                {
                    style.LineSymbolizer.Render(map, (ILineString)feature, g);
                    return(RectangleF.Empty);
                }
                return(VectorRenderer.DrawLineStringEx(g, (ILineString)feature, style.Line, map, style.LineOffset));

            case OgcGeometryType.MultiLineString:
                if (style.LineSymbolizer != null)
                {
                    style.LineSymbolizer.Render(map, (IMultiLineString)feature, g);
                    return(RectangleF.Empty);
                }
                return(VectorRenderer.DrawMultiLineStringEx(g, (IMultiLineString)feature, style.Line, map, style.LineOffset));


            case OgcGeometryType.Point:
                if (style.PointSymbolizer != null)
                {
                    return(VectorRenderer.DrawPointEx(style.PointSymbolizer, g, (IPoint)feature, map));
                }

                if (style.Symbol != null || style.PointColor == null)
                {
                    return(VectorRenderer.DrawPointEx(g, (IPoint)feature, style.Symbol, style.SymbolScale, style.SymbolOffset,
                                                      style.SymbolRotation, map));
                }

                return(VectorRenderer.DrawPointEx(g, (IPoint)feature, style.PointColor, style.PointSize, style.SymbolOffset, map));

            case OgcGeometryType.MultiPoint:
                if (style.PointSymbolizer != null)
                {
                    return(VectorRenderer.DrawMultiPointEx(style.PointSymbolizer, g, (IMultiPoint)feature, map));
                }

                if (style.Symbol != null || style.PointColor == null)
                {
                    return(VectorRenderer.DrawMultiPointEx(g, (IMultiPoint)feature, style.Symbol, style.SymbolScale, style.SymbolOffset, style.SymbolRotation, map));
                }

                return(VectorRenderer.DrawMultiPointEx(g, (IMultiPoint)feature, style.PointColor, style.PointSize, style.SymbolOffset, map));

            case OgcGeometryType.GeometryCollection:
                var coll         = (IGeometryCollection)feature;
                var combinedArea = RectangleF.Empty;
                for (var i = 0; i < coll.NumGeometries; i++)
                {
                    IGeometry geom       = coll[i];
                    var       canvasArea = RenderGeometryEx(g, map, geom, style);
                    combinedArea = canvasArea.ExpandToInclude(combinedArea);
                }
                return(combinedArea);
            }
            throw new NotSupportedException();
        }
Exemple #3
0
        /// <summary>
        /// Method to render this layer to the map, applying <paramref name="theme"/>.
        /// </summary>
        /// <param name="g">The graphics object</param>
        /// <param name="map">The map object</param>
        /// <param name="envelope">The envelope to render</param>
        /// <param name="theme">The theme to apply</param>
        protected void RenderInternal(Graphics g, MapViewport map, Envelope envelope, ITheme theme)
        {
            var canvasArea   = RectangleF.Empty;
            var combinedArea = RectangleF.Empty;

            var ds = new FeatureDataSet();

            lock (_dataSource)
            {
                // Is datasource already open?
                bool wasOpen = DataSource.IsOpen;
                if (!wasOpen)
                {
                    DataSource.Open();
                }

                DataSource.ExecuteIntersectionQuery(envelope, ds);

                if (!wasOpen)
                {
                    DataSource.Close();
                }
            }

            double scale = map.GetMapScale((int)g.DpiX);
            double zoom  = map.Zoom;

            Func <MapViewport, FeatureDataRow, IStyle> evalStyle;

            if (theme is IThemeEx)
            {
                evalStyle = new ThemeExEvaluator((IThemeEx)theme).GetStyle;
            }
            else
            {
                evalStyle = new ThemeEvaluator(theme).GetStyle;
            }

            foreach (FeatureDataTable features in ds.Tables)
            {
                // Transform geometries if necessary
                if (CoordinateTransformation != null)
                {
                    for (int i = 0; i < features.Count; i++)
                    {
                        features[i].Geometry = ToTarget(features[i].Geometry);
                    }
                }

                //Linestring outlines is drawn by drawing the layer once with a thicker line
                //before drawing the "inline" on top.
                if (Style.EnableOutline)
                {
                    for (int i = 0; i < features.Count; i++)
                    {
                        var feature      = features[i];
                        var outlineStyle = evalStyle(map, feature) as VectorStyle;
                        if (outlineStyle == null)
                        {
                            continue;
                        }
                        if (!(outlineStyle.Enabled && outlineStyle.EnableOutline))
                        {
                            continue;
                        }

                        var compare = outlineStyle.VisibilityUnits == VisibilityUnits.ZoomLevel ? zoom : scale;

                        if (!(outlineStyle.MinVisible <= compare && compare <= outlineStyle.MaxVisible))
                        {
                            continue;
                        }

                        using (outlineStyle = outlineStyle.Clone())
                        {
                            if (outlineStyle != null)
                            {
                                //Draw background of all line-outlines first
                                if (feature.Geometry is ILineString)
                                {
                                    canvasArea = VectorRenderer.DrawLineStringEx(g, feature.Geometry as ILineString, outlineStyle.Outline,
                                                                                 map, outlineStyle.LineOffset);
                                }
                                else if (feature.Geometry is IMultiLineString)
                                {
                                    canvasArea = VectorRenderer.DrawMultiLineStringEx(g, feature.Geometry as IMultiLineString,
                                                                                      outlineStyle.Outline, map, outlineStyle.LineOffset);
                                }
                                combinedArea = canvasArea.ExpandToInclude(combinedArea);
                            }
                        }
                    }
                }


                for (int i = 0; i < features.Count; i++)
                {
                    var feature = features[i];
                    var style   = evalStyle(map, feature);
                    if (style == null)
                    {
                        continue;
                    }
                    if (!style.Enabled)
                    {
                        continue;
                    }

                    double compare = style.VisibilityUnits == VisibilityUnits.ZoomLevel ? zoom : scale;

                    if (!(style.MinVisible <= compare && compare <= style.MaxVisible))
                    {
                        continue;
                    }


                    IEnumerable <IStyle> stylesToRender = GetStylesToRender(style);

                    if (stylesToRender == null)
                    {
                        return;
                    }

                    foreach (var vstyle in stylesToRender)
                    {
                        if (!(vstyle is VectorStyle) || !vstyle.Enabled)
                        {
                            continue;
                        }

                        using (var clone = (vstyle as VectorStyle).Clone())
                        {
                            if (clone != null)
                            {
                                canvasArea   = RenderGeometryEx(g, map, feature.Geometry, clone);
                                combinedArea = canvasArea.ExpandToInclude(combinedArea);
                            }
                        }
                    }
                }
            }

            CanvasArea = combinedArea;
        }