示例#1
0
 private void EnsureAreaStyle()
 {
     if (_ats == null)
     {
         _ats = _editedLayer.CreateDefaultAreaStyle();
     }
 }
        private void SetItemInternal(IVectorScaleRange parent, object item)
        {
            m_parent = parent;
            m_point  = item as IPointVectorStyle;
            m_line   = item as ILineVectorStyle;
            m_area   = item as IAreaVectorStyle;
            m_comp   = item as ICompositeTypeStyle;

            this.Controls.Clear();

            try
            {
                this.Visible = false;
                this.SuspendLayout();

                if (m_point != null)
                {
                    int idx = 0;
                    foreach (IPointRule prt in m_point.Rules)
                    {
                        AddRuleControl(prt, idx);
                        idx++;
                    }
                }
                else if (m_line != null)
                {
                    int idx = 0;
                    foreach (ILineRule lrt in m_line.Rules)
                    {
                        AddRuleControl(lrt, idx);
                        idx++;
                    }
                }
                else if (m_area != null)
                {
                    int idx = 0;
                    foreach (IAreaRule art in m_area.Rules)
                    {
                        AddRuleControl(art, idx);
                        idx++;
                    }
                }
                else if (m_comp != null)
                {
                    int idx = 0;
                    foreach (ICompositeRule comp in m_comp.CompositeRule)
                    {
                        AddRuleControl(comp, idx);
                        idx++;
                    }
                }
            }
            finally
            {
                this.ResumeLayout();
                this.Visible = true;
            }
        }
示例#3
0
        public VectorScaleRangeGrid(IVectorScaleRange vsr, VectorLayerStyleSectionCtrl parent)
            : this()
        {
            try
            {
                _init        = true;
                _parent      = parent;
                _editedLayer = (ILayerDefinition)_parent.EditorService.GetEditedResource();
                _vsr         = vsr;
                _pts         = _vsr.PointStyle;
                _lts         = _vsr.LineStyle;
                _ats         = _vsr.AreaStyle;

                chkPoints.Checked = (_pts != null);
                chkLine.Checked   = (_lts != null);
                chkArea.Checked   = (_ats != null);

                var vsr2 = _vsr as IVectorScaleRange2;
                if (vsr2 != null)
                {
                    _cts = new BindingList <ICompositeTypeStyle>();
                    if (chkArea.Checked || chkLine.Checked || chkArea.Checked)
                    {
                        chkComposite.Checked = false;
                    }
                    else
                    {
                        foreach (var r in vsr2.CompositeStyle)
                        {
                            _cts.Add(r);
                        }
                        chkComposite.Checked = (vsr2.CompositeStyleCount > 0);
                    }
                }
                else
                {
                    chkComposite.Visible = false;
                    SetCompositeTabVisibility(false);
                }

                SetPointUI();
                SetLineUI();
                SetAreaUI();
                SetCompositeUI();

                pointRuleGrid.Init(_parent.EditorService, _vsr, _vsr.PointStyle);
                lineRuleGrid.Init(_parent.EditorService, _vsr, _vsr.LineStyle);
                areaRuleGrid.Init(_parent.EditorService, _vsr, _vsr.AreaStyle);
            }
            finally
            {
                _init = false;
            }
        }
