umap-project 1.14.0a4__py3-none-any.whl → 2.0.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of umap-project might be problematic. Click here for more details.

Files changed (226) hide show
  1. umap/__init__.py +1 -1
  2. umap/decorators.py +0 -14
  3. umap/locale/br/LC_MESSAGES/django.mo +0 -0
  4. umap/locale/br/LC_MESSAGES/django.po +137 -85
  5. umap/locale/cs_CZ/LC_MESSAGES/django.mo +0 -0
  6. umap/locale/cs_CZ/LC_MESSAGES/django.po +136 -84
  7. umap/locale/el/LC_MESSAGES/django.mo +0 -0
  8. umap/locale/el/LC_MESSAGES/django.po +136 -84
  9. umap/locale/en/LC_MESSAGES/django.po +128 -88
  10. umap/locale/es/LC_MESSAGES/django.mo +0 -0
  11. umap/locale/es/LC_MESSAGES/django.po +136 -84
  12. umap/locale/fr/LC_MESSAGES/django.mo +0 -0
  13. umap/locale/fr/LC_MESSAGES/django.po +131 -91
  14. umap/locale/hu/LC_MESSAGES/django.mo +0 -0
  15. umap/locale/hu/LC_MESSAGES/django.po +137 -85
  16. umap/locale/it/LC_MESSAGES/django.mo +0 -0
  17. umap/locale/it/LC_MESSAGES/django.po +136 -84
  18. umap/locale/ms/LC_MESSAGES/django.mo +0 -0
  19. umap/locale/ms/LC_MESSAGES/django.po +136 -84
  20. umap/locale/pl/LC_MESSAGES/django.mo +0 -0
  21. umap/locale/pl/LC_MESSAGES/django.po +136 -84
  22. umap/locale/sv/LC_MESSAGES/django.mo +0 -0
  23. umap/locale/sv/LC_MESSAGES/django.po +135 -83
  24. umap/locale/zh_TW/LC_MESSAGES/django.mo +0 -0
  25. umap/locale/zh_TW/LC_MESSAGES/django.po +143 -91
  26. umap/models.py +23 -1
  27. umap/settings/__init__.py +1 -4
  28. umap/settings/base.py +1 -0
  29. umap/static/umap/base.css +5 -0
  30. umap/static/umap/content.css +185 -13
  31. umap/static/umap/favicons/icon.svg +2 -2
  32. umap/static/umap/img/edit.svg +3 -3
  33. umap/static/umap/img/icon-delete.svg +4 -0
  34. umap/static/umap/img/icon-download.svg +13 -0
  35. umap/static/umap/img/icon-duplicate.svg +5 -0
  36. umap/static/umap/img/icon-edit.svg +12 -0
  37. umap/static/umap/img/icon-share.svg +11 -0
  38. umap/static/umap/img/icon-view.svg +12 -0
  39. umap/static/umap/img/logo.svg +2 -2
  40. umap/static/umap/img/logo_small.svg +2 -2
  41. umap/static/umap/img/marker.svg +4 -0
  42. umap/static/umap/img/opensource.svg +2 -2
  43. umap/static/umap/img/osm.svg +2 -2
  44. umap/static/umap/js/components/fragment.js +1 -1
  45. umap/static/umap/js/modules/browser.js +159 -0
  46. umap/static/umap/js/modules/global.js +3 -1
  47. umap/static/umap/js/modules/request.js +155 -0
  48. umap/static/umap/js/umap.autocomplete.js +28 -38
  49. umap/static/umap/js/umap.controls.js +73 -58
  50. umap/static/umap/js/umap.core.js +4 -9
  51. umap/static/umap/js/umap.datalayer.permissions.js +13 -12
  52. umap/static/umap/js/umap.features.js +51 -49
  53. umap/static/umap/js/umap.forms.js +19 -19
  54. umap/static/umap/js/umap.icon.js +17 -17
  55. umap/static/umap/js/umap.importer.js +2 -1
  56. umap/static/umap/js/umap.js +242 -291
  57. umap/static/umap/js/umap.layer.js +173 -140
  58. umap/static/umap/js/umap.permissions.js +24 -25
  59. umap/static/umap/js/umap.popup.js +14 -14
  60. umap/static/umap/js/umap.share.js +4 -4
  61. umap/static/umap/js/umap.slideshow.js +4 -4
  62. umap/static/umap/js/umap.tableeditor.js +2 -2
  63. umap/static/umap/js/umap.ui.js +1 -1
  64. umap/static/umap/locale/am_ET.js +1 -11
  65. umap/static/umap/locale/am_ET.json +1 -11
  66. umap/static/umap/locale/ar.js +1 -11
  67. umap/static/umap/locale/ar.json +1 -11
  68. umap/static/umap/locale/ast.js +1 -11
  69. umap/static/umap/locale/ast.json +1 -11
  70. umap/static/umap/locale/bg.js +1 -11
  71. umap/static/umap/locale/bg.json +1 -11
  72. umap/static/umap/locale/br.js +1 -11
  73. umap/static/umap/locale/br.json +1 -11
  74. umap/static/umap/locale/ca.js +1 -11
  75. umap/static/umap/locale/ca.json +1 -11
  76. umap/static/umap/locale/cs_CZ.js +1 -11
  77. umap/static/umap/locale/cs_CZ.json +1 -11
  78. umap/static/umap/locale/da.js +1 -11
  79. umap/static/umap/locale/da.json +1 -11
  80. umap/static/umap/locale/de.js +1 -11
  81. umap/static/umap/locale/de.json +1 -11
  82. umap/static/umap/locale/el.js +1 -11
  83. umap/static/umap/locale/el.json +1 -11
  84. umap/static/umap/locale/en.js +1 -11
  85. umap/static/umap/locale/en.json +1 -11
  86. umap/static/umap/locale/en_US.json +1 -11
  87. umap/static/umap/locale/es.js +1 -11
  88. umap/static/umap/locale/es.json +1 -11
  89. umap/static/umap/locale/et.js +1 -11
  90. umap/static/umap/locale/et.json +1 -11
  91. umap/static/umap/locale/fa_IR.js +6 -16
  92. umap/static/umap/locale/fa_IR.json +6 -16
  93. umap/static/umap/locale/fi.js +1 -11
  94. umap/static/umap/locale/fi.json +1 -11
  95. umap/static/umap/locale/fr.js +1 -11
  96. umap/static/umap/locale/fr.json +1 -11
  97. umap/static/umap/locale/gl.js +1 -11
  98. umap/static/umap/locale/gl.json +1 -11
  99. umap/static/umap/locale/he.js +1 -11
  100. umap/static/umap/locale/he.json +1 -11
  101. umap/static/umap/locale/hr.js +1 -11
  102. umap/static/umap/locale/hr.json +1 -11
  103. umap/static/umap/locale/hu.js +1 -11
  104. umap/static/umap/locale/hu.json +1 -11
  105. umap/static/umap/locale/id.js +1 -11
  106. umap/static/umap/locale/id.json +1 -11
  107. umap/static/umap/locale/is.js +1 -11
  108. umap/static/umap/locale/is.json +1 -11
  109. umap/static/umap/locale/it.js +1 -11
  110. umap/static/umap/locale/it.json +1 -11
  111. umap/static/umap/locale/ja.js +1 -11
  112. umap/static/umap/locale/ja.json +1 -11
  113. umap/static/umap/locale/ko.js +1 -11
  114. umap/static/umap/locale/ko.json +1 -11
  115. umap/static/umap/locale/lt.js +1 -11
  116. umap/static/umap/locale/lt.json +1 -11
  117. umap/static/umap/locale/ms.js +1 -11
  118. umap/static/umap/locale/ms.json +1 -11
  119. umap/static/umap/locale/nl.js +1 -11
  120. umap/static/umap/locale/nl.json +1 -11
  121. umap/static/umap/locale/no.js +1 -11
  122. umap/static/umap/locale/no.json +1 -11
  123. umap/static/umap/locale/pl.js +1 -11
  124. umap/static/umap/locale/pl.json +1 -11
  125. umap/static/umap/locale/pl_PL.json +1 -11
  126. umap/static/umap/locale/pt.js +1 -11
  127. umap/static/umap/locale/pt.json +1 -11
  128. umap/static/umap/locale/pt_BR.js +1 -11
  129. umap/static/umap/locale/pt_BR.json +1 -11
  130. umap/static/umap/locale/pt_PT.js +1 -11
  131. umap/static/umap/locale/pt_PT.json +1 -11
  132. umap/static/umap/locale/ro.js +1 -11
  133. umap/static/umap/locale/ro.json +1 -11
  134. umap/static/umap/locale/ru.js +1 -11
  135. umap/static/umap/locale/ru.json +1 -11
  136. umap/static/umap/locale/sk_SK.js +1 -11
  137. umap/static/umap/locale/sk_SK.json +1 -11
  138. umap/static/umap/locale/sl.js +1 -11
  139. umap/static/umap/locale/sl.json +1 -11
  140. umap/static/umap/locale/sr.js +1 -11
  141. umap/static/umap/locale/sr.json +1 -11
  142. umap/static/umap/locale/sv.js +1 -11
  143. umap/static/umap/locale/sv.json +1 -11
  144. umap/static/umap/locale/th_TH.js +1 -11
  145. umap/static/umap/locale/th_TH.json +1 -11
  146. umap/static/umap/locale/tr.js +1 -11
  147. umap/static/umap/locale/tr.json +1 -11
  148. umap/static/umap/locale/uk_UA.js +1 -11
  149. umap/static/umap/locale/uk_UA.json +1 -11
  150. umap/static/umap/locale/vi.js +1 -11
  151. umap/static/umap/locale/vi.json +1 -11
  152. umap/static/umap/locale/vi_VN.json +1 -11
  153. umap/static/umap/locale/zh.js +1 -11
  154. umap/static/umap/locale/zh.json +1 -11
  155. umap/static/umap/locale/zh_CN.json +1 -11
  156. umap/static/umap/locale/zh_TW.Big5.json +1 -11
  157. umap/static/umap/locale/zh_TW.js +17 -27
  158. umap/static/umap/locale/zh_TW.json +17 -27
  159. umap/static/umap/map.css +2 -2
  160. umap/static/umap/nav.css +2 -1
  161. umap/static/umap/test/.eslintrc +0 -1
  162. umap/static/umap/test/Choropleth.js +29 -27
  163. umap/static/umap/test/DataLayer.js +207 -239
  164. umap/static/umap/test/Feature.js +33 -58
  165. umap/static/umap/test/Map.Export.js +11 -11
  166. umap/static/umap/test/Map.js +66 -67
  167. umap/static/umap/test/Marker.js +36 -32
  168. umap/static/umap/test/Polygon.js +95 -95
  169. umap/static/umap/test/Polyline.js +31 -31
  170. umap/static/umap/test/TableEditor.js +29 -25
  171. umap/static/umap/test/_pre.js +2 -7
  172. umap/static/umap/test/index.html +4 -4
  173. umap/static/umap/vendors/contextmenu/leaflet.contextmenu.css +54 -0
  174. umap/static/umap/vendors/contextmenu/leaflet.contextmenu.js +586 -0
  175. umap/static/umap/vendors/csv2geojson/index.js +259 -0
  176. umap/static/umap/vendors/dompurify/purify.js +1633 -0
  177. umap/static/umap/vendors/locatecontrol/L.Control.Locate.css +63 -0
  178. umap/static/umap/vendors/locatecontrol/L.Control.Locate.js +950 -0
  179. umap/static/umap/vendors/minimap/Control.MiniMap.css +88 -0
  180. umap/static/umap/vendors/minimap/Control.MiniMap.js +352 -0
  181. umap/static/umap/vendors/togeojson/togeojson.js +2 -0
  182. umap/templates/auth/user_form.html +3 -2
  183. umap/templates/base.html +1 -0
  184. umap/templates/registration/login.html +51 -36
  185. umap/templates/umap/about_summary.html +1 -1
  186. umap/templates/umap/branding.html +3 -0
  187. umap/templates/umap/content.html +15 -39
  188. umap/templates/umap/header.html +0 -0
  189. umap/templates/umap/home.html +4 -2
  190. umap/templates/umap/js.html +0 -1
  191. umap/templates/umap/map_detail.html +9 -0
  192. umap/templates/umap/map_init.html +1 -1
  193. umap/templates/umap/map_messages.html +4 -2
  194. umap/templates/umap/map_table.html +130 -69
  195. umap/templates/umap/navigation.html +2 -4
  196. umap/templates/umap/user_dashboard.html +29 -6
  197. umap/tests/base.py +1 -1
  198. umap/tests/integration/conftest.py +18 -0
  199. umap/tests/integration/test_anonymous_owned_map.py +6 -3
  200. umap/tests/integration/test_browser.py +166 -6
  201. umap/tests/integration/test_collaborative_editing.py +142 -0
  202. umap/tests/integration/test_dashboard.py +17 -0
  203. umap/tests/integration/test_edit_datalayer.py +4 -3
  204. umap/tests/integration/test_export_map.py +1 -1
  205. umap/tests/integration/test_import.py +9 -4
  206. umap/tests/integration/test_map.py +64 -0
  207. umap/tests/integration/test_map_preview.py +75 -0
  208. umap/tests/integration/test_owned_map.py +11 -25
  209. umap/tests/integration/test_picto.py +3 -3
  210. umap/tests/integration/test_querystring.py +52 -0
  211. umap/tests/integration/test_share.py +22 -0
  212. umap/tests/test_map_views.py +157 -14
  213. umap/tests/test_merge_features.py +5 -5
  214. umap/tests/test_views.py +50 -11
  215. umap/urls.py +6 -12
  216. umap/utils.py +1 -1
  217. umap/views.py +170 -47
  218. {umap_project-1.14.0a4.dist-info → umap_project-2.0.0a0.dist-info}/METADATA +13 -15
  219. {umap_project-1.14.0a4.dist-info → umap_project-2.0.0a0.dist-info}/RECORD +222 -200
  220. umap/static/umap/js/umap.browser.js +0 -148
  221. umap/static/umap/js/umap.xhr.js +0 -304
  222. umap/static/umap/test/Controls.js +0 -100
  223. umap/static/umap/test/Map.Init.js +0 -46
  224. {umap_project-1.14.0a4.dist-info → umap_project-2.0.0a0.dist-info}/WHEEL +0 -0
  225. {umap_project-1.14.0a4.dist-info → umap_project-2.0.0a0.dist-info}/entry_points.txt +0 -0
  226. {umap_project-1.14.0a4.dist-info → umap_project-2.0.0a0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,586 @@
1
+ /*
2
+ Leaflet.contextmenu, a context menu for Leaflet.
3
+ (c) 2015, Adam Ratcliffe, GeoSmart Maps Limited
4
+
5
+ @preserve
6
+ */
7
+
8
+ (function(factory) {
9
+ // Packaging/modules magic dance
10
+ var L;
11
+ if (typeof define === 'function' && define.amd) {
12
+ // AMD
13
+ define(['leaflet'], factory);
14
+ } else if (typeof module === 'object' && typeof module.exports === 'object') {
15
+ // Node/CommonJS
16
+ L = require('leaflet');
17
+ module.exports = factory(L);
18
+ } else {
19
+ // Browser globals
20
+ if (typeof window.L === 'undefined') {
21
+ throw new Error('Leaflet must be loaded first');
22
+ }
23
+ factory(window.L);
24
+ }
25
+ })(function(L) {
26
+ L.Map.mergeOptions({
27
+ contextmenuItems: []
28
+ });
29
+
30
+ L.Map.ContextMenu = L.Handler.extend({
31
+ _touchstart: L.Browser.msPointer ? 'MSPointerDown' : L.Browser.pointer ? 'pointerdown' : 'touchstart',
32
+
33
+ statics: {
34
+ BASE_CLS: 'leaflet-contextmenu'
35
+ },
36
+
37
+ initialize: function (map) {
38
+ L.Handler.prototype.initialize.call(this, map);
39
+
40
+ this._items = [];
41
+ this._visible = false;
42
+
43
+ var container = this._container = L.DomUtil.create('div', L.Map.ContextMenu.BASE_CLS, map._container);
44
+ container.style.zIndex = 10000;
45
+ container.style.position = 'absolute';
46
+
47
+ if (map.options.contextmenuWidth) {
48
+ container.style.width = map.options.contextmenuWidth + 'px';
49
+ }
50
+
51
+ this._createItems();
52
+
53
+ L.DomEvent
54
+ .on(container, 'click', L.DomEvent.stop)
55
+ .on(container, 'mousedown', L.DomEvent.stop)
56
+ .on(container, 'dblclick', L.DomEvent.stop)
57
+ .on(container, 'contextmenu', L.DomEvent.stop);
58
+ },
59
+
60
+ addHooks: function () {
61
+ var container = this._map.getContainer();
62
+
63
+ L.DomEvent
64
+ .on(container, 'mouseleave', this._hide, this)
65
+ .on(document, 'keydown', this._onKeyDown, this);
66
+
67
+ if (L.Browser.touch) {
68
+ L.DomEvent.on(document, this._touchstart, this._hide, this);
69
+ }
70
+
71
+ this._map.on({
72
+ contextmenu: this._show,
73
+ mousedown: this._hide,
74
+ movestart: this._hide,
75
+ zoomstart: this._hide
76
+ }, this);
77
+ },
78
+
79
+ removeHooks: function () {
80
+ var container = this._map.getContainer();
81
+
82
+ L.DomEvent
83
+ .off(container, 'mouseleave', this._hide, this)
84
+ .off(document, 'keydown', this._onKeyDown, this);
85
+
86
+ if (L.Browser.touch) {
87
+ L.DomEvent.off(document, this._touchstart, this._hide, this);
88
+ }
89
+
90
+ this._map.off({
91
+ contextmenu: this._show,
92
+ mousedown: this._hide,
93
+ movestart: this._hide,
94
+ zoomstart: this._hide
95
+ }, this);
96
+ },
97
+
98
+ showAt: function (point, data) {
99
+ if (point instanceof L.LatLng) {
100
+ point = this._map.latLngToContainerPoint(point);
101
+ }
102
+ this._showAtPoint(point, data);
103
+ },
104
+
105
+ hide: function () {
106
+ this._hide();
107
+ },
108
+
109
+ addItem: function (options) {
110
+ return this.insertItem(options);
111
+ },
112
+
113
+ insertItem: function (options, index) {
114
+ index = index !== undefined ? index: this._items.length;
115
+
116
+ var item = this._createItem(this._container, options, index);
117
+
118
+ this._items.push(item);
119
+
120
+ this._sizeChanged = true;
121
+
122
+ this._map.fire('contextmenu.additem', {
123
+ contextmenu: this,
124
+ el: item.el,
125
+ index: index
126
+ });
127
+
128
+ return item.el;
129
+ },
130
+
131
+ removeItem: function (item) {
132
+ var container = this._container;
133
+
134
+ if (!isNaN(item)) {
135
+ item = container.children[item];
136
+ }
137
+
138
+ if (item) {
139
+ this._removeItem(L.Util.stamp(item));
140
+
141
+ this._sizeChanged = true;
142
+
143
+ this._map.fire('contextmenu.removeitem', {
144
+ contextmenu: this,
145
+ el: item
146
+ });
147
+
148
+ return item;
149
+ }
150
+
151
+ return null;
152
+ },
153
+
154
+ removeAllItems: function () {
155
+ var items = this._container.children,
156
+ item;
157
+
158
+ while (items.length) {
159
+ item = items[0];
160
+ this._removeItem(L.Util.stamp(item));
161
+ }
162
+ return items;
163
+ },
164
+
165
+ hideAllItems: function () {
166
+ var item, i, l;
167
+
168
+ for (i = 0, l = this._items.length; i < l; i++) {
169
+ item = this._items[i];
170
+ item.el.style.display = 'none';
171
+ }
172
+ },
173
+
174
+ showAllItems: function () {
175
+ var item, i, l;
176
+
177
+ for (i = 0, l = this._items.length; i < l; i++) {
178
+ item = this._items[i];
179
+ item.el.style.display = '';
180
+ }
181
+ },
182
+
183
+ setDisabled: function (item, disabled) {
184
+ var container = this._container,
185
+ itemCls = L.Map.ContextMenu.BASE_CLS + '-item';
186
+
187
+ if (!isNaN(item)) {
188
+ item = container.children[item];
189
+ }
190
+
191
+ if (item && L.DomUtil.hasClass(item, itemCls)) {
192
+ if (disabled) {
193
+ L.DomUtil.addClass(item, itemCls + '-disabled');
194
+ this._map.fire('contextmenu.disableitem', {
195
+ contextmenu: this,
196
+ el: item
197
+ });
198
+ } else {
199
+ L.DomUtil.removeClass(item, itemCls + '-disabled');
200
+ this._map.fire('contextmenu.enableitem', {
201
+ contextmenu: this,
202
+ el: item
203
+ });
204
+ }
205
+ }
206
+ },
207
+
208
+ isVisible: function () {
209
+ return this._visible;
210
+ },
211
+
212
+ _createItems: function () {
213
+ var itemOptions = this._map.options.contextmenuItems,
214
+ item,
215
+ i, l;
216
+
217
+ for (i = 0, l = itemOptions.length; i < l; i++) {
218
+ this._items.push(this._createItem(this._container, itemOptions[i]));
219
+ }
220
+ },
221
+
222
+ _createItem: function (container, options, index) {
223
+ if (options.separator || options === '-') {
224
+ return this._createSeparator(container, index);
225
+ }
226
+
227
+ var itemCls = L.Map.ContextMenu.BASE_CLS + '-item',
228
+ cls = options.disabled ? (itemCls + ' ' + itemCls + '-disabled') : itemCls,
229
+ el = this._insertElementAt('a', cls, container, index),
230
+ callback = this._createEventHandler(el, options.callback, options.context, options.hideOnSelect),
231
+ icon = this._getIcon(options),
232
+ iconCls = this._getIconCls(options),
233
+ html = '';
234
+
235
+ if (icon) {
236
+ html = '<img class="' + L.Map.ContextMenu.BASE_CLS + '-icon" src="' + icon + '"/>';
237
+ } else if (iconCls) {
238
+ html = '<span class="' + L.Map.ContextMenu.BASE_CLS + '-icon ' + iconCls + '"></span>';
239
+ }
240
+
241
+ el.innerHTML = html + options.text;
242
+ el.href = '#';
243
+
244
+ L.DomEvent
245
+ .on(el, 'mouseover', this._onItemMouseOver, this)
246
+ .on(el, 'mouseout', this._onItemMouseOut, this)
247
+ .on(el, 'mousedown', L.DomEvent.stopPropagation)
248
+ .on(el, 'click', callback);
249
+
250
+ if (L.Browser.touch) {
251
+ L.DomEvent.on(el, this._touchstart, L.DomEvent.stopPropagation);
252
+ }
253
+
254
+ // Devices without a mouse fire "mouseover" on tap, but never “mouseout"
255
+ if (!L.Browser.pointer) {
256
+ L.DomEvent.on(el, 'click', this._onItemMouseOut, this);
257
+ }
258
+
259
+ return {
260
+ id: L.Util.stamp(el),
261
+ el: el,
262
+ callback: callback
263
+ };
264
+ },
265
+
266
+ _removeItem: function (id) {
267
+ var item,
268
+ el,
269
+ i, l, callback;
270
+
271
+ for (i = 0, l = this._items.length; i < l; i++) {
272
+ item = this._items[i];
273
+
274
+ if (item.id === id) {
275
+ el = item.el;
276
+ callback = item.callback;
277
+
278
+ if (callback) {
279
+ L.DomEvent
280
+ .off(el, 'mouseover', this._onItemMouseOver, this)
281
+ .off(el, 'mouseover', this._onItemMouseOut, this)
282
+ .off(el, 'mousedown', L.DomEvent.stopPropagation)
283
+ .off(el, 'click', callback);
284
+
285
+ if (L.Browser.touch) {
286
+ L.DomEvent.off(el, this._touchstart, L.DomEvent.stopPropagation);
287
+ }
288
+
289
+ if (!L.Browser.pointer) {
290
+ L.DomEvent.on(el, 'click', this._onItemMouseOut, this);
291
+ }
292
+ }
293
+
294
+ this._container.removeChild(el);
295
+ this._items.splice(i, 1);
296
+
297
+ return item;
298
+ }
299
+ }
300
+ return null;
301
+ },
302
+
303
+ _createSeparator: function (container, index) {
304
+ var el = this._insertElementAt('div', L.Map.ContextMenu.BASE_CLS + '-separator', container, index);
305
+
306
+ return {
307
+ id: L.Util.stamp(el),
308
+ el: el
309
+ };
310
+ },
311
+
312
+ _createEventHandler: function (el, func, context, hideOnSelect) {
313
+ var me = this,
314
+ map = this._map,
315
+ disabledCls = L.Map.ContextMenu.BASE_CLS + '-item-disabled',
316
+ hideOnSelect = (hideOnSelect !== undefined) ? hideOnSelect : true;
317
+
318
+ return function (e) {
319
+ if (L.DomUtil.hasClass(el, disabledCls)) {
320
+ return;
321
+ }
322
+
323
+ if (hideOnSelect) {
324
+ me._hide();
325
+ }
326
+
327
+ if (func) {
328
+ func.call(context || map, me._showLocation);
329
+ }
330
+
331
+ me._map.fire('contextmenu.select', {
332
+ contextmenu: me,
333
+ el: el
334
+ });
335
+ };
336
+ },
337
+
338
+ _insertElementAt: function (tagName, className, container, index) {
339
+ var refEl,
340
+ el = document.createElement(tagName);
341
+
342
+ el.className = className;
343
+
344
+ if (index !== undefined) {
345
+ refEl = container.children[index];
346
+ }
347
+
348
+ if (refEl) {
349
+ container.insertBefore(el, refEl);
350
+ } else {
351
+ container.appendChild(el);
352
+ }
353
+
354
+ return el;
355
+ },
356
+
357
+ _show: function (e) {
358
+ this._showAtPoint(e.containerPoint, e);
359
+ },
360
+
361
+ _showAtPoint: function (pt, data) {
362
+ if (this._items.length) {
363
+ var map = this._map,
364
+ layerPoint = map.containerPointToLayerPoint(pt),
365
+ latlng = map.layerPointToLatLng(layerPoint),
366
+ event = L.extend(data || {}, {contextmenu: this});
367
+
368
+ this._showLocation = {
369
+ latlng: latlng,
370
+ layerPoint: layerPoint,
371
+ containerPoint: pt
372
+ };
373
+
374
+ if (data && data.relatedTarget){
375
+ this._showLocation.relatedTarget = data.relatedTarget;
376
+ }
377
+
378
+ this._setPosition(pt);
379
+
380
+ if (!this._visible) {
381
+ this._container.style.display = 'block';
382
+ this._visible = true;
383
+ }
384
+
385
+ this._map.fire('contextmenu.show', event);
386
+ }
387
+ },
388
+
389
+ _hide: function () {
390
+ if (this._visible) {
391
+ this._visible = false;
392
+ this._container.style.display = 'none';
393
+ this._map.fire('contextmenu.hide', {contextmenu: this});
394
+ }
395
+ },
396
+
397
+ _getIcon: function (options) {
398
+ return L.Browser.retina && options.retinaIcon || options.icon;
399
+ },
400
+
401
+ _getIconCls: function (options) {
402
+ return L.Browser.retina && options.retinaIconCls || options.iconCls;
403
+ },
404
+
405
+ _setPosition: function (pt) {
406
+ var mapSize = this._map.getSize(),
407
+ container = this._container,
408
+ containerSize = this._getElementSize(container),
409
+ anchor;
410
+
411
+ if (this._map.options.contextmenuAnchor) {
412
+ anchor = L.point(this._map.options.contextmenuAnchor);
413
+ pt = pt.add(anchor);
414
+ }
415
+
416
+ container._leaflet_pos = pt;
417
+
418
+ if (pt.x + containerSize.x > mapSize.x) {
419
+ container.style.left = 'auto';
420
+ container.style.right = Math.min(Math.max(mapSize.x - pt.x, 0), mapSize.x - containerSize.x - 1) + 'px';
421
+ } else {
422
+ container.style.left = Math.max(pt.x, 0) + 'px';
423
+ container.style.right = 'auto';
424
+ }
425
+
426
+ if (pt.y + containerSize.y > mapSize.y) {
427
+ container.style.top = 'auto';
428
+ container.style.bottom = Math.min(Math.max(mapSize.y - pt.y, 0), mapSize.y - containerSize.y - 1) + 'px';
429
+ } else {
430
+ container.style.top = Math.max(pt.y, 0) + 'px';
431
+ container.style.bottom = 'auto';
432
+ }
433
+ },
434
+
435
+ _getElementSize: function (el) {
436
+ var size = this._size,
437
+ initialDisplay = el.style.display;
438
+
439
+ if (!size || this._sizeChanged) {
440
+ size = {};
441
+
442
+ el.style.left = '-999999px';
443
+ el.style.right = 'auto';
444
+ el.style.display = 'block';
445
+
446
+ size.x = el.offsetWidth;
447
+ size.y = el.offsetHeight;
448
+
449
+ el.style.left = 'auto';
450
+ el.style.display = initialDisplay;
451
+
452
+ this._sizeChanged = false;
453
+ }
454
+
455
+ return size;
456
+ },
457
+
458
+ _onKeyDown: function (e) {
459
+ var key = e.keyCode;
460
+
461
+ // If ESC pressed and context menu is visible hide it
462
+ if (key === 27) {
463
+ this._hide();
464
+ }
465
+ },
466
+
467
+ _onItemMouseOver: function (e) {
468
+ L.DomUtil.addClass(e.target || e.srcElement, 'over');
469
+ },
470
+
471
+ _onItemMouseOut: function (e) {
472
+ L.DomUtil.removeClass(e.target || e.srcElement, 'over');
473
+ }
474
+ });
475
+
476
+ L.Map.addInitHook('addHandler', 'contextmenu', L.Map.ContextMenu);
477
+ L.Mixin.ContextMenu = {
478
+ bindContextMenu: function (options) {
479
+ L.setOptions(this, options);
480
+ this._initContextMenu();
481
+
482
+ return this;
483
+ },
484
+
485
+ unbindContextMenu: function (){
486
+ this.off('contextmenu', this._showContextMenu, this);
487
+
488
+ return this;
489
+ },
490
+
491
+ addContextMenuItem: function (item) {
492
+ this.options.contextmenuItems.push(item);
493
+ },
494
+
495
+ removeContextMenuItemWithIndex: function (index) {
496
+ var items = [];
497
+ for (var i = 0; i < this.options.contextmenuItems.length; i++) {
498
+ if (this.options.contextmenuItems[i].index == index){
499
+ items.push(i);
500
+ }
501
+ }
502
+ var elem = items.pop();
503
+ while (elem !== undefined) {
504
+ this.options.contextmenuItems.splice(elem,1);
505
+ elem = items.pop();
506
+ }
507
+ },
508
+
509
+ replaceContextMenuItem: function (item) {
510
+ this.removeContextMenuItemWithIndex(item.index);
511
+ this.addContextMenuItem(item);
512
+ },
513
+
514
+ _initContextMenu: function () {
515
+ this._items = [];
516
+
517
+ this.on('contextmenu', this._showContextMenu, this);
518
+ },
519
+
520
+ _showContextMenu: function (e) {
521
+ var itemOptions,
522
+ data, pt, i, l;
523
+
524
+ if (this._map.contextmenu) {
525
+ data = L.extend({relatedTarget: this}, e);
526
+
527
+ pt = this._map.mouseEventToContainerPoint(e.originalEvent);
528
+
529
+ if (!this.options.contextmenuInheritItems) {
530
+ this._map.contextmenu.hideAllItems();
531
+ }
532
+
533
+ for (i = 0, l = this.options.contextmenuItems.length; i < l; i++) {
534
+ itemOptions = this.options.contextmenuItems[i];
535
+ this._items.push(this._map.contextmenu.insertItem(itemOptions, itemOptions.index));
536
+ }
537
+
538
+ this._map.once('contextmenu.hide', this._hideContextMenu, this);
539
+
540
+ this._map.contextmenu.showAt(pt, data);
541
+ }
542
+ },
543
+
544
+ _hideContextMenu: function () {
545
+ var i, l;
546
+
547
+ for (i = 0, l = this._items.length; i < l; i++) {
548
+ this._map.contextmenu.removeItem(this._items[i]);
549
+ }
550
+ this._items.length = 0;
551
+
552
+ if (!this.options.contextmenuInheritItems) {
553
+ this._map.contextmenu.showAllItems();
554
+ }
555
+ }
556
+ };
557
+
558
+ var classes = [L.Marker, L.Path],
559
+ defaultOptions = {
560
+ contextmenu: false,
561
+ contextmenuItems: [],
562
+ contextmenuInheritItems: true
563
+ },
564
+ cls, i, l;
565
+
566
+ for (i = 0, l = classes.length; i < l; i++) {
567
+ cls = classes[i];
568
+
569
+ // L.Class should probably provide an empty options hash, as it does not test
570
+ // for it here and add if needed
571
+ if (!cls.prototype.options) {
572
+ cls.prototype.options = defaultOptions;
573
+ } else {
574
+ cls.mergeOptions(defaultOptions);
575
+ }
576
+
577
+ cls.addInitHook(function () {
578
+ if (this.options.contextmenu) {
579
+ this._initContextMenu();
580
+ }
581
+ });
582
+
583
+ cls.include(L.Mixin.ContextMenu);
584
+ }
585
+ return L.Map.ContextMenu;
586
+ });