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,950 @@
1
+ /*!
2
+ Copyright (c) 2016 Dominik Moritz
3
+
4
+ This file is part of the leaflet locate control. It is licensed under the MIT license.
5
+ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
6
+ */
7
+ (function (factory, window) {
8
+ // see https://github.com/Leaflet/Leaflet/blob/master/PLUGIN-GUIDE.md#module-loaders
9
+ // for details on how to structure a leaflet plugin.
10
+
11
+ // define an AMD module that relies on 'leaflet'
12
+ if (typeof define === "function" && define.amd) {
13
+ define(["leaflet"], factory);
14
+
15
+ // define a Common JS module that relies on 'leaflet'
16
+ } else if (typeof exports === "object") {
17
+ if (typeof window !== "undefined" && window.L) {
18
+ module.exports = factory(L);
19
+ } else {
20
+ module.exports = factory(require("leaflet"));
21
+ }
22
+ }
23
+
24
+ // attach your plugin to the global 'L' variable
25
+ if (typeof window !== "undefined" && window.L) {
26
+ window.L.Control.Locate = factory(L);
27
+ }
28
+ })(function (L) {
29
+ const LDomUtilApplyClassesMethod = (method, element, classNames) => {
30
+ classNames = classNames.split(" ");
31
+ classNames.forEach(function (className) {
32
+ L.DomUtil[method].call(this, element, className);
33
+ });
34
+ };
35
+
36
+ const addClasses = (el, names) => LDomUtilApplyClassesMethod("addClass", el, names);
37
+ const removeClasses = (el, names) => LDomUtilApplyClassesMethod("removeClass", el, names);
38
+
39
+ /**
40
+ * Compatible with L.Circle but a true marker instead of a path
41
+ */
42
+ const LocationMarker = L.Marker.extend({
43
+ initialize(latlng, options) {
44
+ L.Util.setOptions(this, options);
45
+ this._latlng = latlng;
46
+ this.createIcon();
47
+ },
48
+
49
+ /**
50
+ * Create a styled circle location marker
51
+ */
52
+ createIcon() {
53
+ const opt = this.options;
54
+
55
+ let style = "";
56
+
57
+ if (opt.color !== undefined) {
58
+ style += `stroke:${opt.color};`;
59
+ }
60
+ if (opt.weight !== undefined) {
61
+ style += `stroke-width:${opt.weight};`;
62
+ }
63
+ if (opt.fillColor !== undefined) {
64
+ style += `fill:${opt.fillColor};`;
65
+ }
66
+ if (opt.fillOpacity !== undefined) {
67
+ style += `fill-opacity:${opt.fillOpacity};`;
68
+ }
69
+ if (opt.opacity !== undefined) {
70
+ style += `opacity:${opt.opacity};`;
71
+ }
72
+
73
+ const icon = this._getIconSVG(opt, style);
74
+
75
+ this._locationIcon = L.divIcon({
76
+ className: icon.className,
77
+ html: icon.svg,
78
+ iconSize: [icon.w, icon.h]
79
+ });
80
+
81
+ this.setIcon(this._locationIcon);
82
+ },
83
+
84
+ /**
85
+ * Return the raw svg for the shape
86
+ *
87
+ * Split so can be easily overridden
88
+ */
89
+ _getIconSVG(options, style) {
90
+ const r = options.radius;
91
+ const w = options.weight;
92
+ const s = r + w;
93
+ const s2 = s * 2;
94
+ const svg =
95
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${s2}" height="${s2}" version="1.1" viewBox="-${s} -${s} ${s2} ${s2}">` +
96
+ '<circle r="' +
97
+ r +
98
+ '" style="' +
99
+ style +
100
+ '" />' +
101
+ "</svg>";
102
+ return {
103
+ className: "leaflet-control-locate-location",
104
+ svg,
105
+ w: s2,
106
+ h: s2
107
+ };
108
+ },
109
+
110
+ setStyle(style) {
111
+ L.Util.setOptions(this, style);
112
+ this.createIcon();
113
+ }
114
+ });
115
+
116
+ const CompassMarker = LocationMarker.extend({
117
+ initialize(latlng, heading, options) {
118
+ L.Util.setOptions(this, options);
119
+ this._latlng = latlng;
120
+ this._heading = heading;
121
+ this.createIcon();
122
+ },
123
+
124
+ setHeading(heading) {
125
+ this._heading = heading;
126
+ },
127
+
128
+ /**
129
+ * Create a styled arrow compass marker
130
+ */
131
+ _getIconSVG(options, style) {
132
+ const r = options.radius;
133
+ const w = options.width + options.weight;
134
+ const h = (r + options.depth + options.weight) * 2;
135
+ const path = `M0,0 l${options.width / 2},${options.depth} l-${w},0 z`;
136
+ const svgstyle = `transform: rotate(${this._heading}deg)`;
137
+ const svg =
138
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" version="1.1" viewBox="-${w / 2} 0 ${w} ${h}" style="${svgstyle}">` +
139
+ '<path d="' +
140
+ path +
141
+ '" style="' +
142
+ style +
143
+ '" />' +
144
+ "</svg>";
145
+ return {
146
+ className: "leaflet-control-locate-heading",
147
+ svg,
148
+ w,
149
+ h
150
+ };
151
+ }
152
+ });
153
+
154
+ const LocateControl = L.Control.extend({
155
+ options: {
156
+ /** Position of the control */
157
+ position: "topleft",
158
+ /** The layer that the user's location should be drawn on. By default creates a new layer. */
159
+ layer: undefined,
160
+ /**
161
+ * Automatically sets the map view (zoom and pan) to the user's location as it updates.
162
+ * While the map is following the user's location, the control is in the `following` state,
163
+ * which changes the style of the control and the circle marker.
164
+ *
165
+ * Possible values:
166
+ * - false: never updates the map view when location changes.
167
+ * - 'once': set the view when the location is first determined
168
+ * - 'always': always updates the map view when location changes.
169
+ * The map view follows the user's location.
170
+ * - 'untilPan': like 'always', except stops updating the
171
+ * view if the user has manually panned the map.
172
+ * The map view follows the user's location until she pans.
173
+ * - 'untilPanOrZoom': (default) like 'always', except stops updating the
174
+ * view if the user has manually panned the map.
175
+ * The map view follows the user's location until she pans.
176
+ */
177
+ setView: "untilPanOrZoom",
178
+ /** Keep the current map zoom level when setting the view and only pan. */
179
+ keepCurrentZoomLevel: false,
180
+ /** After activating the plugin by clicking on the icon, zoom to the selected zoom level, even when keepCurrentZoomLevel is true. Set to 'false' to disable this feature. */
181
+ initialZoomLevel: false,
182
+ /**
183
+ * This callback can be used to override the viewport tracking
184
+ * This function should return a LatLngBounds object.
185
+ *
186
+ * For example to extend the viewport to ensure that a particular LatLng is visible:
187
+ *
188
+ * getLocationBounds: function(locationEvent) {
189
+ * return locationEvent.bounds.extend([-33.873085, 151.219273]);
190
+ * },
191
+ */
192
+ getLocationBounds(locationEvent) {
193
+ return locationEvent.bounds;
194
+ },
195
+ /** Smooth pan and zoom to the location of the marker. Only works in Leaflet 1.0+. */
196
+ flyTo: false,
197
+ /**
198
+ * The user location can be inside and outside the current view when the user clicks on the
199
+ * control that is already active. Both cases can be configures separately.
200
+ * Possible values are:
201
+ * - 'setView': zoom and pan to the current location
202
+ * - 'stop': stop locating and remove the location marker
203
+ */
204
+ clickBehavior: {
205
+ /** What should happen if the user clicks on the control while the location is within the current view. */
206
+ inView: "stop",
207
+ /** What should happen if the user clicks on the control while the location is outside the current view. */
208
+ outOfView: "setView",
209
+ /**
210
+ * What should happen if the user clicks on the control while the location is within the current view
211
+ * and we could be following but are not. Defaults to a special value which inherits from 'inView';
212
+ */
213
+ inViewNotFollowing: "inView"
214
+ },
215
+ /**
216
+ * If set, save the map bounds just before centering to the user's
217
+ * location. When control is disabled, set the view back to the
218
+ * bounds that were saved.
219
+ */
220
+ returnToPrevBounds: false,
221
+ /**
222
+ * Keep a cache of the location after the user deactivates the control. If set to false, the user has to wait
223
+ * until the locate API returns a new location before they see where they are again.
224
+ */
225
+ cacheLocation: true,
226
+ /** If set, a circle that shows the location accuracy is drawn. */
227
+ drawCircle: true,
228
+ /** If set, the marker at the users' location is drawn. */
229
+ drawMarker: true,
230
+ /** If set and supported then show the compass heading */
231
+ showCompass: true,
232
+ /** The class to be used to create the marker. For example L.CircleMarker or L.Marker */
233
+ markerClass: LocationMarker,
234
+ /** The class us be used to create the compass bearing arrow */
235
+ compassClass: CompassMarker,
236
+ /** Accuracy circle style properties. NOTE these styles should match the css animations styles */
237
+ circleStyle: {
238
+ className: "leaflet-control-locate-circle",
239
+ color: "#136AEC",
240
+ fillColor: "#136AEC",
241
+ fillOpacity: 0.15,
242
+ weight: 0
243
+ },
244
+ /** Inner marker style properties. Only works if your marker class supports `setStyle`. */
245
+ markerStyle: {
246
+ className: "leaflet-control-locate-marker",
247
+ color: "#fff",
248
+ fillColor: "#2A93EE",
249
+ fillOpacity: 1,
250
+ weight: 3,
251
+ opacity: 1,
252
+ radius: 9
253
+ },
254
+ /** Compass */
255
+ compassStyle: {
256
+ fillColor: "#2A93EE",
257
+ fillOpacity: 1,
258
+ weight: 0,
259
+ color: "#fff",
260
+ opacity: 1,
261
+ radius: 9, // How far is the arrow is from the center of of the marker
262
+ width: 9, // Width of the arrow
263
+ depth: 6 // Length of the arrow
264
+ },
265
+ /**
266
+ * Changes to accuracy circle and inner marker while following.
267
+ * It is only necessary to provide the properties that should change.
268
+ */
269
+ followCircleStyle: {},
270
+ followMarkerStyle: {
271
+ // color: '#FFA500',
272
+ // fillColor: '#FFB000'
273
+ },
274
+ followCompassStyle: {},
275
+ /** The CSS class for the icon. For example fa-location-arrow or fa-map-marker */
276
+ icon: "leaflet-control-locate-location-arrow",
277
+ iconLoading: "leaflet-control-locate-spinner",
278
+ /** The element to be created for icons. For example span or i */
279
+ iconElementTag: "span",
280
+ /** The element to be created for the text. For example small or span */
281
+ textElementTag: "small",
282
+ /** Padding around the accuracy circle. */
283
+ circlePadding: [0, 0],
284
+ /** Use metric units. */
285
+ metric: true,
286
+ /**
287
+ * This callback can be used in case you would like to override button creation behavior.
288
+ * This is useful for DOM manipulation frameworks such as angular etc.
289
+ * This function should return an object with HtmlElement for the button (link property) and the icon (icon property).
290
+ */
291
+ createButtonCallback(container, options) {
292
+ const link = L.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", container);
293
+ link.title = options.strings.title;
294
+ link.href = "#";
295
+ link.setAttribute("role", "button");
296
+ const icon = L.DomUtil.create(options.iconElementTag, options.icon, link);
297
+
298
+ if (options.strings.text !== undefined) {
299
+ const text = L.DomUtil.create(options.textElementTag, "leaflet-locate-text", link);
300
+ text.textContent = options.strings.text;
301
+ link.classList.add("leaflet-locate-text-active");
302
+ link.parentNode.style.display = "flex";
303
+ if (options.icon.length > 0) {
304
+ icon.classList.add("leaflet-locate-icon");
305
+ }
306
+ }
307
+
308
+ return { link, icon };
309
+ },
310
+ /** This event is called in case of any location error that is not a time out error. */
311
+ onLocationError(err, control) {
312
+ alert(err.message);
313
+ },
314
+ /**
315
+ * This event is called when the user's location is outside the bounds set on the map.
316
+ * The event is called repeatedly when the location changes.
317
+ */
318
+ onLocationOutsideMapBounds(control) {
319
+ control.stop();
320
+ alert(control.options.strings.outsideMapBoundsMsg);
321
+ },
322
+ /** Display a pop-up when the user click on the inner marker. */
323
+ showPopup: true,
324
+ strings: {
325
+ title: "Show me where I am",
326
+ metersUnit: "meters",
327
+ feetUnit: "feet",
328
+ popup: "You are within {distance} {unit} from this point",
329
+ outsideMapBoundsMsg: "You seem located outside the boundaries of the map"
330
+ },
331
+ /** The default options passed to leaflets locate method. */
332
+ locateOptions: {
333
+ maxZoom: Infinity,
334
+ watch: true, // if you overwrite this, visualization cannot be updated
335
+ setView: false // have to set this to false because we have to
336
+ // do setView manually
337
+ }
338
+ },
339
+
340
+ initialize(options) {
341
+ // set default options if nothing is set (merge one step deep)
342
+ for (const i in options) {
343
+ if (typeof this.options[i] === "object") {
344
+ L.extend(this.options[i], options[i]);
345
+ } else {
346
+ this.options[i] = options[i];
347
+ }
348
+ }
349
+
350
+ // extend the follow marker style and circle from the normal style
351
+ this.options.followMarkerStyle = L.extend({}, this.options.markerStyle, this.options.followMarkerStyle);
352
+ this.options.followCircleStyle = L.extend({}, this.options.circleStyle, this.options.followCircleStyle);
353
+ this.options.followCompassStyle = L.extend({}, this.options.compassStyle, this.options.followCompassStyle);
354
+ },
355
+
356
+ /**
357
+ * Add control to map. Returns the container for the control.
358
+ */
359
+ onAdd(map) {
360
+ const container = L.DomUtil.create("div", "leaflet-control-locate leaflet-bar leaflet-control");
361
+ this._container = container;
362
+ this._map = map;
363
+ this._layer = this.options.layer || new L.LayerGroup();
364
+ this._layer.addTo(map);
365
+ this._event = undefined;
366
+ this._compassHeading = null;
367
+ this._prevBounds = null;
368
+
369
+ const linkAndIcon = this.options.createButtonCallback(container, this.options);
370
+ this._link = linkAndIcon.link;
371
+ this._icon = linkAndIcon.icon;
372
+
373
+ L.DomEvent.on(
374
+ this._link,
375
+ "click",
376
+ function (ev) {
377
+ L.DomEvent.stopPropagation(ev);
378
+ L.DomEvent.preventDefault(ev);
379
+ this._onClick();
380
+ },
381
+ this
382
+ ).on(this._link, "dblclick", L.DomEvent.stopPropagation);
383
+
384
+ this._resetVariables();
385
+
386
+ this._map.on("unload", this._unload, this);
387
+
388
+ return container;
389
+ },
390
+
391
+ /**
392
+ * This method is called when the user clicks on the control.
393
+ */
394
+ _onClick() {
395
+ this._justClicked = true;
396
+ const wasFollowing = this._isFollowing();
397
+ this._userPanned = false;
398
+ this._userZoomed = false;
399
+
400
+ if (this._active && !this._event) {
401
+ // click while requesting
402
+ this.stop();
403
+ } else if (this._active) {
404
+ const behaviors = this.options.clickBehavior;
405
+ let behavior = behaviors.outOfView;
406
+ if (this._map.getBounds().contains(this._event.latlng)) {
407
+ behavior = wasFollowing ? behaviors.inView : behaviors.inViewNotFollowing;
408
+ }
409
+
410
+ // Allow inheriting from another behavior
411
+ if (behaviors[behavior]) {
412
+ behavior = behaviors[behavior];
413
+ }
414
+
415
+ switch (behavior) {
416
+ case "setView":
417
+ this.setView();
418
+ break;
419
+ case "stop":
420
+ this.stop();
421
+ if (this.options.returnToPrevBounds) {
422
+ const f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
423
+ f.bind(this._map)(this._prevBounds);
424
+ }
425
+ break;
426
+ }
427
+ } else {
428
+ if (this.options.returnToPrevBounds) {
429
+ this._prevBounds = this._map.getBounds();
430
+ }
431
+ this.start();
432
+ }
433
+
434
+ this._updateContainerStyle();
435
+ },
436
+
437
+ /**
438
+ * Starts the plugin:
439
+ * - activates the engine
440
+ * - draws the marker (if coordinates available)
441
+ */
442
+ start() {
443
+ this._activate();
444
+
445
+ if (this._event) {
446
+ this._drawMarker(this._map);
447
+
448
+ // if we already have a location but the user clicked on the control
449
+ if (this.options.setView) {
450
+ this.setView();
451
+ }
452
+ }
453
+ this._updateContainerStyle();
454
+ },
455
+
456
+ /**
457
+ * Stops the plugin:
458
+ * - deactivates the engine
459
+ * - reinitializes the button
460
+ * - removes the marker
461
+ */
462
+ stop() {
463
+ this._deactivate();
464
+
465
+ this._cleanClasses();
466
+ this._resetVariables();
467
+
468
+ this._removeMarker();
469
+ },
470
+
471
+ /**
472
+ * Keep the control active but stop following the location
473
+ */
474
+ stopFollowing() {
475
+ this._userPanned = true;
476
+ this._updateContainerStyle();
477
+ this._drawMarker();
478
+ },
479
+
480
+ /**
481
+ * This method launches the location engine.
482
+ * It is called before the marker is updated,
483
+ * event if it does not mean that the event will be ready.
484
+ *
485
+ * Override it if you want to add more functionalities.
486
+ * It should set the this._active to true and do nothing if
487
+ * this._active is true.
488
+ */
489
+ _activate() {
490
+ if (this._active || !this._map) {
491
+ return;
492
+ }
493
+
494
+ this._map.locate(this.options.locateOptions);
495
+ this._map.fire("locateactivate", this);
496
+ this._active = true;
497
+
498
+ // bind event listeners
499
+ this._map.on("locationfound", this._onLocationFound, this);
500
+ this._map.on("locationerror", this._onLocationError, this);
501
+ this._map.on("dragstart", this._onDrag, this);
502
+ this._map.on("zoomstart", this._onZoom, this);
503
+ this._map.on("zoomend", this._onZoomEnd, this);
504
+ if (this.options.showCompass) {
505
+ const oriAbs = "ondeviceorientationabsolute" in window;
506
+ if (oriAbs || "ondeviceorientation" in window) {
507
+ const _this = this;
508
+ const deviceorientation = function () {
509
+ L.DomEvent.on(window, oriAbs ? "deviceorientationabsolute" : "deviceorientation", _this._onDeviceOrientation, _this);
510
+ };
511
+ if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") {
512
+ DeviceOrientationEvent.requestPermission().then(function (permissionState) {
513
+ if (permissionState === "granted") {
514
+ deviceorientation();
515
+ }
516
+ });
517
+ } else {
518
+ deviceorientation();
519
+ }
520
+ }
521
+ }
522
+ },
523
+
524
+ /**
525
+ * Called to stop the location engine.
526
+ *
527
+ * Override it to shutdown any functionalities you added on start.
528
+ */
529
+ _deactivate() {
530
+ if (!this._active || !this._map) {
531
+ return;
532
+ }
533
+
534
+ this._map.stopLocate();
535
+ this._map.fire("locatedeactivate", this);
536
+ this._active = false;
537
+
538
+ if (!this.options.cacheLocation) {
539
+ this._event = undefined;
540
+ }
541
+
542
+ // unbind event listeners
543
+ this._map.off("locationfound", this._onLocationFound, this);
544
+ this._map.off("locationerror", this._onLocationError, this);
545
+ this._map.off("dragstart", this._onDrag, this);
546
+ this._map.off("zoomstart", this._onZoom, this);
547
+ this._map.off("zoomend", this._onZoomEnd, this);
548
+ if (this.options.showCompass) {
549
+ this._compassHeading = null;
550
+ if ("ondeviceorientationabsolute" in window) {
551
+ L.DomEvent.off(window, "deviceorientationabsolute", this._onDeviceOrientation, this);
552
+ } else if ("ondeviceorientation" in window) {
553
+ L.DomEvent.off(window, "deviceorientation", this._onDeviceOrientation, this);
554
+ }
555
+ }
556
+ },
557
+
558
+ /**
559
+ * Zoom (unless we should keep the zoom level) and an to the current view.
560
+ */
561
+ setView() {
562
+ this._drawMarker();
563
+ if (this._isOutsideMapBounds()) {
564
+ this._event = undefined; // clear the current location so we can get back into the bounds
565
+ this.options.onLocationOutsideMapBounds(this);
566
+ } else {
567
+ if (this._justClicked && this.options.initialZoomLevel !== false) {
568
+ var f = this.options.flyTo ? this._map.flyTo : this._map.setView;
569
+ f.bind(this._map)([this._event.latitude, this._event.longitude], this.options.initialZoomLevel);
570
+ } else if (this.options.keepCurrentZoomLevel) {
571
+ var f = this.options.flyTo ? this._map.flyTo : this._map.panTo;
572
+ f.bind(this._map)([this._event.latitude, this._event.longitude]);
573
+ } else {
574
+ var f = this.options.flyTo ? this._map.flyToBounds : this._map.fitBounds;
575
+ // Ignore zoom events while setting the viewport as these would stop following
576
+ this._ignoreEvent = true;
577
+ f.bind(this._map)(this.options.getLocationBounds(this._event), {
578
+ padding: this.options.circlePadding,
579
+ maxZoom: this.options.initialZoomLevel || this.options.locateOptions.maxZoom
580
+ });
581
+ L.Util.requestAnimFrame(function () {
582
+ // Wait until after the next animFrame because the flyTo can be async
583
+ this._ignoreEvent = false;
584
+ }, this);
585
+ }
586
+ }
587
+ },
588
+
589
+ /**
590
+ *
591
+ */
592
+ _drawCompass() {
593
+ if (!this._event) {
594
+ return;
595
+ }
596
+
597
+ const latlng = this._event.latlng;
598
+
599
+ if (this.options.showCompass && latlng && this._compassHeading !== null) {
600
+ const cStyle = this._isFollowing() ? this.options.followCompassStyle : this.options.compassStyle;
601
+ if (!this._compass) {
602
+ this._compass = new this.options.compassClass(latlng, this._compassHeading, cStyle).addTo(this._layer);
603
+ } else {
604
+ this._compass.setLatLng(latlng);
605
+ this._compass.setHeading(this._compassHeading);
606
+ // If the compassClass can be updated with setStyle, update it.
607
+ if (this._compass.setStyle) {
608
+ this._compass.setStyle(cStyle);
609
+ }
610
+ }
611
+ //
612
+ }
613
+ if (this._compass && (!this.options.showCompass || this._compassHeading === null)) {
614
+ this._compass.removeFrom(this._layer);
615
+ this._compass = null;
616
+ }
617
+ },
618
+
619
+ /**
620
+ * Draw the marker and accuracy circle on the map.
621
+ *
622
+ * Uses the event retrieved from onLocationFound from the map.
623
+ */
624
+ _drawMarker() {
625
+ if (this._event.accuracy === undefined) {
626
+ this._event.accuracy = 0;
627
+ }
628
+
629
+ const radius = this._event.accuracy;
630
+ const latlng = this._event.latlng;
631
+
632
+ // circle with the radius of the location's accuracy
633
+ if (this.options.drawCircle) {
634
+ const style = this._isFollowing() ? this.options.followCircleStyle : this.options.circleStyle;
635
+
636
+ if (!this._circle) {
637
+ this._circle = L.circle(latlng, radius, style).addTo(this._layer);
638
+ } else {
639
+ this._circle.setLatLng(latlng).setRadius(radius).setStyle(style);
640
+ }
641
+ }
642
+
643
+ let distance;
644
+ let unit;
645
+ if (this.options.metric) {
646
+ distance = radius.toFixed(0);
647
+ unit = this.options.strings.metersUnit;
648
+ } else {
649
+ distance = (radius * 3.2808399).toFixed(0);
650
+ unit = this.options.strings.feetUnit;
651
+ }
652
+
653
+ // small inner marker
654
+ if (this.options.drawMarker) {
655
+ const mStyle = this._isFollowing() ? this.options.followMarkerStyle : this.options.markerStyle;
656
+ if (!this._marker) {
657
+ this._marker = new this.options.markerClass(latlng, mStyle).addTo(this._layer);
658
+ } else {
659
+ this._marker.setLatLng(latlng);
660
+ // If the markerClass can be updated with setStyle, update it.
661
+ if (this._marker.setStyle) {
662
+ this._marker.setStyle(mStyle);
663
+ }
664
+ }
665
+ }
666
+
667
+ this._drawCompass();
668
+
669
+ const t = this.options.strings.popup;
670
+ function getPopupText() {
671
+ if (typeof t === "string") {
672
+ return L.Util.template(t, { distance, unit });
673
+ } else if (typeof t === "function") {
674
+ return t({ distance, unit });
675
+ } else {
676
+ return t;
677
+ }
678
+ }
679
+ if (this.options.showPopup && t && this._marker) {
680
+ this._marker.bindPopup(getPopupText())._popup.setLatLng(latlng);
681
+ }
682
+ if (this.options.showPopup && t && this._compass) {
683
+ this._compass.bindPopup(getPopupText())._popup.setLatLng(latlng);
684
+ }
685
+ },
686
+
687
+ /**
688
+ * Remove the marker from map.
689
+ */
690
+ _removeMarker() {
691
+ this._layer.clearLayers();
692
+ this._marker = undefined;
693
+ this._circle = undefined;
694
+ },
695
+
696
+ /**
697
+ * Unload the plugin and all event listeners.
698
+ * Kind of the opposite of onAdd.
699
+ */
700
+ _unload() {
701
+ this.stop();
702
+ this._map.off("unload", this._unload, this);
703
+ },
704
+
705
+ /**
706
+ * Sets the compass heading
707
+ */
708
+ _setCompassHeading(angle) {
709
+ if (!isNaN(parseFloat(angle)) && isFinite(angle)) {
710
+ angle = Math.round(angle);
711
+
712
+ this._compassHeading = angle;
713
+ L.Util.requestAnimFrame(this._drawCompass, this);
714
+ } else {
715
+ this._compassHeading = null;
716
+ }
717
+ },
718
+
719
+ /**
720
+ * If the compass fails calibration just fail safely and remove the compass
721
+ */
722
+ _onCompassNeedsCalibration() {
723
+ this._setCompassHeading();
724
+ },
725
+
726
+ /**
727
+ * Process and normalise compass events
728
+ */
729
+ _onDeviceOrientation(e) {
730
+ if (!this._active) {
731
+ return;
732
+ }
733
+
734
+ if (e.webkitCompassHeading) {
735
+ // iOS
736
+ this._setCompassHeading(e.webkitCompassHeading);
737
+ } else if (e.absolute && e.alpha) {
738
+ // Android
739
+ this._setCompassHeading(360 - e.alpha);
740
+ }
741
+ },
742
+
743
+ /**
744
+ * Calls deactivate and dispatches an error.
745
+ */
746
+ _onLocationError(err) {
747
+ // ignore time out error if the location is watched
748
+ if (err.code == 3 && this.options.locateOptions.watch) {
749
+ return;
750
+ }
751
+
752
+ this.stop();
753
+ this.options.onLocationError(err, this);
754
+ },
755
+
756
+ /**
757
+ * Stores the received event and updates the marker.
758
+ */
759
+ _onLocationFound(e) {
760
+ // no need to do anything if the location has not changed
761
+ if (this._event && this._event.latlng.lat === e.latlng.lat && this._event.latlng.lng === e.latlng.lng && this._event.accuracy === e.accuracy) {
762
+ return;
763
+ }
764
+
765
+ if (!this._active) {
766
+ // we may have a stray event
767
+ return;
768
+ }
769
+
770
+ this._event = e;
771
+
772
+ this._drawMarker();
773
+ this._updateContainerStyle();
774
+
775
+ switch (this.options.setView) {
776
+ case "once":
777
+ if (this._justClicked) {
778
+ this.setView();
779
+ }
780
+ break;
781
+ case "untilPan":
782
+ if (!this._userPanned) {
783
+ this.setView();
784
+ }
785
+ break;
786
+ case "untilPanOrZoom":
787
+ if (!this._userPanned && !this._userZoomed) {
788
+ this.setView();
789
+ }
790
+ break;
791
+ case "always":
792
+ this.setView();
793
+ break;
794
+ case false:
795
+ // don't set the view
796
+ break;
797
+ }
798
+
799
+ this._justClicked = false;
800
+ },
801
+
802
+ /**
803
+ * When the user drags. Need a separate event so we can bind and unbind event listeners.
804
+ */
805
+ _onDrag() {
806
+ // only react to drags once we have a location
807
+ if (this._event && !this._ignoreEvent) {
808
+ this._userPanned = true;
809
+ this._updateContainerStyle();
810
+ this._drawMarker();
811
+ }
812
+ },
813
+
814
+ /**
815
+ * When the user zooms. Need a separate event so we can bind and unbind event listeners.
816
+ */
817
+ _onZoom() {
818
+ // only react to drags once we have a location
819
+ if (this._event && !this._ignoreEvent) {
820
+ this._userZoomed = true;
821
+ this._updateContainerStyle();
822
+ this._drawMarker();
823
+ }
824
+ },
825
+
826
+ /**
827
+ * After a zoom ends update the compass and handle sideways zooms
828
+ */
829
+ _onZoomEnd() {
830
+ if (this._event) {
831
+ this._drawCompass();
832
+ }
833
+
834
+ if (this._event && !this._ignoreEvent) {
835
+ // If we have zoomed in and out and ended up sideways treat it as a pan
836
+ if (this._marker && !this._map.getBounds().pad(-0.3).contains(this._marker.getLatLng())) {
837
+ this._userPanned = true;
838
+ this._updateContainerStyle();
839
+ this._drawMarker();
840
+ }
841
+ }
842
+ },
843
+
844
+ /**
845
+ * Compute whether the map is following the user location with pan and zoom.
846
+ */
847
+ _isFollowing() {
848
+ if (!this._active) {
849
+ return false;
850
+ }
851
+
852
+ if (this.options.setView === "always") {
853
+ return true;
854
+ } else if (this.options.setView === "untilPan") {
855
+ return !this._userPanned;
856
+ } else if (this.options.setView === "untilPanOrZoom") {
857
+ return !this._userPanned && !this._userZoomed;
858
+ }
859
+ },
860
+
861
+ /**
862
+ * Check if location is in map bounds
863
+ */
864
+ _isOutsideMapBounds() {
865
+ if (this._event === undefined) {
866
+ return false;
867
+ }
868
+ return this._map.options.maxBounds && !this._map.options.maxBounds.contains(this._event.latlng);
869
+ },
870
+
871
+ /**
872
+ * Toggles button class between following and active.
873
+ */
874
+ _updateContainerStyle() {
875
+ if (!this._container) {
876
+ return;
877
+ }
878
+
879
+ if (this._active && !this._event) {
880
+ // active but don't have a location yet
881
+ this._setClasses("requesting");
882
+ } else if (this._isFollowing()) {
883
+ this._setClasses("following");
884
+ } else if (this._active) {
885
+ this._setClasses("active");
886
+ } else {
887
+ this._cleanClasses();
888
+ }
889
+ },
890
+
891
+ /**
892
+ * Sets the CSS classes for the state.
893
+ */
894
+ _setClasses(state) {
895
+ if (state == "requesting") {
896
+ removeClasses(this._container, "active following");
897
+ addClasses(this._container, "requesting");
898
+
899
+ removeClasses(this._icon, this.options.icon);
900
+ addClasses(this._icon, this.options.iconLoading);
901
+ } else if (state == "active") {
902
+ removeClasses(this._container, "requesting following");
903
+ addClasses(this._container, "active");
904
+
905
+ removeClasses(this._icon, this.options.iconLoading);
906
+ addClasses(this._icon, this.options.icon);
907
+ } else if (state == "following") {
908
+ removeClasses(this._container, "requesting");
909
+ addClasses(this._container, "active following");
910
+
911
+ removeClasses(this._icon, this.options.iconLoading);
912
+ addClasses(this._icon, this.options.icon);
913
+ }
914
+ },
915
+
916
+ /**
917
+ * Removes all classes from button.
918
+ */
919
+ _cleanClasses() {
920
+ L.DomUtil.removeClass(this._container, "requesting");
921
+ L.DomUtil.removeClass(this._container, "active");
922
+ L.DomUtil.removeClass(this._container, "following");
923
+
924
+ removeClasses(this._icon, this.options.iconLoading);
925
+ addClasses(this._icon, this.options.icon);
926
+ },
927
+
928
+ /**
929
+ * Reinitializes state variables.
930
+ */
931
+ _resetVariables() {
932
+ // whether locate is active or not
933
+ this._active = false;
934
+
935
+ // true if the control was clicked for the first time
936
+ // we need this so we can pan and zoom once we have the location
937
+ this._justClicked = false;
938
+
939
+ // true if the user has panned the map after clicking the control
940
+ this._userPanned = false;
941
+
942
+ // true if the user has zoomed the map after clicking the control
943
+ this._userZoomed = false;
944
+ }
945
+ });
946
+
947
+ L.control.locate = (options) => new L.Control.Locate(options);
948
+
949
+ return LocateControl;
950
+ }, window);