예제 #1
0
        public static bool DoRender(this ILayer self, Graphics g, MapViewport map)
        {
            // Is the layer enabled for rendering at all
            if (!self.Enabled)
            {
                return(false);
            }

            // Get the compare value, zoom or scale
            var compare = self.VisibilityUnits == Styles.VisibilityUnits.ZoomLevel
                ? map.Zoom
                : map.GetMapScale((int)g.DpiX);

            // Is the layer enabled for the current scale
            if (self.MinVisible <= compare || compare <= self.MaxVisible)
            {
                return(false);
            }

            // Does the layer intersect the viewport at all
            if (!self.Envelope.Intersects(map.Envelope))
            {
                return(false);
            }

            return(true);
        }
 public void Render(Graphics g, MapViewport mapViewPort, bool allowParallel)
 {
     _mapViewPort = mapViewPort;
     _mapScale    = _mapViewPort.GetMapScale((int)g.DpiX);
     //_transform = _map.MapTransform;
     g.PageUnit = GraphicsUnit.Pixel;
     if (AllowParallel && allowParallel && ParallelHeuristic(mapViewPort.Size, g.DpiX, _layers.Length))
     {
         RenderParellel(g);
     }
     else
     {
         RenderSequenial(g);
     }
 }
예제 #3
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(Graphics g, MapViewport map)
        {
            var layers  = GetSnapshot();
            var compare = VisibilityUnits == VisibilityUnits.ZoomLevel
                ? map.Zoom
                : map.GetMapScale((int)g.DpiX);

            foreach (var layer in layers)
            {
                if (layer.Enabled && layer.MaxVisible >= compare &&
                    layer.MinVisible < compare)
                {
                    layer.Render(g, map);
                }
            }
        }
예제 #4
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 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)
                                {
                                    VectorRenderer.DrawLineString(g, feature.Geometry as ILineString, outlineStyle.Outline,
                                                                  map, outlineStyle.LineOffset);
                                }
                                else if (feature.Geometry is IMultiLineString)
                                {
                                    VectorRenderer.DrawMultiLineString(g, feature.Geometry as IMultiLineString,
                                                                       outlineStyle.Outline, map, outlineStyle.LineOffset);
                                }
                            }
                        }
                    }
                }


                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)
                            {
                                RenderGeometry(g, map, feature.Geometry, clone);
                            }
                        }
                    }
                }
            }
        }