Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
abf4f34
Adapt doc
oterral Aug 18, 2021
da3c2ed
Clean tracker doc and constructor
oterral Aug 19, 2021
6c49725
Clean tracker doc and constructor
oterral Aug 19, 2021
ad1d2c2
v1.3.6-beta.0
oterral Aug 19, 2021
45d8251
Merge branch 'master' into olivier/tracker
oterral Sep 22, 2021
229c2f7
Abort previous requests
oterral Sep 22, 2021
3c6d8d1
Try CODEOWNERS file
oterral Sep 22, 2021
571478e
Remove CODEOWNERS file
oterral Sep 22, 2021
0bf509a
v1.3.13-beta.1
oterral Sep 28, 2021
ce9b48c
Unsubscribe previous call with same callback function
oterral Sep 28, 2021
5c4ebdd
v1.3.13-beta.2
oterral Sep 28, 2021
9a5a87a
MAke sure setBBox doesn't read event twice
oterral Sep 29, 2021
f6c14a3
v1.3.13-beta.3
oterral Sep 29, 2021
84b6e67
Fix render in the past activating on new live mode
oterral Sep 30, 2021
1e205b7
v1.3.13-beta.4
oterral Sep 30, 2021
1205ea6
Test pixelRatio
oterral Sep 30, 2021
69a0fc0
Fix style with pixelRatio
oterral Sep 30, 2021
636cde8
Fix pixelRatio
oterral Sep 30, 2021
a907785
Fix pixelRatio for tralis
oterral Sep 30, 2021
a5a51d6
v1.3.13-beta.5
oterral Sep 30, 2021
201f9b3
Clean TrackerLayerMixin
oterral Oct 1, 2021
ab127df
Remove useless property
oterral Oct 1, 2021
bfcad67
Allow rotation on mapbox tralis layer
oterral Oct 1, 2021
5ffeb24
Allow rotation on mapbox tralis layer
oterral Oct 1, 2021
016035d
Allow rotation for tracke rwith ol
oterral Oct 1, 2021
d1e70be
Update src/common/Tracker.js
oterral Oct 4, 2021
b242bd0
Clean TrackerLayer
oterral Oct 4, 2021
ddd8e6c
Merge branch 'olivier/tracker' of github.com:geops/mobility-toolbox-j…
oterral Oct 4, 2021
9dd0c12
v1.3.13-beta.6
oterral Oct 4, 2021
b18e256
Clean TrackerLayer
oterral Oct 4, 2021
d517ecf
v1.3.13-beta.7
oterral Oct 4, 2021
d30077a
Use trnasorm
oterral Oct 6, 2021
b281780
Merge branch 'master' into olivier/transform
oterral Oct 12, 2021
195f0b0
Use transform
oterral Oct 13, 2021
b60addd
USe transform for mb
oterral Oct 18, 2021
5fee4ee
v1.4.0-beta.1
oterral Oct 18, 2021
c27e6d3
Add worker support
oterral Oct 19, 2021
ee9ca9d
Use OffscreenCanvas to render trajectories
oterral Oct 19, 2021
771cfa8
Fetch trajectories in a worker
oterral Oct 21, 2021
a211560
Don't send message on aborted request
oterral Oct 22, 2021
5b42f02
Abort render when the function is too slow
oterral Oct 22, 2021
e62df48
Optimize time between request and apply of the render result
oterral Oct 22, 2021
8ff9af8
Manage properly the pixel ratio
oterral Oct 22, 2021
fe1f5ab
Tsest separate build and lint test
oterral Oct 22, 2021
f7738ec
Merge branch 'master' into olivier/transform
oterral Nov 12, 2021
37496a8
Merge branch 'olivier/transform' into olivier/offscreencanvas2
oterral Nov 12, 2021
f254ca2
Set bbox on each move end
oterral Nov 18, 2021
f7c4d48
Deactivate the GET request after the bbox is set
oterral Nov 18, 2021
3388303
v1.5.0-beta.3
oterral Nov 18, 2021
ea75645
Merge branch 'master' into olivier/tracker
oterral Nov 18, 2021
99938de
v1.5.0-beta.4
oterral Nov 18, 2021
77beff4
Add eslint
oterral Nov 18, 2021
1567b6d
Use dev url
oterral Nov 23, 2021
bb8167a
Manage the new api
oterral Nov 23, 2021
77f705d
v1.6.0-beta.1
oterral Nov 23, 2021
ab240b0
v1.6.0-beta.2
oterral Nov 23, 2021
0f7f0e0
v1.6.0-beta.3
oterral Nov 23, 2021
2725f42
v1.6.0-beta.4
oterral Nov 23, 2021
af20ccb
Merge branch 'master' into olivier/tracker
oterral Nov 23, 2021
1a5c6e5
Request full trajectory
oterral Nov 23, 2021
f46e90c
Request full trajectory
oterral Nov 23, 2021
2226ea9
Merge branch 'master' into olivier/tracker
oterral Nov 23, 2021
40745c6
Fix highlight of tracker trajectory
oterral Nov 23, 2021
c4beb5b
Use black border
oterral Nov 23, 2021
551587f
Use black border
oterral Nov 23, 2021
3222b97
Use black border
oterral Nov 23, 2021
d7a7481
Add missing file
oterral Nov 23, 2021
92c0bf6
v1.6.0-beta.5
oterral Nov 23, 2021
633b656
Merge branch 'master' into olivier/tracker
oterral Nov 25, 2021
4b7fd1d
v1.6.0-beta.6
oterral Nov 25, 2021
d8eb29d
Fix color
oterral Nov 25, 2021
7b4ab10
v1.6.0-beta.7
oterral Nov 25, 2021
1d59f92
Add filters and useDelayXXX properety to TrackerLayer
oterral Nov 26, 2021
380dfee
USe good color for fullTrajectory
oterral Nov 26, 2021
3eb2abf
v1.6.0-beta.8
oterral Nov 26, 2021
d72a434
Use delayTrackerStyle by default
oterral Nov 26, 2021
a17142c
Use optimized version of the style
oterral Nov 26, 2021
87e0bc5
Use optimized version of the style
oterral Nov 26, 2021
e891f74
Add possibility to parse worker
oterral Nov 26, 2021
e8f6b83
v1.6.0-beta.9
oterral Nov 26, 2021
3bc0997
Merge branch 'olivier/tracker' into olivier/offscreen
oterral Nov 29, 2021
a88f9ab
Manage new tralis
oterral Nov 29, 2021
70d067a
Manage new tralis
oterral Nov 29, 2021
f074571
Merge branch 'master' into olivier/offscreen
oterral Feb 4, 2022
699706d
Optimizw worker
oterral Feb 4, 2022
e6033df
Replace array of trajectories by an object
oterral Feb 15, 2022
e662cc0
Clean code
oterral Feb 18, 2022
65b6e99
Merge branch 'master' into olivier/arrayToObj
oterral Mar 21, 2022
21d63e4
Small change
oterral Mar 28, 2022
d1fe893
Fix pixelRatio, and add useDebounce and useThrottle experimental options
oterral Apr 8, 2022
7d4f0da
Fix disappearance of vehicles
oterral Apr 8, 2022
72a83b7
Don't render when interacting
oterral Apr 8, 2022
d507941
Fix tests
oterral Apr 8, 2022
8abc3d1
Fix tests
oterral Apr 8, 2022
3f6a2e7
Fix tests
oterral Apr 8, 2022
2dc1269
Merge branch 'master' into olivier/arrayToObj
oterral Apr 8, 2022
cb61c69
v1.7.8-beta.1
oterral Apr 8, 2022
56b7af4
Clean doc
oterral Apr 8, 2022
2d27dac
Merge branch 'olivier/arrayToObj' into olivier/offscreen
oterral Apr 8, 2022
deda20e
Use the tracker class
oterral Apr 8, 2022
292e70c
Remove useless canvas stuff
oterral Apr 8, 2022
0d68144
Improve rendering debounce and throttle time
oterral Apr 19, 2022
878d7b1
v1.7.8-beta.2
oterral Apr 19, 2022
5010871
Fix call of style
oterral Apr 19, 2022
2632be4
v1.7.8-beta.3
oterral Apr 19, 2022
dd4a4e7
Fix parse json
oterral Apr 20, 2022
bc19f00
Use travic_v2 everywhere
oterral Apr 20, 2022
0e9f06a
v1.7.8-beta.4
oterral Apr 20, 2022
9fe3b69
Use 100 as buffer size
oterral Apr 20, 2022
73ca1c7
v1.7.8-beta.5
oterral Apr 20, 2022
1998b7c
Manage buffer as specific case
oterral Apr 20, 2022
26d11f7
v1.7.8-beta.6
oterral Apr 20, 2022
a210853
Fix clear of tracker
oterral Apr 21, 2022
1136582
v1.7.8-beta.7
oterral Apr 21, 2022
d59befc
Merge branch 'olivier/arrayToObj' into olivier/offscreen
oterral Apr 22, 2022
5f8e02c
v1.7.8-beta.8
oterral Apr 22, 2022
03dcf5d
Merge branch 'master' into olivier/offscreen
oterral May 6, 2022
cd5b137
Make example map bigger
oterral May 6, 2022
be3d5eb
Remove useless code
oterral May 6, 2022
83ba519
Merge branch 'master' into olivier/offscreen
oterral Nov 3, 2022
fe1d97a
Merge branch 'master' into olivier/offscreen
oterral Nov 3, 2022
b513e31
chore: ake offscreen canvas work
oterral Nov 16, 2022
3ee02e6
Merge branch 'master' into olivier/offscreen
oterral Nov 16, 2022
85c376c
chore: put same code as in master
oterral Nov 16, 2022
1d2d231
chore: clean code
oterral Nov 16, 2022
3c8992a
Merge branch 'master' into olivier/offscreen
oterral Nov 17, 2022
8ec0945
chore: make map 's size bigger
oterral Nov 17, 2022
74a5574
chore: fix lint
oterral Nov 17, 2022
77633b6
chore: add exemple
oterral Nov 29, 2022
010b2ef
chore: add options to use worker
oterral Nov 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/pages/example/[example].js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const useStyles = makeStyles({
paddingBottom: 115,
margin: 'auto',
marginTop: 30,
maxWidth: '100% !important',
},
});

