Exemplo n.º 1
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();
        }