Esempio n. 1
0
        private void AddRuleButton_Click(object sender, EventArgs e)
        {
            if (m_point != null)
            {
                IPointRule prt = _factory.CreateDefaultPointRule();
                int        idx = m_point.RuleCount;
                conditionList.AddRuleControl(prt, idx).Focus();
                m_point.AddRule(prt);
            }
            else if (m_line != null)
            {
                ILineRule lrt = _factory.CreateDefaultLineRule();
                int       idx = m_line.RuleCount;
                conditionList.AddRuleControl(lrt, idx).Focus();
                m_line.AddRule(lrt);
            }
            else if (m_area != null)
            {
                IAreaRule art = _factory.CreateDefaultAreaRule();
                int       idx = m_area.RuleCount;
                conditionList.AddRuleControl(art, idx).Focus();
                m_area.AddRule(art);
            }
            else if (m_comp != null)
            {
                ICompositeRule cr  = _factory.CreateDefaultCompositeRule();
                int            idx = m_area.RuleCount;
                conditionList.AddRuleControl(cr, idx).Focus();
                m_comp.AddCompositeRule(cr);
            }

            ItemChanged?.Invoke(this, null);
        }
        void IAreaVectorStyle.RemoveRule(IAreaRule rule)
        {
            var ar = rule as AreaRuleType;

            if (ar != null)
            {
                this.AreaRule.Remove(ar);
            }
        }
