Skip to content

Commit b5b40a8

Browse files
committed
typescript version
1 parent d5489a6 commit b5b40a8

39 files changed

+1731
-4591
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist
22
/node_modules
3+
/examples

.eslintrc.cjs

+13
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ module.exports = {
1414
'no-magic-numbers': 'off',
1515
'no-unused-vars': 'off',
1616
'no-this-before-super': 'off',
17+
'no-use-before-define': 'off',
1718
'class-methods-use-this': 'off',
1819
'import/no-unused-modules': 'off',
20+
'import/no-extraneous-dependencies': 'off',
1921
'unicorn/prevent-abbreviations': 'off',
2022
'unicorn/prefer-dom-node-append': 'off',
2123
'security/detect-object-injection': 'off',
2224
'@typescript-eslint/naming-convention': 'off',
2325
'@typescript-eslint/no-magic-numbers': 'off',
2426
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
27+
'@typescript-eslint/no-use-before-define': [
28+
'error',
29+
{ typedefs: false, ignoreTypeReferences: true },
30+
],
31+
32+
'import/extensions': [
33+
'error',
34+
{
35+
js: 'ignorePackages',
36+
},
37+
],
2538
},
2639
};

.gitignore

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
# Logs
21
logs
32
*.log
43
npm-debug.log*
5-
6-
# Dependency directories
74
node_modules
8-
9-
# dist
105
dist
11-
12-
# Optional npm cache directory
136
.npm
14-
15-
# eslint
167
.eslintcache
8+
coverage

.travis.yml

-15
This file was deleted.

.vscode/settings.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
"editor.codeActionsOnSave": ["source.fixAll.eslint"],
77
"eslint.validate": ["javascript", "javascriptreact", "typescript"],
88
"typescript.tsdk": "./node_modules/typescript/lib",
9-
"svg.preview.background": "editor"
9+
"svg.preview.background": "editor",
10+
"[ignore]": {
11+
"editor.defaultFormatter": "foxundermoon.shell-format"
12+
}
1013
}

README.md

+111-103
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,77 @@
11
# OpenLayers Custom Context Menu
22

33
<p align="center">
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-
</a>
7-
<a href="https://www.npmjs.com/package/ol-contextmenu">
8-
<img src="https://img.shields.io/npm/v/ol-contextmenu.svg"
9-
alt="npm version">
10-
</a>
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-
alt="license">
14-
</a>
15-
<a href="https://david-dm.org/jonataswalker/ol-contextmenu">
16-
<img src="https://david-dm.org/jonataswalker/ol-contextmenu/status.svg"
17-
alt="dependency status">
18-
</a>
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-
</a>
4+
<a href="https://github.com/jonataswalker/ol-contextmenu/actions/workflows/test.yml">
5+
<img src="https://github.com/jonataswalker/ol-contextmenu/actions/workflows/test.yml/badge.svg?branch=master" alt="Build Status">
6+
</a>
7+
<a href="https://www.npmjs.com/package/ol-contextmenu">
8+
<img src="https://img.shields.io/npm/v/ol-contextmenu.svg" alt="npm version">
9+
</a>
10+
<a href="https://img.shields.io/npm/dm/ol-contextmenu">
11+
<img alt="npm" src="https://img.shields.io/npm/dm/ol-contextmenu">
12+
</a>
13+
<a href="https://github.com/jonataswalker/ol-contextmenu/blob/master/LICENSE">
14+
<img src="https://img.shields.io/npm/l/ol-contextmenu.svg" alt="license">
15+
</a>
2216
</p>
2317

