mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.21
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/HttpAPI.d.ts +20 -0
- package/api/HttpAPI.js +0 -11
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +342 -276
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +16 -10
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -164
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +31 -31
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
- package/common/mixins/RealtimeLayerMixin.js +401 -393
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -6
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -5
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/typedefs.d.ts +219 -0
- package/common/typedefs.js +7 -1
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.js +5 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +9 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +16 -0
- package/common/utils/renderTrajectories.js +6 -6
- package/common/utils/sortAndFilterDepartures.d.ts +15 -0
- package/common/utils/sortAndFilterDepartures.js +1 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +35 -0
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +28 -0
- package/maplibre/layers/Layer.js +1 -1
- package/maplibre/layers/RealtimeLayer.d.ts +181 -0
- package/maplibre/layers/RealtimeLayer.js +29 -5
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.js +5 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +22103 -14430
- package/mbt.js.map +4 -4
- package/mbt.min.js +61 -58
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.js +18 -8
- package/ol/controls/RoutingControl.d.ts +202 -0
- package/ol/controls/RoutingControl.js +220 -219
- package/ol/controls/StopFinderControl.d.ts +37 -0
- package/ol/controls/StopFinderControl.js +4 -1
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +7 -0
- package/ol/index.js +1 -0
- package/ol/layers/Layer.d.ts +101 -0
- package/ol/layers/Layer.js +25 -0
- package/ol/layers/MaplibreLayer.d.ts +160 -0
- package/ol/layers/MaplibreLayer.js +97 -27
- package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
- package/ol/layers/MaplibreStyleLayer.js +291 -267
- package/ol/layers/RealtimeLayer.d.ts +283 -0
- package/ol/layers/RealtimeLayer.js +143 -128
- package/ol/layers/VectorLayer.d.ts +18 -0
- package/ol/layers/VectorLayer.js +31 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
- package/ol/mixins/MobilityLayerMixin.js +1 -4
- package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
- package/ol/mixins/PropertiesLayerMixin.js +112 -140
- package/ol/mixins/index.d.ts +1 -0
- package/ol/mixins/index.js +2 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +58 -53
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +4 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
- package/ol/utils/index.d.ts +1 -0
- package/package.json +31 -31
- package/setupTests.d.ts +1 -0
- package/setupTests.js +3 -4
- package/types/common.d.ts +55 -48
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +91 -93
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/ol/layers/MapGlLayer.js +0 -142
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import OLLayer from 'ol/layer/Layer';
|
|
2
|
+
import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
|
|
3
|
+
declare const Layer_base: {
|
|
4
|
+
new (...args: any[]): {
|
|
5
|
+
olEventsKeys: import("ol/events").EventsKey[];
|
|
6
|
+
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
7
|
+
attachToMap(map: import("ol").Map): void;
|
|
8
|
+
detachFromMap(): void;
|
|
9
|
+
flat(): any[];
|
|
10
|
+
onChildrenChange(oldValue: OLLayer[]): void;
|
|
11
|
+
setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
|
|
12
|
+
children: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
|
|
13
|
+
get copyrights(): string;
|
|
14
|
+
set copyrights(newCopyrights: string | string[]);
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
readonly group: string;
|
|
17
|
+
readonly hitTolerance: number;
|
|
18
|
+
readonly key: string;
|
|
19
|
+
readonly map: import("ol").Map;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
olLayer: OLLayer;
|
|
22
|
+
parent: OLLayer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
|
|
23
|
+
visible: boolean;
|
|
24
|
+
on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
25
|
+
once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
26
|
+
un: import("ol/layer/Layer").LayerOnSignature<void>;
|
|
27
|
+
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
28
|
+
getSource: () => import("ol/source").Source | null;
|
|
29
|
+
getRenderSource: () => import("ol/source").Source | null;
|
|
30
|
+
getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
|
|
31
|
+
getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
|
|
32
|
+
isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
|
|
33
|
+
getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
|
|
34
|
+
unrender: () => void;
|
|
35
|
+
getDeclutter: () => string;
|
|
36
|
+
renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
|
|
37
|
+
renderDeferred: (frameState: import("ol/Map").FrameState) => void;
|
|
38
|
+
getMapInternal: () => import("ol").default | null;
|
|
39
|
+
setMap: (map: import("ol").default | null) => void;
|
|
40
|
+
setSource: (source: import("ol/source").Source | null) => void;
|
|
41
|
+
getRenderer: () => import("ol/renderer/Layer").default<any> | null;
|
|
42
|
+
hasRenderer: () => boolean;
|
|
43
|
+
getBackground: () => import("ol/layer/Base").BackgroundColor | false;
|
|
44
|
+
getClassName: () => string;
|
|
45
|
+
getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
|
|
46
|
+
getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
|
|
47
|
+
getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
|
|
48
|
+
getExtent: () => import("ol/extent").Extent | undefined;
|
|
49
|
+
getMaxResolution: () => number;
|
|
50
|
+
getMinResolution: () => number;
|
|
51
|
+
getMinZoom: () => number;
|
|
52
|
+
getMaxZoom: () => number;
|
|
53
|
+
getOpacity: () => number;
|
|
54
|
+
getSourceState: () => import("ol/source/Source").State;
|
|
55
|
+
getVisible: () => boolean;
|
|
56
|
+
getZIndex: () => number | undefined;
|
|
57
|
+
setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
|
|
58
|
+
setExtent: (extent: import("ol/extent").Extent | undefined) => void;
|
|
59
|
+
setMaxResolution: (maxResolution: number) => void;
|
|
60
|
+
setMinResolution: (minResolution: number) => void;
|
|
61
|
+
setMaxZoom: (maxZoom: number) => void;
|
|
62
|
+
setMinZoom: (minZoom: number) => void;
|
|
63
|
+
setOpacity: (opacity: number) => void;
|
|
64
|
+
setVisible: (visible: boolean) => void;
|
|
65
|
+
setZIndex: (zindex: number) => void;
|
|
66
|
+
get: (key: string) => any;
|
|
67
|
+
getKeys: () => Array<string>;
|
|
68
|
+
getProperties: () => {
|
|
69
|
+
[x: string]: any;
|
|
70
|
+
};
|
|
71
|
+
getPropertiesInternal: () => {
|
|
72
|
+
[x: string]: any;
|
|
73
|
+
} | null;
|
|
74
|
+
hasProperties: () => boolean;
|
|
75
|
+
notify: (key: string, oldValue: any) => void;
|
|
76
|
+
addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
|
|
77
|
+
removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
|
|
78
|
+
set: (key: string, value: any, silent?: boolean | undefined) => void;
|
|
79
|
+
setProperties: (values: {
|
|
80
|
+
[x: string]: any;
|
|
81
|
+
}, silent?: boolean | undefined) => void;
|
|
82
|
+
unset: (key: string, silent?: boolean | undefined) => void;
|
|
83
|
+
changed: () => void;
|
|
84
|
+
getRevision: () => number;
|
|
85
|
+
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
86
|
+
dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
|
|
87
|
+
getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
|
|
88
|
+
hasListener: (type?: string | undefined) => boolean;
|
|
89
|
+
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
90
|
+
dispose: () => void;
|
|
91
|
+
};
|
|
92
|
+
} & typeof OLLayer;
|
|
93
|
+
/**
|
|
94
|
+
* An OpenLayers layer here only for backward compatibility v2.
|
|
95
|
+
* @deprecated Use an OpenLayers Layer instead.
|
|
96
|
+
*/
|
|
97
|
+
declare class Layer extends Layer_base {
|
|
98
|
+
constructor(options: MobilityLayerOptions);
|
|
99
|
+
clone(newOptions: MobilityLayerOptions): Layer;
|
|
100
|
+
}
|
|
101
|
+
export default Layer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import debounce from 'lodash.debounce';
|
|
2
|
+
import OLLayer from 'ol/layer/Layer';
|
|
3
|
+
import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
|
|
4
|
+
let deprecated = () => { };
|
|
5
|
+
if (typeof window !== 'undefined' &&
|
|
6
|
+
new URLSearchParams(window.location.search).get('deprecated')) {
|
|
7
|
+
deprecated = debounce((message) => {
|
|
8
|
+
// eslint-disable-next-line no-console
|
|
9
|
+
console.warn(message);
|
|
10
|
+
}, 1000);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An OpenLayers layer here only for backward compatibility v2.
|
|
14
|
+
* @deprecated Use an OpenLayers Layer instead.
|
|
15
|
+
*/
|
|
16
|
+
class Layer extends MobilityLayerMixin(OLLayer) {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
deprecated('Layer is deprecated. Use an OpenLayers Layer instead.');
|
|
20
|
+
}
|
|
21
|
+
clone(newOptions) {
|
|
22
|
+
return new Layer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default Layer;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { MapLibreLayer } from '@geoblocks/ol-maplibre-layer';
|
|
2
|
+
import OlMap from 'ol/Map';
|
|
3
|
+
import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
|
|
4
|
+
import type { MapLibreLayerOptions, MapLibreOptions } from '@geoblocks/ol-maplibre-layer/lib/types/MapLibreLayer';
|
|
5
|
+
export type MaplibreLayerOptions = {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
apiKeyName?: string;
|
|
8
|
+
mapLibreOptions?: MapLibreOptions;
|
|
9
|
+
style?: maplibregl.StyleSpecification | null | string;
|
|
10
|
+
url?: string;
|
|
11
|
+
} & MapLibreLayerOptions & MobilityLayerOptions;
|
|
12
|
+
declare const MaplibreLayer_base: {
|
|
13
|
+
new (...args: any[]): {
|
|
14
|
+
olEventsKeys: import("ol/events").EventsKey[];
|
|
15
|
+
options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
|
|
16
|
+
attachToMap(map: OlMap): void;
|
|
17
|
+
detachFromMap(): void;
|
|
18
|
+
flat(): any[];
|
|
19
|
+
onChildrenChange(oldValue: import("ol/layer").Layer[]): void;
|
|
20
|
+
setMapInternal: ((map: OlMap) => void) & ((map: import("ol/Map").default | null) => void);
|
|
21
|
+
children: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
|
|
22
|
+
get copyrights(): string;
|
|
23
|
+
set copyrights(newCopyrights: string | string[]);
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
readonly group: string;
|
|
26
|
+
readonly hitTolerance: number;
|
|
27
|
+
readonly key: string;
|
|
28
|
+
readonly map: OlMap;
|
|
29
|
+
readonly name: string;
|
|
30
|
+
olLayer: import("ol/layer").Layer;
|
|
31
|
+
parent: import("ol/layer").Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
|
|
32
|
+
visible: boolean;
|
|
33
|
+
on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
34
|
+
once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
|
|
35
|
+
un: import("ol/layer/Layer").LayerOnSignature<void>;
|
|
36
|
+
render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
|
|
37
|
+
getSource: () => import("ol/source").Source | null;
|
|
38
|
+
getRenderSource: () => import("ol/source").Source | null;
|
|
39
|
+
getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
|
|
40
|
+
getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
|
|
41
|
+
isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
|
|
42
|
+
getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
|
|
43
|
+
unrender: () => void;
|
|
44
|
+
getDeclutter: () => string;
|
|
45
|
+
renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
|
|
46
|
+
renderDeferred: (frameState: import("ol/Map").FrameState) => void;
|
|
47
|
+
getMapInternal: () => import("ol/Map").default | null;
|
|
48
|
+
setMap: (map: import("ol/Map").default | null) => void;
|
|
49
|
+
setSource: (source: import("ol/source").Source | null) => void;
|
|
50
|
+
getRenderer: () => import("ol/renderer/Layer").default<any> | null;
|
|
51
|
+
hasRenderer: () => boolean;
|
|
52
|
+
getBackground: () => import("ol/layer/Base").BackgroundColor | false;
|
|
53
|
+
getClassName: () => string;
|
|
54
|
+
getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
|
|
55
|
+
getLayersArray: (array?: import("ol/layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer").default>;
|
|
56
|
+
getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
|
|
57
|
+
getExtent: () => import("ol/extent").Extent | undefined;
|
|
58
|
+
getMaxResolution: () => number;
|
|
59
|
+
getMinResolution: () => number;
|
|
60
|
+
getMinZoom: () => number;
|
|
61
|
+
getMaxZoom: () => number;
|
|
62
|
+
getOpacity: () => number;
|
|
63
|
+
getSourceState: () => import("ol/source/Source").State;
|
|
64
|
+
getVisible: () => boolean;
|
|
65
|
+
getZIndex: () => number | undefined;
|
|
66
|
+
setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
|
|
67
|
+
setExtent: (extent: import("ol/extent").Extent | undefined) => void;
|
|
68
|
+
setMaxResolution: (maxResolution: number) => void;
|
|
69
|
+
setMinResolution: (minResolution: number) => void;
|
|
70
|
+
setMaxZoom: (maxZoom: number) => void;
|
|
71
|
+
setMinZoom: (minZoom: number) => void;
|
|
72
|
+
setOpacity: (opacity: number) => void;
|
|
73
|
+
setVisible: (visible: boolean) => void;
|
|
74
|
+
setZIndex: (zindex: number) => void;
|
|
75
|
+
get: (key: string) => any;
|
|
76
|
+
getKeys: () => Array<string>;
|
|
77
|
+
getProperties: () => {
|
|
78
|
+
[x: string]: any;
|
|
79
|
+
};
|
|
80
|
+
getPropertiesInternal: () => {
|
|
81
|
+
[x: string]: any;
|
|
82
|
+
} | null;
|
|
83
|
+
hasProperties: () => boolean;
|
|
84
|
+
notify: (key: string, oldValue: any) => void;
|
|
85
|
+
addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
|
|
86
|
+
removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
|
|
87
|
+
set: (key: string, value: any, silent?: boolean | undefined) => void;
|
|
88
|
+
setProperties: (values: {
|
|
89
|
+
[x: string]: any;
|
|
90
|
+
}, silent?: boolean | undefined) => void;
|
|
91
|
+
unset: (key: string, silent?: boolean | undefined) => void;
|
|
92
|
+
changed: () => void;
|
|
93
|
+
getRevision: () => number;
|
|
94
|
+
addEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
95
|
+
dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
|
|
96
|
+
getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
|
|
97
|
+
hasListener: (type?: string | undefined) => boolean;
|
|
98
|
+
removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
|
|
99
|
+
dispose: () => void;
|
|
100
|
+
};
|
|
101
|
+
} & typeof MapLibreLayer;
|
|
102
|
+
/**
|
|
103
|
+
* An OpenLayers layer able to display data from the [geOps Maps API](https://developer.geops.io/apis/maps).
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* import { MaplibreLayer } from 'mobility-toolbox-js/ol';
|
|
107
|
+
*
|
|
108
|
+
* const layer = new MaplibreLayer({
|
|
109
|
+
* apiKey: 'yourApiKey',
|
|
110
|
+
* // apiKeyName: 'key',
|
|
111
|
+
* // mapLibreOptions: {
|
|
112
|
+
* // interactive: false,
|
|
113
|
+
* // trackResize: false,
|
|
114
|
+
* // attributionControl: false,
|
|
115
|
+
* // }
|
|
116
|
+
* // queryRenderedFeaturesOptions: {
|
|
117
|
+
* // layers: ['waters_lakes'], // map.getFeaturesAtPixel will only return lakes.
|
|
118
|
+
* // },
|
|
119
|
+
* // style: 'travic_v2',
|
|
120
|
+
* // url: 'https://maps.geops.io',
|
|
121
|
+
* });
|
|
122
|
+
*
|
|
123
|
+
* @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
|
|
124
|
+
* @classproperty {string} style - geOps Maps api style.
|
|
125
|
+
* @extends {ol/layer/Layer~Layer}
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
declare class MaplibreLayer extends MaplibreLayer_base {
|
|
129
|
+
/**
|
|
130
|
+
* Constructor.
|
|
131
|
+
*
|
|
132
|
+
* @param {MaplibreLayerOptions} options
|
|
133
|
+
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
134
|
+
* @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
|
|
135
|
+
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
|
|
136
|
+
* @param {string} [options.style="travic_v2"] The geOps Maps API style.
|
|
137
|
+
* @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
|
|
138
|
+
*/
|
|
139
|
+
constructor(options: MaplibreLayerOptions);
|
|
140
|
+
/**
|
|
141
|
+
* Initialize the layer and listen to feature clicks.
|
|
142
|
+
* @param {ol/Map~Map} map
|
|
143
|
+
*/
|
|
144
|
+
attachToMap(map: OlMap): void;
|
|
145
|
+
/**
|
|
146
|
+
* Create a copy of the MaplibreLayer.
|
|
147
|
+
* @param {MaplibreLayerOptions} newOptions Options to override
|
|
148
|
+
* @return {MaplibreLayer} A MaplibreLayer layer
|
|
149
|
+
*/
|
|
150
|
+
clone(newOptions: MaplibreLayerOptions): MaplibreLayer;
|
|
151
|
+
getStyle(): string;
|
|
152
|
+
updateMaplibreMap(): void;
|
|
153
|
+
get maplibreMap(): maplibregl.Map | undefined;
|
|
154
|
+
get mbMap(): maplibregl.Map | undefined;
|
|
155
|
+
get style(): string;
|
|
156
|
+
set style(newValue: string);
|
|
157
|
+
get url(): string;
|
|
158
|
+
set url(newValue: string);
|
|
159
|
+
}
|
|
160
|
+
export default MaplibreLayer;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { MapLibreLayer } from '@geoblocks/ol-maplibre-layer';
|
|
2
|
+
import debounce from 'lodash.debounce';
|
|
3
|
+
import { getUrlWithParams } from '../../common/utils';
|
|
4
|
+
import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
|
|
5
|
+
const buildStyleUrl = (url, style, apiKey, apiKeyName) => {
|
|
6
|
+
return getUrlWithParams(`${url}/styles/${style}/style.json`, {
|
|
7
|
+
[apiKeyName]: apiKey,
|
|
8
|
+
}).toString();
|
|
9
|
+
};
|
|
10
|
+
let deprecated = () => { };
|
|
11
|
+
if (typeof window !== 'undefined' &&
|
|
12
|
+
new URLSearchParams(window.location.search).get('deprecated')) {
|
|
13
|
+
deprecated = debounce((message) => {
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
15
|
+
console.warn(message);
|
|
16
|
+
}, 1000);
|
|
17
|
+
}
|
|
4
18
|
/**
|
|
5
|
-
*
|
|
19
|
+
* An OpenLayers layer able to display data from the [geOps Maps API](https://developer.geops.io/apis/maps).
|
|
6
20
|
*
|
|
7
21
|
* @example
|
|
8
22
|
* import { MaplibreLayer } from 'mobility-toolbox-js/ol';
|
|
@@ -10,7 +24,7 @@ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
|
|
|
10
24
|
* const layer = new MaplibreLayer({
|
|
11
25
|
* apiKey: 'yourApiKey',
|
|
12
26
|
* // apiKeyName: 'key',
|
|
13
|
-
* //
|
|
27
|
+
* // mapLibreOptions: {
|
|
14
28
|
* // interactive: false,
|
|
15
29
|
* // trackResize: false,
|
|
16
30
|
* // attributionControl: false,
|
|
@@ -22,43 +36,53 @@ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
|
|
|
22
36
|
* // url: 'https://maps.geops.io',
|
|
23
37
|
* });
|
|
24
38
|
*
|
|
25
|
-
* @classproperty {maplibregl.Map}
|
|
26
|
-
* @classproperty {maplibregl.QueryRenderedFeaturesOptions} queryRenderedFeaturesOptions - Options used when we query features using map.getFeaturesAtPixel().
|
|
39
|
+
* @classproperty {maplibregl.Map} mapLibreMap - The Maplibre map object. Readonly.
|
|
27
40
|
* @classproperty {string} style - geOps Maps api style.
|
|
28
41
|
* @extends {ol/layer/Layer~Layer}
|
|
29
42
|
* @public
|
|
30
43
|
*/
|
|
31
|
-
|
|
32
|
-
/** @private */
|
|
33
|
-
get maplibreMap() {
|
|
34
|
-
return this.mbMap;
|
|
35
|
-
}
|
|
44
|
+
class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
|
|
36
45
|
/**
|
|
37
46
|
* Constructor.
|
|
38
47
|
*
|
|
39
48
|
* @param {MaplibreLayerOptions} options
|
|
40
49
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
41
|
-
* @param {string} [options.apiKeyName="key"] The geOps Maps
|
|
42
|
-
* @param {maplibregl.MapOptions} [options.
|
|
43
|
-
* @param {string} [options.style="travic_v2"] The geOps Maps
|
|
44
|
-
* @param {string} [options.url="https://maps.geops.io"] The geOps Maps
|
|
50
|
+
* @param {string} [options.apiKeyName="key"] The geOps Maps API key name.
|
|
51
|
+
* @param {maplibregl.MapOptions} [options.mapLibreOptions={ interactive: false, trackResize: false, attributionControl: false }] Maplibre map options.
|
|
52
|
+
* @param {string} [options.style="travic_v2"] The geOps Maps API style.
|
|
53
|
+
* @param {string} [options.url="https://maps.geops.io"] The geOps Maps API url.
|
|
45
54
|
*/
|
|
46
55
|
constructor(options) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
const newOptions = Object.assign(Object.assign({ apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), { mapLibreOptions: Object.assign({}, (options.mapLibreOptions || {})) });
|
|
57
|
+
if (!newOptions.mapLibreOptions.style &&
|
|
58
|
+
newOptions.apiKey &&
|
|
59
|
+
newOptions.style &&
|
|
60
|
+
typeof newOptions.style === 'string') {
|
|
61
|
+
newOptions.mapLibreOptions.style = buildStyleUrl(newOptions.url, newOptions.style, newOptions.apiKey, newOptions.apiKeyName);
|
|
62
|
+
}
|
|
63
|
+
super(newOptions);
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
|
-
*
|
|
66
|
+
* Initialize the layer and listen to feature clicks.
|
|
67
|
+
* @param {ol/Map~Map} map
|
|
57
68
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
attachToMap(map) {
|
|
70
|
+
super.attachToMap(map);
|
|
71
|
+
const updateMaplibreMapDebounced = debounce(this.updateMaplibreMap.bind(this), 150);
|
|
72
|
+
this.olEventsKeys.push(this.on('propertychange', (evt) => {
|
|
73
|
+
if (/(url|style)/.test(evt.key)) {
|
|
74
|
+
updateMaplibreMapDebounced();
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
61
77
|
}
|
|
78
|
+
// get queryRenderedFeaturesOptions(): maplibregl.QueryRenderedFeaturesOptions {
|
|
79
|
+
// return this.get('queryRenderedFeaturesOptions');
|
|
80
|
+
// }
|
|
81
|
+
// set queryRenderedFeaturesOptions(
|
|
82
|
+
// newValue: maplibregl.QueryRenderedFeaturesOptions,
|
|
83
|
+
// ) {
|
|
84
|
+
// this.set('queryRenderedFeaturesOptions', newValue);
|
|
85
|
+
// }
|
|
62
86
|
/**
|
|
63
87
|
* Create a copy of the MaplibreLayer.
|
|
64
88
|
* @param {MaplibreLayerOptions} newOptions Options to override
|
|
@@ -67,4 +91,50 @@ export default class MaplibreLayer extends MapGlLayer {
|
|
|
67
91
|
clone(newOptions) {
|
|
68
92
|
return new MaplibreLayer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
|
|
69
93
|
}
|
|
94
|
+
getStyle() {
|
|
95
|
+
// If the style is a complete style object, use it directly.
|
|
96
|
+
if (this.style &&
|
|
97
|
+
typeof this.style === 'object' &&
|
|
98
|
+
this.style.name &&
|
|
99
|
+
this.style.version) {
|
|
100
|
+
return this.style;
|
|
101
|
+
}
|
|
102
|
+
// If the url set is already a complete style url, use it directly.
|
|
103
|
+
if (this.url.includes('style.json')) {
|
|
104
|
+
return this.url;
|
|
105
|
+
}
|
|
106
|
+
/// Otherwise build the complete style url.
|
|
107
|
+
return buildStyleUrl(this.url, this.style, this.get('apiKey'), this.get('apiKeyName'));
|
|
108
|
+
}
|
|
109
|
+
updateMaplibreMap() {
|
|
110
|
+
var _a;
|
|
111
|
+
try {
|
|
112
|
+
(_a = this.mapLibreMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
// eslint-disable-next-line no-console
|
|
116
|
+
console.error('Error while updating MaplibreMap', e);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
get maplibreMap() {
|
|
120
|
+
deprecated('MaplibreLayer.maplibreMap is deprecated. Use layer.mapLibreMap.');
|
|
121
|
+
return this.mapLibreMap;
|
|
122
|
+
}
|
|
123
|
+
get mbMap() {
|
|
124
|
+
deprecated('MaplibreLayer.mbMap is deprecated. Use layer.maplibreMap.');
|
|
125
|
+
return this.maplibreMap;
|
|
126
|
+
}
|
|
127
|
+
get style() {
|
|
128
|
+
return this.get('style');
|
|
129
|
+
}
|
|
130
|
+
set style(newValue) {
|
|
131
|
+
this.set('style', newValue);
|
|
132
|
+
}
|
|
133
|
+
get url() {
|
|
134
|
+
return this.get('url');
|
|
135
|
+
}
|
|
136
|
+
set url(newValue) {
|
|
137
|
+
this.set('url', newValue);
|
|
138
|
+
}
|
|
70
139
|
}
|
|
140
|
+
export default MaplibreLayer;
|