public MapGuideLayer(ServerConnectionI con, string layername)
        {
            m_con = con;

            m_layerDef = m_con.GetLayerDefinition(layername);
            if (!(m_layerDef.Item is VectorLayerDefinitionType))
                throw new Exception("The resource " + layername + " is not a vector layer");

            VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

            m_columnnames = new Dictionary<string, string>();

            m_columnnames[vldef.Geometry] = null;

            ExtractColumnNames(vldef.Url, m_columnnames);
            ExtractColumnNames(vldef.ToolTip, m_columnnames);

            try
            {
                FeatureSource fs = m_con.GetFeatureSource(vldef.ResourceId);
                FdoSpatialContextList lst = fs.GetSpatialInfo();
                if (lst != null && lst.SpatialContext != null && lst.SpatialContext.Count > 0)
                {
                    Topology.CoordinateSystems.CoordinateSystemFactory cf = new Topology.CoordinateSystems.CoordinateSystemFactory();
                    m_coordSys = cf.CreateFromWkt(lst.SpatialContext[0].CoordinateSystemWkt);
                }
            }
            catch
            {
            }

            foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
            {
                ScaleRange sr = new ScaleRange(vsr.MinScaleSpecified ? vsr.MinScale : 0, vsr.MaxScaleSpecified ? vsr.MaxScale : double.MaxValue);

                foreach (object style in vsr.Items)
                    if (style is PointTypeStyleType)
                    {
                        if (((PointTypeStyleType)style).PointRule != null)
                            foreach (PointRuleType rule in ((PointTypeStyleType)style).PointRule)
                            {
                                if (rule.Item != null && rule.Item.Item != null)
                                {
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);

                                    LittleSharpRenderEngine.Style.Point p = new LittleSharpRenderEngine.Style.Point();
                                    p.Center = new System.Drawing.Point(
                                        (int)(rule.Item.Item.InsertionPointXSpecified ? rule.Item.Item.InsertionPointX : 0.5),
                                        (int)(rule.Item.Item.InsertionPointYSpecified ? rule.Item.Item.InsertionPointY : 0.5));

                                    p.Rotation = double.Parse(rule.Item.Item.Rotation, System.Globalization.CultureInfo.InvariantCulture);
                                    p.Size = new System.Drawing.Size(
                                        (int)double.Parse(rule.Item.Item.SizeX, System.Globalization.CultureInfo.InvariantCulture),
                                        (int)double.Parse(rule.Item.Item.SizeY, System.Globalization.CultureInfo.InvariantCulture));

                                    if (rule.Item.Item is MarkSymbolType)
                                    {
                                        MarkSymbolType mark = rule.Item.Item as MarkSymbolType;
                                        switch (mark.Shape)
                                        {
                                            case ShapeType.Circle:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                                break;
                                            case ShapeType.Square:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Square;
                                                break;
                                            case ShapeType.Triangle:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Triangle;
                                                break;
                                            default:
                                                p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                                break;
                                        }

                                        if (mark.Fill != null)
                                        {
                                            p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                            p.Fill.BackgroundColor = mark.Fill.BackgroundColor;
                                            p.Fill.ForegroundColor = mark.Fill.ForegroundColor;
                                            //p.Fill.Pattern = mark.Fill.FillPattern;
                                            //TODO: Deal with unit/sizecontext
                                        }

                                        if (mark.Edge != null)
                                        {
                                            p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                            p.Outline.ForegroundColor = mark.Edge.Color;
                                            //p.Outline.DashStyle = mark.Edge.LineStyle;
                                            //p.Outline.Pattern = mark.Edge.LineStyle;
                                            p.Outline.Width = (int)double.Parse(mark.Edge.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                            //TODO: Deal with unit/sizecontext
                                        }
                                    }
                                    else
                                    {
                                        p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                        p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        p.Fill.BackgroundColor = System.Drawing.Color.Red;
                                        p.Fill.ForegroundColor = System.Drawing.Color.Black;

                                        p.Outline.ForegroundColor = System.Drawing.Color.Black;
                                    }

                                    sr.PointRules.Add(new KeyValuePair<OperationOrParameter, IPointStyle>(op, p));
                                }
                            }
                    }
                    else if (style is LineTypeStyleType)
                    {
                        if (((LineTypeStyleType)style).LineRule != null)
                            foreach (LineRuleType rule in ((LineTypeStyleType)style).LineRule)
                            {
                                if (rule.Items != null && rule.Items.Count > 0)
                                {
                                    List<IOutline> lines = new List<IOutline>();
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);

                                    foreach (StrokeType st in rule.Items)
                                    {
                                        LittleSharpRenderEngine.Style.Base.Outline outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        outline.ForegroundColor = st.Color;
                                        outline.Width = (int)double.Parse(st.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //outline.Pattern = st.LineStyle;
                                        //outline.DashStyle = st.LineStyle;
                                        //TODO: Deal with unit/sizecontext

                                        lines.Add(outline);
                                    }

                                    sr.LineRules.Add(new KeyValuePair<OperationOrParameter, ILineStyle>(op, new LittleSharpRenderEngine.Style.Line(lines)));
                                }

                            }
                    }
                    else if (style is AreaTypeStyleType)
                    {
                        if (((AreaTypeStyleType)style).AreaRule != null)
                            foreach (AreaRuleType rule in ((AreaTypeStyleType)style).AreaRule)
                            {
                                OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                if (rule.Label != null)
                                    ExtractColumnNames(rule.Label.Text, m_columnnames);

                                LittleSharpRenderEngine.Style.Area a = new Area();
                                if (rule.Item != null)
                                {
                                    if (rule.Item.Fill != null)
                                    {
                                        a.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        a.Fill.BackgroundColor = rule.Item.Fill.BackgroundColor;
                                        a.Fill.ForegroundColor = rule.Item.Fill.ForegroundColor;
                                        //p.Fill.Pattern = rule.Item.Fill.FillPattern;
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    if (rule.Item.Stroke != null)
                                    {
                                        a.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        a.Outline.ForegroundColor = rule.Item.Stroke.Color;
                                        //p.Outline.DashStyle = rule.Item.Stroke.LineStyle;
                                        //p.Outline.Pattern = rule.Item.Stroke.LineStyle;
                                        a.Outline.Width = (int)double.Parse(rule.Item.Stroke.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    sr.AreaRules.Add(new KeyValuePair<OperationOrParameter, IAreaStyle>(op, a));
                                }
                            }
                    }

                if (sr.PointRules.Count + sr.LineRules.Count + sr.AreaRules.Count > 0)
                    m_scaleRanges.Add(sr);
            }
        }
Exemplo n.º 2
0
        public MapGuideLayer(ServerConnectionI con, string layername)
        {
            m_con = con;

            m_layerDef = m_con.GetLayerDefinition(layername);
            if (!(m_layerDef.Item is VectorLayerDefinitionType))
            {
                throw new Exception("The resource " + layername + " is not a vector layer");
            }

            VectorLayerDefinitionType vldef = m_layerDef.Item as VectorLayerDefinitionType;

            m_columnnames = new Dictionary <string, string>();

            m_columnnames[vldef.Geometry] = null;

            ExtractColumnNames(vldef.Url, m_columnnames);
            ExtractColumnNames(vldef.ToolTip, m_columnnames);

            try
            {
                FeatureSource         fs  = m_con.GetFeatureSource(vldef.ResourceId);
                FdoSpatialContextList lst = fs.GetSpatialInfo();
                if (lst != null && lst.SpatialContext != null && lst.SpatialContext.Count > 0)
                {
                    Topology.CoordinateSystems.CoordinateSystemFactory cf = new Topology.CoordinateSystems.CoordinateSystemFactory();
                    m_coordSys = cf.CreateFromWkt(lst.SpatialContext[0].CoordinateSystemWkt);
                }
            }
            catch
            {
            }

            foreach (VectorScaleRangeType vsr in vldef.VectorScaleRange)
            {
                ScaleRange sr = new ScaleRange(vsr.MinScaleSpecified ? vsr.MinScale : 0, vsr.MaxScaleSpecified ? vsr.MaxScale : double.MaxValue);

                foreach (object style in vsr.Items)
                {
                    if (style is PointTypeStyleType)
                    {
                        if (((PointTypeStyleType)style).PointRule != null)
                        {
                            foreach (PointRuleType rule in ((PointTypeStyleType)style).PointRule)
                            {
                                if (rule.Item != null && rule.Item.Item != null)
                                {
                                    OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    LittleSharpRenderEngine.Style.Point p = new LittleSharpRenderEngine.Style.Point();
                                    p.Center = new System.Drawing.Point(
                                        (int)(rule.Item.Item.InsertionPointXSpecified ? rule.Item.Item.InsertionPointX : 0.5),
                                        (int)(rule.Item.Item.InsertionPointYSpecified ? rule.Item.Item.InsertionPointY : 0.5));

                                    p.Rotation = double.Parse(rule.Item.Item.Rotation, System.Globalization.CultureInfo.InvariantCulture);
                                    p.Size     = new System.Drawing.Size(
                                        (int)double.Parse(rule.Item.Item.SizeX, System.Globalization.CultureInfo.InvariantCulture),
                                        (int)double.Parse(rule.Item.Item.SizeY, System.Globalization.CultureInfo.InvariantCulture));

                                    if (rule.Item.Item is MarkSymbolType)
                                    {
                                        MarkSymbolType mark = rule.Item.Item as MarkSymbolType;
                                        switch (mark.Shape)
                                        {
                                        case ShapeType.Circle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;

                                        case ShapeType.Square:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Square;
                                            break;

                                        case ShapeType.Triangle:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Triangle;
                                            break;

                                        default:
                                            p.Type = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                            break;
                                        }

                                        if (mark.Fill != null)
                                        {
                                            p.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                            p.Fill.BackgroundColor = mark.Fill.BackgroundColor;
                                            p.Fill.ForegroundColor = mark.Fill.ForegroundColor;
                                            //p.Fill.Pattern = mark.Fill.FillPattern;
                                            //TODO: Deal with unit/sizecontext
                                        }

                                        if (mark.Edge != null)
                                        {
                                            p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                            p.Outline.ForegroundColor = mark.Edge.Color;
                                            //p.Outline.DashStyle = mark.Edge.LineStyle;
                                            //p.Outline.Pattern = mark.Edge.LineStyle;
                                            p.Outline.Width = (int)double.Parse(mark.Edge.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                            //TODO: Deal with unit/sizecontext
                                        }
                                    }
                                    else
                                    {
                                        p.Type    = LittleSharpRenderEngine.Style.Point.PointType.Circle;
                                        p.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        p.Fill    = new LittleSharpRenderEngine.Style.Base.Fill();
                                        p.Fill.BackgroundColor = System.Drawing.Color.Red;
                                        p.Fill.ForegroundColor = System.Drawing.Color.Black;

                                        p.Outline.ForegroundColor = System.Drawing.Color.Black;
                                    }

                                    sr.PointRules.Add(new KeyValuePair <OperationOrParameter, IPointStyle>(op, p));
                                }
                            }
                        }
                    }
                    else if (style is LineTypeStyleType)
                    {
                        if (((LineTypeStyleType)style).LineRule != null)
                        {
                            foreach (LineRuleType rule in ((LineTypeStyleType)style).LineRule)
                            {
                                if (rule.Items != null && rule.Items.Count > 0)
                                {
                                    List <IOutline>      lines = new List <IOutline>();
                                    OperationOrParameter op    = ExtractColumnNames(rule.Filter, m_columnnames);
                                    if (rule.Label != null)
                                    {
                                        ExtractColumnNames(rule.Label.Text, m_columnnames);
                                    }

                                    foreach (StrokeType st in rule.Items)
                                    {
                                        LittleSharpRenderEngine.Style.Base.Outline outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        outline.ForegroundColor = st.Color;
                                        outline.Width           = (int)double.Parse(st.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //outline.Pattern = st.LineStyle;
                                        //outline.DashStyle = st.LineStyle;
                                        //TODO: Deal with unit/sizecontext

                                        lines.Add(outline);
                                    }

                                    sr.LineRules.Add(new KeyValuePair <OperationOrParameter, ILineStyle>(op, new LittleSharpRenderEngine.Style.Line(lines)));
                                }
                            }
                        }
                    }
                    else if (style is AreaTypeStyleType)
                    {
                        if (((AreaTypeStyleType)style).AreaRule != null)
                        {
                            foreach (AreaRuleType rule in ((AreaTypeStyleType)style).AreaRule)
                            {
                                OperationOrParameter op = ExtractColumnNames(rule.Filter, m_columnnames);
                                if (rule.Label != null)
                                {
                                    ExtractColumnNames(rule.Label.Text, m_columnnames);
                                }

                                LittleSharpRenderEngine.Style.Area a = new Area();
                                if (rule.Item != null)
                                {
                                    if (rule.Item.Fill != null)
                                    {
                                        a.Fill = new LittleSharpRenderEngine.Style.Base.Fill();
                                        a.Fill.BackgroundColor = rule.Item.Fill.BackgroundColor;
                                        a.Fill.ForegroundColor = rule.Item.Fill.ForegroundColor;
                                        //p.Fill.Pattern = rule.Item.Fill.FillPattern;
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    if (rule.Item.Stroke != null)
                                    {
                                        a.Outline = new LittleSharpRenderEngine.Style.Base.Outline();
                                        a.Outline.ForegroundColor = rule.Item.Stroke.Color;
                                        //p.Outline.DashStyle = rule.Item.Stroke.LineStyle;
                                        //p.Outline.Pattern = rule.Item.Stroke.LineStyle;
                                        a.Outline.Width = (int)double.Parse(rule.Item.Stroke.Thickness, System.Globalization.CultureInfo.InvariantCulture);
                                        //TODO: Deal with unit/sizecontext
                                    }

                                    sr.AreaRules.Add(new KeyValuePair <OperationOrParameter, IAreaStyle>(op, a));
                                }
                            }
                        }
                    }
                }

                if (sr.PointRules.Count + sr.LineRules.Count + sr.AreaRules.Count > 0)
                {
                    m_scaleRanges.Add(sr);
                }
            }
        }