2418
A `contextmenu` extension for [OpenLayers](http://openlayers.org/). **Requires** OpenLayers **v3.11.0** or higher.
2519

2620
![contextmenu anim](https://raw.githubusercontent.com/jonataswalker/ol-contextmenu/screenshot/images/anim.gif)
2721

2822
## Demo
23+
2924
You can see [here a demo](http://rawgit.com/jonataswalker/ol-contextmenu/master/examples/contextmenu.html) or [JSFiddle](https://jsfiddle.net/jonataswalker/ooxs1w5d/).
3025

3126
## How to use it?
27+
3228
##### NPM
29+
3330
`npm install ol-contextmenu`
3431

3532
##### CDN Hosted - [jsDelivr](https://www.jsdelivr.com/package/npm/ol-contextmenu)
33+
3634
Load CSS and Javascript:
35+
3736
```HTML
38-
<link href="https://cdn.jsdelivr.net/npm/ol-contextmenu@latest/dist/ol-contextmenu.min.css" rel="stylesheet">
37+
<link href="https://cdn.jsdelivr.net/npm/ol-contextmenu@latest/dist/ol-contextmenu.css" rel="stylesheet">
3938
<script src="https://cdn.jsdelivr.net/npm/ol-contextmenu"></script>
4039
```
4140

4241
##### CDN Hosted - UNPKG
42+
4343
Load CSS and Javascript:
44+
4445
```HTML
45-
<link href="https://unpkg.com/ol-contextmenu/dist/ol-contextmenu.min.css" rel="stylesheet">
46+
<link href="https://unpkg.com/ol-contextmenu/dist/ol-contextmenu.css" rel="stylesheet">
4647
<script src="https://unpkg.com/ol-contextmenu"></script>
4748
```
49+
4850
##### Self hosted
51+
4952
Download [latest release](https://github.com/jonataswalker/ol-contextmenu/releases/latest) and (obviously) load CSS and Javascript.
5053

5154
##### Instantiate with some options and add the Control
55+
5256
```javascript
5357
var contextmenu = new ContextMenu({
54-
width: 170,
55-
defaultItems: true, // defaultItems are (for now) Zoom In/Zoom Out
56-
items: [
57-
{
58-
text: 'Center map here',
59-
classname: 'some-style-class', // add some CSS rules
60-
callback: center // `center` is your callback function
61-
},
62-
{
63-
text: 'Add a Marker',
64-
classname: 'some-style-class', // you can add this icon with a CSS class
65-
// instead of `icon` property (see next line)
66-
icon: 'img/marker.png', // this can be relative or absolute
67-
callback: marker
68-
},
69-
'-' // this is a separator
70-
]
58+
width: 170,
59+
defaultItems: true, // defaultItems are (for now) Zoom In/Zoom Out
60+
items: [
61+
{
62+
text: 'Center map here',
63+
classname: 'some-style-class', // add some CSS rules
64+
callback: center, // `center` is your callback function
65+
},
66+
{
67+
text: 'Add a Marker',
68+
classname: 'some-style-class', // you can add this icon with a CSS class
69+
// instead of `icon` property (see next line)
70+
icon: 'img/marker.png', // this can be relative or absolute
71+
callback: marker,
72+
},
73+
'-', // this is a separator
74+
],
7175
});
7276
map.addControl(contextmenu);
7377
```
@@ -78,55 +82,57 @@ If you provide `items {Array}` a submenu will be created as a child of the curre
7882

7983
```javascript
8084
var all_items = [
81-
{
82-
text: 'Some Actions',
83-
items: [ // <== this is a submenu
84-
{
85-
text: 'Action 1',
86-
callback: action
87-
},
88-
{
89-
text: 'Other action',
90-
callback: action2
91-
}
92-
]
93-
},
94-
{
95-
text: 'Add a Marker',
96-
icon: 'img/marker.png',
97-
callback: marker
98-
},
99-
'-' // this is a separator
85+
{
86+
text: 'Some Actions',
87+
items: [
88+
// <== this is a submenu
89+
{
90+
text: 'Action 1',
91+
callback: action,
92+
},
93+
{
94+
text: 'Other action',
95+
callback: action2,
96+
},
97+
],
98+
},
99+
{
100+
text: 'Add a Marker',
101+
icon: 'img/marker.png',
102+
callback: marker,
103+
},
104+
'-', // this is a separator
100105
];
101106
```
102107

103108
##### Would you like to propagate custom data to the callback handler?
109+
104110
```javascript
105111
var removeMarker = function (obj) {
106-
vectorLayer.getSource().removeFeature(obj.data.marker);
112+
vectorLayer.getSource().removeFeature(obj.data.marker);
107113
};
108114
var removeMarkerItem = {
109-
text: 'Remove this Marker',
110-
icon: 'img/marker.png',
111-
callback: removeMarker
115+
text: 'Remove this Marker',
116+
icon: 'img/marker.png',
117+
callback: removeMarker,
112118
};
113119

114120
var restore = false;
115121
contextmenu.on('open', function (evt) {
116-
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
117-
return ft;
118-
});
119-
if (feature) {
120-
contextmenu.clear();
121-
removeMarkerItem.data = { marker: feature };
122-
contextmenu.push(removeMarkerItem);
123-
restore = true;
124-
} else if (restore) {
125-
contextmenu.clear();
126-
contextmenu.extend(contextmenu_items);
127-
contextmenu.extend(contextmenu.getDefaultItems());
128-
restore = false;
129-
}
122+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
123+
return ft;
124+
});
125+
if (feature) {
126+
contextmenu.clear();
127+
removeMarkerItem.data = { marker: feature };
128+
contextmenu.push(removeMarkerItem);
129+
restore = true;
130+
} else if (restore) {
131+
contextmenu.clear();
132+
contextmenu.extend(contextmenu_items);
133+
contextmenu.extend(contextmenu.getDefaultItems());
134+
restore = false;
135+
}
130136
});
131137
```
132138

@@ -137,10 +143,11 @@ contextmenu.on('open', function (evt) {
137143
#### `new ContextMenu(options)`
138144

139145
###### `options` is an object with the following possible properties:
140-
* `eventType`: `contextmenu`; The listening event type (You could use `'click'`, `'dblclick'`)
141-
* `defaultItems`: `true`; Whether the default items (which are: Zoom In/Out) are enabled
142-
* `width`: `150`; The menu's width
143-
* `items`: `[]`; An array of object|string
146+
147+
- `eventType`: `contextmenu`; The listening event type (You could use `'click'`, `'dblclick'`)
148+
- `defaultItems`: `true`; Whether the default items (which are: Zoom In/Out) are enabled
149+
- `width`: `150`; The menu's width
150+
- `items`: `[]`; An array of object|string
144151

145152
## Methods
146153

@@ -159,17 +166,18 @@ Close the menu programmatically.
159166
Add items to the menu. This pushes each item in the provided array to the end of the menu.
160167

161168
Example:
169+
162170
```js
163171
var contextmenu = new ContextMenu();
164172
map.addControl(contextmenu);
165173

166174
var add_later = [
167-
'-', // this is a separator
168-
{
169-
text: 'Add a Marker',
170-
icon: 'img/marker.png',
171-
callback: marker
172-
}
175+
'-', // this is a separator
176+
{
177+
text: 'Add a Marker',
178+
icon: 'img/marker.png',
179+
callback: marker,
180+
},
173181
];
174182
contextmenu.extend(add_later);
175183
```
@@ -202,43 +210,43 @@ Whether the menu is open.
202210

203211
Update menu's position.
204212

205-
206213
## Events
207214

208215
#### If you want to disable this plugin under certain circumstances, listen to `beforeopen`
209216

210217
```javascript
211218
contextmenu.on('beforeopen', function (evt) {
212-
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
213-
return ft;
214-
});
215-
216-
if (feature) { // open only on features
217-
contextmenu.enable();
218-
} else {
219-
contextmenu.disable();
220-
}
219+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
220+
return ft;
221+
});
222+
223+
if (feature) {
224+
// open only on features
225+
contextmenu.enable();
226+
} else {
227+
contextmenu.disable();
228+
}
221229
});
222230
```
223231

224232
#### Listen and make some changes when context menu opens
225233

226234
```javascript
227-
contextmenu.on('open', function(evt){
228-
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
229-
return ft;
230-
});
231-
232-
if (feature) {
233-
// add some other items to the menu
234-
}
235+
contextmenu.on('open', function (evt) {
236+
var feature = map.forEachFeatureAtPixel(evt.pixel, function (ft, l) {
237+
return ft;
238+
});
239+
240+
if (feature) {
241+
// add some other items to the menu
242+
}
235243
});
236244
```
237245

238246
#### Any action when context menu gets closed?
239247

240248
```javascript
241249
contextmenu.on('close', function (evt) {
242-
// it's upon you
250+
// it's upon you
243251
});
244252
```

0 commit comments

Comments
 (0)