mobility-toolbox-js 2.0.0-beta.8 → 2.0.1-beta.13

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.
Files changed (304) hide show
  1. package/api/RoutingAPI.js +15 -0
  2. package/api/RoutingAPI.test.js +25 -0
  3. package/api/StopsAPI.js +12 -0
  4. package/api/StopsAPI.test.js +22 -0
  5. package/api/TralisAPI.js +359 -0
  6. package/api/TralisAPI.test.js +67 -0
  7. package/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
  8. package/api/index.js +3 -0
  9. package/{index.html → api/typedefs.js} +0 -0
  10. package/common/Tracker.js +93 -0
  11. package/common/api/HttpAPI.js +30 -0
  12. package/common/api/HttpAPI.test.js +50 -0
  13. package/common/api/WebSocketAPI.js +175 -0
  14. package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
  15. package/common/controls/Control.js +81 -0
  16. package/{src/common → common}/controls/Control.test.js +32 -43
  17. package/common/index.js +4 -0
  18. package/common/layers/Layer.js +213 -0
  19. package/{src/common → common}/layers/Layer.test.js +185 -244
  20. package/common/mixins/CopyrightMixin.js +24 -0
  21. package/common/mixins/SearchMixin.js +110 -0
  22. package/common/mixins/TralisLayerMixin.js +479 -0
  23. package/common/styles/index.js +4 -0
  24. package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
  25. package/common/styles/trackerDelayStyle.js +8 -0
  26. package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
  27. package/{src/common → common}/trackerConfig.js +61 -99
  28. package/common/trackerConfig.test.js +23 -0
  29. package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
  30. package/common/utils/createTrackerFilters.js +56 -0
  31. package/common/utils/createTrackerFilters.test.js +79 -0
  32. package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
  33. package/common/utils/getMapboxMapCopyrights.test.js +40 -0
  34. package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
  35. package/{src/common → common}/utils/getVehiclePosition.js +3 -33
  36. package/common/utils/index.js +5 -0
  37. package/common/utils/removeDuplicate.js +8 -0
  38. package/common/utils/removeDuplicate.test.js +19 -0
  39. package/{src/common → common}/utils/sortByDelay.js +2 -7
  40. package/common/utils/timeUtils.js +20 -0
  41. package/common/utils/timeUtils.test.js +10 -0
  42. package/index.js +8 -0
  43. package/mapbox/controls/CopyrightControl.js +29 -0
  44. package/mapbox/controls/index.js +1 -0
  45. package/mapbox/index.js +4 -0
  46. package/mapbox/layers/Layer.js +57 -0
  47. package/mapbox/layers/Layer.test.js +182 -0
  48. package/mapbox/layers/TralisLayer.js +182 -0
  49. package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
  50. package/mapbox/layers/index.js +2 -0
  51. package/{src/mapbox → mapbox}/utils.js +7 -21
  52. package/mbt.js +50444 -0
  53. package/mbt.js.map +7 -0
  54. package/mbt.min.js +1005 -0
  55. package/mbt.min.js.map +7 -0
  56. package/ol/controls/CopyrightControl.js +42 -0
  57. package/ol/controls/CopyrightControl.test.js +165 -0
  58. package/ol/controls/RoutingControl.js +387 -0
  59. package/ol/controls/RoutingControl.test.js +151 -0
  60. package/ol/controls/StopFinderControl.js +10 -0
  61. package/ol/controls/StopFinderControl.test.js +48 -0
  62. package/ol/controls/index.js +3 -0
  63. package/ol/index.js +5 -0
  64. package/ol/layers/Layer.js +88 -0
  65. package/ol/layers/Layer.test.js +174 -0
  66. package/ol/layers/MapboxLayer.js +203 -0
  67. package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
  68. package/ol/layers/MapboxStyleLayer.js +187 -0
  69. package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
  70. package/ol/layers/MaplibreLayer.js +139 -0
  71. package/ol/layers/RoutingLayer.js +61 -0
  72. package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
  73. package/ol/layers/TralisLayer.js +185 -0
  74. package/ol/layers/TralisLayer.test.js +79 -0
  75. package/ol/layers/VectorLayer.js +22 -0
  76. package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
  77. package/ol/layers/WMSLayer.js +38 -0
  78. package/ol/layers/WMSLayer.test.js +76 -0
  79. package/ol/layers/index.js +8 -0
  80. package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
  81. package/ol/styles/fullTrajectoryStyle.js +43 -0
  82. package/ol/styles/index.js +2 -0
  83. package/package.json +34 -74
  84. package/.babelrc +0 -6
  85. package/.esdoc.json +0 -17
  86. package/.eslintignore +0 -1
  87. package/.github/workflows/conventional-pr-title.yml +0 -21
  88. package/.github/workflows/cypress.yml +0 -29
  89. package/.github/workflows/nodejs.yml +0 -28
  90. package/.husky/commit-msg +0 -4
  91. package/.husky/post-checkout +0 -4
  92. package/.husky/post-merge +0 -4
  93. package/.husky/post-rebase +0 -4
  94. package/.husky/pre-commit +0 -4
  95. package/.neutrinorc.js +0 -176
  96. package/.nvmrc +0 -1
  97. package/CHANGELOG.md +0 -10
  98. package/LICENSE +0 -21
  99. package/__mocks__/mapbox-gl.js +0 -81
  100. package/__mocks__/maplibre-gl.js +0 -81
  101. package/commitlint.config.js +0 -1
  102. package/cypress/fixtures/example.json +0 -5
  103. package/cypress/integration/examples/api.spec.js +0 -7
  104. package/cypress/integration/examples/examples.spec.js +0 -7
  105. package/cypress/integration/examples/navigation.spec.js +0 -29
  106. package/cypress/plugins/index.js +0 -21
  107. package/cypress/support/commands.js +0 -25
  108. package/cypress/support/index.js +0 -20
  109. package/cypress.json +0 -4
  110. package/data/fetchRoute.json +0 -292
  111. package/data/fetchTrajectories.json +0 -18
  112. package/data/fetchTrajectoryById.json +0 -3
  113. package/data/fetchTrajectoryStations.json +0 -18
  114. package/data/stopsSearch.json +0 -15
  115. package/documentation.yml +0 -4
  116. package/esdoc/README.md +0 -27
  117. package/esdoc/plugins/MyPlugin.js +0 -69
  118. package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
  119. package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
  120. package/esdoc/plugins/externals-plugin/externals.js +0 -96
  121. package/global-setup.js +0 -3
  122. package/indexweb.html +0 -49
  123. package/jest.config.js +0 -5
  124. package/pull_request_template.md +0 -17
  125. package/renovate.json +0 -4
  126. package/scripts/read-pkg-json.js +0 -22
  127. package/src/api/index.js +0 -3
  128. package/src/api/routing/RoutingAPI.js +0 -44
  129. package/src/api/routing/RoutingAPI.test.js +0 -41
  130. package/src/api/stops/StopsAPI.js +0 -41
  131. package/src/api/stops/StopsAPI.test.js +0 -34
  132. package/src/api/tralis/TralisAPI.js +0 -731
  133. package/src/api/tralis/TralisAPI.test.js +0 -75
  134. package/src/api/tralis/WebSocketConnector.js +0 -338
  135. package/src/api/tralis/typedefs.js +0 -81
  136. package/src/assets/Lato-Black.ttf +0 -0
  137. package/src/assets/Lato-BlackItalic.ttf +0 -0
  138. package/src/assets/Lato-Bold.ttf +0 -0
  139. package/src/assets/Lato-BoldItalic.ttf +0 -0
  140. package/src/assets/Lato-Italic.ttf +0 -0
  141. package/src/assets/Lato-Light.ttf +0 -0
  142. package/src/assets/Lato-LightItalic.ttf +0 -0
  143. package/src/assets/Lato-Regular.ttf +0 -0
  144. package/src/assets/Lato-Thin.ttf +0 -0
  145. package/src/assets/Lato-ThinItalic.ttf +0 -0
  146. package/src/assets/OFL.txt +0 -93
  147. package/src/common/Tracker.js +0 -197
  148. package/src/common/api/api.js +0 -64
  149. package/src/common/api/api.test.js +0 -68
  150. package/src/common/controls/Control.js +0 -146
  151. package/src/common/index.js +0 -5
  152. package/src/common/layers/Layer.js +0 -404
  153. package/src/common/mixins/CopyrightMixin.js +0 -48
  154. package/src/common/mixins/SearchMixin.js +0 -176
  155. package/src/common/mixins/TralisLayerMixin.js +0 -930
  156. package/src/common/styles/index.js +0 -4
  157. package/src/common/styles/trackerDelayStyle.js +0 -17
  158. package/src/common/trackerConfig.test.js +0 -25
  159. package/src/common/typedefs.js +0 -23
  160. package/src/common/utils/createTrackerFilters.js +0 -87
  161. package/src/common/utils/createTrackerFilters.test.js +0 -95
  162. package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
  163. package/src/common/utils/index.js +0 -5
  164. package/src/common/utils/removeDuplicate.js +0 -22
  165. package/src/common/utils/removeDuplicate.test.js +0 -22
  166. package/src/common/utils/timeUtils.js +0 -44
  167. package/src/common/utils/timeUtils.test.js +0 -16
  168. package/src/doc/App.js +0 -116
  169. package/src/doc/App.scss +0 -51
  170. package/src/doc/_redirects +0 -2
  171. package/src/doc/components/CodeSandboxButton.js +0 -103
  172. package/src/doc/components/Documentation.js +0 -40
  173. package/src/doc/components/Esdoc/Anchor.js +0 -57
  174. package/src/doc/components/Esdoc/ClassDoc.js +0 -272
  175. package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
  176. package/src/doc/components/Esdoc/DetailDocs.js +0 -281
  177. package/src/doc/components/Esdoc/DetailHTML.js +0 -33
  178. package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
  179. package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
  180. package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
  181. package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
  182. package/src/doc/components/Esdoc/Esdoc.js +0 -63
  183. package/src/doc/components/Esdoc/EsdocContent.js +0 -51
  184. package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
  185. package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
  186. package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
  187. package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
  188. package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
  189. package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
  190. package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
  191. package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
  192. package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
  193. package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
  194. package/src/doc/components/Esdoc/NavDoc.js +0 -112
  195. package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
  196. package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
  197. package/src/doc/components/Esdoc/Properties.js +0 -89
  198. package/src/doc/components/Esdoc/README.md +0 -45
  199. package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
  200. package/src/doc/components/Esdoc/SingleDoc.js +0 -31
  201. package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
  202. package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
  203. package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
  204. package/src/doc/components/Esdoc/css/identifiers.css +0 -38
  205. package/src/doc/components/Esdoc/css/search.css +0 -76
  206. package/src/doc/components/Esdoc/css/style.css +0 -603
  207. package/src/doc/components/Esdoc/index.js +0 -7
  208. package/src/doc/components/Example.js +0 -153
  209. package/src/doc/components/Examples.js +0 -183
  210. package/src/doc/components/Home.js +0 -106
  211. package/src/doc/components/TrackerExample.js +0 -38
  212. package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
  213. package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
  214. package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
  215. package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
  216. package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
  217. package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
  218. package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
  219. package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
  220. package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
  221. package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
  222. package/src/doc/examples/mb-copyright.html +0 -26
  223. package/src/doc/examples/mb-copyright.js +0 -37
  224. package/src/doc/examples/mb-tracker.html +0 -1
  225. package/src/doc/examples/mb-tracker.js +0 -39
  226. package/src/doc/examples/mb-tracker.md +0 -1
  227. package/src/doc/examples/mb-tralis.html +0 -1
  228. package/src/doc/examples/mb-tralis.js +0 -34
  229. package/src/doc/examples/ol-copyright.html +0 -26
  230. package/src/doc/examples/ol-copyright.js +0 -43
  231. package/src/doc/examples/ol-mapbox-layer.html +0 -1
  232. package/src/doc/examples/ol-mapbox-layer.js +0 -28
  233. package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
  234. package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
  235. package/src/doc/examples/ol-query.html +0 -32
  236. package/src/doc/examples/ol-query.js +0 -83
  237. package/src/doc/examples/ol-routing.html +0 -26
  238. package/src/doc/examples/ol-routing.js +0 -59
  239. package/src/doc/examples/ol-routing.md +0 -1
  240. package/src/doc/examples/ol-stop-finder.html +0 -15
  241. package/src/doc/examples/ol-stop-finder.js +0 -31
  242. package/src/doc/examples/ol-stop-finder.md +0 -1
  243. package/src/doc/examples/ol-tracker.html +0 -1
  244. package/src/doc/examples/ol-tracker.js +0 -44
  245. package/src/doc/examples/ol-tracker.md +0 -1
  246. package/src/doc/examples/ol-tralis.html +0 -5
  247. package/src/doc/examples/ol-tralis.js +0 -57
  248. package/src/doc/examples/tralis-live-map.html +0 -1
  249. package/src/doc/examples/tralis-live-map.js +0 -51
  250. package/src/doc/examples/tralis-live-map.md +0 -3
  251. package/src/doc/examples.js +0 -107
  252. package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
  253. package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
  254. package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
  255. package/src/doc/img/examples/mapbox.jpg +0 -0
  256. package/src/doc/img/examples/mapbox_style.jpg +0 -0
  257. package/src/doc/img/examples/ol-copyright.png +0 -0
  258. package/src/doc/img/examples/query_objects.jpg +0 -0
  259. package/src/doc/img/examples/routing.jpg +0 -0
  260. package/src/doc/img/examples/simple_map.jpg +0 -0
  261. package/src/doc/img/examples/stops.jpg +0 -0
  262. package/src/doc/img/favico.ico +0 -0
  263. package/src/doc/index.js +0 -21
  264. package/src/iife.js +0 -7
  265. package/src/index.js +0 -10
  266. package/src/mapbox/controls/CopyrightControl.js +0 -58
  267. package/src/mapbox/controls/index.js +0 -2
  268. package/src/mapbox/index.js +0 -4
  269. package/src/mapbox/layers/Layer.js +0 -118
  270. package/src/mapbox/layers/Layer.test.js +0 -202
  271. package/src/mapbox/layers/TralisLayer.js +0 -329
  272. package/src/mapbox/layers/index.js +0 -2
  273. package/src/ol/README.md +0 -0
  274. package/src/ol/controls/CopyrightControl.js +0 -80
  275. package/src/ol/controls/CopyrightControl.test.js +0 -211
  276. package/src/ol/controls/RoutingControl.js +0 -752
  277. package/src/ol/controls/RoutingControl.test.js +0 -216
  278. package/src/ol/controls/StopFinderControl.js +0 -38
  279. package/src/ol/controls/StopFinderControl.test.js +0 -59
  280. package/src/ol/controls/index.js +0 -3
  281. package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  282. package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  283. package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  284. package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  285. package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  286. package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  287. package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  288. package/src/ol/index.js +0 -5
  289. package/src/ol/layers/Layer.js +0 -193
  290. package/src/ol/layers/Layer.test.js +0 -197
  291. package/src/ol/layers/MapboxLayer.js +0 -378
  292. package/src/ol/layers/MapboxStyleLayer.js +0 -417
  293. package/src/ol/layers/MaplibreLayer.js +0 -280
  294. package/src/ol/layers/RoutingLayer.js +0 -91
  295. package/src/ol/layers/TralisLayer.js +0 -359
  296. package/src/ol/layers/TralisLayer.test.js +0 -97
  297. package/src/ol/layers/VectorLayer.js +0 -43
  298. package/src/ol/layers/WMSLayer.js +0 -80
  299. package/src/ol/layers/WMSLayer.test.js +0 -84
  300. package/src/ol/layers/index.js +0 -8
  301. package/src/ol/styles/fullTrajectoryStyle.js +0 -51
  302. package/src/ol/styles/index.js +0 -2
  303. package/src/setupTests.js +0 -15
  304. package/webpack.config.js +0 -6
