1
1
# OpenLayers Custom Context Menu
2
2
3
3
<p align =" center " >
4
- <a href =" https://travis-ci.org/jonataswalker/ol3 -contextmenu " >
5
- <img src="https://travis-ci.org/jonataswalker/ol3 -contextmenu.svg?branch=master" alt="build status">
4
+ <a href =" https://travis-ci.org/jonataswalker/ol -contextmenu " >
5
+ <img src="https://travis-ci.org/jonataswalker/ol -contextmenu.svg?branch=master" alt="build status">
6
6
</a >
7
- <a href =" https://www.npmjs.com/package/ol3 -contextmenu " >
8
- <img src="https://img.shields.io/npm/v/ol3 -contextmenu.svg"
7
+ <a href =" https://www.npmjs.com/package/ol -contextmenu " >
8
+ <img src="https://img.shields.io/npm/v/ol -contextmenu.svg"
9
9
alt="npm version">
10
10
</a >
11
- <a href =" https://github.com/jonataswalker/ol3 -contextmenu/blob/master/LICENSE " >
12
- <img src="https://img.shields.io/npm/l/ol3 -contextmenu.svg"
11
+ <a href =" https://github.com/jonataswalker/ol -contextmenu/blob/master/LICENSE " >
12
+ <img src="https://img.shields.io/npm/l/ol -contextmenu.svg"
13
13
alt="license">
14
14
</a >
15
- <a href =" https://david-dm.org/jonataswalker/ol3 -contextmenu " >
16
- <img src="https://david-dm.org/jonataswalker/ol3 -contextmenu/status.svg"
15
+ <a href =" https://david-dm.org/jonataswalker/ol -contextmenu " >
16
+ <img src="https://david-dm.org/jonataswalker/ol -contextmenu/status.svg"
17
17
alt="dependency status">
18
18
</a >
19
- <a href =" https://david-dm.org/jonataswalker/ol3 -contextmenu " >
20
- <img src="https://david-dm.org/jonataswalker/ol3 -contextmenu/dev-status.svg" alt="devDependency status">
19
+ <a href =" https://david-dm.org/jonataswalker/ol -contextmenu " >
20
+ <img src="https://david-dm.org/jonataswalker/ol -contextmenu/dev-status.svg" alt="devDependency status">
21
21
</a >
22
22
</p >
23
23
24
24
A ` contextmenu ` extension for [ OpenLayers] ( http://openlayers.org/ ) . ** Requires** OpenLayers ** v3.11.0** or higher.
25
25
26
- ![ contextmenu anim] ( https://raw.githubusercontent.com/jonataswalker/ol3 -contextmenu/screenshot/images/anim.gif )
26
+ ![ contextmenu anim] ( https://raw.githubusercontent.com/jonataswalker/ol -contextmenu/screenshot/images/anim.gif )
27
27
28
28
## Demo
29
- You can see [ here a demo] ( http://rawgit.com/jonataswalker/ol3 -contextmenu/master/examples/contextmenu.html ) or [ JSFiddle] ( https://jsfiddle.net/jonataswalker/ooxs1w5d/ ) .
29
+ You can see [ here a demo] ( http://rawgit.com/jonataswalker/ol -contextmenu/master/examples/contextmenu.html ) or [ JSFiddle] ( https://jsfiddle.net/jonataswalker/ooxs1w5d/ ) .
30
30
31
31
## How to use it?
32
- ##### CDN Hosted - [ jsDelivr] ( http://www.jsdelivr.com/projects/openlayers.contextmenu )
33
- Load CSS and Javascript:
34
- ``` HTML
35
- <link href =" //cdn.jsdelivr.net/openlayers.contextmenu/latest/ol3-contextmenu.min.css" rel =" stylesheet" >
36
- <script src =" //cdn.jsdelivr.net/openlayers.contextmenu/latest/ol3-contextmenu.js" ></script >
37
- ```
32
+ ##### NPM
33
+ ` npm install ol-contextmenu `
34
+
38
35
##### CDN Hosted - UNPKG
39
36
Load CSS and Javascript:
40
37
``` HTML
41
- <link href =" https://unpkg.com/ol3 -contextmenu/build/ol3 -contextmenu.min.css" rel =" stylesheet" >
42
- <script src =" https://unpkg.com/ol3 -contextmenu/build/ol3-contextmenu.js " ></script >
38
+ <link href =" https://unpkg.com/ol -contextmenu/dist/ol -contextmenu.min.css" rel =" stylesheet" >
39
+ <script src =" https://unpkg.com/ol -contextmenu" ></script >
43
40
```
44
41
##### Self hosted
45
- Download [ latest release] ( https://github.com/jonataswalker/ol3 -contextmenu/releases/latest ) and (obviously) load CSS and Javascript.
42
+ Download [ latest release] ( https://github.com/jonataswalker/ol -contextmenu/releases/latest ) and (obviously) load CSS and Javascript.
46
43
47
44
##### Instantiate with some options and add the Control
48
45
``` javascript
@@ -98,7 +95,7 @@ var all_items = [
98
95
99
96
##### Would you like to propagate custom data to the callback handler?
100
97
``` javascript
101
- var removeMarker = function (obj ){
98
+ var removeMarker = function (obj ) {
102
99
vectorLayer .getSource ().removeFeature (obj .data .marker );
103
100
};
104
101
var removeMarkerItem = {
@@ -108,15 +105,13 @@ var removeMarkerItem = {
108
105
};
109
106
110
107
var restore = false ;
111
- contextmenu .on (' open' , function (evt ){
112
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ){
108
+ contextmenu .on (' open' , function (evt ) {
109
+ var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
113
110
return ft;
114
111
});
115
112
if (feature) {
116
113
contextmenu .clear ();
117
- removeMarkerItem .data = {
118
- marker: feature
119
- };
114
+ removeMarkerItem .data = { marker: feature };
120
115
contextmenu .push (removeMarkerItem);
121
116
restore = true ;
122
117
} else if (restore) {
@@ -206,8 +201,8 @@ Update menu's position.
206
201
#### If you want to disable this plugin under certain circumstances, listen to ` beforeopen `
207
202
208
203
``` javascript
209
- contextmenu .on (' beforeopen' , function (evt ){
210
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ){
204
+ contextmenu .on (' beforeopen' , function (evt ) {
205
+ var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
211
206
return ft;
212
207
});
213
208
@@ -223,7 +218,7 @@ contextmenu.on('beforeopen', function(evt){
223
218
224
219
``` javascript
225
220
contextmenu .on (' open' , function (evt ){
226
- var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ){
221
+ var feature = map .forEachFeatureAtPixel (evt .pixel , function (ft , l ) {
227
222
return ft;
228
223
});
229
224
@@ -236,7 +231,7 @@ contextmenu.on('open', function(evt){
236
231
#### Any action when context menu gets closed?
237
232
238
233
``` javascript
239
- contextmenu .on (' close' , function (evt ){
234
+ contextmenu .on (' close' , function (evt ) {
240
235
// it's upon you
241
236
});
242
237
```
0 commit comments