Skip to content

Commit 582025d

Browse files
committed
Add beforeopen event
1 parent 3dbebea commit 582025d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,30 @@ Get an array of default items.
159159

160160
## Events
161161

162-
#### Listen and make some changes before context menu opens
162+
#### If you want to disable this plugin under certain circumstances, listen to `beforeopen`
163+
164+
```javascript
165+
contextmenu.on('beforeopen', function(evt){
166+
var feature = map.forEachFeatureAtPixel(evt.pixel, function(ft, l){
167+
return ft;
168+
});
169+
170+
if (feature) { // open only on features
171+
contextmenu.disable();
172+
} else {
173+
contextmenu.enable();
174+
}
175+
});
176+
```
177+
178+
#### Listen and make some changes when context menu opens
163179

164180
```javascript
165181
contextmenu.on('open', function(evt){
166182
var feature = map.forEachFeatureAtPixel(evt.pixel, function(ft, l){
167183
return ft;
168184
});
185+
169186
if (feature) {
170187
// add some other items to the menu
171188
}

0 commit comments

Comments
 (0)