mobility-toolbox-js 2.0.0-beta.66 → 2.0.0-beta.68
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.d.ts +1 -1
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +0 -1
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +12 -5
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -1
- package/common/mixins/RealtimeLayerMixin.js +20 -4
- package/common/styles/realtimeDefaultStyle.d.ts +1 -1
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +58 -50
- package/common/utils/renderTrajectories.d.ts.map +1 -1
- package/common/utils/renderTrajectories.js +12 -23
- package/mapbox/layers/RealtimeLayer.js +2 -2
- package/mbt.js +96 -68
- package/mbt.js.map +2 -2
- package/mbt.min.js +40 -40
- package/mbt.min.js.map +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +12 -1
- package/package.json +5 -4
- package/types/common.d.ts +3 -1
- package/types/realtime.d.ts +6 -1
- package/README.md +0 -44
package/mbt.js
CHANGED
|
@@ -33944,7 +33944,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33944
33944
|
defineProperties() {
|
|
33945
33945
|
Object.defineProperties(this, {
|
|
33946
33946
|
closed: {
|
|
33947
|
-
get: () => !!(this.websocket
|
|
33947
|
+
get: () => !!(!this.websocket || this.websocket.readyState === this.websocket.CLOSED)
|
|
33948
33948
|
},
|
|
33949
33949
|
closing: {
|
|
33950
33950
|
get: () => !!(this.websocket && this.websocket.readyState === this.websocket.CLOSING)
|
|
@@ -33978,7 +33978,11 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33978
33978
|
connect(url, onOpen = () => {
|
|
33979
33979
|
}) {
|
|
33980
33980
|
if (this.websocket && !this.closed) {
|
|
33981
|
-
this.websocket.
|
|
33981
|
+
if (!this.closing && this.websocket.url !== url) {
|
|
33982
|
+
this.websocket.close();
|
|
33983
|
+
} else if (this.connecting) {
|
|
33984
|
+
return;
|
|
33985
|
+
}
|
|
33982
33986
|
}
|
|
33983
33987
|
this.websocket = new WebSocket(url);
|
|
33984
33988
|
if (!this.open) {
|
|
@@ -33992,10 +33996,11 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33992
33996
|
}
|
|
33993
33997
|
}
|
|
33994
33998
|
close() {
|
|
33995
|
-
if (this.websocket) {
|
|
33996
|
-
this.websocket.onclose =
|
|
33999
|
+
if (this.websocket && (this.open || this.connecting)) {
|
|
34000
|
+
this.websocket.onclose = () => {
|
|
34001
|
+
this.websocket = void 0;
|
|
34002
|
+
};
|
|
33997
34003
|
this.websocket.close();
|
|
33998
|
-
this.websocket = void 0;
|
|
33999
34004
|
this.messagesOnOpen = [];
|
|
34000
34005
|
}
|
|
34001
34006
|
}
|
|
@@ -34249,7 +34254,6 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34249
34254
|
});
|
|
34250
34255
|
}
|
|
34251
34256
|
open() {
|
|
34252
|
-
this.close();
|
|
34253
34257
|
this.wsApi.connect(this.url, this.onOpen);
|
|
34254
34258
|
if (this.wsApi.websocket) {
|
|
34255
34259
|
this.wsApi.websocket.onclose = () => {
|
|
@@ -34783,7 +34787,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34783
34787
|
noInterpolate = false,
|
|
34784
34788
|
hoverVehicleId,
|
|
34785
34789
|
selectedVehicleId,
|
|
34786
|
-
filter
|
|
34790
|
+
filter,
|
|
34791
|
+
getScreenPixel = (pixel, viewStat) => (viewStat.zoom || 0) < 12 ? pixel.map((coord) => Math.floor(coord)) : pixel
|
|
34787
34792
|
} = options;
|
|
34788
34793
|
const context = canvas2.getContext("2d");
|
|
34789
34794
|
context?.clearRect(0, 0, canvas2.width, canvas2.height);
|
|
@@ -34798,12 +34803,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34798
34803
|
}
|
|
34799
34804
|
let hoverVehicleImg;
|
|
34800
34805
|
let hoverVehiclePx;
|
|
34801
|
-
let hoverVehicleWidth;
|
|
34802
|
-
let hoverVehicleHeight;
|
|
34803
34806
|
let selectedVehicleImg;
|
|
34804
34807
|
let selectedVehiclePx;
|
|
34805
|
-
let selectedVehicleWidth;
|
|
34806
|
-
let selectedVehicleHeight;
|
|
34807
34808
|
const renderedTrajectories = [];
|
|
34808
34809
|
for (let i = trajectories.length - 1; i >= 0; i -= 1) {
|
|
34809
34810
|
const trajectory = trajectories[i];
|
|
@@ -34829,30 +34830,25 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34829
34830
|
if (!vehicleImg) {
|
|
34830
34831
|
continue;
|
|
34831
34832
|
}
|
|
34832
|
-
const imgWidth = vehicleImg.width;
|
|
34833
|
-
const imgHeight = vehicleImg.height;
|
|
34834
34833
|
if (hoverVehicleId !== id && selectedVehicleId !== id) {
|
|
34835
|
-
|
|
34834
|
+
const [x, y] = getScreenPixel([px[0] - vehicleImg.width / 2, px[1] - vehicleImg.height / 2], viewState);
|
|
34835
|
+
context?.drawImage(vehicleImg, x, y);
|
|
34836
34836
|
}
|
|
34837
34837
|
if (hoverVehicleId && hoverVehicleId === id) {
|
|
34838
34838
|
hoverVehicleImg = vehicleImg;
|
|
34839
34839
|
hoverVehiclePx = px;
|
|
34840
|
-
hoverVehicleWidth = imgWidth;
|
|
34841
|
-
hoverVehicleHeight = imgHeight;
|
|
34842
34840
|
}
|
|
34843
34841
|
if (selectedVehicleId && selectedVehicleId === id) {
|
|
34844
34842
|
selectedVehicleImg = vehicleImg;
|
|
34845
34843
|
selectedVehiclePx = px;
|
|
34846
|
-
selectedVehicleWidth = imgWidth;
|
|
34847
|
-
selectedVehicleHeight = imgHeight;
|
|
34848
34844
|
}
|
|
34849
34845
|
renderedTrajectories.push(trajectory);
|
|
34850
34846
|
}
|
|
34851
|
-
if (selectedVehicleImg && selectedVehiclePx
|
|
34852
|
-
context?.drawImage(selectedVehicleImg, selectedVehiclePx[0] -
|
|
34847
|
+
if (selectedVehicleImg && selectedVehiclePx) {
|
|
34848
|
+
context?.drawImage(selectedVehicleImg, Math.floor(selectedVehiclePx[0] - selectedVehicleImg.width / 2), Math.floor(selectedVehiclePx[1] - selectedVehicleImg.height / 2));
|
|
34853
34849
|
}
|
|
34854
|
-
if (hoverVehicleImg && hoverVehiclePx
|
|
34855
|
-
context?.drawImage(hoverVehicleImg, hoverVehiclePx[0] -
|
|
34850
|
+
if (hoverVehicleImg && hoverVehiclePx) {
|
|
34851
|
+
context?.drawImage(hoverVehicleImg, Math.floor(hoverVehiclePx[0] - hoverVehicleImg.width / 2), Math.floor(hoverVehiclePx[1] - hoverVehicleImg.height / 2));
|
|
34856
34852
|
}
|
|
34857
34853
|
return {
|
|
34858
34854
|
renderedTrajectories
|
|
@@ -36091,24 +36087,24 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
36091
36087
|
return cacheDelayBg[key];
|
|
36092
36088
|
};
|
|
36093
36089
|
var cacheDelayText = {};
|
|
36094
|
-
var getDelayTextCanvas = (
|
|
36095
|
-
const key = `${
|
|
36090
|
+
var getDelayTextCanvas = (text, fontSize, font, delayColor, delayOutlineColor = "#000", pixelRatio = 1) => {
|
|
36091
|
+
const key = `${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
|
|
36096
36092
|
if (!cacheDelayText[key]) {
|
|
36097
|
-
const canvas2 = createCanvas_default(
|
|
36093
|
+
const canvas2 = createCanvas_default(Math.ceil(text.length * fontSize), Math.ceil(fontSize + 8 * pixelRatio));
|
|
36098
36094
|
if (canvas2) {
|
|
36099
36095
|
const ctx = canvas2.getContext("2d");
|
|
36100
36096
|
if (!ctx) {
|
|
36101
36097
|
return null;
|
|
36102
36098
|
}
|
|
36099
|
+
ctx.font = font;
|
|
36103
36100
|
ctx.textAlign = "left";
|
|
36104
36101
|
ctx.textBaseline = "middle";
|
|
36105
36102
|
ctx.font = font;
|
|
36106
36103
|
ctx.fillStyle = delayColor;
|
|
36107
36104
|
ctx.strokeStyle = delayOutlineColor;
|
|
36108
36105
|
ctx.lineWidth = 1.5 * pixelRatio;
|
|
36109
|
-
|
|
36110
|
-
ctx.
|
|
36111
|
-
ctx.fillText(delayText, 0, fontSize);
|
|
36106
|
+
ctx.strokeText(text, 0, fontSize);
|
|
36107
|
+
ctx.fillText(text, 0, fontSize);
|
|
36112
36108
|
cacheDelayText[key] = canvas2;
|
|
36113
36109
|
}
|
|
36114
36110
|
}
|
|
@@ -36242,52 +36238,58 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
36242
36238
|
const margin = 1 * pixelRatio;
|
|
36243
36239
|
const radiusDelay = radius + 2;
|
|
36244
36240
|
const markerSize = radius * 2;
|
|
36245
|
-
const size = radiusDelay * 2 + margin * 2
|
|
36241
|
+
const size = radiusDelay * 2 + margin * 2;
|
|
36246
36242
|
const origin = size / 2;
|
|
36247
|
-
|
|
36243
|
+
let delayBg = null;
|
|
36244
|
+
if (isDisplayStrokeAndDelay && delay !== null) {
|
|
36245
|
+
delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor2(delay, cancelled));
|
|
36246
|
+
}
|
|
36247
|
+
let delayText = null;
|
|
36248
|
+
let fontSize = 0;
|
|
36249
|
+
if (isDisplayStrokeAndDelay && (hover || (delay || 0) >= delayDisplay || cancelled)) {
|
|
36250
|
+
fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
|
|
36251
|
+
const text = getDelayText2(delay, cancelled);
|
|
36252
|
+
if (text) {
|
|
36253
|
+
delayText = getDelayTextCanvas(text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor2(delay, cancelled, true), delayOutlineColor, pixelRatio);
|
|
36254
|
+
}
|
|
36255
|
+
}
|
|
36256
|
+
let circleFillColor;
|
|
36257
|
+
if (useDelayStyle) {
|
|
36258
|
+
circleFillColor = getDelayColor2(delay, cancelled);
|
|
36259
|
+
} else {
|
|
36260
|
+
circleFillColor = color || getBgColor2(type);
|
|
36261
|
+
}
|
|
36262
|
+
const hasStroke = isDisplayStrokeAndDelay || hover || selected;
|
|
36263
|
+
const hasDash = !!isDisplayStrokeAndDelay && !!useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
36264
|
+
const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
|
|
36265
|
+
const width = size + (delayText?.width || 0) * 2;
|
|
36266
|
+
const height = size;
|
|
36267
|
+
const canvas2 = createCanvas_default(width, height);
|
|
36248
36268
|
if (canvas2) {
|
|
36249
36269
|
const ctx = canvas2.getContext("2d");
|
|
36250
36270
|
if (!ctx) {
|
|
36251
36271
|
return null;
|
|
36252
36272
|
}
|
|
36253
|
-
|
|
36254
|
-
|
|
36255
|
-
|
|
36256
|
-
ctx.drawImage(delayBg, 0, 0);
|
|
36257
|
-
}
|
|
36258
|
-
}
|
|
36259
|
-
if (isDisplayStrokeAndDelay && (hover || (delay || 0) >= delayDisplay || cancelled)) {
|
|
36260
|
-
const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
|
|
36261
|
-
const text = getDelayText2(delay, cancelled);
|
|
36262
|
-
if (text) {
|
|
36263
|
-
const textWidth = text.length * fontSize;
|
|
36264
|
-
const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor2(delay, cancelled, true), delayOutlineColor, pixelRatio);
|
|
36265
|
-
if (delayText) {
|
|
36266
|
-
ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
|
|
36267
|
-
}
|
|
36268
|
-
}
|
|
36269
|
-
}
|
|
36270
|
-
let circleFillColor;
|
|
36271
|
-
if (useDelayStyle) {
|
|
36272
|
-
circleFillColor = getDelayColor2(delay, cancelled);
|
|
36273
|
-
} else {
|
|
36274
|
-
circleFillColor = color || getBgColor2(type);
|
|
36273
|
+
const originX = delayText?.width || 0;
|
|
36274
|
+
if (delayBg) {
|
|
36275
|
+
ctx.drawImage(delayBg, originX, 0);
|
|
36275
36276
|
}
|
|
36276
|
-
const hasStroke = isDisplayStrokeAndDelay || hover || selected;
|
|
36277
|
-
const hasDash = !!isDisplayStrokeAndDelay && !!useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
36278
|
-
const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
|
|
36279
36277
|
if (circle) {
|
|
36280
|
-
ctx.drawImage(circle,
|
|
36278
|
+
ctx.drawImage(circle, originX, 0);
|
|
36281
36279
|
}
|
|
36282
|
-
|
|
36283
|
-
|
|
36284
|
-
const
|
|
36280
|
+
let circleText = null;
|
|
36281
|
+
if (isDisplayText) {
|
|
36282
|
+
const fontSize2 = Math.max(radius, 10);
|
|
36283
|
+
const textSize = getTextSize2(ctx, markerSize, name, fontSize2);
|
|
36285
36284
|
const textColor2 = !useDelayStyle ? textColor || getTextColor2(type) : "#000000";
|
|
36286
36285
|
const hasStroke2 = !!useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
|
|
36287
|
-
|
|
36288
|
-
|
|
36289
|
-
|
|
36290
|
-
|
|
36286
|
+
circleText = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
|
|
36287
|
+
}
|
|
36288
|
+
if (circleText) {
|
|
36289
|
+
ctx.drawImage(circleText, originX, 0);
|
|
36290
|
+
}
|
|
36291
|
+
if (delayText) {
|
|
36292
|
+
ctx.drawImage(delayText, originX + Math.ceil(origin + radiusDelay) + margin, Math.ceil(origin - fontSize));
|
|
36291
36293
|
}
|
|
36292
36294
|
cache2[key] = canvas2;
|
|
36293
36295
|
}
|
|
@@ -49157,7 +49159,25 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49157
49159
|
"funicular",
|
|
49158
49160
|
"coach"
|
|
49159
49161
|
];
|
|
49160
|
-
|
|
49162
|
+
const onlyRail = ["rail"];
|
|
49163
|
+
const withoutCable = ["tram", "subway", "rail", "bus"];
|
|
49164
|
+
this.motsByZoom = options.motsByZoom || [
|
|
49165
|
+
onlyRail,
|
|
49166
|
+
onlyRail,
|
|
49167
|
+
onlyRail,
|
|
49168
|
+
onlyRail,
|
|
49169
|
+
onlyRail,
|
|
49170
|
+
onlyRail,
|
|
49171
|
+
onlyRail,
|
|
49172
|
+
onlyRail,
|
|
49173
|
+
onlyRail,
|
|
49174
|
+
withoutCable,
|
|
49175
|
+
withoutCable,
|
|
49176
|
+
allMots,
|
|
49177
|
+
allMots,
|
|
49178
|
+
allMots,
|
|
49179
|
+
allMots
|
|
49180
|
+
];
|
|
49161
49181
|
this.getMotsByZoom = (zoom) => {
|
|
49162
49182
|
return options.getMotsByZoom && options.getMotsByZoom(zoom, this.motsByZoom) || this.motsByZoom[zoom] || this.motsByZoom[this.motsByZoom.length - 1];
|
|
49163
49183
|
};
|
|
@@ -49519,7 +49539,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49519
49539
|
}
|
|
49520
49540
|
purgeTrajectory(trajectory, extent, zoom) {
|
|
49521
49541
|
const { type, bounds } = trajectory.properties;
|
|
49522
|
-
if (!intersects(extent, bounds) || this.mots && !this.mots.includes(type)
|
|
49542
|
+
if (!intersects(extent, bounds) || this.mots && !this.mots.includes(type)) {
|
|
49523
49543
|
this.removeTrajectory(trajectory);
|
|
49524
49544
|
return true;
|
|
49525
49545
|
}
|
|
@@ -49787,7 +49807,9 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49787
49807
|
}
|
|
49788
49808
|
hasFeatureInfoAtCoordinate(coordinate) {
|
|
49789
49809
|
if (this.map && this.canvas) {
|
|
49790
|
-
const context = this.canvas.getContext("2d"
|
|
49810
|
+
const context = this.canvas.getContext("2d", {
|
|
49811
|
+
willReadFrequently: true
|
|
49812
|
+
});
|
|
49791
49813
|
const pixel = this.map.getPixelFromCoordinate(coordinate);
|
|
49792
49814
|
return !!context?.getImageData(pixel[0] * (this.pixelRatio || 1), pixel[1] * (this.pixelRatio || 1), 1, 1).data[3];
|
|
49793
49815
|
}
|
|
@@ -49843,6 +49865,12 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49843
49865
|
}
|
|
49844
49866
|
onZoomEnd() {
|
|
49845
49867
|
super.onZoomEnd();
|
|
49868
|
+
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
49869
|
+
this.setBbox();
|
|
49870
|
+
}
|
|
49871
|
+
if (this.visible && this.isUpdateBboxOnMoveEnd && this.userClickInteractions && this.selectedVehicleId) {
|
|
49872
|
+
this.highlightTrajectory(this.selectedVehicleId);
|
|
49873
|
+
}
|
|
49846
49874
|
}
|
|
49847
49875
|
onFeatureHover(features, layer, coordinate) {
|
|
49848
49876
|
super.onFeatureHover(features, layer, coordinate);
|
|
@@ -50709,7 +50737,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
50709
50737
|
center: fromLonLat([center.lng, center.lat]),
|
|
50710
50738
|
extent: bounds,
|
|
50711
50739
|
resolution: res,
|
|
50712
|
-
zoom: this.
|
|
50740
|
+
zoom: this.getOlZoom(),
|
|
50713
50741
|
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
50714
50742
|
pixelRatio: this.pixelRatio
|
|
50715
50743
|
};
|
|
@@ -50733,7 +50761,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
50733
50761
|
}
|
|
50734
50762
|
}
|
|
50735
50763
|
purgeTrajectory(trajectory, extent, zoom) {
|
|
50736
|
-
return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.
|
|
50764
|
+
return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.getOlZoom()));
|
|
50737
50765
|
}
|
|
50738
50766
|
setBbox(extent, zoom) {
|
|
50739
50767
|
let newExtent = extent;
|