# How to RemoveLayer?

**URL:** <https://mapwindow.discourse.group/t/how-to-removelayer/1718>\
**Category:** MapWinGIS\
**Created:** [April 23, 2024, 7:08am UTC](https://mapwindow.discourse.group/t/how-to-removelayer/1718 "2024-04-23T07:08:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thesorus](https://avatars.discourse-cdn.com/v4/letter/t/ac91a4/32.png) [@thesorus](https://mapwindow.discourse.group/u/thesorus)\
**Post date:** [April 23, 2024, 7:08am UTC](https://mapwindow.discourse.group/t/how-to-removelayer/1718/1 "2024-04-23T07:08:03Z")

</div>

Hi, Everyone, good afternoon.

I tried to load and remove layer.  
But after remove layer(ex DEM) then the map removed together.  
Please let me know how to remain the map after removelayer(DEM).

Thank you.

below are code and result images

1. Load map  
axMap1.TileProvider = tkTileProvider.OpenHumanitarianMap;  
axMap1.CursorMode = tkCursorMode.cmPan;  
axMap1.Projection = tkMapProjection.PROJECTION\_GOOGLE\_MERCATOR;  
axMap1.KnownExtents = tkKnownExtents.keSouth\_Korea;  
axMap1.ZoomBarMaxZoom = 15;  
axMap1.ZoomBarMinZoom = 7;  
axMap1.CurrentZoom = 7;  
 ![image](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/443724ee300b9f66fa3bd96f2377d333ab1d28b7.jpeg)

2. Load Image  
string demFileName = ofd.FileName;  
MapWinGIS.Image mydem = new MapWinGIS.Image();  
mydem.Open(demFileName);  
demlayerHandler = axMap1.AddLayer(mydem, true);  
 ![image](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/dddc88a165bbdc3e447cdacb0ca3c9030e18d95b.jpeg)

3. RemoveLayer  
axMap1.RemoveLayer(demlayerHandler);  
 ![image](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/12921174332627f06c1ec0ab9003b82038cac8e8.png)

---

<div class="post-metadata">

**Author:** ![schufti](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@schufti](https://mapwindow.discourse.group/u/schufti)\
**Post date:** [December 12, 2024, 8:05pm UTC](https://mapwindow.discourse.group/t/how-to-removelayer/1718/2 "2024-12-12T20:05:30Z")

</div>

I experienced the same problem.  
Workaround that worked for me:  
reapply projection and knownExtents

---

<div class="post-metadata">

**Author:** ![schufti](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@schufti](https://mapwindow.discourse.group/u/schufti)\
**Post date:** [December 14, 2024, 11:12am UTC](https://mapwindow.discourse.group/t/how-to-removelayer/1718/3 "2024-12-14T11:12:06Z")

</div>

p.s.: once I sorted out my problems with “LayerHandle” variables, this was no longer necessary.  
caveat: initialize your (public/global) LayerHandle variables to -1 if not using  
Dim LayerHandle as integer = AxMap1.addLayer()
