ThinkGeo.com    |     Documentation    |     Premium Support

Retrieve Layer Key

I am sure this can be found somewhere, but my searches haven't brought up any results.  


Is there a way, given a Feature, to find out the "key" of the layer it is currently on.  I am able to find the layer and the layer name easy enough, but what I want is the key, so I can reference this in another function. 


Here is what I am trying to do.


I have multiple shape files, say, Road1, Road2, and Road3.  These are mapped to ShapeFileFeatureLayers "street", "road", "highway".  If I want to update a feature from "street", I move the feature to the EditOverlay and give them control points to move around.  They click on a button when finished and I take the shape on the EditOverlay and I want to put it back on "street".  I can find the shapefile path, the layer name and a few other items from the feature, but I can't seem to find the layer "key" that it came from.  Without this key, I have a few options, cycle through all the layers and find one with a matching name, but I would like to reference the layer directly if possible.  


If I need to change the key to mirror the layer name, I can do that, but I would prefer to keep them seperate if possible.



Jake,



  One way you could do this is when you select the feature out of the layer at the beginning add a new column value in the column values dictionary to point to the layer it came from.  When you are finished editing you can check this value and then remove it before you add it back to the layer.  I attached some very simple methods to show you kind of what I mean.




        private void MarkFeature(Feature feature, string layerKey)
        {
            // Mark the layer on the feature
            feature.ColumnValues.Add("LayerName", layerKey);
        }

        private Layer GetLayerFromMarkedFeature(GeoCollection<Layer> layers, Feature feature)
        {
            // You can put some checking in to make sure it is marked
            string layerName = feature.ColumnValues["LayerName"].ToString();
            feature.ColumnValues.Remove("LayerName");
            Layer layer = layers[layerName];
            return layer;
        }
 




David