(function () {
    "use strict";


    Mapbender.Digitizer.MapContextMenu = function(olMap, widget) {
        this.widget = widget;
        this.olMap = olMap;
        this.contextmenu = new ContextMenu({
            defaultItems: false
        });
        this.onMap_ = false;
    };
    Object.assign(Mapbender.Digitizer.MapContextMenu.prototype, {
        enable: function() {
            if (!this.onMap_) {
                this.olMap.addControl(this.contextmenu);
                this.registerEvents(this.olMap);
                this.onMap_ = true;
            }
            return this.contextmenu.enable.apply(this.contextmenu, arguments);
        },
        disable: function() {
            return this.contextmenu.disable.apply(this.contextmenu, arguments);
        },
        /**
         * @param {ol.PluggableMap} olMap
         */
        registerEvents: function(olMap) {
            var self = this;
            olMap.getViewport().addEventListener('contextmenu', function (e) {
                self._handleContextMenu(e);
            });
        },
        _handleContextMenu: function(e) {
            var schema = this.widget._getCurrentSchema();
            e.preventDefault();

            this.contextmenu.clear();

            var feature = this.olMap.forEachFeatureAtPixel(this.olMap.getEventPixel(e),
                function (feature, layer) {
                    return feature;
                }
            );
            var contextmenu = this.contextmenu; // @todo: disambiguate

            if (feature) {
                var subitems = [];
                if (schema.allowLocate) {
                    subitems.push({
                        text: Mapbender.trans('mb.digitizer.feature.zoomTo'),
                        callback: function () {
                            schema.zoomToFeature(feature);
                        }
                    });
                }

                if (schema.allowEditData) {
                    subitems.push({
                        text: Mapbender.trans('mb.digitizer.feature.edit'),
                        callback: function () {
                            schema.openFeatureEditDialog(feature);
                        }
                    });
                }

                if (schema.allowDelete) {
                    subitems.push({
                        text: Mapbender.trans('mb.digitizer.feature.remove.title'),
                        callback: function () {
                            schema.removeFeature(feature);
                        }
                    });
                }
                contextmenu.push({
                    text: "Feature #" + (feature.getId() || ''),
                    items: subitems
                });
            } else {
                contextmenu.push({text: "Nothing selected!"});
            }
        }
    });

})();

@@ -271,16 +271,47 @@
  false;%0A
+        this.enabled_ = false;%0A
     %7D;%0A 
@@ -584,32 +584,66 @@
 ;%0A            %7D%0A
+            this.enabled_ = true;%0A
             retu
@@ -738,32 +738,67 @@
 e: function() %7B%0A
+            this.enabled_ = false;%0A
             retu
@@ -1009,16 +1009,433 @@
 = this;%0A
+            this.contextmenu.on('beforeopen', function (evt) %7B%0A                self.feature = olMap.forEachFeatureAtPixel(evt.pixel, function (feature) %7B%0A                    return feature;%0A                %7D);%0A                if (self.feature && self.enabled_) %7B%0A                    self.contextmenu.enable();%0A                %7D else %7B%0A                    self.contextmenu.disable();%0A                %7D%0A            %7D);%0A
         
@@ -1783,177 +1783,53 @@
 his.
-olMap.forEachFeatureAtPixel(this.olMap.getEventPixel(e),%0A                function (feature, layer) %7B%0A                    return feature;%0A                %7D%0A            );
+feature; // initialized by beforeopen handler
 %0A   
@@ -1901,39 +1901,8 @@
 te%0A%0A
-            if (feature) %7B%0A    
     
@@ -1928,20 +1928,16 @@
 s = %5B%5D;%0A
-    
         
@@ -1974,36 +1974,32 @@
                 
-    
 subitems.push(%7B%0A
@@ -1990,36 +1990,32 @@
 subitems.push(%7B%0A
-    
                 
@@ -2084,36 +2084,32 @@
                 
-    
 callback: functi
@@ -2136,28 +2136,24 @@
             
- 
-   
 schema.zoomT
@@ -2187,34 +2187,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -2221,35 +2221,27 @@
             
-  
-  
 %7D%0A%0A
-    
             
@@ -2276,36 +2276,32 @@
                 
-    
 subitems.push(%7B%0A
@@ -2312,36 +2312,32 @@
                 
-   
- 
 text: Mapbender.
@@ -2384,36 +2384,32 @@
                 
-    
 callback: functi
@@ -2436,28 +2436,24 @@
             
-  
-  
 schema.openF
@@ -2471,36 +2471,32 @@
 ialog(feature);%0A
-    
                 
@@ -2509,36 +2509,32 @@
                 
-    
 %7D);%0A            
@@ -2529,35 +2529,27 @@
             
-    %7D%0A%0A    
+%7D%0A%0A
             
@@ -2582,36 +2582,32 @@
                 
- 
-   
 subitems.push(%7B%0A
@@ -2598,36 +2598,32 @@
 subitems.push(%7B%0A
-    
                 
@@ -2698,36 +2698,32 @@
                 
-    
 callback: functi
@@ -2750,28 +2750,24 @@
             
-  
-  
 schema.remov
@@ -2801,34 +2801,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -2835,34 +2835,26 @@
             
-   
- 
 %7D%0A
-    
             
@@ -2864,36 +2864,32 @@
 textmenu.push(%7B%0A
-    
                 
@@ -2949,20 +2949,16 @@
         
-   
- 
 items: s
@@ -2981,113 +2981,11 @@
     
-    %7D);%0A            %7D else %7B%0A                contextmenu.push(%7Btext: %22Nothing selected!%22%7D);%0A            %7D
+%7D);
 %0A   

Remove unhelpful "nothing selected" context menu behavior