示例#4
0
        public VectorScaleRangeGrid(IVectorScaleRange vsr, VectorLayerStyleSectionCtrl parent)
            : this()
        {
            try
            {
                _init = true;
                _parent = parent;
                _editedLayer = (ILayerDefinition)_parent.EditorService.GetEditedResource();
                _vsr = vsr;
                _pts = _vsr.PointStyle;
                _lts = _vsr.LineStyle;
                _ats = _vsr.AreaStyle;

                chkPoints.Checked = (_pts != null);
                chkLine.Checked = (_lts != null);
                chkArea.Checked = (_ats != null);

                var vsr2 = _vsr as IVectorScaleRange2;
                if (vsr2 != null)
                {
                    _cts = new BindingList<ICompositeTypeStyle>();
                    if (chkArea.Checked || chkLine.Checked || chkArea.Checked)
                    {
                        chkComposite.Checked = false;
                    }
                    else
                    {
                        foreach (var r in vsr2.CompositeStyle)
                        {
                            _cts.Add(r);
                        }
                        chkComposite.Checked = (vsr2.CompositeStyleCount > 0);
                    }
                }
                else
                {
                    chkComposite.Visible = false;
                    SetCompositeTabVisibility(false);
                }

                SetPointUI();
                SetLineUI();
                SetAreaUI();
                SetCompositeUI();

                pointRuleGrid.Init(_parent.EditorService, _vsr, _vsr.PointStyle);
                lineRuleGrid.Init(_parent.EditorService, _vsr, _vsr.LineStyle);
                areaRuleGrid.Init(_parent.EditorService, _vsr, _vsr.AreaStyle);
            }
            finally
            {
                _init = false;
            }
        }
        private void SetItemInternal(IVectorScaleRange parent, object item)
        {
            m_parent = parent;
            m_point  = item as IPointVectorStyle;
            m_line   = item as ILineVectorStyle;
            m_area   = item as IAreaVectorStyle;
            m_comp   = item as ICompositeTypeStyle;

            var ar2 = m_area as IAreaVectorStyle2;
            var pt2 = m_point as IPointVectorStyle2;
            var ln2 = m_line as ILineVectorStyle2;
            var cm2 = m_comp as ICompositeTypeStyle2;

            //Check if we're working with a 1.3.0 schema
            ShowInLegend.Enabled    = (ar2 != null || pt2 != null || ln2 != null || cm2 != null);
            btnExplodeTheme.Enabled = (m_comp == null);
        }
示例#6
0
        private void GenerateAreaThemeRules(List<RuleItem> rules, IAreaVectorStyle col)
        {
            string fillAlpha = "";
            IAreaRule template = null;
            if (chkUseFirstRuleAsTemplate.Checked && col.RuleCount > 0)
            {
                template = col.GetRuleAt(0);

                if (template.AreaSymbolization2D != null)
                {
                    if (template.AreaSymbolization2D.Fill != null)
                    {
                        if (template.AreaSymbolization2D.Fill.ForegroundColor.Length == 8)
                            fillAlpha = template.AreaSymbolization2D.Fill.ForegroundColor.Substring(0, 2);
                    }
                }
            }

            if (OverwriteRules.Checked)
                col.RemoveAllRules();

            foreach (RuleItem entry in rules)
            {
                var r = (template != null) ? CreateAreaRule(template, _factory) : _factory.CreateDefaultAreaRule();
                r.Filter = entry.Filter;
                r.LegendLabel = entry.Label;
                r.AreaSymbolization2D.Fill.ForegroundColor = fillAlpha + Utility.SerializeHTMLColor(entry.Color, string.IsNullOrEmpty(fillAlpha));

                col.AddRule(r);
            }
        }
示例#7
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);
        }
示例#8
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;
                }
            }
        }
