@record-evolution/widget-mapbox 1.4.20 → 1.5.1
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/dist/src/widget-mapbox.d.ts +6 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-mapbox.js +345 -332
- package/dist/widget-mapbox.js.map +1 -1
- package/package.json +28 -26
- package/src/default-data.json +3 -5
- package/src/definition-schema.d.ts +10 -14
- package/src/definition-schema.json +42 -49
- package/src/widget-mapbox.ts +33 -17
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "REWidget widget-mapbox",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "widget-mapbox",
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.5.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-mapbox.js",
|
|
9
9
|
"types": "dist/src/widget-mapbox.d.ts",
|
|
@@ -23,37 +23,39 @@
|
|
|
23
23
|
"cors": "gcloud storage buckets update gs://reswarm-images --cors-file=src/cors-config.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@types/geojson": "^7946.0.
|
|
27
|
-
"@types/mapbox-gl": "^
|
|
28
|
-
"lit": "^3.0
|
|
29
|
-
"mapbox-gl": "^
|
|
26
|
+
"@types/geojson": "^7946.0.14",
|
|
27
|
+
"@types/mapbox-gl": "^3.4.0",
|
|
28
|
+
"lit": "^3.2.0",
|
|
29
|
+
"mapbox-gl": "^3.7.0",
|
|
30
30
|
"tinycolor2": "^1.6.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/plugin-syntax-import-assertions": "^7.
|
|
34
|
-
"@custom-elements-manifest/analyzer": "^0.
|
|
35
|
-
"@open-wc/eslint-config": "^12.0.2",
|
|
33
|
+
"@babel/plugin-syntax-import-assertions": "^7.25.7",
|
|
34
|
+
"@custom-elements-manifest/analyzer": "^0.10.3",
|
|
36
35
|
"@rollup/plugin-babel": "^6.0.4",
|
|
37
|
-
"@rollup/plugin-commonjs": "^
|
|
38
|
-
"@rollup/plugin-json": "^6.0
|
|
39
|
-
"@rollup/plugin-node-resolve": "^15.
|
|
40
|
-
"@rollup/plugin-replace": "^
|
|
41
|
-
"@rollup/plugin-typescript": "^
|
|
36
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
37
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
39
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
40
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
41
|
+
"@types/glob": "^8.1.0",
|
|
42
42
|
"@types/tinycolor2": "^1.4.6",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
44
|
-
"@typescript-eslint/parser": "^
|
|
45
|
-
"@web/dev-server": "^0.4.
|
|
46
|
-
"concurrently": "^
|
|
47
|
-
"eslint": "^
|
|
48
|
-
"eslint-config-prettier": "^9.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
|
44
|
+
"@typescript-eslint/parser": "^8.8.0",
|
|
45
|
+
"@web/dev-server": "^0.4.6",
|
|
46
|
+
"concurrently": "^9.0.1",
|
|
47
|
+
"eslint": "^9.12.0",
|
|
48
|
+
"eslint-config-prettier": "^9.1.0",
|
|
49
|
+
"glob": "^11.0.0",
|
|
50
|
+
"husky": "^9.1.6",
|
|
51
|
+
"json-schema-to-typescript": "^15.0.2",
|
|
52
|
+
"lint-staged": "^15.2.10",
|
|
53
|
+
"minimatch": "3.1.2",
|
|
54
|
+
"prettier": "^3.3.3",
|
|
55
|
+
"rollup": "^4.24.0",
|
|
54
56
|
"rollup-plugin-copy": "^3.5.0",
|
|
55
|
-
"tslib": "^2.
|
|
56
|
-
"typescript": "
|
|
57
|
+
"tslib": "^2.7.0",
|
|
58
|
+
"typescript": "5.3.2"
|
|
57
59
|
},
|
|
58
60
|
"repository": {
|
|
59
61
|
"type": "git",
|
package/src/default-data.json
CHANGED
|
@@ -32,7 +32,6 @@ export type SeriesLabel = string;
|
|
|
32
32
|
* Create the specified type of layer on the map.
|
|
33
33
|
*/
|
|
34
34
|
export type LayerType = "circle" | "symbol" | "heatmap" | "line";
|
|
35
|
-
export type LayerBaseColor = string;
|
|
36
35
|
/**
|
|
37
36
|
* Restrict the number of rows for this dataseries to the given number of newest values. (If pivoted, then per each of the pivot dataseries.)
|
|
38
37
|
*/
|
|
@@ -45,7 +44,6 @@ export type Blur = number;
|
|
|
45
44
|
* Opactity 1 means fully opaque, 0 means fully transparent.
|
|
46
45
|
*/
|
|
47
46
|
export type Opacity = number;
|
|
48
|
-
export type TextColor = string;
|
|
49
47
|
export type TextSize = number;
|
|
50
48
|
/**
|
|
51
49
|
* For available icons check the maki icon set here https://labs.mapbox.com/maki-icons/
|
|
@@ -97,21 +95,16 @@ export type Dataseries = {
|
|
|
97
95
|
/**
|
|
98
96
|
* A map-chart
|
|
99
97
|
*/
|
|
100
|
-
export interface
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
subTitle?: Subtitle;
|
|
107
|
-
style?: MapStyle;
|
|
108
|
-
showLegend?: ShowLegend;
|
|
109
|
-
follow?: AutoFollow;
|
|
110
|
-
[k: string]: unknown;
|
|
111
|
-
};
|
|
98
|
+
export interface InputData {
|
|
99
|
+
title?: Title;
|
|
100
|
+
subTitle?: Subtitle;
|
|
101
|
+
style?: MapStyle;
|
|
102
|
+
showLegend?: ShowLegend;
|
|
103
|
+
follow?: AutoFollow;
|
|
112
104
|
dataseries?: Dataseries;
|
|
113
105
|
[k: string]: unknown;
|
|
114
106
|
}
|
|
107
|
+
export type LayerBaseColor = string;
|
|
115
108
|
export interface LayerConfiguration {
|
|
116
109
|
circle?: CircleLayer;
|
|
117
110
|
symbol?: SymbolLayer;
|
|
@@ -131,6 +124,9 @@ export interface SymbolLayer {
|
|
|
131
124
|
"icon-size"?: IconSize;
|
|
132
125
|
[k: string]: unknown;
|
|
133
126
|
}
|
|
127
|
+
export interface TextColor {
|
|
128
|
+
[k: string]: unknown;
|
|
129
|
+
}
|
|
134
130
|
export interface HeatmapLayer {
|
|
135
131
|
"heatmap-intensity"?: Intensity;
|
|
136
132
|
"heatmap-opacity"?: Opacity1;
|
|
@@ -1,52 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
"title": "
|
|
2
|
+
"title": "InputData",
|
|
3
3
|
"description": "A map-chart",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"type": "
|
|
9
|
-
"order":
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"follow": {
|
|
44
|
-
"title": "Auto Follow",
|
|
45
|
-
"description": "If true, the map automatically keeps the drawn locations in focus.",
|
|
46
|
-
"type": "boolean",
|
|
47
|
-
"order": 5
|
|
48
|
-
}
|
|
49
|
-
}
|
|
6
|
+
"title": {
|
|
7
|
+
"title": "Title",
|
|
8
|
+
"type": "string",
|
|
9
|
+
"order": 1
|
|
10
|
+
},
|
|
11
|
+
"subTitle": {
|
|
12
|
+
"title": "Subtitle",
|
|
13
|
+
"type": "string",
|
|
14
|
+
"order": 2
|
|
15
|
+
},
|
|
16
|
+
"style": {
|
|
17
|
+
"title": "Map Style",
|
|
18
|
+
"description": "The basic style of the map.",
|
|
19
|
+
"type": "string",
|
|
20
|
+
"enum": [
|
|
21
|
+
"streets-v12",
|
|
22
|
+
"outdoors-v12",
|
|
23
|
+
"light-v11",
|
|
24
|
+
"dark-v11",
|
|
25
|
+
"satellite-v9",
|
|
26
|
+
"satellite-streets-v12",
|
|
27
|
+
"navigation-day-v1",
|
|
28
|
+
"navigation-night-v1"
|
|
29
|
+
],
|
|
30
|
+
"required": true,
|
|
31
|
+
"order": 3
|
|
32
|
+
},
|
|
33
|
+
"showLegend": {
|
|
34
|
+
"title": "Show Legend",
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"order": 4
|
|
37
|
+
},
|
|
38
|
+
"follow": {
|
|
39
|
+
"title": "Auto Follow",
|
|
40
|
+
"description": "If true, the map automatically keeps the drawn locations in focus.",
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"order": 5
|
|
50
43
|
},
|
|
51
44
|
"dataseries": {
|
|
52
45
|
"title": "Dataseries",
|
|
@@ -78,7 +71,7 @@
|
|
|
78
71
|
},
|
|
79
72
|
"latestValues": {
|
|
80
73
|
"title": "Latest Values",
|
|
81
|
-
"description": "Restrict the number of rows for this dataseries to the given number of newest values. (If
|
|
74
|
+
"description": "Restrict the number of rows for this dataseries to the given number of newest values. (If you use split data, then per each of the split dataseries.)",
|
|
82
75
|
"type": "number",
|
|
83
76
|
"order": 4
|
|
84
77
|
},
|
|
@@ -212,13 +205,13 @@
|
|
|
212
205
|
"order": 3
|
|
213
206
|
},
|
|
214
207
|
"value": {
|
|
215
|
-
"title": "
|
|
208
|
+
"title": "Data point value",
|
|
216
209
|
"type": "number",
|
|
217
210
|
"order": 4
|
|
218
211
|
},
|
|
219
212
|
"pivot": {
|
|
220
|
-
"title": "
|
|
221
|
-
"description": "You can specify a column in the input data to autogenerate dataseries for each distinct entry in this column. E.g. if you have a table with columns [city, lon, lat, temperature] and specify 'city' as
|
|
213
|
+
"title": "Split Data by",
|
|
214
|
+
"description": "You can specify a column in the input data to autogenerate dataseries for each distinct entry in this column. E.g. if you have a table with columns [city, lon, lat, temperature] and specify 'city' as split column, then you will get a layer for each city.",
|
|
222
215
|
"type": "string",
|
|
223
216
|
"order": 5
|
|
224
217
|
}
|
package/src/widget-mapbox.ts
CHANGED
|
@@ -6,14 +6,14 @@ import { repeat } from 'lit/directives/repeat.js'
|
|
|
6
6
|
import mapboxgl from 'https://esm.run/mapbox-gl@3.0.1'
|
|
7
7
|
import * as GeoJSON from 'geojson'
|
|
8
8
|
import tinycolor from 'tinycolor2'
|
|
9
|
-
import {
|
|
9
|
+
import { LayerBaseColor, InputData } from './definition-schema.js'
|
|
10
10
|
|
|
11
|
-
type Dataseries = Exclude<
|
|
11
|
+
type Dataseries = Exclude<InputData['dataseries'], undefined>[number]
|
|
12
12
|
type Point = Exclude<Dataseries['data'], undefined>[number]
|
|
13
13
|
|
|
14
14
|
export class WidgetMapbox extends LitElement {
|
|
15
15
|
@property({ type: Object })
|
|
16
|
-
inputData?:
|
|
16
|
+
inputData?: InputData
|
|
17
17
|
@state()
|
|
18
18
|
private map: any | undefined = undefined
|
|
19
19
|
|
|
@@ -30,17 +30,24 @@ export class WidgetMapbox extends LitElement {
|
|
|
30
30
|
private mapLoaded: boolean = false
|
|
31
31
|
private resizeObserver: ResizeObserver
|
|
32
32
|
private mapStyle?: string
|
|
33
|
+
private customDebounce?: any
|
|
33
34
|
private imageList: string[] = []
|
|
34
35
|
constructor() {
|
|
35
36
|
super()
|
|
36
37
|
this.resizeObserver = new ResizeObserver(() => {
|
|
37
|
-
this.
|
|
38
|
-
this.fitBounds()
|
|
38
|
+
this.updateMap()
|
|
39
39
|
})
|
|
40
40
|
mapboxgl.accessToken =
|
|
41
41
|
'pk.eyJ1IjoibWFya29wZSIsImEiOiJjazc1OWlsNjkwN2pyM2VxajV1eGRnYzgwIn0.3lVksk1nej_0KnWjCkBDAA'
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
disconnectedCallback() {
|
|
45
|
+
super.disconnectedCallback()
|
|
46
|
+
if(this.resizeObserver) {
|
|
47
|
+
this.resizeObserver.disconnect()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
44
51
|
update(changedProperties: Map<string, any>) {
|
|
45
52
|
if (changedProperties.has('inputData')) {
|
|
46
53
|
this.transformInputData()
|
|
@@ -55,6 +62,15 @@ export class WidgetMapbox extends LitElement {
|
|
|
55
62
|
this.fitBounds()
|
|
56
63
|
}
|
|
57
64
|
|
|
65
|
+
updateMap() {
|
|
66
|
+
if (this.customDebounce) clearTimeout(this.customDebounce)
|
|
67
|
+
|
|
68
|
+
this.customDebounce = setTimeout(() => {
|
|
69
|
+
this.map?.resize()
|
|
70
|
+
this.fitBounds()
|
|
71
|
+
}, 300)
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
fitBounds() {
|
|
59
75
|
const bounds = new mapboxgl.LngLatBounds()
|
|
60
76
|
this.dataSources.forEach((col: GeoJSON.FeatureCollection) => {
|
|
@@ -70,16 +86,16 @@ export class WidgetMapbox extends LitElement {
|
|
|
70
86
|
}
|
|
71
87
|
|
|
72
88
|
transformInputData() {
|
|
73
|
-
if (!this?.inputData
|
|
89
|
+
if (!this?.inputData || !this?.inputData?.dataseries?.length) return
|
|
74
90
|
|
|
75
|
-
if (this.map && this.inputData
|
|
91
|
+
if (this.map && this.inputData?.style !== this.mapStyle) {
|
|
76
92
|
this.createMap()
|
|
77
93
|
}
|
|
78
94
|
|
|
79
95
|
// choose random color if dataseries has none and store it for furure updates
|
|
80
96
|
this.inputData.dataseries.forEach((ds) => {
|
|
81
97
|
if (!this.colors.has(ds.label)) {
|
|
82
|
-
ds.color = ds.color ?? tinycolor.random().toString()
|
|
98
|
+
ds.color = ds.color ?? (tinycolor.random().toString() as LayerBaseColor)
|
|
83
99
|
this.colors.set(ds.label, ds.color)
|
|
84
100
|
}
|
|
85
101
|
})
|
|
@@ -96,7 +112,7 @@ export class WidgetMapbox extends LitElement {
|
|
|
96
112
|
distincts.forEach((piv, i) => {
|
|
97
113
|
const prefix = piv ? `${piv} - ` : ''
|
|
98
114
|
const pds: any = {
|
|
99
|
-
label: prefix + ds.label
|
|
115
|
+
label: prefix + ds.label,
|
|
100
116
|
order: ds.order,
|
|
101
117
|
type: ds.type,
|
|
102
118
|
latestValues: ds.latestValues,
|
|
@@ -420,7 +436,7 @@ export class WidgetMapbox extends LitElement {
|
|
|
420
436
|
this.addLineLayer(ds)
|
|
421
437
|
}
|
|
422
438
|
})
|
|
423
|
-
if (this.inputData?.
|
|
439
|
+
if (this.inputData?.follow) this.fitBounds()
|
|
424
440
|
}
|
|
425
441
|
|
|
426
442
|
addBuildingLayer() {
|
|
@@ -474,7 +490,7 @@ export class WidgetMapbox extends LitElement {
|
|
|
474
490
|
|
|
475
491
|
createMap() {
|
|
476
492
|
if (this.map) return
|
|
477
|
-
this.mapStyle = this.inputData?.
|
|
493
|
+
this.mapStyle = this.inputData?.style
|
|
478
494
|
this.map = new mapboxgl.Map({
|
|
479
495
|
container: this.shadowRoot?.getElementById('map') as HTMLCanvasElement,
|
|
480
496
|
style: `mapbox://styles/mapbox/${this.mapStyle ?? 'light-v11'}`,
|
|
@@ -581,17 +597,17 @@ export class WidgetMapbox extends LitElement {
|
|
|
581
597
|
<div class="wrapper">
|
|
582
598
|
<header
|
|
583
599
|
class="paging"
|
|
584
|
-
?active=${this.inputData?.
|
|
600
|
+
?active=${this.inputData?.title || this.inputData?.subTitle}
|
|
585
601
|
>
|
|
586
602
|
<div class="title">
|
|
587
|
-
<h3 class="paging" ?active=${this.inputData?.
|
|
588
|
-
${this.inputData?.
|
|
603
|
+
<h3 class="paging" ?active=${this.inputData?.title}>
|
|
604
|
+
${this.inputData?.title}
|
|
589
605
|
</h3>
|
|
590
|
-
<p class="paging" ?active=${this.inputData?.
|
|
591
|
-
${this.inputData?.
|
|
606
|
+
<p class="paging" ?active=${this.inputData?.subTitle}>
|
|
607
|
+
${this.inputData?.subTitle}
|
|
592
608
|
</p>
|
|
593
609
|
</div>
|
|
594
|
-
<div class="legend paging" ?active=${this?.inputData?.
|
|
610
|
+
<div class="legend paging" ?active=${this?.inputData?.showLegend}>
|
|
595
611
|
${repeat(
|
|
596
612
|
this.dataSets,
|
|
597
613
|
(ds) => ds.label,
|