Ejemplo n.º 1
0
        private void DrawFeature(IFeature feature)
        {
            if (LayerData.GeoType == "1")
            {
                Geometry.Point2D pos = new Geometry.Point2D(feature.GeoData);
                AddSpot(new Point(pos.x, pos.y), feature);
                AddLable(new Point(pos.x, pos.y), LayerLableStyle.GetLable(feature));
            }
            else if (LayerData.GeoType == "2")
            {
                Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                if (IsRoad())
                {
                    AddRoadStroke(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                }
                if (!IsRoad())
                {
                    AddPolyline(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                }
                else
                {
                    AddRoadFill(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                }

                string        text = LayerLableStyle.GetLable(feature);
                double        linearRepeatInterval = LayerLableStyle.LinearRepeatInterval;
                double        length    = poly.Length;
                List <double> positions = new List <double>(); // mod 20130528 与SVG同步
                if (length > 0 && length < 2 * linearRepeatInterval)
                {
                    positions.Add(length / 2);
                }
                else
                {
                    int index = 1;
                    while (index * linearRepeatInterval < length)
                    {
                        positions.Add(index * linearRepeatInterval);
                        index++;
                    }
                }
                foreach (double position in positions)
                {
                    Geometry.Point2D tempPt   = poly.GetPointAtDist(position);
                    double           tanVal   = poly.GetFirstDerivative(position);
                    double           rotation = Math.Atan(tanVal);
                    double           angle    = 180 / Math.PI * rotation;
                    AddLable(new Point(tempPt.x, tempPt.y), text, angle);
                }
            }
            else if (LayerData.GeoType == "4")
            {
                Geometry.Polygon poly   = new Geometry.Polygon(feature.GeoData);
                Geometry.Point2D center = poly.Centroid; // mod 20130507
                AddPolygon(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                AddLable(new Point(center.x, center.y), LayerLableStyle.GetLable(feature));
            }
        }
Ejemplo n.º 2
0
        public virtual void SetData(VectorLayer layer)
        {
            LayerData       = layer;
            LayerStyle      = GetLayerStyle(layer);
            LayerLableStyle = GetLabelStyle(layer);
            Features.Clear();
            Overlays.Clear();
            Children.Clear();
            LabelLayer = new MapLayer();

            if (layer.GeoType == "1")
            {
                foreach (Feature feature in layer.Features)
                {
                    Geometry.Point2D pos = new Geometry.Point2D(feature.GeoData);
                    AddSpot(new Point(pos.x, pos.y), feature);
                    AddLable(new Point(pos.x, pos.y), LayerLableStyle.GetLable(feature));
                }
            }
            else if (layer.GeoType == "2")
            {
                if (IsRoad())
                {
                    foreach (Feature feature in layer.Features)
                    {
                        Geometry.Polyline polyline = new Geometry.Polyline(feature.GeoData);
                        AddRoadStroke(polyline.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                    }
                }
                foreach (Feature feature in layer.Features)
                {
                    Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                    if (!IsRoad())
                    {
                        AddPolyline(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                    }
                    else
                    {
                        AddRoadFill(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                    }
                }
                foreach (Feature feature in layer.Features) // mod 20130516 最后统一加标签
                {
                    Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                    string            text = LayerLableStyle.GetLable(feature);
                    double            linearRepeatInterval = LayerLableStyle.LinearRepeatInterval;
                    double            length = poly.Length;
                    //double scale = 4;  // 这个时候出现主窗口的Scale是不合适的。
                    List <double> positions = new List <double>(); // mod 20130528 与SVG同步
                    if (length > 0 && length < 2 * linearRepeatInterval)
                    {
                        positions.Add(length / 2);
                    }
                    else
                    {
                        int index = 1;
                        while (index * linearRepeatInterval < length)
                        {
                            positions.Add(index * linearRepeatInterval);
                            index++;
                        }
                    }
                    foreach (double position in positions)
                    {
                        Geometry.Point2D tempPt   = poly.GetPointAtDist(position);
                        double           tanVal   = poly.GetFirstDerivative(position);
                        double           rotation = Math.Atan(tanVal);
                        double           angle    = 180 / Math.PI * rotation;
                        AddLable(new Point(tempPt.x, tempPt.y), text, angle);
                    }
                }
            }
            else if (layer.GeoType == "4")
            {
                foreach (Feature feature in layer.Features)
                {
                    Geometry.Polygon poly   = new Geometry.Polygon(feature.GeoData);
                    Geometry.Point2D center = poly.Centroid;
                    AddPolygon(poly.Points.Select(p => new Point(p.x, p.y)).ToArray(), feature);
                    AddLable(new Point(center.x, center.y), LayerLableStyle.GetLable(feature));
                }
            }
        }
Ejemplo n.º 3
0
        public string Render(int width = 0, int height = 0)
        {
            SetSvgCanvas(_svgWriter, _extents, width, height);

            var layers = _map.Layers.OrderBy(l => GetLayerOrder(l.Name)).ToList();

            foreach (VectorLayer layer in layers)
            {
                // Run overlay procedure
                var order = GetLayerOrder(layer.Name);
                if (_overlayRenderProcedures.ContainsKey(order))
                {
                    _overlayRenderProcedures[order]();
                }

                // Set SVG styles using layer style config
                var layerConfig = GetLayerConfigByName(layer.Name);
                SetVectorStyles(_svgWriter, layerConfig);
                var themeFilter = _themeFilters.ContainsKey(layer.Name) ? _themeFilters[layer.Name] : null;

                if (layer.GeoType == "1")
                {
                    foreach (Feature feature in layer.Features)
                    {
                        // Set SVG styles using theme
                        SetVectorStyles(_svgWriter, themeFilter, feature);
                        Geometry.Point2D pos = new Geometry.Point2D(feature.GeoData);
                        AddCircle(20, pos.x, pos.y);
                    }

                    SetTextStyles(_svgWriter, layerConfig);
                    foreach (Feature feature in layer.Features)
                    {
                        Geometry.Point2D pos = new Geometry.Point2D(feature.GeoData);
                        AddText(GetLabel(layerConfig, feature), pos.x, pos.y);
                    }
                }
                else if (layer.GeoType == "2")
                {
                    if (layerConfig != null && layerConfig.StrokeBundle != null && layerConfig.StrokeBundle.Strokes.Count > 0)
                    {
                        foreach (VectorStyle strokeStyle in layerConfig.StrokeBundle.Strokes)
                        {
                            // Set SVG styles using this bundle element style
                            SetVectorStyles(_svgWriter, strokeStyle);
                            foreach (Feature feature in layer.Features)
                            {
                                Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                                AddPolyline(poly.Points);
                            }
                        }
                    }
                    else
                    {
                        foreach (Feature feature in layer.Features)
                        {
                            // Set SVG styles using theme
                            SetVectorStyles(_svgWriter, themeFilter, feature);
                            _svgWriter.SetFill("none");
                            Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                            AddPolyline(poly.Points);
                        }
                    }

                    // Whatever case, add label in the end in case of overlapping with shapes
                    if (layerConfig != null && layerConfig.LabelStyle != null)
                    {
                        SetTextStyles(_svgWriter, layerConfig);
                        foreach (Feature feature in layer.Features)
                        {
                            // Add label every specified length
                            Geometry.Polyline poly = new Geometry.Polyline(feature.GeoData);
                            string            text = GetLabel(layerConfig, feature);
                            double            linearRepeatInterval = layerConfig.LabelStyle.LinearRepeatInterval;
                            double            length    = poly.Length;
                            List <double>     positions = new List <double>();
                            if (length > 0 && length < 2 * linearRepeatInterval)
                            {
                                positions.Add(length / 2);
                            }
                            else
                            {
                                int index = 1;
                                while (index * linearRepeatInterval < length)
                                {
                                    positions.Add(index * linearRepeatInterval);
                                    index++;
                                }
                            }
                            foreach (double position in positions)
                            {
                                Geometry.Point2D pos      = poly.GetPointAtDist(position);
                                double           tan      = poly.GetFirstDerivative(position);
                                double           rotation = Math.Atan(tan);
                                double           angle    = -180 / Math.PI * rotation;
                                AddText(text, pos.x, pos.y, angle);
                            }
                        }
                    }
                }
                else if (layer.GeoType == "4")
                {
                    foreach (Feature feature in layer.Features)
                    {
                        // Set SVG styles using theme
                        SetVectorStyles(_svgWriter, themeFilter, feature);
                        Geometry.Polygon poly = new Geometry.Polygon(feature.GeoData);
                        AddPolygon(poly.Points);
                    }

                    SetTextStyles(_svgWriter, layerConfig);
                    foreach (Feature feature in layer.Features)
                    {
                        Geometry.Polygon poly   = new Geometry.Polygon(feature.GeoData);
                        Geometry.Point2D center = poly.Centroid;
                        AddText(GetLabel(layerConfig, feature), center.x, center.y);
                    }
                }
            }

            return(_svgWriter.ToString());
        }