示例#9
0
        public VectorScaleRangeCtrl(IVectorScaleRange vsr, VectorLayerStyleSectionCtrl parent)
        {
            InitializeComponent();
            _init = true;

            try
            {
                _parent = parent;
                _vsr = vsr;

                _pts = vsr.PointStyle;
                _lns = vsr.LineStyle;
                _ars = vsr.AreaStyle;

                chkPoints.Checked = true;
                chkLine.Checked = true;
                chkArea.Checked = true;
                chkComposite.Checked = true;

                chkPoints.Checked = (_pts != null);
                chkLine.Checked = (_lns != null);
                chkArea.Checked = (_ars != null);

                pointList.Owner = parent.Owner;
                lineList.Owner = parent.Owner;
                areaList.Owner = parent.Owner;

                pointList.Factory = parent.Factory;
                lineList.Factory = parent.Factory;
                areaList.Factory = parent.Factory;

                if (_pts == null)
                    _pts = parent.Factory.CreateDefaultPointStyle();

                chkDisplayAsText.Checked = _pts.DisplayAsText;
                chkAllowOverpost.Checked = _pts.AllowOverpost;

                if (_lns == null)
                    _lns = parent.Factory.CreateDefaultLineStyle();

                if (_ars == null)
                    _ars = parent.Factory.CreateDefaultAreaStyle();

                pointList.SetItem(vsr, _pts);
                lineList.SetItem(vsr, _lns);
                areaList.SetItem(vsr, _ars);

                if (_pts.RuleCount == 0)
                    pointList.AddRule();

                if (_lns.RuleCount == 0)
                    lineList.AddRule();

                if (_ars.RuleCount == 0)
                    areaList.AddRule();

                var vsr2 = vsr as IVectorScaleRange2;
                if (vsr2 != null)
                {
                    _cts = new BindingList<ICompositeTypeStyle>();
                    foreach (var c in vsr2.CompositeStyle)
                        _cts.Add(c);

                    chkComposite.Checked = (_cts.Count > 0);

                    compList.Owner = parent.Owner;
                    compList.Factory = parent.Factory;
                    if (_cts.Count == 0)
                        _cts.Add(parent.Factory.CreateDefaultCompositeStyle());

                    compList.LoadStyles(vsr2, _cts);
                }
                else
                {
                    chkComposite.Checked = false;
                }
                chkComposite.Enabled = (vsr2 != null);
            }
            finally
            {
                _init = false;
            }
        }
        public VectorScaleRangeCtrl(IVectorScaleRange vsr, VectorLayerStyleSectionCtrl parent)
        {
            InitializeComponent();
            _init = true;

            try
            {
                _parent = parent;
                _vsr    = vsr;

                _pts = vsr.PointStyle;
                _lns = vsr.LineStyle;
                _ars = vsr.AreaStyle;

                chkPoints.Checked    = true;
                chkLine.Checked      = true;
                chkArea.Checked      = true;
                chkComposite.Checked = true;

                chkPoints.Checked = (_pts != null);
                chkLine.Checked   = (_lns != null);
                chkArea.Checked   = (_ars != null);

                pointList.Owner = parent.Owner;
                lineList.Owner  = parent.Owner;
                areaList.Owner  = parent.Owner;

                pointList.Factory = parent.Factory;
                lineList.Factory  = parent.Factory;
                areaList.Factory  = parent.Factory;

                if (_pts == null)
                {
                    _pts = parent.Factory.CreateDefaultPointStyle();
                }

                chkDisplayAsText.Checked = _pts.DisplayAsText;
                chkAllowOverpost.Checked = _pts.AllowOverpost;

                if (_lns == null)
                {
                    _lns = parent.Factory.CreateDefaultLineStyle();
                }

                if (_ars == null)
                {
                    _ars = parent.Factory.CreateDefaultAreaStyle();
                }

                pointList.SetItem(vsr, _pts);
                lineList.SetItem(vsr, _lns);
                areaList.SetItem(vsr, _ars);

                if (_pts.RuleCount == 0)
                {
                    pointList.AddRule();
                }

                if (_lns.RuleCount == 0)
                {
                    lineList.AddRule();
                }

                if (_ars.RuleCount == 0)
                {
                    areaList.AddRule();
                }

                var vsr2 = vsr as IVectorScaleRange2;
                if (vsr2 != null)
                {
                    _cts = new BindingList <ICompositeTypeStyle>();
                    foreach (var c in vsr2.CompositeStyle)
                    {
                        _cts.Add(c);
                    }

                    chkComposite.Checked = (_cts.Count > 0);

                    compList.Owner   = parent.Owner;
                    compList.Factory = parent.Factory;
                    if (_cts.Count == 0)
                    {
                        _cts.Add(parent.Factory.CreateDefaultCompositeStyle());
                    }

                    compList.LoadStyles(vsr2, _cts);
                }
                else
                {
                    chkComposite.Checked = false;
                }
                chkComposite.Enabled = (vsr2 != null);
            }
            finally
            {
                _init = false;
            }
        }
示例#11
0
        private void SetItemInternal(IVectorScaleRange parent, object item)
        {
            m_parent = parent;
            m_point = item as IPointVectorStyle;
            m_line = item as ILineVectorStyle;
            m_area = item as IAreaVectorStyle;
            m_comp = item as ICompositeTypeStyle;

            this.Controls.Clear();

            try
            {
                this.Visible = false;
                this.SuspendLayout();

                if (m_point != null)
                {
                    int idx = 0;
                    foreach (IPointRule prt in m_point.Rules)
                    {
                        AddRuleControl(prt, idx);
                        idx++;
                    }
                }
                else if (m_line != null)
                {
                    int idx = 0;
                    foreach (ILineRule lrt in m_line.Rules)
                    {
                        AddRuleControl(lrt, idx);
                        idx++;
                    }
                }
                else if (m_area != null)
                {
                    int idx = 0;
                    foreach (IAreaRule art in m_area.Rules)
                    {
                        AddRuleControl(art, idx);
                        idx++;
                    }
                }
                else if (m_comp != null)
                {
                    int idx = 0;
                    foreach (ICompositeRule comp in m_comp.CompositeRule)
                    {
                        AddRuleControl(comp, idx);
                        idx++;
                    }
                }
            }
            finally
            {
                this.ResumeLayout();
                this.Visible = true;
            }
        }
