mobility-toolbox-js 2.0.0-beta.67 → 2.0.0-beta.69

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.
@@ -65,7 +65,6 @@ declare const RealtimeLayer_base: {
65
65
  renderTrajectoriesInternal(viewState: import("../../types").ViewState, noInterpolate?: boolean): boolean;
66
66
  renderTrajectories(viewState: import("../../types").ViewState | undefined, noInterpolate: boolean | undefined): void;
67
67
  setBbox(extent?: [number, number, number, number] | undefined, zoom?: number | undefined): void;
68
- setMode(mode: import("../../types").RealtimeMode): void;
69
68
  getRefreshTimeInMs(zoom?: number | undefined): number;
70
69
  getVehicle(filterFc: Function): GeoJSONFeature[];
71
70
  getFeatureInfoAtCoordinate(coordinate: Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"RealtimeLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RealtimeLayer.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAKxC,OAAO,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAc,EACZ,yBAAyB,EAC1B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACL,MAAM,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAK7E,oBAAY,sBAAsB,GAAG,yBAAyB,GAAG;IAC/D,mBAAmB,EAAE,CACnB,OAAO,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) {
137
137
  */
138
138
  hasFeatureInfoAtCoordinate(coordinate) {
139
139
  if (this.map && this.canvas) {
140
- const context = this.canvas.getContext('2d');
140
+ const context = this.canvas.getContext('2d', {
141
+ willReadFrequently: true,
142
+ });
141
143
  const pixel = this.map.getPixelFromCoordinate(coordinate);
142
144
  return !!(context === null || context === void 0 ? void 0 : context.getImageData(pixel[0] * (this.pixelRatio || 1), pixel[1] * (this.pixelRatio || 1), 1, 1).data[3]);
143
145
  }
@@ -198,6 +200,13 @@ class RealtimeLayer extends mixin(Layer) {
198
200
  return super.getRefreshTimeInMs(this.map.getView().getZoom());
199
201
  }
200
202
  getFeatureInfoAtCoordinate(coordinate, options = {}) {
203
+ if (!this.map || !this.map.getView()) {
204
+ return Promise.resolve({
205
+ layer: this,
206
+ features: [],
207
+ coordinate,
208
+ });
209
+ }
201
210
  const resolution = this.map.getView().getResolution();
202
211
  return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
203
212
  }
@@ -229,6 +238,15 @@ class RealtimeLayer extends mixin(Layer) {
229
238
  // eslint-disable-next-line no-unused-vars
230
239
  onZoomEnd() {
231
240
  super.onZoomEnd();
241
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
242
+ this.setBbox();
243
+ }
244
+ if (this.visible &&
245
+ this.isUpdateBboxOnMoveEnd &&
246
+ this.userClickInteractions &&
247
+ this.selectedVehicleId) {
248
+ this.highlightTrajectory(this.selectedVehicleId);
249
+ }
232
250
  }
233
251
  /**
234
252
  * Update the cursor style when hovering a vehicle.
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": "2.0.0-beta.67",
5
+ "version": "2.0.0-beta.69",
6
6
  "module": "index.js",
7
7
  "exports": {
8
8
  ".": "./index.js",
@@ -97,15 +97,16 @@
97
97
  },
98
98
  "scripts": {
99
99
  "apidoc": "esdoc && cp apidoc/index.json doc/src/components/Esdoc",
100
- "build": "rm -rf build && yarn tsc && yarn esbuild:iife && cp README.md build/ && cp package.json build/ && cp -R src/types build/ && find build -type f -name '*.test.*' -delete",
100
+ "build": "yarn build:tsc && yarn esbuild:iife",
101
+ "build:tsc": "rm -rf build && yarn tsc && cp package.json build/ && cp -R src/types build/ && find build -type f -name '*.test.*' -delete",
101
102
  "coverage": "yarn test --watchAll=false --coverage --coverageDirectory=coverage",
102
103
  "cy:open": "cypress open",
103
104
  "cy:test": "start-server-and-test dev http://localhost:3000 'cypress run --browser chrome'",
104
105
  "cy:test:chrome": "yarn build && start-server-and-test start http://localhost:3000 'cypress run --browser chrome'",
105
106
  "cy:test:edge": "yarn build && start-server-and-test start http://localhost:3000 'cypress run --browser edge'",
106
107
  "cy:test:firefox": "yarn build && start-server-and-test start http://localhost:3000 'cypress run --browser firefox'",
107
- "dev": "yarn doc && yarn dev:examples",
108
- "dev:examples": "cd doc && yarn dev",
108
+ "dev": "rm -rf .next && yarn doc && yarn dev:examples",
109
+ "dev:examples": "rm -rf .next && cd doc && yarn dev",
109
110
  "doc": "yarn build && yarn apidoc && cd doc && rm -rf .next && rm -rf node_modules/mobility-toolbox-js && yarn install --force && yarn build",
110
111
  "esbuild": "yarn esbuild:all && yarn esbuild:iife",
111
112
  "esbuild:all": "esbuild src/index.js src/**/*.js src/**/*.ts src/**/**/*.js src/**/**/*.ts --target=chrome100 --outdir=build/ --loader:.js=jsx",
package/types/common.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Feature } from 'ol';
2
2
  import { Coordinate } from 'ol/coordinate';
3
3
  import { ObjectEvent } from 'ol/Object';
4
+ import { Pixel } from 'ol/pixel';
4
5
  import type { RealtimeTrainId } from './realtime';
5
6
  import type {
6
7
  CopyrightControl as MbCopyrightControl,
@@ -38,6 +39,7 @@ export type RealtimeStyleOptions = {
38
39
  delayOutlineColor?: string;
39
40
  delayDisplay?: number;
40
41
  noInterpolate?: boolean;
42
+ filter?: FilterFunction;
41
43
  getRadius?: (type: number, z: number) => number;
42
44
  getBgColor?: (type: number) => string;
43
45
  getDelayColor?: (
@@ -55,7 +57,7 @@ export type RealtimeStyleOptions = {
55
57
  ) => number;
56
58
  getMaxRadiusForText?: () => number;
57
59
  getMaxRadiusForStrokeAndDelay?: () => number;
58
- filter?: FilterFunction;
60
+ getScreenPixel?: (pixel: Pixel, viewState: ViewState) => Pixel;
59
61
  };
60
62
 
61
63
  export type RealtimeTrajectories = {
@@ -165,6 +165,11 @@ export interface RealtimeExtraGeom extends Feature {
165
165
  properties: RealtimeExtraGeomProperties;
166
166
  }
167
167
 
168
+ export interface RealtimeExtraGeomDeleted {
169
+ type: 'Deleted';
170
+ properties: RealtimeExtraGeomProperties;
171
+ }
172
+
168
173
  export type RealtimeExtraGeoms = {
169
174
  [index: string]: Feature[];
170
175
  };
@@ -255,7 +260,7 @@ export interface RealtimeExtraGeomsResponse {
255
260
  source: `extra_geoms`;
256
261
  timestamp: number;
257
262
  client_reference: null;
258
- content: RealtimeExtraGeom;
263
+ content: RealtimeExtraGeom | RealtimeExtraGeomDeleted;
259
264
  }
260
265
 
261
266
  export interface RealtimeStationResponse {
package/README.md DELETED
@@ -1,44 +0,0 @@
1
- # mobility-toolbox-js
2
-
3
- Toolbox for JavaScript applications in the domains of mobility and logistics.
4
- The tools in this library have been inspired by many projects realized for public transport agencies, mobility providers and logistics companies.
5
-
6
- [![npm](https://img.shields.io/npm/v/mobility-toolbox-js.svg?style=flat-square)](https://www.npmjs.com/package/mobility-toolbox-js)
7
- [![Build](https://github.com/geops/mobility-toolbox-js/workflows/Build/badge.svg)](https://github.com/geops/mobility-toolbox-js/actions?query=workflow%3ABuild)
8
- ![Vercel](https://vercelbadge.vercel.app/api/geops/mobility-toolbox-js)
9
-
10
- ## Documentation and examples
11
-
12
- Visit https://mobility-toolbox-js.vercel.app/
13
-
14
- ## Demos
15
-
16
- * Display [real-time vehicle positions and prognosis data](https://mobility.portal.geops.io) on a map.
17
- * Search for [stops and stations](https://maps.trafimage.ch) all over the world.
18
- * Get [precise geographic courses](https://routing-demo.geops.io/) for all modes of transport.
19
- * Generate beautiful [schematic](https://mobility.portal.geops.io/world.geops.networkplans) or [topographic](https://mobility.portal.geops.io) maps for public transport, mobility and logistics.
20
-
21
- ## Install
22
-
23
- Install the library and the peer dependencies:
24
-
25
- ```bash
26
- yarn add mobility-toolbox-js ol@6.14.1 mapbox-gl@1 maplibre-gl@2
27
- ```
28
-
29
- ## Development
30
-
31
- ```bash
32
- yarn install
33
- yarn dev
34
- ```
35
-
36
- ## Deploy
37
-
38
- This library website is deployed automatically using [Vercel](https://vercel.com/geops).
39
- For Vercel we have to add the nextjs and raw-loader modules in the dev dependencies of the main package.json.
40
- But those 2 librairies are not need to build the library.
41
-
42
- ## Version 1.x.x
43
-
44
- The master branch is now open for the version 2 development. The version 1 is still available in [1.x.x](https://github.com/geops/mobility-toolbox-js/tree/1.x.x) branch.