mobility-toolbox-js 3.0.0-beta.6 → 3.0.0-beta.8
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.
- package/api/RealtimeAPI.js +96 -89
- package/common/utils/getLayersAsFlatArray.js +5 -1
- package/maplibre/layers/RealtimeLayer.js +2 -2
- package/mbt.js +105 -136
- package/mbt.js.map +3 -3
- package/mbt.min.js +5 -5
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.js +18 -8
- package/ol/controls/RoutingControl.js +3 -0
- package/ol/controls/StopFinderControl.js +3 -0
- package/ol/layers/RealtimeLayer.js +2 -2
- package/ol/mixins/PropertiesLayerMixin.js +0 -60
- package/ol/utils/getFeatureInfoAtCoordinate.js +1 -1
- package/package.json +1 -1
|
@@ -26,6 +26,11 @@ class CopyrightControl extends Control {
|
|
|
26
26
|
const element = createDefaultCopyrightElement();
|
|
27
27
|
element.className = options.className || 'mbt-copyright';
|
|
28
28
|
super(Object.assign({ element }, options));
|
|
29
|
+
this.format =
|
|
30
|
+
options.format ||
|
|
31
|
+
((copyrights) => {
|
|
32
|
+
return copyrights === null || copyrights === void 0 ? void 0 : copyrights.join(' | ');
|
|
33
|
+
});
|
|
29
34
|
}
|
|
30
35
|
render({ frameState }) {
|
|
31
36
|
if (!frameState) {
|
|
@@ -35,18 +40,23 @@ class CopyrightControl extends Control {
|
|
|
35
40
|
let copyrights = [];
|
|
36
41
|
// This code loop comes mainly from ol.
|
|
37
42
|
frameState === null || frameState === void 0 ? void 0 : frameState.layerStatesArray.forEach((layerState) => {
|
|
43
|
+
var _a;
|
|
38
44
|
const { layer } = layerState;
|
|
39
|
-
if (frameState &&
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
layer.
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (frameState && inView(layerState, frameState.viewState)) {
|
|
46
|
+
if ((_a = layer === null || layer === void 0 ? void 0 : layer.getSource()) === null || _a === void 0 ? void 0 : _a.getAttributions()) {
|
|
47
|
+
copyrights = copyrights.concat(layer.getSource().getAttributions()(frameState));
|
|
48
|
+
}
|
|
49
|
+
if (layer === null || layer === void 0 ? void 0 : layer.get('copyrights')) {
|
|
50
|
+
let copyProp = layer.get('copyrights');
|
|
51
|
+
copyProp = !Array.isArray(copyProp) ? [copyProp] : copyProp;
|
|
52
|
+
if (copyProp === null || copyProp === void 0 ? void 0 : copyProp.length) {
|
|
53
|
+
copyrights.push(...copyProp);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
});
|
|
48
58
|
const unique = removeDuplicate(copyrights) || [];
|
|
49
|
-
this.element.innerHTML =
|
|
59
|
+
this.element.innerHTML = this.format(unique);
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
export default CopyrightControl;
|
|
@@ -114,6 +114,9 @@ class RoutingControl extends Control {
|
|
|
114
114
|
this.segments = [];
|
|
115
115
|
this.format = new GeoJSON({ featureProjection: 'EPSG:3857' });
|
|
116
116
|
this.initialRouteDrag = {};
|
|
117
|
+
if (!this.element) {
|
|
118
|
+
this.createDefaultElement();
|
|
119
|
+
}
|
|
117
120
|
/** True if the control is requesting the backend. */
|
|
118
121
|
this.loading = false;
|
|
119
122
|
/** @private */
|
|
@@ -39,5 +39,8 @@ class StopFinderControl extends Control {
|
|
|
39
39
|
const coord = fromLonLat(suggestion.geometry.coordinates);
|
|
40
40
|
(_a = this.getMap()) === null || _a === void 0 ? void 0 : _a.getView().setCenter(coord);
|
|
41
41
|
}
|
|
42
|
+
search(q, abortController) {
|
|
43
|
+
return this.controller.search(q, abortController);
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
export default StopFinderControl;
|
|
@@ -11,7 +11,7 @@ import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
|
11
11
|
/** @private */
|
|
12
12
|
const format = new GeoJSON();
|
|
13
13
|
/**
|
|
14
|
-
* Responsible for loading and display data from the geOps
|
|
14
|
+
* Responsible for loading and display data from the geOps realtime API.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* import { RealtimeLayer } from 'mobility-toolbox-js/ol';
|
|
@@ -38,7 +38,7 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
|
|
|
38
38
|
* @param {RealtimeLayerOptions} options
|
|
39
39
|
* @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
|
|
40
40
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
41
|
-
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps
|
|
41
|
+
* @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps realtime API url.
|
|
42
42
|
*
|
|
43
43
|
*/
|
|
44
44
|
constructor(options) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import BaseEvent from 'ol/events/Event';
|
|
2
1
|
import { getUid } from 'ol';
|
|
3
2
|
import getLayersAsFlatArray from '../../common/utils/getLayersAsFlatArray';
|
|
4
3
|
/**
|
|
@@ -87,25 +86,6 @@ function PropertiesLayerMixin(Base) {
|
|
|
87
86
|
if (evt.key === 'children') {
|
|
88
87
|
this.onChildrenChange(evt.oldValue);
|
|
89
88
|
}
|
|
90
|
-
}),
|
|
91
|
-
// Manage group visiblity
|
|
92
|
-
this.on('change:visible', () => {
|
|
93
|
-
this.onVisibleChange();
|
|
94
|
-
}),
|
|
95
|
-
// Listen for group visiblity change
|
|
96
|
-
// if a layer from a group is newly visible we hide the others.
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
this.on(`change:visible:group`, (evt) => {
|
|
99
|
-
// We hide layer of the same group
|
|
100
|
-
if (this.group === evt.target.group &&
|
|
101
|
-
this !== evt.target &&
|
|
102
|
-
this.visible) {
|
|
103
|
-
this.visible = false;
|
|
104
|
-
// Propagate event to parent
|
|
105
|
-
}
|
|
106
|
-
else if (this.children) {
|
|
107
|
-
this.children.forEach((child) => child.dispatchEvent(evt));
|
|
108
|
-
}
|
|
109
89
|
}));
|
|
110
90
|
this.options = options;
|
|
111
91
|
this.children = options.children || []; // Trigger the on children change event
|
|
@@ -129,46 +109,6 @@ function PropertiesLayerMixin(Base) {
|
|
|
129
109
|
child.set('parent', this);
|
|
130
110
|
});
|
|
131
111
|
}
|
|
132
|
-
/** @private */
|
|
133
|
-
onVisibleChange() {
|
|
134
|
-
const parent = this.get('parent');
|
|
135
|
-
const children = this.get('children') || [];
|
|
136
|
-
if (this.getVisible()) {
|
|
137
|
-
const group = this.get('group');
|
|
138
|
-
// We make the parent visible
|
|
139
|
-
if (parent) {
|
|
140
|
-
parent.setVisible(true);
|
|
141
|
-
}
|
|
142
|
-
// If children doesn't contain any visible layers, we display all children.
|
|
143
|
-
if (children && !children.some((child) => child.getVisible())) {
|
|
144
|
-
children.forEach((child) => {
|
|
145
|
-
child.setVisible(true);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
// Warn the same group that a new layer is visible
|
|
149
|
-
if (parent && group) {
|
|
150
|
-
// We search for the higher parent then it will dispatch to all the tree.
|
|
151
|
-
let higherParent = parent;
|
|
152
|
-
while (higherParent.get('parent')) {
|
|
153
|
-
higherParent = higherParent.get('parent');
|
|
154
|
-
}
|
|
155
|
-
const evt = new BaseEvent(`change:visible:group`);
|
|
156
|
-
evt.target = this;
|
|
157
|
-
higherParent.dispatchEvent(evt);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
// We hide all the children
|
|
162
|
-
children.forEach((child) => {
|
|
163
|
-
child.setVisible(false);
|
|
164
|
-
});
|
|
165
|
-
// If the parent has no more visible child we also hide it.
|
|
166
|
-
if ((parent === null || parent === void 0 ? void 0 : parent.getVisible()) &&
|
|
167
|
-
!(parent === null || parent === void 0 ? void 0 : parent.get('children').find((child) => child.getVisible()))) {
|
|
168
|
-
parent.setVisible(false);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
112
|
/**
|
|
173
113
|
* Initialize the layer with the map passed in parameters.
|
|
174
114
|
*
|
|
@@ -63,7 +63,7 @@ const getFeatureInfoAtCoordinate = (coordinate, layers, hitTolerance = 5) => __a
|
|
|
63
63
|
const source = layer === null || layer === void 0 ? void 0 : layer.getSource();
|
|
64
64
|
// @ts-ignore
|
|
65
65
|
if (source === null || source === void 0 ? void 0 : source.getFeatureInfoUrl) {
|
|
66
|
-
const id = getUid(
|
|
66
|
+
const id = getUid(layer);
|
|
67
67
|
// Abort and recreates one controller per layer
|
|
68
68
|
(_c = abortControllers[id]) === null || _c === void 0 ? void 0 : _c.abort();
|
|
69
69
|
abortControllers[id] = new AbortController();
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mobility-toolbox-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
|
|
5
|
-
"version": "3.0.0-beta.
|
|
5
|
+
"version": "3.0.0-beta.8",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
7
|
"module": "index.js",
|
|
8
8
|
"exports": {
|