示例#12
0
 public void SetItem(IVectorScaleRange parent, IAreaVectorStyle area)
 {
     SetItemInternal(parent, area);
 }
 public void SetItem(IVectorScaleRange parent, IAreaVectorStyle area)
 {
     SetItemInternal(parent, area);
     conditionList.SetItem(parent, area);
 }
示例#14
0
        public async Task WritePolygonStyleFunctionAsync(StreamWriter sw, IVectorLayerDefinition vl, IAreaVectorStyle areaStyle)
        {
            await sw.WriteLineAsync(INDENT + "var fillColor;");

            await sw.WriteLineAsync(INDENT + "var edgeColor;");

            await sw.WriteLineAsync(INDENT + "var edgeThickness;");

            var sb = new StringBuilder(512);
            var defaultRuleBlock = "";
            var themes           = new List <(string conditon, string filter, string block)>();

            foreach (var rule in areaStyle.Rules)
            {
                if (rule.AreaSymbolization2D != null)
                {
                    if (string.IsNullOrEmpty(rule.Filter)) //No filter = default rule effectively
                    {
                        if (string.IsNullOrEmpty(defaultRuleBlock))
                        {
                            BuildPolygonRuleAssignment(sb, rule);
                            defaultRuleBlock = sb.ToString();
                        }
                    }
                    else
                    {
                        //Parse this filter and see if it's translateable
                        var filter = FdoFilter.Parse(rule.Filter);
                        var check  = TryTranslateFdoFilter(filter, _featureVarName);
                        BuildPolygonRuleAssignment(sb, rule);
                        themes.Add((check, rule.Filter, sb.ToString()));
                    }
                }
            }

            //Now write out the theme
            if (themes.Count > 0)
            {
                bool bFirst = true;
                foreach (var th in themes)
                {
                    if (bFirst)
                    {
                        await sw.WriteLineAsync(INDENT + $"if ({th.conditon}) {{ // Translated from rule filter: {th.filter}");

                        await sw.WriteLineAsync(th.block);

                        await sw.WriteLineAsync(INDENT + "}");
                    }
                    else
                    {
                        await sw.WriteLineAsync(INDENT + $"else if ({th.conditon}) {{  // Translated from rule filter: {th.filter}");

                        await sw.WriteLineAsync(th.block);

                        await sw.WriteLineAsync(INDENT + "}");
                    }

                    bFirst = false;
                }

                if (!string.IsNullOrEmpty(defaultRuleBlock))
                {
                    await sw.WriteLineAsync(INDENT + $"else {{  // Default rule");

                    await sw.WriteLineAsync(defaultRuleBlock);

                    await sw.WriteLineAsync(INDENT + "}");
                }
            }
            else
            {
                await sw.WriteLineAsync("//Default rule");

                await sw.WriteLineAsync(defaultRuleBlock);
            }

            await sw.WriteLineAsync(INDENT + "var style = {");

            await sw.WriteLineAsync(INDENT + INDENT + $"fill: new ol.style.Fill({{ color: fillColor }}),");

            await sw.WriteLineAsync(INDENT + INDENT + $"stroke: new ol.style.Stroke({{ color: edgeColor, width: edgeThickness }})");

            await sw.WriteLineAsync(INDENT + "}");

            await sw.WriteLineAsync(INDENT + "return new ol.style.Style(style);");
        }
示例#15
0
        private void SetItemInternal(IVectorScaleRange parent, object item)
        {
            m_parent = parent;
            m_point = item as IPointVectorStyle;
            m_line = item as ILineVectorStyle;
            m_area = item as IAreaVectorStyle;
            m_comp = item as ICompositeTypeStyle;

            var ar2 = m_area as IAreaVectorStyle2;
            var pt2 = m_point as IPointVectorStyle2;
            var ln2 = m_line as ILineVectorStyle2;
            var cm2 = m_comp as ICompositeTypeStyle2;

            //Check if we're working with a 1.3.0 schema
            ShowInLegend.Enabled = (ar2 != null || pt2 != null || ln2 != null || cm2 != null);
            btnExplodeTheme.Enabled = (m_comp == null);
        }