Index: gui/MapFrame.java
===================================================================
--- gui/MapFrame.java	(revision 4453)
+++ gui/MapFrame.java	(working copy)
@@ -285,7 +285,7 @@
         }
         return button;
     }
-    
+
     public void validateToolBarToggle() {
         toolBarToggle.removeAll();
         for (ToggleDialog dlg : allDialogs) {
@@ -317,10 +317,25 @@
 
     /**
      * Change the operating map mode for the view. Will call unregister on the
-     * old MapMode and register on the new one.
+     * old MapMode and register on the new one. Now this function also verifies
+     * if new map mode is correct mode for current layer and does not change mode
+     * in such cases.
      * @param mapMode   The new mode to set.
      */
     public void selectMapMode(MapMode newMapMode) {
+        selectMapMode(newMapMode, mapView.getActiveLayer());
+    }
+
+    /**
+     * Another version of the selectMapMode for changing layer action.
+     * Pass newly selected layer to this method.
+     * @param newMapMode
+     * @param newLayer
+     */
+    public void selectMapMode(MapMode newMapMode, Layer newLayer) {
+        if (newMapMode == null || !newMapMode.layerIsSupported(newLayer))
+            return;
+
         MapMode oldMapMode = this.mapMode;
         if (newMapMode == oldMapMode)
             return;
@@ -329,7 +344,7 @@
         }
         this.mapMode = newMapMode;
         newMapMode.enterMode();
-        lastMapMode.put(mapView.getActiveLayer(), newMapMode);
+        lastMapMode.put(newLayer, newMapMode);
         fireMapModeChanged(oldMapMode, newMapMode);
     }
 
@@ -471,8 +486,10 @@
             MapMode newMapMode = lastMapMode.get(newLayer);
             modeChanged = newMapMode != mapMode;
             if (newMapMode != null) {
-                selectMapMode(newMapMode);
-            } // it would be nice to select first supported mode when layer is first selected, but it don't work well with for example editgpx layer
+                selectMapMode(newMapMode, newLayer); // it would be nice to select first supported mode when layer is first selected, but it don't work well with for example editgpx layer
+            } else {
+                mapMode.exitMode(); // if new mode is null - simply exit from previous mode
+            }
         }
         if (!modeChanged && mapMode != null) {
             // Let mapmodes know about new active layer
Index: Main.java
===================================================================
--- Main.java	(revision 4453)
+++ Main.java	(working copy)
@@ -266,7 +266,7 @@
         if (map == null) {
             final MapFrame mapFrame = new MapFrame(contentPanePrivate);
             setMapFrame(mapFrame);
-            mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction());
+            mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction(), layer);
             mapFrame.setVisible(true);
             mapFrame.initializeDialogsPane();
             // bootstrapping problem: make sure the layer list dialog is going to
