@@ -21,7 +21,8 @@ A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires**
21
21
22
22
## Demo
23
23
24
- [ JSFiddle] ( https://jsfiddle.net/jonataswalker/ooxs1w5d/ ) .
24
+ [ JSFiddle] ( https://jsfiddle.net/jonataswalker/ooxs1w5d/ )
25
+ [ CodeSandbox] ( https://codesandbox.io/s/openlayers-custom-context-menu-5s99kb?file=/src/index.js )
25
26
26
27
## How to use it?
27
28
@@ -54,7 +55,7 @@ Download [latest release](https://github.com/jonataswalker/ol-contextmenu/releas
54
55
##### Instantiate with some options and add the Control
55
56
56
57
``` javascript
57
- var contextmenu = new ContextMenu ({
58
+ const contextmenu = new ContextMenu ({
58
59
width: 170 ,
59
60
defaultItems: true , // defaultItems are (for now) Zoom In/Zoom Out
60
61
items: [
@@ -81,7 +82,7 @@ map.addControl(contextmenu);
81
82
If you provide ` items {Array} ` a submenu will be created as a child of the current item.
82
83
83
84
``` javascript
84
- var all_items = [
85
+ const all_items = [
85
86
{
86
87
text: ' Some Actions' ,
87
88
items: [
@@ -108,18 +109,18 @@ var all_items = [
108
109
##### Would you like to propagate custom data to the callback handler?
109
110
110
111
``` javascript
111
- var removeMarker = function (obj ) {
112
+ const removeMarker = function (obj ) {
112
113
vectorLayer .getSource ().removeFeature (obj .data .marker );
113
114
};
114
- var removeMarkerItem = {
115
+ const removeMarkerItem = {
115
116
text: ' Remove this Marker' ,
116
117
icon: ' img/marker.png' ,
117
118
callback: removeMarker,
118
119
};
119
120
120
- var restore = false ;
121
+ let restore = false ;
121
122
contextmenu .on (' open' , function (evt ) {
122
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
123
+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
123
124
return ft;
124
125
});
125
126
if (feature) {
@@ -168,10 +169,10 @@ Add items to the menu. This pushes each item in the provided array to the end of
168
169
Example:
169
170
170
171
``` js
171
- var contextmenu = new ContextMenu ();
172
+ const contextmenu = new ContextMenu ();
172
173
map .addControl (contextmenu);
173
174
174
- var add_later = [
175
+ const add_later = [
175
176
' -' , // this is a separator
176
177
{
177
178
text: ' Add a Marker' ,
@@ -216,7 +217,7 @@ Update menu's position.
216
217
217
218
``` javascript
218
219
contextmenu .on (' beforeopen' , function (evt ) {
219
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
220
+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
220
221
return ft;
221
222
});
222
223
@@ -233,7 +234,7 @@ contextmenu.on('beforeopen', function (evt) {
233
234
234
235
``` javascript
235
236
contextmenu .on (' open' , function (evt ) {
236
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
237
+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
237
238
return ft;
238
239
});
239
240
0 commit comments