private void CreateFeatureModifierElement(XmlDocument _doc, FeatureLayer layer, XmlElement lyrElement, string uniqueID) { FeatureStyleModifiers mods = layer.Modifiers; foreach (FeatureStyleModifier fsm in mods) { XmlElement element = _doc.CreateElement("branch"); element.SetAttribute("branchtype", "", "leaf"); element.SetAttribute("title", null, fsm.Name); if (fsm.Enabled) { element.SetAttribute("visible", "true"); } else { element.SetAttribute("visible", "false"); } element.SetAttribute("uniqueid", "", uniqueID); element.SetAttribute("code", "", "nonselectable"); element.SetAttribute("img", null, "lcmodifier.bmp"); element.SetAttribute("alias", "", fsm.Alias); element.SetAttribute("type", "", "Mod"); lyrElement.AppendChild(element); } }
// Remove all IndividualValueThemes from the World layer private void DoClearThemes() { // First obtain a reference to the layer FeatureLayer lyr = (FeatureLayer)mapControl1.Map.Layers[_layerName]; if (lyr == null) { MessageBox.Show( "Layer " + _layerName + " not found; no themes to remove."); return; } // Reference the layer's collection of themes and other modifiers FeatureStyleModifiers modifiers = lyr.Modifiers; // remove any IndividualValueTheme objects ArrayList aliases = new ArrayList(); foreach (FeatureStyleModifier mod in modifiers) { IndividualValueTheme ivTheme = mod as IndividualValueTheme; if (ivTheme != null) { // We found a modifier that is an IndividualValueTheme. // Remember its name so we can remove it after this loop. aliases.Add(ivTheme.Alias); } } foreach (string s in aliases) { modifiers.Remove(s); } MessageBox.Show("Removed " + aliases.Count + " IndividualValueTheme(s) from layer: " + _layerName); }
// Examine the layer's IndividualValueTheme, if there is one, // and display information about some of the theme's properties. private void DoThemeInfo() { // First obtain a reference to the layer FeatureLayer lyr = (FeatureLayer)mapControl1.Map.Layers[_layerName]; if (lyr == null) { MessageBox.Show( "Layer " + _layerName + " not found; no theme information to display."); return; } // Reference the layer's collection of themes and other modifiers FeatureStyleModifiers modifiers = lyr.Modifiers; // See if the collection contains any IndividualValueTheme objects IndividualValueTheme ivTheme = null; int counter = 0; foreach (FeatureStyleModifier mod in modifiers) { if (mod is IndividualValueTheme) { // We did find an IndividualValueTheme in the collection counter++; if (ivTheme == null) { // Keep a reference to the top-most theme we find ivTheme = mod as IndividualValueTheme; } } } if (counter > 1) { MessageBox.Show("Found " + counter + " IndividualValueThemes on layer " + _layerName + "; displaying information for topmost theme."); } if (ivTheme != null) { string str = "Individual Value Theme properties: "; str += "Theme name: '" + ivTheme.Name + "'. "; str += "Theme expression: '" + ivTheme.Expression + "'. "; str += "Theme has " + ivTheme.Bins.Count + " bins. "; if (ivTheme.Visible) { str += " Theme is visible at the current zoom level. "; } else { str += " Theme is not currently visible. "; } MessageBox.Show(str); } else { MessageBox.Show("No IndividualValueTheme objects found for layer " + _layerName); } }
private void SetUpRasterLayer() { FeatureLayer myRasterLayer = _map.Layers["florida"] as FeatureLayer; _rasterTable = myRasterLayer.Table; RasterStyle rs = new RasterStyle(); rs.Contrast = 33; rs.Grayscale = true; // this composite style will affect the raster as intended CompositeStyle csRaster = new CompositeStyle(rs); FeatureOverrideStyleModifier fosm = new FeatureOverrideStyleModifier("Style Mod", csRaster); FeatureStyleModifiers modifiers = myRasterLayer.Modifiers; modifiers.Append(fosm); }
private void StyleButton_Click(object sender, System.EventArgs e) { if (_mStyle == null) { MessageBox.Show("Please click GridInfo before clicking Style."); return; } GridStyle aStyle = _mStyle.Clone() as GridStyle; GridStyleForm f = new GridStyleForm(); f.AlphaTextBox.Text = aStyle.Alpha.ToString(); f.BrightnessBox.Text = aStyle.Brightness.ToString(); f.ContrastBox.Text = aStyle.Contrast.ToString(); f.GrayScale.CheckState = (aStyle.Grayscale) ? CheckState.Checked : CheckState.Unchecked; f.Transparency.CheckState = (aStyle.Transparent) ? CheckState.Checked : CheckState.Unchecked; f.DisplayHillshade.CheckState = (aStyle.DisplayHillshade) ? CheckState.Checked : CheckState.Unchecked; f.TransparentColor.BackColor = aStyle.TransparentColor; if (f.ShowDialog() == DialogResult.OK) { aStyle.Alpha = int.Parse(f.AlphaTextBox.Text); aStyle.Brightness = int.Parse(f.BrightnessBox.Text); aStyle.Contrast = int.Parse(f.ContrastBox.Text); aStyle.Grayscale = f.GrayScale.CheckState == CheckState.Checked ? true : false; aStyle.Transparent = (f.Transparency.CheckState == CheckState.Checked) ? true : false; aStyle.DisplayHillshade = (f.DisplayHillshade.CheckState == CheckState.Checked) ? true : false; aStyle.TransparentColor = f.TransparentColor.BackColor; // this composite style will affect the raster as intended CompositeStyle csRaster = new CompositeStyle(aStyle); FeatureOverrideStyleModifier fosm = new FeatureOverrideStyleModifier("Style Mod", csRaster); FeatureStyleModifiers modifiers = _lyr.Modifiers; modifiers.Clear(); modifiers.Append(fosm); } }
/// <summary> /// Sets a given layer's visibility for a given map. /// </summary> /// <remarks>This method sets the layers visibility with a given layer alias to <c>true</c> or <c>false</c>. /// If the layer type is a feature layer, then it also sets the visibility for all modifers. If it is a group layer then it sets the visibility for all internal layers. /// If it is a label layer then it sets the visibility of all label sources. If the layer type passed is either a modifier or label source then it finds the modifier or label and sets the visibility. /// </remarks> /// <param name="mapAlias">MapAlias of the map.</param> /// <param name="layerAlias">LayerAlias of the layer.</param> /// <param name="lyrType">Type of the layer.</param> /// <param name="visible">Visibility to be set.</param> public virtual void SetLayerVisibility(string mapAlias, string layerAlias, string lyrType, bool visible) { Map map = GetMapObj(mapAlias); MapLayerEnumerator lenum = map.Layers.GetMapLayerEnumerator(MapLayerEnumeratorOptions.Recurse); foreach (IMapLayer lyr in lenum) { if (lyr.Alias.Equals(layerAlias) && lyr.Type.ToString().Equals(lyrType)) { lyr.Enabled = visible; if (lyr.Type == LayerType.Normal) { FeatureStyleModifiers mods = ((FeatureLayer)lyr).Modifiers; // Go through modifiers to set visibility foreach (FeatureStyleModifier fsm in mods) { fsm.Enabled = visible; } break; } if (lyr.Type == LayerType.Group) { // Go through collection to set visibility foreach (IMapLayer inlayer in (GroupLayer)lyr) { inlayer.Enabled = visible; } break; } if (lyr.Type == LayerType.Label) { // go through label sources to set visibility foreach (LabelSource source in ((LabelLayer)lyr).Sources) { source.Enabled = visible; foreach (LabelModifier lm in source.Modifiers) { lm.Enabled = visible; } } break; } } else { // The layeralias did not match, hence the alias may be modifier or label source // If it is modifier find it if (lyrType.Equals("Mod")) { // Find it and set visibility if (lyr.Type == LayerType.Normal) { FeatureStyleModifiers mods = ((FeatureLayer)lyr).Modifiers; foreach (FeatureStyleModifier fsm in mods) { if (fsm.Alias.Equals(layerAlias)) { fsm.Enabled = visible; } } } } // If it is label source find it and set it's visibility if (lyrType.Equals("Label")) { if (lyr.Type == LayerType.Label) { foreach (LabelSource source in ((LabelLayer)lyr).Sources) { if (source.Alias.Equals(layerAlias)) { source.Enabled = visible; foreach (LabelModifier lm in source.Modifiers) { lm.Enabled = visible; } } } } } // If it is label source modifier then set it's visibility if (lyrType.Equals("LabelMod")) { if (lyr.Type == LayerType.Label) { foreach (LabelSource source in ((LabelLayer)lyr).Sources) { foreach (LabelModifier lm in source.Modifiers) { if (lm.Alias.Equals(layerAlias)) { lm.Enabled = visible; } } } } } } } }
private XmlElement CreateFeatureLayerElement(XmlDocument _doc, IMapLayer layer, string uniqueID) { Map map = GetMapObj(_mapAlias); FeatureLayer flayer = (FeatureLayer)layer; bool bRasterLayer = false; bool bHasModifiers = false; FeatureStyleModifiers mods = flayer.Modifiers; if (mods.Count > 0) { bHasModifiers = true; } if (flayer.Type == LayerType.Raster || flayer.Type == LayerType.Grid || flayer.Type == LayerType.Wms) { bRasterLayer = true; } XmlElement element = _doc.CreateElement("branch"); if (bHasModifiers) { element.SetAttribute("branchtype", "", "folder"); element.SetAttribute("expanded", null, "true"); } else { element.SetAttribute("branchtype", "", "leaf"); } element.SetAttribute("title", null, layer.Name); element.SetAttribute("alias", "", layer.Alias); element.SetAttribute("type", "", layer.Type.ToString()); element.SetAttribute("uniqueid", "", uniqueID); if (bRasterLayer) { element.SetAttribute("code", "", "nonselectable"); } else if (bHasModifiers) { element.SetAttribute("code", "", "4"); } else { element.SetAttribute("code", "", "featurelayer"); } if (layer.IsVisible) { element.SetAttribute("visible", "true"); } else { element.SetAttribute("visible", "false"); if (flayer.VisibleRangeEnabled && !flayer.VisibleRange.Within(map.Zoom)) { element.SetAttribute("rangevisible", "true"); } else { element.SetAttribute("rangevisible", "false"); } } // If layer is remote, image can be set from database style // null value returned if layer is not remote string image = DetermineRemoteGeomType(flayer); if (image == null) { image = "lclayerpoint.bmp"; if (bRasterLayer) { image = "lclayerraster.bmp"; } else { TableInfo tableInfo = flayer.Table.TableInfo; GeometryColumn geoCol = null; Columns columns = tableInfo.Columns; foreach (Column col in columns) { geoCol = col as GeometryColumn; if (geoCol != null) { break; // TODO: Check for the case where there are MULTIPLE columns. } } if (geoCol != null) { if (geoCol.PredominantGeometryType == GeometryType.MultiCurve) { image = "lclayerline.bmp"; } else if ((geoCol.PredominantGeometryType == GeometryType.MultiPolygon) || (geoCol.PredominantGeometryType == GeometryType.Rectangle)) { image = "lclayerregion.bmp"; } else if (geoCol.PredominantGeometryType == GeometryType.Point) { image = "lclayerpoint.bmp"; } } } } element.SetAttribute("img", null, image); if (bHasModifiers) { CreateFeatureModifierElement(_doc, flayer, element, uniqueID); } return(element); }