private void btnExplodeTheme_Click(object sender, EventArgs e) { var ed = m_owner.EditorService; var layer = ed.GetEditedResource() as ILayerDefinition; var style = m_point as IVectorStyle ?? m_line as IVectorStyle ?? m_area as IVectorStyle; var diag = new ExplodeThemeDialog(ed, m_parent, style, layer); if (diag.ShowDialog() == DialogResult.OK) { var options = new ExplodeThemeOptions() { ActiveStyle = style, FolderId = diag.CreateInFolder, Layer = layer, LayerNameFormat = diag.LayerNameFormat, LayerPrefix = diag.LayerPrefix, Range = m_parent }; var progress = new ProgressDialog(); var worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; progress.RunOperationAsync(null, ExplodeThemeWorker, options); } }
/// <summary> /// Explodes a themed layer into filtered sub-layers where each sub-layer is filtered on the individual theme rule's filter /// </summary> /// <param name="options"></param> /// <param name="progress"></param> public static void ExplodeThemeIntoFilteredLayers(ExplodeThemeOptions options, LengthyOperationProgressCallBack progress) { var conn = options.Layer.CurrentConnection; var origLayerId = options.Layer.ResourceID; string layerPrefix = options.LayerPrefix; var origVl = (IVectorLayerDefinition)options.Layer.SubLayer; var origRange = options.Range; var origStyle = options.ActiveStyle; int processed = 0; for (int i = 0; i < origStyle.RuleCount; i++) { var currentRule = origStyle.GetRuleAt(i); var newLayer = ObjectFactory.CreateDefaultLayer(conn, LayerType.Vector, options.Layer.ResourceVersion); var vl = (IVectorLayerDefinition)newLayer.SubLayer; vl.ResourceId = origVl.ResourceId; vl.FeatureName = origVl.FeatureName; vl.Geometry = origVl.Geometry; //Set this layer's filter to be that of the current rule vl.Filter = currentRule.Filter; //A newly created Layer Definition will only have one scale range var range = vl.GetScaleRangeAt(0); range.MinScale = origRange.MinScale; range.MaxScale = origRange.MaxScale; //Composite styles aren't applicable, so remove them if they exist var range2 = range as IVectorScaleRange2; if (range2 != null) range2.CompositeStyle = null; //Invalidate geometry types not of the original style switch (origStyle.StyleType) { case StyleType.Area: range.LineStyle = null; range.PointStyle = null; IAreaRule ar = range.AreaStyle.GetRuleAt(0); IAreaRule oar = (IAreaRule)currentRule; if (oar.AreaSymbolization2D != null) ar.AreaSymbolization2D = oar.AreaSymbolization2D.Clone(); if (oar.Label != null) ar.Label = oar.Label.Clone(); break; case StyleType.Line: range.AreaStyle = null; range.PointStyle = null; ILineRule lr = range.LineStyle.GetRuleAt(0); ILineRule olr = (ILineRule)currentRule; if (olr.StrokeCount > 0) { foreach (var stroke in olr.Strokes) { lr.AddStroke(stroke.Clone()); } } if (olr.Label != null) lr.Label = olr.Label.Clone(); break; case StyleType.Point: range.AreaStyle = null; range.LineStyle = null; IPointRule pr = range.PointStyle.GetRuleAt(0); IPointRule opr = (IPointRule)currentRule; if (opr.Label != null) pr.Label = opr.Label.Clone(); if (opr.PointSymbolization2D != null) pr.PointSymbolization2D = opr.PointSymbolization2D.Clone(); break; } string newResId = options.FolderId + GenerateLayerName(options.LayerNameFormat, layerPrefix, GetScaleRangeStr(options.Range), i, currentRule) + ".LayerDefinition"; conn.ResourceService.SaveResourceAs(newLayer, newResId); processed++; if (progress != null) progress(null, new LengthyOperationProgressArgs(newResId, (processed / origStyle.RuleCount) * 100)); } }