@@ -21,7 +21,8 @@ A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires**
2121
2222## Demo
2323
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 )
2526
2627## How to use it?
2728
@@ -54,7 +55,7 @@ Download [latest release](https://github.com/jonataswalker/ol-contextmenu/releas
5455##### Instantiate with some options and add the Control
5556
5657``` javascript
57- var contextmenu = new ContextMenu ({
58+ const contextmenu = new ContextMenu ({
5859 width: 170 ,
5960 defaultItems: true , // defaultItems are (for now) Zoom In/Zoom Out
6061 items: [
@@ -81,7 +82,7 @@ map.addControl(contextmenu);
8182If you provide ` items {Array} ` a submenu will be created as a child of the current item.
8283
8384``` javascript
84- var all_items = [
85+ const all_items = [
8586 {
8687 text: ' Some Actions' ,
8788 items: [
@@ -108,18 +109,18 @@ var all_items = [
108109##### Would you like to propagate custom data to the callback handler?
109110
110111``` javascript
111- var removeMarker = function (obj ) {
112+ const removeMarker = function (obj ) {
112113 vectorLayer .getSource ().removeFeature (obj .data .marker );
113114};
114- var removeMarkerItem = {
115+ const removeMarkerItem = {
115116 text: ' Remove this Marker' ,
116117 icon: ' img/marker.png' ,
117118 callback: removeMarker,
118119};
119120
120- var restore = false ;
121+ let restore = false ;
121122contextmenu .on (' open' , function (evt ) {
122- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
123+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
123124 return ft;
124125 });
125126 if (feature) {
@@ -168,10 +169,10 @@ Add items to the menu. This pushes each item in the provided array to the end of
168169Example:
169170
170171``` js
171- var contextmenu = new ContextMenu ();
172+ const contextmenu = new ContextMenu ();
172173map .addControl (contextmenu);
173174
174- var add_later = [
175+ const add_later = [
175176 ' -' , // this is a separator
176177 {
177178 text: ' Add a Marker' ,
@@ -216,7 +217,7 @@ Update menu's position.
216217
217218``` javascript
218219contextmenu .on (' beforeopen' , function (evt ) {
219- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
220+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
220221 return ft;
221222 });
222223
@@ -233,7 +234,7 @@ contextmenu.on('beforeopen', function (evt) {
233234
234235``` javascript
235236contextmenu .on (' open' , function (evt ) {
236- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
237+ const feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
237238 return ft;
238239 });
239240
0 commit comments