Dear Sir,
I want to change layer name after add a layer as given below.
--------------------------------------------------------------------
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(path);
worldLayer.FeatureSource.Open();
worldLayer.Name ="layer_name";
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
layerOverlay.Layers.Add(layer_name_Form.layer_name, worldLayer);
winformsMap1.Overlays.Add(layerOverlay);
worldLayer.FeatureSource.Close();
winformsMap1.CurrentExtent = new RectangleShape(34.814453125, 35.771484375, 135.2734375, 7.734375);
winformsMap1.Refresh();
---------------------------------------------------------------------------
Please give me a solution.
Thanks
Regards
Harish Upadhyay
How to change layer name
Hi Harish,
I think it should be simple if we can find the shapefilefeaturelay. There are some ways we can find the layer from a map:
1. winformsMap1.FindFeatureLayer("layer_name") as ShapeFileFeatureLayer;
2. During init the map,we can give a key when we add the layer into the layeroverlay, and also give another key when we add the layeroverlay into the map. Then we can get the layer by those keys.
Init map:
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("WorldLayer", worldLayer);
winformsMap1.Overlays.Add("WorldOverlay", staticOverlay);
Change the layer name:
LayerOverlay layerOverlay = winformsMap1.Overlays["WorldOverlay"] as LayerOverlay;
ShapeFileFeatureLayer layer = layerOverlay.Layers["WorldLayer"] as ShapeFileFeatureLayer;
layer.Name = "xxx";
Thanks,
Troy
Dear sir,
Thanks for reply.
But i want change a name multiple time.I have a Exception in this code as given below
-----------------------------------------------------------
winformsMap1.FindFeatureLayer("name")
-----------------------------------------------------------
i am adding multiple layer in LayerOverlay and use only single Overlays.
So please give me a right solution about my problem.
Regards
Harish Upadhyay
Harish,
Yes, with the codes we can change the layer name any time if we put the second section codes to any where let’s say a button click event.
private
void
Test_Click(
object
sender, EventArgs e)
{
// option 1
ShapeFileFeatureLayer worldLayer = winformsMap1.FindFeatureLayer(
“WorldLayer”
)
as
ShapeFileFeatureLayer;
// option 2
LayerOverlay layerOverlay = winformsMap1.Overlays[
“WorldOverlay”
]
as
LayerOverlay;
ShapeFileFeatureLayer worldLayer = layerOverlay.Layers[
“WorldLayer”
]
as
ShapeFileFeatureLayer;
worldLayer.Name =
“xxx”
;
winformsMap1.Refresh(winformsMap1.Overlays[
“WorldOverlay”
]);
}
Please notice the “WorldLayer” and “WorldOverlay”, they are the keys when we add the layer/layeroverlay into the map rather than the Layer name. I guess that’s the reason whey you got the exception when trying to call the FindFeatureLayer with the layer name value not the key value.
Hope it’s clear now.
Thanks,
Troy
Dear Sir,
Thanks.
But sir. May i change together layerOverlay key and layer name.
Regards
Harish Upadhyay
Harish,
Try the below codes:
LayerOverlay layerOverlay = winformsMap1.Overlays["WorldOverlay"] as LayerOverlay;
winformsMap1.Overlays.Remove("WorldOverlay");
winformsMap1.Overlays.Add("newkey",layerOverlay);
ShapeFileFeatureLayer layer = layerOverlay.Layers["WorldLayer"] as ShapeFileFeatureLayer;
layer.Name = "xxx";
Thanks,
Troy
Harish,
Try the below codes:
LayerOverlay layerOverlay = winformsMap1.Overlays["WorldOverlay"] as LayerOverlay;
winformsMap1.Overlays.Remove("WorldOverlay");
winformsMap1.Overlays.Add("newkey",layerOverlay);
ShapeFileFeatureLayer layer = layerOverlay.Layers["WorldLayer"] as ShapeFileFeatureLayer;
layer.Name = "xxx";
Thanks,
Troy
Harish,
Try the below codes:
LayerOverlay layerOverlay = winformsMap1.Overlays["WorldOverlay"] as LayerOverlay;
winformsMap1.Overlays.Remove("WorldOverlay");
winformsMap1.Overlays.Add("newkey",layerOverlay);
ShapeFileFeatureLayer layer = layerOverlay.Layers["WorldLayer"] as ShapeFileFeatureLayer;
layer.Name = "xxx";
Thanks,
Troy
Dear Sir,
Thanks.
This is not update process this is remove and add. But i wand replace same key and value at a time.
Regards
Harish Upadhyay
Harish,
We can’t change the key as the key is an index in the map overlays collection. More details please refer to GeoCollection class, both of the map’ Overlays property and the LayerOverlay’s Layers property are GeoCollection instance.
Thanks,
Troy