How are you adding layer names to the ComboBox? are you using recursion to find any nested layers inside a group layer? Or simply looping through the layers in the table of contents?
What exactly are you doing with the layer that the user selects?
See...handling same layers name is not an issue...only thing is how user can feel good to use...what he suppose to select if he wants to see the building or something...why he suppose to check all building layers ?
Sub getlayers() Dim pMxDocument As IMxDocument Dim pMap As IMap Set pMxDocument = ThisDocument Set pMap = pMxDocument.FocusMap Dim Player As ILayer Dim pEnumLayers As IEnumLayer Dim pFeatureLayer As IFeatureLayer Dim pId As New UID pId = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}" 'Find only IGeoFeatureLayers Set pEnumLayers = pMap.Layers(pId, True) If pEnumLayers Is Nothing Then Exit Sub Dim newName As String Randomize Set Player = pEnumLayers.Next Do While Not Player Is Nothing If Player.Valid Then Set pFeatureLayer = Player If nameInList(ComboBoxLayers, pFeatureLayer.name) Then newName = pFeatureLayer.name & Int(Rnd * 100) MsgBox "Layer " & pFeatureLayer.name & " renamed to " & newName, vbInformation pFeatureLayer.name = newName pMxDocument.CurrentContentsView.Refresh 1 End If ComboBoxLayers.AddItem pFeatureLayer.name End If Set Player = pEnumLayers.Next Loop End Sub Function nameInList(ComboBoxIn As ComboBox, name As String) As Boolean Dim i As Long For i = 0 To ComboBoxInlistCount - 1 If ComboBoxIn.List(i) = name Then nameInList = True Next i End Function
Dim theListOfLayers As List(Of String) = GetLayerList() pDoc = m_pApp.Document pMap = pDoc.FocusMap For l = 0 To pMap.LayerCount - 1 For x = 0 To theListOfLayers.Count - 1 Dim indxOrig As Integer = theListOfLayers.IndexOf(theListOfLayers(x).Trim) Dim indx As Integer = theListOfLayers.LastIndexOf(theListOfLayers(x).Trim) If indxOrig <> indx Then pMap.Layer(l).Name = theListOfLayers(x).Trim & "2" theListOfLayers(x) = theListOfLayers(x).Trim & "2" End If Next Exit For Next 'update the TOC pDoc.UpdateContents() 'add the list of layernames to the ComboBox cboLayerList.DataSource = theListOfLayers
Private Function GetLayerList() As List(Of String) Dim LayerList As New List(Of String) Dim pDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument Dim pMap As ESRI.ArcGIS.Carto.IMap pDoc = m_pApp.Document pMap = pDoc.FocusMap For i = 0 To pMap.LayerCount - 1 LayerList.Add(pMap.Layer(i).Name) Next Return LayerList End Function
I know, but it is up to the user of my tool what names he uses. My tool must be able to handle layers with equal names.
public FeatureLayer getLayerByName(String layerName, com.esri.arcgis.carto.Map map) { FeatureLayer layer = null; try { for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i).getName().equalsIgnoreCase(layerName)) { layer = (FeatureLayer) map.getLayer(i); break; } } } catch (AutomationException ae) { ae.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return layer; }
Why don't you make names as by type Commercial building and residential or by size Large Constructions and Small Constructions something like that ?
Thank for this tip!I agree that showing two items with the same name is not nice.Do you have other ideas for names without using groupnames? Something like "Buildings (1ste entry)", Buildings (2de entry) ?
I have dealt with a similar situation in .net (both vb and C#.) The way I dealt with it was to build a list of IFeatureLayers (generic list (of IFeatureLayer). Then bind the list to combobox and set the display property to "Name". This way your combobox doesn't contain a list of featurelayer name strings but a list of actual featurelayer objects. When the user picks one the selecteditem is a feature layer not a string but the featurelayer so there is no need to find the layer by name. Of course showing the user two items in a combo box with the same name is not very nice for the user. But there are other solutions to that (showing the group and name, etc.)
Well, even if "you" can tell which layer is the right layer, how do the "users" know which layer they are choosing if both layers have the same name in the combo box?
I was afraid for this answer and it happened. Renaming seems the only solution.Thanks.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.