mobility-toolbox-js 3.0.0-beta.10 → 3.0.0-beta.11

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.
@@ -1,144 +0,0 @@
1
- import Source from 'ol/source/Source';
2
- import OlMap from 'ol/Map';
3
- import BaseEvent from 'ol/events/Event';
4
- import Layer from 'ol/layer/Layer';
5
- import { AnyMapGlMap } from '../../types';
6
- import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
7
- export type MapGlLayerOptions = MobilityLayerOptions & {
8
- apiKey?: string;
9
- apiKeyName?: string;
10
- style?: string | maplibregl.StyleSpecification;
11
- url?: string;
12
- mapOptions?: maplibregl.MapOptions;
13
- queryRenderedFeaturesOptions?: maplibregl.QueryRenderedFeaturesOptions;
14
- };
15
- declare const MapGlLayer_base: {
16
- new (...args: any[]): {
17
- options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions | undefined;
18
- olListenersKeys: import("ol/events").EventsKey[];
19
- children: Layer<Source, import("ol/renderer/Layer").default<any>>[];
20
- get copyrights(): string;
21
- set copyrights(newCopyrights: string | string[]);
22
- disabled: boolean;
23
- readonly group: string;
24
- readonly hitTolerance: boolean;
25
- readonly key: string;
26
- readonly map: OlMap;
27
- readonly name: string;
28
- olLayer: Layer<Source, import("ol/renderer/Layer").default<any>>;
29
- parent: Layer<Source, import("ol/renderer/Layer").default<any>>;
30
- visible: boolean;
31
- setMapInternal: ((map: OlMap) => void) & ((map: OlMap | null) => void);
32
- onChildrenChange(oldValue: Layer<Source, import("ol/renderer/Layer").default<any>>[]): void;
33
- attachToMap(map: OlMap): void;
34
- detachFromMap(): void;
35
- flat(): any[];
36
- addEventListener: (type: string, listener: import("ol/events").Listener) => void;
37
- removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
38
- on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
39
- render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
40
- once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
41
- un: import("ol/layer/Layer").LayerOnSignature<void>;
42
- getSource: () => Source | null;
43
- getRenderSource: () => Source | null;
44
- getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<import("ol/Feature").FeatureLike[]>;
45
- getData: (pixel: import("ol/pixel").Pixel) => Float32Array | Uint8ClampedArray | Uint8Array | DataView | null;
46
- isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
47
- getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => string[];
48
- unrender: () => void;
49
- getDeclutter: () => string;
50
- renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
51
- renderDeferred: (frameState: import("ol/Map").FrameState) => void;
52
- getMapInternal: () => OlMap | null;
53
- setMap: (map: OlMap | null) => void;
54
- setSource: (source: Source | null) => void;
55
- getRenderer: () => import("ol/renderer/Layer").default<any> | null;
56
- hasRenderer: () => boolean;
57
- getBackground: () => false | import("ol/layer/Base").BackgroundColor;
58
- getClassName: () => string;
59
- getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
60
- getLayersArray: (array?: Layer<Source, import("ol/renderer/Layer").default<any>>[] | undefined) => Layer<Source, import("ol/renderer/Layer").default<any>>[];
61
- getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => import("ol/layer/Layer").State[];
62
- getExtent: () => import("ol/extent").Extent | undefined;
63
- getMaxResolution: () => number;
64
- getMinResolution: () => number;
65
- getMinZoom: () => number;
66
- getMaxZoom: () => number;
67
- getOpacity: () => number;
68
- getSourceState: () => import("ol/source/Source").State;
69
- getVisible: () => boolean;
70
- getZIndex: () => number | undefined;
71
- setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
72
- setExtent: (extent: import("ol/extent").Extent | undefined) => void;
73
- setMaxResolution: (maxResolution: number) => void;
74
- setMinResolution: (minResolution: number) => void;
75
- setMaxZoom: (maxZoom: number) => void;
76
- setMinZoom: (minZoom: number) => void;
77
- setOpacity: (opacity: number) => void;
78
- setVisible: (visible: boolean) => void;
79
- setZIndex: (zindex: number) => void;
80
- get: (key: string) => any;
81
- getKeys: () => string[];
82
- getProperties: () => {
83
- [x: string]: any;
84
- };
85
- getPropertiesInternal: () => {
86
- [x: string]: any;
87
- } | null;
88
- hasProperties: () => boolean;
89
- notify: (key: string, oldValue: any) => void;
90
- addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
91
- removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
92
- set: (key: string, value: any, silent?: boolean | undefined) => void;
93
- setProperties: (values: {
94
- [x: string]: any;
95
- }, silent?: boolean | undefined) => void;
96
- unset: (key: string, silent?: boolean | undefined) => void;
97
- changed: () => void;
98
- getRevision: () => number;
99
- dispatchEvent: (event: string | BaseEvent) => boolean | undefined;
100
- getListeners: (type: string) => import("ol/events").Listener[] | undefined;
101
- hasListener: (type?: string | undefined) => boolean;
102
- dispose: () => void;
103
- };
104
- } & typeof Layer;
105
- /**
106
- * Common class for Maplibre and Maplibre and potential other fork from Maplibre.
107
- * It's used to share code between Maplibre and Maplibre layers without importing both libs.
108
- * @private
109
- */
110
- declare class MapGlLayer extends MapGlLayer_base {
111
- loaded: boolean;
112
- mbMap?: AnyMapGlMap;
113
- get apiKey(): string;
114
- set apiKey(newValue: string);
115
- get apiKeyName(): string;
116
- set apiKeyName(newValue: string);
117
- get style(): string;
118
- set style(newValue: string);
119
- get url(): string;
120
- set url(newValue: string);
121
- get queryRenderedFeaturesOptions(): maplibregl.QueryRenderedFeaturesOptions;
122
- set queryRenderedFeaturesOptions(newValue: maplibregl.QueryRenderedFeaturesOptions);
123
- constructor(options: MapGlLayerOptions);
124
- /**
125
- * Initialize the layer and listen to feature clicks.
126
- * @param {ol/Map~Map} map
127
- */
128
- attachToMap(map: OlMap): void;
129
- /**
130
- * Terminate what was initialized in init function. Remove layer, events...
131
- */
132
- detachFromMap(): void;
133
- /**
134
- * Create the Maplibre map.
135
- * @private
136
- */
137
- loadMbMap(): void;
138
- getStyle(): string;
139
- createMap(options: {
140
- [id: string]: any;
141
- }): AnyMapGlMap;
142
- updateMbMap(): void;
143
- }
144
- export default MapGlLayer;
@@ -1,144 +0,0 @@
1
- import Source from 'ol/source/Source';
2
- import BaseEvent from 'ol/events/Event';
3
- import Layer from 'ol/layer/Layer';
4
- import debounce from 'lodash.debounce';
5
- import { getUrlWithParams, getMapGlCopyrights } from '../../common/utils';
6
- import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
7
- /**
8
- * Common class for Maplibre and Maplibre and potential other fork from Maplibre.
9
- * It's used to share code between Maplibre and Maplibre layers without importing both libs.
10
- * @private
11
- */
12
- class MapGlLayer extends MobilityLayerMixin(Layer) {
13
- get apiKey() {
14
- return this.get('apiKey');
15
- }
16
- set apiKey(newValue) {
17
- this.set('apiKey', newValue);
18
- }
19
- get apiKeyName() {
20
- return this.get('apiKeyName');
21
- }
22
- set apiKeyName(newValue) {
23
- this.set('apiKeyName', newValue);
24
- }
25
- get style() {
26
- return this.get('style');
27
- }
28
- set style(newValue) {
29
- this.set('style', newValue);
30
- }
31
- get url() {
32
- return this.get('url');
33
- }
34
- set url(newValue) {
35
- this.set('url', newValue);
36
- }
37
- get queryRenderedFeaturesOptions() {
38
- return this.get('queryRenderedFeaturesOptions');
39
- }
40
- set queryRenderedFeaturesOptions(newValue) {
41
- this.set('queryRenderedFeaturesOptions', newValue);
42
- }
43
- constructor(options) {
44
- super(Object.assign(Object.assign({ source: new Source({
45
- attributions: () => {
46
- return (this.mbMap && getMapGlCopyrights(this.mbMap)) || [];
47
- },
48
- }), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), {
49
- // @ts-expect-error mapOptions must be saved by the mixin in this.options
50
- mapOptions: Object.assign({ interactive: false, trackResize: false, attributionControl: false }, ((options === null || options === void 0 ? void 0 : options.mapOptions) || {})), queryRenderedFeaturesOptions: Object.assign({}, ((options === null || options === void 0 ? void 0 : options.queryRenderedFeaturesOptions) || {})) }));
51
- }
52
- /**
53
- * Initialize the layer and listen to feature clicks.
54
- * @param {ol/Map~Map} map
55
- */
56
- attachToMap(map) {
57
- super.attachToMap(map);
58
- this.loadMbMap();
59
- const updateMbMapDebounced = debounce(this.updateMbMap.bind(this), 150);
60
- this.olListenersKeys.push(this.on('propertychange', (evt) => {
61
- if (/(apiKey|apiKeyName|url|style)/.test(evt.key)) {
62
- updateMbMapDebounced();
63
- }
64
- }));
65
- }
66
- /**
67
- * Terminate what was initialized in init function. Remove layer, events...
68
- */
69
- detachFromMap() {
70
- if (this.mbMap) {
71
- // Some asynchrone repaints are triggered even if the mbMap has been removed,
72
- // to avoid display of errors we set an empty function.
73
- this.mbMap.triggerRepaint = () => { };
74
- this.mbMap.remove();
75
- this.mbMap = undefined;
76
- }
77
- this.loaded = false;
78
- super.detachFromMap();
79
- }
80
- /**
81
- * Create the Maplibre map.
82
- * @private
83
- */
84
- loadMbMap() {
85
- var _a, _b, _c;
86
- this.loaded = false;
87
- this.olListenersKeys.push(
88
- // @ts-ignore
89
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('change:target', this.loadMbMap.bind(this)));
90
- if (!((_b = this.map) === null || _b === void 0 ? void 0 : _b.getTargetElement())) {
91
- return;
92
- }
93
- if (!this.visible) {
94
- // On next change of visibility we load the map
95
- this.olListenersKeys.push(
96
- // @ts-ignore
97
- this.once('change:visible', this.loadMbMap.bind(this)));
98
- return;
99
- }
100
- const container = document.createElement('div');
101
- container.style.position = 'absolute';
102
- container.style.width = '100%';
103
- container.style.height = '100%';
104
- /**
105
- * A Maplibre map
106
- * @type {maplibregl.Map}
107
- */
108
- this.mbMap = this.createMap(Object.assign({ style: this.getStyle(), container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
109
- this.mbMap.on('sourcedata', () => {
110
- var _a;
111
- (_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
112
- });
113
- this.mbMap.once('load', () => {
114
- this.loaded = true;
115
- this.dispatchEvent(new BaseEvent('load'));
116
- });
117
- }
118
- getStyle() {
119
- // If the style is a complete style object, use it directly.
120
- if (this.style &&
121
- typeof this.style === 'object' &&
122
- this.style.name &&
123
- this.style.version) {
124
- return this.style;
125
- }
126
- // If the url set is already a complete style url, use it directly.
127
- if (this.url.includes('style.json')) {
128
- return this.url;
129
- }
130
- /// Otherwise build the complete style url.
131
- return getUrlWithParams(`${this.url}/styles/${this.style}/style.json`, {
132
- [this.apiKeyName]: this.apiKey,
133
- }).toString();
134
- }
135
- // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
136
- createMap(options) {
137
- throw new Error('createMap must be implemented in child class');
138
- }
139
- updateMbMap() {
140
- var _a;
141
- (_a = this.mbMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
142
- }
143
- }
144
- export default MapGlLayer;