@@ -1,404 +0,0 @@
1
- import Observable from 'ol/Observable';
2
- import { v4 as uuid } from 'uuid';
3
-
4
- /**
5
- * A class representing a layer to display on map.
6
- *
7
- * @example
8
- * const layer = new Layer({
9
- * name: 'myLayer',
10
- * });
11
- *
12
- * @classproperty {string} name - Name of the layer
13
- * @classproperty {string} key - Identifier of the layer. Must be unique.
14
- * @classproperty {string[]} copyrights - Array of copyrights.
15
- * @classproperty {boolean} isBaseLayer - Define if the layer is a base layer. Read-only.
16
- * @classproperty {boolean} isQueryable - Define if the layer can be queried. If false, it will set isHoverActive and isClickActive to false. Read-only.
17
- * @classproperty {boolean} isClickActive - If true feature information will be queried on user click event. See inherited layers for more informations. Read-only.
18
- * @classproperty {boolean} isHoverActive - If true feature information will be queried on pointer move event. See inherited layers for more informations. Read-only.
19
- * @classproperty {boolean} isMobilityLayer - Custom property for duck typing since `instanceof` is not working when the instance was created on different bundles. Read-only.
20
- * @classproperty {Layer[]} children - List of children.
21
- * @classproperty {boolean} visible - Define if the layer is visible or not.
22
- * @classproperty {number} hitTolerance - Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
23
- * @classproperty {Object} properties - Custom properties.
24
- * @classproperty {ol/Map~Map|mapboxgl.Map} map - The map where the layer is displayed.
25
- */
26
- export default class Layer extends Observable {
27
- /**
28
- * Constructor
29
- *
30
- * @param {Object} options
31
- * @param {string} [options.name=uuid()] Layer name. Default use a generated uuid.
32
- * @param {string} [options.key=uuid().toLowerCase()] Layer key, will use options.name.toLowerCase() if not specified.
33
- * @param {string[]} [options.copyrights=undefined] Array of copyrights.
34
- * @param {Array<Layer>} [options.children=[]] Sublayers.
35
- * @param {Object} [options.properties={}] Application-specific layer properties.
36
- * @param {boolean} [options.visible=true] If true this layer is visible on the map.
37
- * @param {boolean} [options.isBaseLayer=false] If true this layer is a baseLayer.
38
- * @param {boolean} [options.isQueryable=true] Define if the layer can be queried. If false, it will also set isHoverActive and isClickActive to false. Read-only.
39
- * @param {boolean} [options.isClickActive=true] If true feature information will be queried on click event. See inherited layers for more informations. Read-only.
40
- * @param {boolean} [options.isHoverActive=true] If true feature information will be queried on pointer move event. See inherited layers for more informations. Read-only.
41
- * @param {number} [options.hitTolerance=5] Hit-detection tolerance in css pixels. Pixels inside the radius around the given position will be checked for features.
42
- */
43
- constructor(options = {}) {
44
- super();
45
- this.defineProperties(options);
46
-
47
- // Add mouse event callbacks
48
- const { onClick, onHover } = options;
49
-
50
- if (onHover) {
51
- this.onHover(onHover);
52
- }
53
-
54
- if (onClick) {
55
- this.onClick(onClick);
56
- }
57
-
58
- // This if is very important if you remove it you break the copyright control.
59
- if (options.copyrights) {
60
- /** @ignore */
61
- this.copyrights = options.copyrights;
62
- }
63
-
64
- /** @ignore */
65
- this.onUserClickCallback = this.onUserClickCallback.bind(this);
66
-
67
- /** @ignore */
68
- this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
69
- }
70
-
71
- /**
72
- * Define layer's properties.
73
- *
74
- * @ignore
75
- */
76
- defineProperties(options) {
77
- const {
78
- name,
79
- key,
80
- children,
81
- visible,
82
- properties,
83
- isBaseLayer,
84
- isQueryable,
85
- isClickActive,
86
- isHoverActive,
87
- hitTolerance,
88
- } = {
89
- isQueryable: true,
90
- isClickActive: true,
91
- isHoverActive: true,
92
- ...options,
93
- };
94
- const uid = uuid();
95
- const dfltName = name || uid;
96
- Object.defineProperties(this, {
97
- // options is used for clone function.
98
- options: {
99
- value: options,
100
- },
101
- name: {
102
- value: dfltName,
103
- },
104
- key: {
105
- value: key || dfltName.toLowerCase(),
106
- },
107
- isBaseLayer: {
108
- value: !!isBaseLayer,
109
- },
110
- isQueryable: {
111
- value: !!isQueryable,
112
- writable: true,
113
- },
114
- isClickActive: {
115
- value: !!isQueryable && !!isClickActive,
116
- writable: true,
117
- },
118
- isHoverActive: {
119
- value: !!isQueryable && !!isHoverActive,
120
- writable: true,
121
- },
122
- hitTolerance: {
123
- value: hitTolerance || 5,
124
- writable: true,
125
- },
126
- // Custom property for duck typing since `instanceof` is not working
127
- // when the instance was created on different bundles.
128
- isMobilityLayer: {
129
- value: true,
130
- },
131
- children: {
132
- value: children || [],
133
- writable: true,
134
- },
135
- copyrights: {
136
- get: () => this.get('copyrights'),
137
- set: (newCopyrights) => {
138
- const arrValue = !Array.isArray(newCopyrights)
139
- ? [newCopyrights]
140
- : newCopyrights;
141
- this.set('copyrights', arrValue);
142
- },
143
- },
144
- visible: {
145
- value: visible === undefined ? true : visible,
146
- writable: true,
147
- },
148
- properties: {
149
- value: { ...(properties || {}) },
150
- },
151
- map: {
152
- writable: true,
153
- },
154
- /**
155
- * Callback function when a user click on a feature.
156
- */
157
- clickCallbacks: {
158
- value: [],
159
- },
160
- /**
161
- * Callback function when a user hover on a feature.
162
- */
163
- hoverCallbacks: {
164
- value: [],
165
- },
166
- });
167
- }
168
-
169
- /**
170
- * Initialize the layer with the map passed in parameters.
171
- *
172
- * @param {ol/Map~Map|mapboxgl.Map} map A map.
173
- */
174
- init(map) {
175
- this.terminate();
176
- /** @ignore */
177
- this.map = map;
178
- }
179
-
180
- /**
181
- * Terminate what was initialized in init function. Remove layer, events...
182
- */
183
- // eslint-disable-next-line class-methods-use-this
184
- terminate() {}
185
-
186
- /**
187
- * Get a layer property.
188
- *
189
- * @param {string} name Property name.
190
- * @return {property} Property
191
- */
192
- get(name) {
193
- return this.properties[name];
194
- }
195
-
196
- /**
197
- * Set a layer property.
198
- *
199
- * @param {string} name Property name.
200
- * @param {string} value Value.
201
- */
202
- set(name, value) {
203
- if (value !== this.properties[name]) {
204
- this.properties[name] = value;
205
- this.dispatchEvent({
206
- type: `change:${name}`,
207
- target: this,
208
- });
209
- }
210
- }
211
-
212
- /**
213
- * Change the visibility of the layer
214
- *
215
- * @param {boolean} visible Defines the visibility of the layer
216
- * @param {boolean} [stopPropagationDown]
217
- * @param {boolean} [stopPropagationUp]
218
- * @param {boolean} [stopPropagationSiblings]
219
- */
220
- setVisible(
221
- visible,
222
- stopPropagationDown = false,
223
- stopPropagationUp = false,
224
- stopPropagationSiblings = false,
225
- ) {
226
- if (visible === this.visible) {
227
- return;
228
- }
229
-
230
- /** @ignore */
231
- this.visible = visible;
232
-
233
- this.dispatchEvent({
234
- type: 'change:visible',
235
- target: this,
236
- stopPropagationDown,
237
- stopPropagationUp,
238
- stopPropagationSiblings,
239
- });
240
- }
241
-
242
- /**
243
- * Returns an array with visible child layers
244
- *
245
- * @return {Layer[]} Visible children
246
- */
247
- getVisibleChildren() {
248
- return this.children.filter((child) => child.visible);
249
- }
250
-
251
- /**
252
- * Checks whether the layer has child layers with visible set to True
253
- *
254
- * @return {boolean} True if the layer has visible child layers
255
- * @deprecated
256
- */
257
- hasVisibleChildren() {
258
- return !!this.children.find((child) => child.visible === true);
259
- }
260
-
261
- /**
262
- * Request feature information for a given coordinate.
263
- * This function must be implemented by inheriting layers.
264
- *
265
- * @param {ol/coordinate~Coordinate} coordinate Coordinate.
266
- * @param {Object} options Some options. See child classes to see which are supported.
267
- * @return {Promise<FeatureInfo>} An empty response.
268
- */
269
- // eslint-disable-next-line no-unused-vars
270
- getFeatureInfoAtCoordinate(coordinate, options) {
271
- // eslint-disable-next-line no-console
272
- console.error(
273
- 'getFeatureInfoAtCoordinate must be implemented by inheriting layers',
274
- this.key,
275
- );
276
-
277
- // No response so we modify the properties accordingly, to avoid spaming the console.
278
- this.isQueryable = false;
279
- // this.isClickActive = false;
280
- // this.isHoverActive = false;
281
-
282
- // This layer returns no feature info.
283
- // The function is implemented by inheriting layers.
284
- return Promise.resolve({
285
- layer: this,
286
- features: [],
287
- coordinate,
288
- });
289
- }
290
-
291
- /**
292
- * Listens to click events on the layer.
293
- * @param {function} callback Callback function, called with the clicked
294
- * features,
295
- * the layer instance and the click event.
296
- */
297
- onClick(callback) {
298
- if (typeof callback === 'function') {
299
- if (!this.clickCallbacks.includes(callback)) {
300
- this.clickCallbacks.push(callback);
301
- }
302
- } else {
303
- throw new Error('onClick callback must be of type function:', callback);
304
- }
305
- }
306
-
307
- /**
308
- * Unlistens to click events on the layer.
309
- * @param {function} callback Callback function, called with the clicked
310
- * features,
311
- * the layer instance and the click event.
312
- */
313
- unClick(callback) {
314
- if (typeof callback === 'function') {
315
- const idx = this.clickCallbacks.indexOf(callback);
316
- if (idx > -1) {
317
- this.clickCallbacks.splice(idx, 1);
318
- }
319
- }
320
- }
321
-
322
- /**
323
- * Function triggered when the user click the map.
324
- * @private
325
- */
326
- onUserClickCallback(evt) {
327
- const emptyFeatureInfo = {
328
- features: [],
329
- layer: this,
330
- coordinate: evt.coordinate,
331
- event: evt,
332
- };
333
-
334
- if (!this.isClickActive || !this.clickCallbacks.length) {
335
- return Promise.resolve(emptyFeatureInfo);
336
- }
337
-
338
- return this.getFeatureInfoAtCoordinate(evt.coordinate)
339
- .then((featureInfo) => {
340
- const { features, layer, coordinate } = featureInfo;
341
- this.clickCallbacks.forEach((callback) =>
342
- callback(features, layer, coordinate),
343
- );
344
- return featureInfo;
345
- })
346
- .catch(() => emptyFeatureInfo);
347
- }
348
-
349
- /**
350
- * Listens to hover events on the layer.
351
- * @param {function} callback Callback function, called with the clicked
352
- * features, the layer instance and the click event.
353
- */
354
- onHover(callback) {
355
- if (typeof callback === 'function') {
356
- if (!this.hoverCallbacks.includes(callback)) {
357
- this.hoverCallbacks.push(callback);
358
- }
359
- } else {
360
- throw new Error('callback must be of type function.');
361
- }
362
- }
363
-
364
- /**
365
- * Unlistens to hover events on the layer.
366
- * @param {function} callback Callback function, called with the hovered
367
- * features, the layer instance and the click event.
368
- */
369
- unHover(callback) {
370
- if (typeof callback === 'function') {
371
- const idx = this.hoverCallbacks.indexOf(callback);
372
- if (idx > -1) {
373
- this.hoverCallbacks.splice(idx, 1);
374
- }
375
- }
376
- }
377
-
378
- /**
379
- * Function triggered when the user move the cursor.
380
- * @private
381
- */
382
- onUserMoveCallback(evt) {
383
- const emptyFeatureInfo = {
384
- features: [],
385
- layer: this,
386
- coordinate: evt.coordinate,
387
- event: evt,
388
- };
389
-
390
- if (!this.isHoverActive || !this.hoverCallbacks.length) {
391
- return Promise.resolve(emptyFeatureInfo);
392
- }
393
-
394
- return this.getFeatureInfoAtCoordinate(evt.coordinate)
395
- .then((featureInfo) => {
396
- const { features, layer, coordinate } = featureInfo;
397
- this.hoverCallbacks.forEach((callback) =>
398
- callback(features, layer, coordinate),
399
- );
400
- return featureInfo;
401
- })
402
- .catch(() => emptyFeatureInfo);
403
- }
404
- }
@@ -1,48 +0,0 @@
1
- /* eslint-disable class-methods-use-this */
2
- /* eslint-disable max-classes-per-file */
3
-
4
- /**
5
- * Copyright control interface.
6
- *
7
- */
8
- export class CopyrightInterface {
9
- /**
10
- * Return an array of layer's copyright.
11
- *
12
- * @return {String[]} A list of copyrights to render.
13
- */
14
- getCopyrights() {}
15
- }
16
-
17
- /**
18
- * Mixin for CopyrightInterface.
19
- *
20
- * @param {Class} Base A class to extend with {CopyrightInterface} functionnalities.
21
- * @return {Class} A class that implements <CopyrightInterface> class and extends Base;
22
- * @private
23
- */
24
- const CopyrightMixin = (Base) =>
25
- class extends Base {
26
- render() {
27
- if (!this.element) {
28
- return;
29
- }
30
- this.element.innerHTML = this.active
31
- ? this.getCopyrights().join(' | ')
32
- : '';
33
- }
34
-
35
- createDefaultElement() {
36
- this.element = document.createElement('div');
37
- this.element.id = 'mbt-copyright';
38
- Object.assign(this.element.style, {
39
- position: 'absolute',
40
- bottom: 0,
41
- right: 0,
42
- fontSize: '.8rem',
43
- padding: '0 10px',
44
- });
45
- }
46
- };
47
-
48
- export default CopyrightMixin;
@@ -1,176 +0,0 @@
1
- /* eslint-disable no-empty-function */
2
- /* eslint-disable no-useless-constructor */
3
- /* eslint-disable class-methods-use-this */
4
- /* eslint-disable max-classes-per-file */
5
- import StopsAPI from '../../api/stops/StopsAPI';
6
-
7
- /**
8
- * Search control interface.
9
- *
10
- * @classproperty {StopsSearchParams} apiParams - Default request parameters used by the search method. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
11
- */
12
- export class SearchInterface {
13
- /**
14
- * Constructor.
15
- *
16
- * @param {Object} options Map options
17
- * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
18
- * @param {string} [options.url='https://api.geops.io/tracker/v1'] Stops service url. See StopsAPI.
19
- * @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
20
- * @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
21
- */
22
- // eslint-disable-next-line no-unused-vars
23
- constructor(options = {}) {}
24
-
25
- /**
26
- * Launch a search.
27
- *
28
- * @param {String} query The query to search for.
29
- * @param {AbortController} abortController Abort controller used to cancel the request.
30
- * @return {Promise<Array<GeoJSONFeature>>} An array of GeoJSON features with coordinates in [EPSG:4326](http://epsg.io/4326).
31
- */
32
- // eslint-disable-next-line no-unused-vars
33
- search(query, abortController) {}
34
- }
35
-
36
- /**
37
- * Mixin for SearchInterface.
38
- *
39
- * @param {Class} Base A class to extend with {SearchInterface} functionnalities.
40
- * @return {Class} A class that implements <SearchInterface> class and extends Base;
41
- * @private
42
- */
43
- const SearchMixin = (Base) =>
44
- class extends Base {
45
- constructor(options = {}) {
46
- super(options);
47
- const { apiParams, apiKey, url } = options;
48
-
49
- this.apiParams = { limit: 20, ...(apiParams || {}) };
50
- this.placeholder = options.placeholder || 'Search for a stop...';
51
-
52
- const apiOptions = { apiKey };
53
- if (url) {
54
- apiOptions.url = url;
55
- }
56
- this.api = new StopsAPI(apiOptions);
57
- this.abortController = new AbortController();
58
- }
59
-
60
- render(suggestions = []) {
61
- if (!this.suggestionsElt) {
62
- return;
63
- }
64
-
65
- this.suggestionsElt.style.display = suggestions.length ? 'block' : 'none';
66
-
67
- this.suggestionsElt.innerHTML = '';
68
-
69
- suggestions.forEach((suggestion) => {
70
- const { properties } = suggestion;
71
- const suggElt = document.createElement('div');
72
- suggElt.innerHTML = properties.name;
73
- suggElt.onclick = () => {
74
- this.onSuggestionClick(suggestion);
75
- };
76
- Object.assign(suggElt.style, {
77
- padding: '5px 12px',
78
- });
79
- this.suggestionsElt.appendChild(suggElt);
80
- });
81
- }
82
-
83
- createDefaultElement() {
84
- /**
85
- * Define a default element.
86
- */
87
- this.element = document.createElement('div');
88
- this.element.id = 'mbt-search';
89
- Object.assign(this.element.style, {
90
- position: 'absolute',
91
- top: 0,
92
- left: '50px',
93
- margin: '10px',
94
- display: 'flex',
95
- flexDirection: 'column',
96
- width: '320px',
97
- });
98
-
99
- // Create input element
100
- this.inputElt = document.createElement('input');
101
- this.inputElt.type = 'text';
102
- this.inputElt.placeholder = this.placeholder;
103
- this.inputElt.autoComplete = 'off';
104
- this.inputElt.onkeyup = (evt) => {
105
- this.abortController.abort();
106
- this.abortController = new AbortController();
107
- this.search(evt.target.value, this.abortController);
108
- };
109
- Object.assign(this.inputElt.style, {
110
- padding: '10px 30px 10px 10px',
111
- });
112
- this.element.appendChild(this.inputElt);
113
-
114
- // Create suggestions list element
115
- this.suggestionsElt = document.createElement('div');
116
- Object.assign(this.suggestionsElt.style, {
117
- backgroundColor: 'white',
118
- overflowY: 'auto',
119
- cursor: 'pointer',
120
- });
121
- this.element.appendChild(this.suggestionsElt);
122
-
123
- this.clearElt = document.createElement('div');
124
- Object.assign(this.clearElt.style, {
125
- display: 'none',
126
- position: 'absolute',
127
- right: '0',
128
- padding: '0 10px',
129
- fontSize: '200%',
130
- cursor: 'pointer',
131
- });
132
- this.clearElt.innerHTML = '×';
133
- this.clearElt.onclick = () => this.clear();
134
- this.element.appendChild(this.clearElt);
135
- }
136
-
137
- search(q, abortController) {
138
- if (q !== undefined || q !== null) {
139
- this.apiParams.q = q;
140
- }
141
-
142
- if (this.clearElt) {
143
- this.clearElt.style.display = 'block';
144
- }
145
-
146
- return this.api
147
- .search(this.apiParams, abortController)
148
- .then((data) => {
149
- this.render(data);
150
- })
151
- .catch(() => {
152
- this.render();
153
- });
154
- }
155
-
156
- /**
157
- * To be defined in inherited class
158
- */
159
- // eslint-disable-next-line no-unused-vars
160
- onSuggestionClick(suggestion) {}
161
-
162
- /**
163
- * Clear the search field and close the control.
164
- */
165
- clear() {
166
- if (!this.suggestionsElt) {
167
- return;
168
- }
169
-
170
- this.inputElt.value = '';
171
- this.suggestionsElt.innerHTML = '';
172
- this.clearElt.style.display = 'none';
173
- }
174
- };
175
-
176
- export default SearchMixin;