Esempio n. 3
0
        private void SetItemInternal(object item, double previewScale, int themeCategory)
        {
            m_prt  = item as IPointRule;
            m_lrt  = item as ILineRule;
            m_art  = item as IAreaRule;
            m_comp = item as ICompositeRule;

            try
            {
                m_isUpdating = true;
                if (m_prt != null)
                {
                    RuleCondition.Text = m_prt.Filter;
                    LegendLabel.Text   = m_prt.LegendLabel;
                    Image w2d = null;
                    if (m_prt.PointSymbolization2D != null)
                    {
                        //Determine if this is a w2d symbol style
                        if (m_prt.PointSymbolization2D.Symbol.Type == PointSymbolType.W2D)
                        {
                            var sym = (IW2DSymbol)m_prt.PointSymbolization2D.Symbol;
                            w2d = SymbolPicker.GetSymbol(_conn, sym.W2DSymbol.ResourceId, sym.W2DSymbol.LibraryItemName);
                        }
                    }
                    FeatureStyle.SetItem(m_prt, m_prt.PointSymbolization2D, w2d, previewScale, themeCategory);
                    LabelStyle.SetItem(m_prt, m_prt.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_lrt != null)
                {
                    RuleCondition.Text = m_lrt.Filter;
                    LegendLabel.Text   = m_lrt.LegendLabel;
                    FeatureStyle.SetItem(m_lrt, m_lrt.Strokes, previewScale, themeCategory);
                    LabelStyle.SetItem(m_lrt, m_lrt.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_art != null)
                {
                    RuleCondition.Text = m_art.Filter;
                    LegendLabel.Text   = m_art.LegendLabel;
                    FeatureStyle.SetItem(m_art, m_art.AreaSymbolization2D, previewScale, themeCategory);
                    LabelStyle.SetItem(m_art, m_art.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_comp != null)
                {
                    RuleCondition.Text = m_comp.Filter;
                    LegendLabel.Text   = m_comp.LegendLabel;
                    FeatureStyle.SetItem(m_comp, m_comp.CompositeSymbolization, previewScale, themeCategory);
                    LabelStyle.Visible = false;
                }
            }
            finally
            {
                m_isUpdating = false;
            }
        }
        public bool MoveDown(IAreaRule rule)
        {
            var r = rule as AreaRuleType;

            if (r != null)
            {
                return(CollectionUtil.MoveDown(this.AreaRule, r));
            }
            return(false);
        }
        public int IndexOfRule(IAreaRule rule)
        {
            var r = rule as AreaRuleType;

            if (r != null)
            {
                return(this.AreaRule.IndexOf(r));
            }
            return(-1);
        }
Esempio n. 6
0
        private void ReSyncRulesToBindingList(IVectorStyle style)
        {
            _rules.Clear();
            if (style != null)
            {
                switch (style.StyleType)
                {
                case StyleType.Point:
                {
                    for (int i = 0; i < style.RuleCount; i++)
                    {
                        IPointRule pr = (IPointRule)style.GetRuleAt(i);
                        _rules.Add(new PointRuleModel(pr, i));
                    }
                }
                break;

                case StyleType.Line:
                {
                    for (int i = 0; i < style.RuleCount; i++)
                    {
                        ILineRule lr = (ILineRule)style.GetRuleAt(i);
                        _rules.Add(new LineRuleModel(lr, i));
                    }
                }
                break;

                case StyleType.Area:
                {
                    for (int i = 0; i < style.RuleCount; i++)
                    {
                        IAreaRule ar = (IAreaRule)style.GetRuleAt(i);
                        _rules.Add(new AreaRuleModel(ar, i));
                    }
                }
                break;

                case StyleType.Composite:
                {
                    for (int i = 0; i < style.RuleCount; i++)
                    {
                        ICompositeRule cr = (ICompositeRule)style.GetRuleAt(i);
                        _rules.Add(new CompositeRuleModel(cr, i));
                    }
                }
                break;
                }
            }
            else
            {
                _rules.Clear();
            }
        }
Esempio n. 7
0
 private static void BuildPolygonRuleAssignment(StringBuilder sb, IAreaRule rule)
 {
     sb.Clear();
     if (rule.AreaSymbolization2D.Fill != null)
     {
         sb.Append(INDENT + INDENT).AppendLine($"fillColor = '#{ToHtmlColor(rule.AreaSymbolization2D.Fill.ForegroundColor)}';");
     }
     if (rule.AreaSymbolization2D.Stroke != null)
     {
         sb.Append(INDENT + INDENT).AppendLine($"edgeColor = '#{ToHtmlColor(rule.AreaSymbolization2D.Stroke.Color)}';");
         sb.Append(INDENT + INDENT).AppendLine($"edgeThickness = '{rule.AreaSymbolization2D.Stroke.Thickness}';");
     }
 }
Esempio n. 8
0
 private IAreaRule CreateAreaRule(IAreaRule template, ILayerElementFactory factory)
 {
     var arule = factory.CreateDefaultAreaRule();
     if (template.AreaSymbolization2D != null)
         arule.AreaSymbolization2D = template.AreaSymbolization2D.Clone();
     if (template.Label != null)
         arule.Label = template.Label.Clone();
     return arule;
 }
Esempio n. 9
0
        private void CreateDistrictsLayer(IServerConnection conn, string resId, string layerId)
        {
            //We use the Utility class to create our layer. You can also use ObjectFactory, but
            //that requires explicitly specifying the resource version. Using Utility will pick
            //the latest supported version
            ILayerDefinition       ldf  = Utility.CreateDefaultLayer(conn, LayerType.Vector);
            IVectorLayerDefinition vldf = (IVectorLayerDefinition)ldf.SubLayer;

            //Set feature source
            vldf.ResourceId = resId;

            //Set the feature class
            //
            //Note: In versions of the Sheboygan Dataset before 2.6, this used to be
            //
            // - Feature Class: SDF_2_Schema:VotingDistricts
            // - Identity Property: Autogenerated_SDF_ID
            // - Geometry Property: Data
            string featureClass = "Default:VotingDistricts";
            string idProp       = "FeatId";
            string geometryProp = "Geometry";

            vldf.FeatureName = featureClass;

            //Set the designated geometry
            vldf.Geometry = geometryProp;

            //Get the first vector scale range. This will have been created for us and is 0 to infinity
            IVectorScaleRange vsr = vldf.GetScaleRangeAt(0);

            //What are we doing here? We're checking if this vector scale range is a
            //IVectorScaleRange2 instance. If it is, it means this layer definition
            //has a composite style attached, which takes precedence over point/area/line
            //styles. We don't want this, so this removes the composite styles if they
            //exist.
            IVectorScaleRange2 vsr2 = vsr as IVectorScaleRange2;

            if (vsr2 != null)
            {
                vsr2.CompositeStyle = null;
            }

            //Get the area style
            IAreaVectorStyle astyle = vsr.AreaStyle;

            //Remove the default rule
            astyle.RemoveAllRules();

            IFeatureService featSvc = conn.FeatureService;
            //Generate a random color for each distinct feature id
            //Perform a distinct value query
            IReader valueReader = featSvc.AggregateQueryFeatureSource(resId, featureClass, null, new NameValueCollection()
            {
                { "Value", "UNIQUE(" + idProp + ")" } //UNIQUE() is the aggregate function that collects all distinct values of FeatId
            });

            while (valueReader.ReadNext())
            {
                //The parent Layer Definition provides all the methods needed to create the necessary child elements
                IAreaRule rule = ldf.CreateDefaultAreaRule();
                //Set the filter for this rule
                rule.Filter = idProp + " = " + valueReader["Value"].ToString();
                //IReader allows object access by name in case you don't care to determine the data type
                rule.LegendLabel = valueReader["Value"].ToString();
                //Assign a random color fill
                rule.AreaSymbolization2D.Fill.ForegroundColor = Utility.SerializeHTMLColor(RandomColor(), true);
                //Add this rule
                astyle.AddRule(rule);
            }
            valueReader.Close();

            //Now save it
            conn.ResourceService.SaveResourceAs(ldf, layerId);
        }
Esempio n. 10
0
        private void ReSyncBindingListToRules(IVectorStyle style)
        {
            if (style != null)
            {
                switch (style.StyleType)
                {
                case StyleType.Point:
                {
                    IPointVectorStyle pts = style as IPointVectorStyle;
                    pts.RemoveAllRules();
                    for (int i = 0; i < _rules.Count; i++)
                    {
                        ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i];
                        IPointRule        pr   = (IPointRule)rule.UnwrapRule();
                        pts.AddRule(pr);
                        rule.SetIndex(i);
                    }
                }
                break;

                case StyleType.Line:
                {
                    ILineVectorStyle lts = style as ILineVectorStyle;
                    lts.RemoveAllRules();
                    for (int i = 0; i < _rules.Count; i++)
                    {
                        ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i];
                        ILineRule         lr   = (ILineRule)rule.UnwrapRule();
                        lts.AddRule(lr);
                        rule.SetIndex(i);
                    }
                }
                break;

                case StyleType.Area:
                {
                    IAreaVectorStyle ats = style as IAreaVectorStyle;
                    ats.RemoveAllRules();
                    for (int i = 0; i < _rules.Count; i++)
                    {
                        ILabeledRuleModel rule = (ILabeledRuleModel)_rules[i];
                        IAreaRule         ar   = (IAreaRule)rule.UnwrapRule();
                        ats.AddRule(ar);
                        rule.SetIndex(i);
                    }
                }
                break;

                case StyleType.Composite:
                {
                    ICompositeTypeStyle cts = style as ICompositeTypeStyle;
                    cts.RemoveAllRules();
                    for (int i = 0; i < _rules.Count; i++)
                    {
                        IRuleModel     rule = (IRuleModel)_rules[i];
                        ICompositeRule cr   = (ICompositeRule)rule.UnwrapRule();
                        cts.AddCompositeRule(cr);
                        rule.SetIndex(i);
                    }
                }
                break;
                }
            }
        }
Esempio n. 11
0
 public void SetItem(IAreaRule parent, IAreaSymbolizationFill area, double previewScale, int themeCategory)
 {
     isArea = true;
     SetItemInternal(parent, area, previewScale, themeCategory);
 }
Esempio n. 12
0
 public void SetItem(IAreaRule parent, IAreaSymbolizationFill area, double previewScale, int themeCategory)
 {
     isArea = true;
     SetItemInternal(parent, area, previewScale, themeCategory);
 }
        private void Rule_ItemDeleted(object sender, EventArgs e)
        {
            foreach (Condition c in this.Controls)
            {
                if (c.Item == sender)
                {
                    this.Controls.Remove(c);
                    break;
                }
            }

            if (m_point != null)
            {
                IPointRule remove = null;
                foreach (var pr in m_point.Rules)
                {
                    if (pr == sender)
                    {
                        remove = pr;
                        break;
                    }
                }

                if (remove != null)
                {
                    m_point.RemoveRule(remove);
                }
            }
            else if (m_line != null)
            {
                ILineRule remove = null;
                foreach (var lr in m_line.Rules)
                {
                    if (lr == sender)
                    {
                        remove = lr;
                        break;
                    }
                }

                if (remove != null)
                {
                    m_line.RemoveRule(remove);
                }
            }
            else if (m_area != null)
            {
                IAreaRule remove = null;
                foreach (var ar in m_area.Rules)
                {
                    if (ar == sender)
                    {
                        remove = ar;
                        break;
                    }
                }

                if (remove != null)
                {
                    m_area.RemoveRule(remove);
                }
            }
            else if (m_comp != null)
            {
                ICompositeRule remove = null;
                foreach (var comp in m_comp.CompositeRule)
                {
                    if (comp == sender)
                    {
                        remove = comp;
                        break;
                    }
                }

                if (remove != null)
                {
                    m_comp.RemoveCompositeRule(remove);
                }
            }

            SignalItemChanged();
        }
Esempio n. 14
0
 public void SetItem(IAreaRule art, double previewScale, int themeCategory)
 {
     SetItemInternal(art, previewScale, themeCategory);
 }
Esempio n. 15
0
        private void SetItemInternal(object item, double previewScale, int themeCategory)
        {
            m_prt = item as IPointRule;
            m_lrt = item as ILineRule;
            m_art = item as IAreaRule;
            m_comp = item as ICompositeRule;

            try
            {
                m_isUpdating = true;
                if (m_prt != null)
                {
                    RuleCondition.Text = m_prt.Filter;
                    LegendLabel.Text = m_prt.LegendLabel;
                    Image w2d = null;
                    if (m_prt.PointSymbolization2D != null)
                    {
                        //Determine if this is a w2d symbol style
                        if (m_prt.PointSymbolization2D.Symbol.Type == PointSymbolType.W2D)
                        {
                            var sym = (IW2DSymbol)m_prt.PointSymbolization2D.Symbol;
                            w2d = SymbolPicker.GetSymbol(_conn, sym.W2DSymbol.ResourceId, sym.W2DSymbol.LibraryItemName);
                        }
                    }
                    FeatureStyle.SetItem(m_prt, m_prt.PointSymbolization2D, w2d, previewScale, themeCategory);
                    LabelStyle.SetItem(m_prt, m_prt.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_lrt != null)
                {
                    RuleCondition.Text = m_lrt.Filter;
                    LegendLabel.Text = m_lrt.LegendLabel;
                    FeatureStyle.SetItem(m_lrt, m_lrt.Strokes, previewScale, themeCategory);
                    LabelStyle.SetItem(m_lrt, m_lrt.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_art != null)
                {
                    RuleCondition.Text = m_art.Filter;
                    LegendLabel.Text = m_art.LegendLabel;
                    FeatureStyle.SetItem(m_art, m_art.AreaSymbolization2D, previewScale, themeCategory);
                    LabelStyle.SetItem(m_art, m_art.Label, previewScale, themeCategory);
                    LabelStyle.Visible = true;
                }
                else if (m_comp != null)
                {
                    RuleCondition.Text = m_comp.Filter;
                    LegendLabel.Text = m_comp.LegendLabel;
                    FeatureStyle.SetItem(m_comp, m_comp.CompositeSymbolization, previewScale, themeCategory);
                    LabelStyle.Visible = false;
                }
            }
            finally
            {
                m_isUpdating = false;
            }
        }
Esempio n. 16
0
 public void SetItem(IAreaRule art, double previewScale, int themeCategory)
 {
     SetItemInternal(art, previewScale, themeCategory);
 }