Expand Down
1 change: 1 addition & 0 deletions doc/public/static/examples/ol-tracker-worker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="map" style="width: 100%; height: 100%"></div>
46 changes: 46 additions & 0 deletions doc/public/static/examples/ol-tracker-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Map, View } from 'ol';
import {
RealtimeLayer,
MaplibreLayer,
CopyrightControl,
} from 'mobility-toolbox-js/ol';
import 'ol/ol.css';

export default () => {
const map = new Map({
target: 'map',
view: new View({
center: [831634, 5933959],
zoom: 13,
minZoom: 5,
}),
controls: [],
});

const control = new CopyrightControl();
control.attachToMap(map);

const layer = new MaplibreLayer({
url: 'https://maps.geops.io/styles/travic_v2/style.json',
apiKey: window.apiKey,
});
layer.attachToMap(map);

const tracker = new RealtimeLayer({
url: 'wss://api.geops.io/tracker-ws/v1/',
apiKey: window.apiKey,
allowRenderWhenAnimating:
new URL(window.location.href)?.searchParams?.get(
'allowRenderWhenAnimating',
) === 'true',
useWorker: true,
});
tracker.attachToMap(map);

tracker.onClick(([feature]) => {
if (feature) {
// eslint-disable-next-line no-console
console.log(feature.getProperties());
}
});
};
1 change: 1 addition & 0 deletions doc/public/static/examples/ol-tracker-worker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Follow [this link](https://developer.geops.io/) to get information about the API and how to get an API key.
4 changes: 4 additions & 0 deletions doc/public/static/examples/ol-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default () => {
const tracker = new RealtimeLayer({
url: 'wss://api.geops.io/tracker-ws/v1/',
apiKey: window.apiKey,
allowRenderWhenAnimating:
new URL(window.location.href)?.searchParams?.get(
'allowRenderWhenAnimating',
) === 'true',
});
tracker.attachToMap(map);

Expand Down
2 changes: 1 addition & 1 deletion doc/src/components/CodeSandboxButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function CodeSandboxButton({ html, js, extraFiles, ...props }) {
'mapbox-gl': '1',
'maplibre-gl': '2',
'mobility-toolbox-js': 'latest@beta',
ol: '6.3.1',
ol: '6',
},
devDependencies: {
'@babel/core': '7.2.0',
Expand Down
2,089 changes: 818 additions & 1,271 deletions doc/src/components/Esdoc/index.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/src/components/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useStyles = makeStyles((theme) => ({
padding: 12,
},
htmlContainer: {
height: 500,
height: 900,
},
noPointer: {
// Remove pointer events for mobile devices on load
Expand Down
11 changes: 10 additions & 1 deletion doc/src/examples.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// We load statically the readme to have the content when the page use server side rendering.
import olTrackerReadme from '../public/static/examples/ol-tracker.md';
import olTrackerWorkerReadme from '../public/static/examples/ol-tracker-worker.md';
import mbTrackerReadme from '../public/static/examples/mb-tracker.md';
import olRoutingReadme from '../public/static/examples/ol-routing.md';
import olStopFinderReadme from '../public/static/examples/ol-stop-finder.md';
Expand All @@ -22,7 +23,15 @@ export default [
name: 'Live tracker with OpenLayers',
key: 'ol-tracker',
description:
'Use the [geOps Realtime API](https://developer.geops.io/apis/realtime/) to show moving trains in a Mapbox map.',
'Use the [geOps Realtime API](https://developer.geops.io/apis/realtime/) to show moving trains in a Openlayers map.',
img: '/static/img/live_tracker_ol.jpg',
readme: olTrackerReadme,
},
{
name: 'Live tracker with OpenLayers using web worker',
key: 'ol-tracker-worker',
description:
'Use the [geOps Realtime API](https://developer.geops.io/apis/realtime/) to show moving trains in a Openlayers map.',
img: '/static/img/live_tracker_ol.jpg',
readme: olTrackerReadme,
},
Expand Down
23 changes: 23 additions & 0 deletions src/api/trajserv/fetchTrajectories.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { translateTrajCollResponse } from './TrajservAPIUtils';

let abortController = new AbortController();

// eslint-disable-next-line no-restricted-globals, func-names
self.onmessage = function (evt) {
// console.log('Worker: Message received from main script', evt.data);
abortController.abort();
abortController = new AbortController();
fetch(evt.data, {
signal: abortController.signal,
})
.then((res) => res.json())
.then((data) => {
const a = translateTrajCollResponse(data.features);
// eslint-disable-next-line no-restricted-globals
self.postMessage(a);
})
.catch(() => {
// eslint-disable-next-line no-restricted-globals
// self.postMessage(null);
});
};
10 changes: 9 additions & 1 deletion src/common/mixins/RealtimeLayerMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,10 @@ function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T) {
this.trajectories = {};
}
this.trajectories[trajectory.properties.train_id] = trajectory;
this.worker?.postMessage({
action: 'addTrajectory',
trajectory,
});
// @ts-ignore the parameter are set by subclasses
this.renderTrajectories();
}
Expand All @@ -971,6 +975,10 @@ function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T) {
if (this.trajectories) {
delete this.trajectories[id];
}
this.worker?.postMessage({
action: 'removeTrajectory',
trajectoryId: id,
});
}

/**
Expand Down Expand Up @@ -1045,7 +1053,7 @@ function RealtimeLayerMixin<T extends AnyLayerClass>(Base: T) {
this.map.getView().getProjection(),
),
};
} else {
} else if (!this.worker) {
trajectory.properties.olGeometry = this.format.readGeometry(geometry);
}

Expand Down
113 changes: 113 additions & 0 deletions src/common/tracker.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/// <reference no-default-lib="true"/>
/// <reference lib="ES2015" />
/// <reference lib="webworker" />
/// <reference lib="dom" />

import GeoJSON from 'ol/format/GeoJSON';
import type { RealtimeStyleOptions, RealtimeTrajectories } from '../types';
import { realtimeDefaultStyle } from './styles';
import { renderTrajectories, realtimeConfig } from './utils';

const debug = false;
const trajectories: RealtimeTrajectories = {};

// Default type of `self` is `WorkerGlobalScope & typeof globalThis`
// https://github.com/microsoft/TypeScript/issues/14877
declare let self: DedicatedWorkerGlobalScope;

export type RealtimeWorkerRenderEvent = {
data: {
viewState: ViewState;
options: RealtimeStyleOptions;
};
};

let renderTimeout: number | null;
let count = 0;
const format = new GeoJSON();
const canvas = new OffscreenCanvas(1, 1);

const render = (evt: RealtimeWorkerRenderEvent) => {
// eslint-disable-next-line no-console
if (debug) console.time('render');
// eslint-disable-next-line no-console
if (debug) console.log('render', evt.data.viewState);
count = 0;
const { viewState, options } = evt.data;

const { renderedTrajectories } = renderTrajectories(
canvas,
Object.values(trajectories),
realtimeDefaultStyle,
viewState,
{
...options,
getRadius: realtimeConfig.getRadius,
getTextColor: realtimeConfig.getTextColor,
getBgColor: realtimeConfig.getBgColor,
getDelayColor: realtimeConfig.getDelayColor,
getTextSize: realtimeConfig.getTextSize,
},
);

if (debug) console.timeEnd('render');
if (debug) console.log('NUMBER OF STYLES CREATED', count);

const imageData = canvas.transferToImageBitmap();

// eslint-disable-next-line no-restricted-globals
self.postMessage(
{
action: 'rendered',
imageData,
viewState,
nbRenderedTRajectories: renderedTrajectories?.length || 0,
},
[imageData],
);
renderTimeout = null;
};

// eslint-disable-next-line no-restricted-globals
self.onmessage = (evt) => {
// debugger;
if (evt.data.action === 'addTrajectory') {
const { trajectory } = evt.data;
const id = trajectory.properties.train_id;
trajectories[id] = trajectory;
trajectories[id].properties.olGeometry = format.readGeometry(
trajectory.geometry,
);
return;
}

if (evt.data.action === 'removeTrajectory') {
delete trajectories[evt.data.trajectoryId];
return;
}

// if (evt.data.action === 'sendData') {
// // eslint-disable-next-line no-console
// if (debug) console.log('sendData', evt.data);
// if (debug) console.time('sendData');
// trajectories = evt.data.trajectories;
// if (debug) console.timeEnd('sendData');
// return;
// }

if (evt.data.action !== 'render') {
return;
}

if (renderTimeout) {
clearTimeout(renderTimeout);
}

// eslint-disable-next-line no-restricted-globals
renderTimeout = self.setTimeout(() => {
render(evt);
}, 0);
};

// We need an export to force this file to act like a module, so TS will let us re-type `self`
// export default null;
1 change: 1 addition & 0 deletions src/common/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as removeDuplicate } from './removeDuplicate';
export { default as createRealtimeFilters } from './createRealtimeFilters';
export { default as getLayersAsFlatArray } from './getLayersAsFlatArray';
export * from './timeUtils';
export { default as getVehiclePosition } from './getVehiclePosition';
export { default as sortByDelay } from './sortByDelay';
export { default as renderTrajectories } from './renderTrajectories';
export { default as getMaplibreRender } from './getMaplibreRender';
Expand Down
Loading