@xyo-network/react-map 2.64.0 → 2.64.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/browser/AnimatedHeatMapSettings.js +56 -3
- package/dist/browser/AnimatedHeatMapSettings.js.map +1 -1
- package/dist/browser/Colors/index.js +0 -1
- package/dist/browser/Colors/index.js.map +1 -1
- package/dist/browser/Components/AnimatedHeatMap.js +623 -10
- package/dist/browser/Components/AnimatedHeatMap.js.map +1 -1
- package/dist/browser/Components/AnimatedHeatMapLoaded.js +864 -13
- package/dist/browser/Components/AnimatedHeatMapLoaded.js.map +1 -1
- package/dist/browser/Components/HeatMapSettings.js +56 -3
- package/dist/browser/Components/HeatMapSettings.js.map +1 -1
- package/dist/browser/Components/LayerAnimator.js +5 -4
- package/dist/browser/Components/LayerAnimator.js.map +1 -1
- package/dist/browser/Components/Legend.js +32 -7
- package/dist/browser/Components/Legend.js.map +1 -1
- package/dist/browser/Components/Legends/ColorGradient.js +3 -2
- package/dist/browser/Components/Legends/ColorGradient.js.map +1 -1
- package/dist/browser/Components/Legends/index.js +25 -1
- package/dist/browser/Components/Legends/index.js.map +1 -1
- package/dist/browser/Components/MapBox.js +66 -12
- package/dist/browser/Components/MapBox.js.map +1 -1
- package/dist/browser/Components/MapBoxHeat.js +151 -6
- package/dist/browser/Components/MapBoxHeat.js.map +1 -1
- package/dist/browser/Components/MapBoxPoints.js +207 -14
- package/dist/browser/Components/MapBoxPoints.js.map +1 -1
- package/dist/browser/Components/MapSettingsComponents/Setting.js +16 -3
- package/dist/browser/Components/MapSettingsComponents/Setting.js.map +1 -1
- package/dist/browser/Components/MapSettingsComponents/SettingsBox.js +38 -6
- package/dist/browser/Components/MapSettingsComponents/SettingsBox.js.map +1 -1
- package/dist/browser/Components/MapSettingsComponents/index.js +50 -2
- package/dist/browser/Components/MapSettingsComponents/index.js.map +1 -1
- package/dist/browser/Components/index.js +1084 -11
- package/dist/browser/Components/index.js.map +1 -1
- package/dist/browser/Contexts/HeatMapInitializer/Context.js +2 -1
- package/dist/browser/Contexts/HeatMapInitializer/Context.js.map +1 -1
- package/dist/browser/Contexts/HeatMapInitializer/Provider.js +235 -14
- package/dist/browser/Contexts/HeatMapInitializer/Provider.js.map +1 -1
- package/dist/browser/Contexts/HeatMapInitializer/index.js +294 -3
- package/dist/browser/Contexts/HeatMapInitializer/index.js.map +1 -1
- package/dist/browser/Contexts/HeatMapInitializer/useHeatMapInitializer.js +8 -2
- package/dist/browser/Contexts/HeatMapInitializer/useHeatMapInitializer.js.map +1 -1
- package/dist/browser/Contexts/MapBoxInstance/Context.js +2 -1
- package/dist/browser/Contexts/MapBoxInstance/Context.js.map +1 -1
- package/dist/browser/Contexts/MapBoxInstance/Provider.js +9 -3
- package/dist/browser/Contexts/MapBoxInstance/Provider.js.map +1 -1
- package/dist/browser/Contexts/MapBoxInstance/index.js +35 -3
- package/dist/browser/Contexts/MapBoxInstance/index.js.map +1 -1
- package/dist/browser/Contexts/MapBoxInstance/useMapBoxInstance.js +8 -2
- package/dist/browser/Contexts/MapBoxInstance/useMapBoxInstance.js.map +1 -1
- package/dist/browser/Contexts/MapSettings/Context.js +2 -1
- package/dist/browser/Contexts/MapSettings/Context.js.map +1 -1
- package/dist/browser/Contexts/MapSettings/Provider.js +117 -5
- package/dist/browser/Contexts/MapSettings/Provider.js.map +1 -1
- package/dist/browser/Contexts/MapSettings/index.js +148 -3
- package/dist/browser/Contexts/MapSettings/index.js.map +1 -1
- package/dist/browser/Contexts/MapSettings/useMapSettings.js +8 -2
- package/dist/browser/Contexts/MapSettings/useMapSettings.js.map +1 -1
- package/dist/browser/Contexts/MapboxAccessToken/Context.js +2 -1
- package/dist/browser/Contexts/MapboxAccessToken/Context.js.map +1 -1
- package/dist/browser/Contexts/MapboxAccessToken/Provider.js +9 -3
- package/dist/browser/Contexts/MapboxAccessToken/Provider.js.map +1 -1
- package/dist/browser/Contexts/MapboxAccessToken/index.js +22 -4
- package/dist/browser/Contexts/MapboxAccessToken/index.js.map +1 -1
- package/dist/browser/Contexts/MapboxAccessToken/use.js +8 -2
- package/dist/browser/Contexts/MapboxAccessToken/use.js.map +1 -1
- package/dist/browser/Contexts/index.js +459 -4
- package/dist/browser/Contexts/index.js.map +1 -1
- package/dist/browser/Layers/Builders/LocationHeatMapLayerBuilder.js +110 -6
- package/dist/browser/Layers/Builders/LocationHeatMapLayerBuilder.js.map +1 -1
- package/dist/browser/Layers/Builders/LocationHeatMapLayerBuilderAnimated.js +36 -4
- package/dist/browser/Layers/Builders/LocationHeatMapLayerBuilderAnimated.js.map +1 -1
- package/dist/browser/Layers/Builders/LocationPointsMapLayerBuilder.js +40 -4
- package/dist/browser/Layers/Builders/LocationPointsMapLayerBuilder.js.map +1 -1
- package/dist/browser/Layers/Builders/index.js +205 -3
- package/dist/browser/Layers/Builders/index.js.map +1 -1
- package/dist/browser/Layers/CircleLayer.js +3 -2
- package/dist/browser/Layers/CircleLayer.js.map +1 -1
- package/dist/browser/Layers/Configs/HeatMapFillLayerConfig.js +2 -1
- package/dist/browser/Layers/Configs/HeatMapFillLayerConfig.js.map +1 -1
- package/dist/browser/Layers/Configs/HeatMapLineLayerConfig.js +2 -1
- package/dist/browser/Layers/Configs/HeatMapLineLayerConfig.js.map +1 -1
- package/dist/browser/Layers/Configs/HeatMapSymbolLayerConfig.js +2 -1
- package/dist/browser/Layers/Configs/HeatMapSymbolLayerConfig.js.map +1 -1
- package/dist/browser/Layers/Configs/LocationPointLayerConfig.js +2 -1
- package/dist/browser/Layers/Configs/LocationPointLayerConfig.js.map +1 -1
- package/dist/browser/Layers/Configs/index.js +62 -4
- package/dist/browser/Layers/Configs/index.js.map +1 -1
- package/dist/browser/Layers/FillLayer.js +3 -2
- package/dist/browser/Layers/FillLayer.js.map +1 -1
- package/dist/browser/Layers/LineLayer.js +3 -2
- package/dist/browser/Layers/LineLayer.js.map +1 -1
- package/dist/browser/Layers/SymbolLayer.js +3 -2
- package/dist/browser/Layers/SymbolLayer.js.map +1 -1
- package/dist/browser/Layers/index.js +213 -7
- package/dist/browser/Layers/index.js.map +1 -1
- package/dist/browser/MapBoxClasses/MapBase.js +3 -2
- package/dist/browser/MapBoxClasses/MapBase.js.map +1 -1
- package/dist/browser/MapBoxClasses/MapHeat.js +41 -11
- package/dist/browser/MapBoxClasses/MapHeat.js.map +1 -1
- package/dist/browser/MapBoxClasses/MapPoints.js +33 -3
- package/dist/browser/MapBoxClasses/MapPoints.js.map +1 -1
- package/dist/browser/MapBoxClasses/MapSettings.js +6 -5
- package/dist/browser/MapBoxClasses/MapSettings.js.map +1 -1
- package/dist/browser/MapBoxClasses/index.js +288 -4
- package/dist/browser/MapBoxClasses/index.js.map +1 -1
- package/dist/browser/Settings/DefaultMapSettings.js +2 -1
- package/dist/browser/Settings/DefaultMapSettings.js.map +1 -1
- package/dist/browser/Settings/index.js +55 -2
- package/dist/browser/Settings/index.js.map +1 -1
- package/dist/browser/hooks/index.js +156 -5
- package/dist/browser/hooks/index.js.map +1 -1
- package/dist/browser/hooks/useDynamicMapResize.js +2 -1
- package/dist/browser/hooks/useDynamicMapResize.js.map +1 -1
- package/dist/browser/hooks/useDynamicPositioning.js +7 -6
- package/dist/browser/hooks/useDynamicPositioning.js.map +1 -1
- package/dist/browser/hooks/useFindHashes.js +4 -3
- package/dist/browser/hooks/useFindHashes.js.map +1 -1
- package/dist/browser/hooks/useHeatMapColors.js +2 -1
- package/dist/browser/hooks/useHeatMapColors.js.map +1 -1
- package/dist/browser/hooks/useQuadKeyPayloadsToFeatures.js +4 -3
- package/dist/browser/hooks/useQuadKeyPayloadsToFeatures.js.map +1 -1
- package/dist/browser/index.js +1298 -10
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/lib/MapStyle.js +1 -0
- package/dist/browser/lib/MapStyle.js.map +1 -1
- package/dist/browser/lib/index.js +13 -2
- package/dist/browser/lib/index.js.map +1 -1
- package/dist/browser/types/index.js +0 -1
- package/dist/browser/types/index.js.map +1 -1
- package/dist/docs.json +296 -296
- package/package.json +14 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/Layers/SymbolLayer.ts
|
|
1
2
|
import { LayerBase } from "@xyo-network/sdk-geo";
|
|
2
|
-
|
|
3
|
+
var SymbolLayerBuilder = class extends LayerBase {
|
|
3
4
|
SymbolLayerOptions;
|
|
4
5
|
// ensures this class passes for `AnyLayer` type in MapBox
|
|
5
6
|
type = "symbol";
|
|
@@ -15,7 +16,7 @@ class SymbolLayerBuilder extends LayerBase {
|
|
|
15
16
|
type: this.type
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
}
|
|
19
|
+
};
|
|
19
20
|
export {
|
|
20
21
|
SymbolLayerBuilder
|
|
21
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Layers/SymbolLayer.ts"],"sourcesContent":["import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { SymbolLayer } from 'mapbox-gl'\n\nexport class SymbolLayerBuilder extends LayerBase<SymbolLayer> {\n SymbolLayerOptions: Partial<SymbolLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'symbol' = 'symbol' as const\n\n constructor(id: string, source: string, SymbolLayerOptions?: Partial<SymbolLayer>) {\n super(id, source)\n this.SymbolLayerOptions = SymbolLayerOptions || { id: this.id, source: this.source }\n }\n buildLayer(): SymbolLayer {\n return {\n ...this.SymbolLayerOptions,\n id: this.id,\n source: this.source,\n type: this.type,\n }\n }\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAInB,
|
|
1
|
+
{"version":3,"sources":["../../../src/Layers/SymbolLayer.ts"],"sourcesContent":["import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { SymbolLayer } from 'mapbox-gl'\n\nexport class SymbolLayerBuilder extends LayerBase<SymbolLayer> {\n SymbolLayerOptions: Partial<SymbolLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'symbol' = 'symbol' as const\n\n constructor(id: string, source: string, SymbolLayerOptions?: Partial<SymbolLayer>) {\n super(id, source)\n this.SymbolLayerOptions = SymbolLayerOptions || { id: this.id, source: this.source }\n }\n buildLayer(): SymbolLayer {\n return {\n ...this.SymbolLayerOptions,\n id: this.id,\n source: this.source,\n type: this.type,\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAInB,IAAM,qBAAN,cAAiC,UAAuB;AAAA,EAC7D;AAAA;AAAA,EAGA,OAAiB;AAAA,EAEjB,YAAY,IAAY,QAAgB,oBAA2C;AACjF,UAAM,IAAI,MAAM;AAChB,SAAK,qBAAqB,sBAAsB,EAAE,IAAI,KAAK,IAAI,QAAQ,KAAK,OAAO;AAAA,EACrF;AAAA,EACA,aAA0B;AACxB,WAAO;AAAA,MACL,GAAG,KAAK;AAAA,MACR,IAAI,KAAK;AAAA,MACT,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,8 +1,214 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// src/Layers/Configs/HeatMapFillLayerConfig.ts
|
|
2
|
+
var HeatMapFillLayerConfig = (color) => ({
|
|
3
|
+
paint: {
|
|
4
|
+
"fill-color": color,
|
|
5
|
+
"fill-opacity": [
|
|
6
|
+
"let",
|
|
7
|
+
"density",
|
|
8
|
+
["+", ["/", ["number", ["get", "value"]], 4], 0.125],
|
|
9
|
+
["interpolate", ["linear"], ["var", "density"], 0.8, ["var", "density"], 1, 0.85]
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// src/Layers/Configs/HeatMapLineLayerConfig.ts
|
|
15
|
+
var HeatMapLineLayerConfig = (color) => ({
|
|
16
|
+
layout: {
|
|
17
|
+
// Enable for debugging
|
|
18
|
+
visibility: "none"
|
|
19
|
+
},
|
|
20
|
+
paint: {
|
|
21
|
+
"line-color": color,
|
|
22
|
+
"line-opacity": ["let", "density", 0, ["interpolate", ["linear"], ["var", "density"], 0.8, ["var", "density"], 1, 0.85]],
|
|
23
|
+
"line-width": 0.5
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/Layers/Configs/HeatMapSymbolLayerConfig.ts
|
|
28
|
+
var HeatMapSymbolLayerConfig = (color) => ({
|
|
29
|
+
layout: {
|
|
30
|
+
"text-anchor": "center",
|
|
31
|
+
"text-field": [
|
|
32
|
+
"concat",
|
|
33
|
+
"value: ",
|
|
34
|
+
["to-string", ["+", ["/", ["number", ["get", "value"]], 2], 0.25]],
|
|
35
|
+
"\n",
|
|
36
|
+
"count: ",
|
|
37
|
+
["to-string", ["get", "count"]]
|
|
38
|
+
],
|
|
39
|
+
"text-size": 10,
|
|
40
|
+
visibility: "none"
|
|
41
|
+
},
|
|
42
|
+
paint: {
|
|
43
|
+
"text-color": color
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// src/Layers/Configs/LocationPointLayerConfig.ts
|
|
48
|
+
var LocationPointLayerConfig = (color, circleRadius, circleOpacity) => {
|
|
49
|
+
return {
|
|
50
|
+
paint: {
|
|
51
|
+
"circle-color": color,
|
|
52
|
+
"circle-opacity": circleOpacity,
|
|
53
|
+
"circle-radius": circleRadius
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/Layers/FillLayer.ts
|
|
59
|
+
import { LayerBase } from "@xyo-network/sdk-geo";
|
|
60
|
+
var FillLayerBuilder = class extends LayerBase {
|
|
61
|
+
FillLayerOptions;
|
|
62
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
63
|
+
type = "fill";
|
|
64
|
+
constructor(id, source, FillLayerOptions) {
|
|
65
|
+
super(id, source);
|
|
66
|
+
this.FillLayerOptions = FillLayerOptions || { id: this.id, source: this.source };
|
|
67
|
+
}
|
|
68
|
+
buildLayer() {
|
|
69
|
+
return {
|
|
70
|
+
...this.FillLayerOptions,
|
|
71
|
+
id: this.id,
|
|
72
|
+
source: this.source,
|
|
73
|
+
type: this.type
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/Layers/LineLayer.ts
|
|
79
|
+
import { LayerBase as LayerBase2 } from "@xyo-network/sdk-geo";
|
|
80
|
+
var LineLayerBuilder = class extends LayerBase2 {
|
|
81
|
+
LineLayerOptions;
|
|
82
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
83
|
+
type = "line";
|
|
84
|
+
constructor(id, source, LineLayerOptions) {
|
|
85
|
+
super(id, source);
|
|
86
|
+
this.LineLayerOptions = LineLayerOptions || { id: this.id, source: this.source };
|
|
87
|
+
}
|
|
88
|
+
buildLayer() {
|
|
89
|
+
return {
|
|
90
|
+
...this.LineLayerOptions,
|
|
91
|
+
id: this.id,
|
|
92
|
+
layout: {},
|
|
93
|
+
source: this.source,
|
|
94
|
+
type: this.type
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/Layers/SymbolLayer.ts
|
|
100
|
+
import { LayerBase as LayerBase3 } from "@xyo-network/sdk-geo";
|
|
101
|
+
var SymbolLayerBuilder = class extends LayerBase3 {
|
|
102
|
+
SymbolLayerOptions;
|
|
103
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
104
|
+
type = "symbol";
|
|
105
|
+
constructor(id, source, SymbolLayerOptions) {
|
|
106
|
+
super(id, source);
|
|
107
|
+
this.SymbolLayerOptions = SymbolLayerOptions || { id: this.id, source: this.source };
|
|
108
|
+
}
|
|
109
|
+
buildLayer() {
|
|
110
|
+
return {
|
|
111
|
+
...this.SymbolLayerOptions,
|
|
112
|
+
id: this.id,
|
|
113
|
+
source: this.source,
|
|
114
|
+
type: this.type
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/Layers/Builders/LocationHeatMapLayerBuilder.ts
|
|
120
|
+
var MapHeatConstants = {
|
|
121
|
+
LocationDebugLayerId: "location-debug-id",
|
|
122
|
+
LocationDebugLayerSource: "location-debug-source",
|
|
123
|
+
LocationFillLayerId: "location-fill-id",
|
|
124
|
+
LocationFillLayerSource: "location-fill-source",
|
|
125
|
+
LocationLineLayerId: "location-line-id",
|
|
126
|
+
LocationLineLayerSource: "location-line-source"
|
|
127
|
+
};
|
|
128
|
+
var LocationHeatMapLayerBuilder = (color, alternateColor = "#000") => {
|
|
129
|
+
const {
|
|
130
|
+
LocationFillLayerId,
|
|
131
|
+
LocationFillLayerSource,
|
|
132
|
+
LocationLineLayerId,
|
|
133
|
+
LocationLineLayerSource,
|
|
134
|
+
LocationDebugLayerId,
|
|
135
|
+
LocationDebugLayerSource
|
|
136
|
+
} = MapHeatConstants;
|
|
137
|
+
const fillLayerConfig = HeatMapFillLayerConfig(color);
|
|
138
|
+
const lineLayerConfig = HeatMapLineLayerConfig(color);
|
|
139
|
+
const debugLayerConfig = HeatMapSymbolLayerConfig(alternateColor);
|
|
140
|
+
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig);
|
|
141
|
+
const lineLayer = new LineLayerBuilder(LocationLineLayerId, LocationLineLayerSource, lineLayerConfig);
|
|
142
|
+
const debugLayer = new SymbolLayerBuilder(LocationDebugLayerId, LocationDebugLayerSource, debugLayerConfig);
|
|
143
|
+
return [fillLayer, lineLayer, debugLayer];
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/Layers/Builders/LocationHeatMapLayerBuilderAnimated.ts
|
|
147
|
+
var MapHeatConstants2 = (index, type) => ({
|
|
148
|
+
LocationDebugLayerId: `location-${type}-debug-id-${index}`,
|
|
149
|
+
LocationDebugLayerSource: `location-${type}-debug-source-${index}`,
|
|
150
|
+
LocationFillLayerId: `location-${type}-fill-id-${index}`,
|
|
151
|
+
LocationFillLayerSource: `location-${type}-fill-source-${index}`,
|
|
152
|
+
LocationLineLayerId: `location-${type}-line-id-${index}`,
|
|
153
|
+
LocationLineLayerSource: `location-${type}-line-source-${index}`
|
|
154
|
+
});
|
|
155
|
+
var LocationHeatMapLayerBuilderAnimated = (color, index, type = "") => {
|
|
156
|
+
const { LocationFillLayerId, LocationFillLayerSource } = MapHeatConstants2(index, type);
|
|
157
|
+
const fillLayerConfig = HeatMapFillLayerConfig(color);
|
|
158
|
+
const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig);
|
|
159
|
+
return fillLayer;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/Layers/CircleLayer.ts
|
|
163
|
+
import { LayerBase as LayerBase4 } from "@xyo-network/sdk-geo";
|
|
164
|
+
var CircleLayerBuilder = class extends LayerBase4 {
|
|
165
|
+
CircleLayerOptions;
|
|
166
|
+
// ensures this class passes for `AnyLayer` type in MapBox
|
|
167
|
+
type = "circle";
|
|
168
|
+
constructor(id, source, CircleLayerOptions) {
|
|
169
|
+
super(id, source);
|
|
170
|
+
this.CircleLayerOptions = CircleLayerOptions || { id: this.id, source: this.source, type: "circle" };
|
|
171
|
+
}
|
|
172
|
+
buildLayer() {
|
|
173
|
+
return {
|
|
174
|
+
filter: ["==", "$type", "Point"],
|
|
175
|
+
layout: {},
|
|
176
|
+
paint: {
|
|
177
|
+
"circle-color": "#ff0000",
|
|
178
|
+
"circle-radius": 6
|
|
179
|
+
},
|
|
180
|
+
type: this.type,
|
|
181
|
+
...this.CircleLayerOptions,
|
|
182
|
+
id: this.id,
|
|
183
|
+
source: this.source
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/Layers/Builders/LocationPointsMapLayerBuilder.ts
|
|
189
|
+
var MapPointsConstants = {
|
|
190
|
+
LocationDotsLayerId: "location-dots",
|
|
191
|
+
LocationDotsLayerSource: "location-dots-source"
|
|
192
|
+
};
|
|
193
|
+
var LocationPointsMapLayerBuilder = (color, circleRadius = 6, circleOpacity = 0.8) => {
|
|
194
|
+
const { LocationDotsLayerId, LocationDotsLayerSource } = MapPointsConstants;
|
|
195
|
+
const dotLayerConfig = LocationPointLayerConfig(color, circleRadius, circleOpacity);
|
|
196
|
+
const dotLayer = new CircleLayerBuilder(LocationDotsLayerId, LocationDotsLayerSource, dotLayerConfig);
|
|
197
|
+
return [dotLayer];
|
|
198
|
+
};
|
|
199
|
+
export {
|
|
200
|
+
CircleLayerBuilder,
|
|
201
|
+
FillLayerBuilder,
|
|
202
|
+
HeatMapFillLayerConfig,
|
|
203
|
+
HeatMapLineLayerConfig,
|
|
204
|
+
HeatMapSymbolLayerConfig,
|
|
205
|
+
LineLayerBuilder,
|
|
206
|
+
LocationHeatMapLayerBuilder,
|
|
207
|
+
LocationHeatMapLayerBuilderAnimated,
|
|
208
|
+
LocationPointLayerConfig,
|
|
209
|
+
LocationPointsMapLayerBuilder,
|
|
210
|
+
MapHeatConstants,
|
|
211
|
+
MapPointsConstants,
|
|
212
|
+
SymbolLayerBuilder
|
|
213
|
+
};
|
|
8
214
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Layers/index.ts"],"sourcesContent":["export * from './Builders'\nexport * from './CircleLayer'\nexport * from './Configs'\nexport * from './FillLayer'\nexport * from './LineLayer'\nexport * from './MapLayer'\nexport * from './SymbolLayer'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/Layers/Configs/HeatMapFillLayerConfig.ts","../../../src/Layers/Configs/HeatMapLineLayerConfig.ts","../../../src/Layers/Configs/HeatMapSymbolLayerConfig.ts","../../../src/Layers/Configs/LocationPointLayerConfig.ts","../../../src/Layers/FillLayer.ts","../../../src/Layers/LineLayer.ts","../../../src/Layers/SymbolLayer.ts","../../../src/Layers/Builders/LocationHeatMapLayerBuilder.ts","../../../src/Layers/Builders/LocationHeatMapLayerBuilderAnimated.ts","../../../src/Layers/CircleLayer.ts","../../../src/Layers/Builders/LocationPointsMapLayerBuilder.ts"],"sourcesContent":["import { FillLayer } from 'mapbox-gl'\n\nexport const HeatMapFillLayerConfig: (color: string) => Partial<FillLayer> = (color) => ({\n paint: {\n 'fill-color': color,\n 'fill-opacity': [\n 'let',\n 'density',\n ['+', ['/', ['number', ['get', 'value']], 4], 0.125],\n ['interpolate', ['linear'], ['var', 'density'], 0.8, ['var', 'density'], 1, 0.85],\n ],\n },\n})\n","import { LineLayer } from 'mapbox-gl'\n\nexport const HeatMapLineLayerConfig: (color: string) => Partial<LineLayer> = (color) => ({\n layout: {\n // Enable for debugging\n visibility: 'none',\n },\n paint: {\n 'line-color': color,\n 'line-opacity': ['let', 'density', 0, ['interpolate', ['linear'], ['var', 'density'], 0.8, ['var', 'density'], 1, 0.85]],\n 'line-width': 0.5,\n },\n})\n","import { SymbolLayer } from 'mapbox-gl'\n\nexport const HeatMapSymbolLayerConfig: (color: string) => Partial<SymbolLayer> = (color) => ({\n layout: {\n 'text-anchor': 'center',\n 'text-field': [\n 'concat',\n 'value: ',\n ['to-string', ['+', ['/', ['number', ['get', 'value']], 2], 0.25]],\n '\\n',\n 'count: ',\n ['to-string', ['get', 'count']],\n ],\n 'text-size': 10,\n visibility: 'none',\n },\n paint: {\n 'text-color': color,\n },\n})\n","import { CircleLayer } from 'mapbox-gl'\n\nexport const LocationPointLayerConfig: (color: string, circleRadius: number, circleOpacity: number) => Partial<CircleLayer> = (\n color,\n circleRadius,\n circleOpacity,\n) => {\n return {\n paint: {\n 'circle-color': color,\n 'circle-opacity': circleOpacity,\n 'circle-radius': circleRadius,\n },\n }\n}\n","import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { FillLayer } from 'mapbox-gl'\n\nexport class FillLayerBuilder extends LayerBase<FillLayer> {\n FillLayerOptions: Partial<FillLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'fill' = 'fill' as const\n\n constructor(id: string, source: string, FillLayerOptions?: Partial<FillLayer>) {\n super(id, source)\n this.FillLayerOptions = FillLayerOptions || { id: this.id, source: this.source }\n }\n buildLayer(): FillLayer {\n return {\n ...this.FillLayerOptions,\n id: this.id,\n source: this.source,\n type: this.type,\n }\n }\n}\n","import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { LineLayer } from 'mapbox-gl'\n\nexport class LineLayerBuilder extends LayerBase<LineLayer> {\n LineLayerOptions: Partial<LineLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'line' = 'line' as const\n\n constructor(id: string, source: string, LineLayerOptions?: Partial<LineLayer>) {\n super(id, source)\n this.LineLayerOptions = LineLayerOptions || { id: this.id, source: this.source }\n }\n buildLayer(): LineLayer {\n return {\n ...this.LineLayerOptions,\n id: this.id,\n layout: {},\n source: this.source,\n type: this.type,\n }\n }\n}\n","import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { SymbolLayer } from 'mapbox-gl'\n\nexport class SymbolLayerBuilder extends LayerBase<SymbolLayer> {\n SymbolLayerOptions: Partial<SymbolLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'symbol' = 'symbol' as const\n\n constructor(id: string, source: string, SymbolLayerOptions?: Partial<SymbolLayer>) {\n super(id, source)\n this.SymbolLayerOptions = SymbolLayerOptions || { id: this.id, source: this.source }\n }\n buildLayer(): SymbolLayer {\n return {\n ...this.SymbolLayerOptions,\n id: this.id,\n source: this.source,\n type: this.type,\n }\n }\n}\n","import { HeatMapFillLayerConfig, HeatMapLineLayerConfig, HeatMapSymbolLayerConfig } from '../Configs'\nimport { FillLayerBuilder } from '../FillLayer'\nimport { LineLayerBuilder } from '../LineLayer'\nimport { SymbolLayerBuilder } from '../SymbolLayer'\n\nexport const MapHeatConstants = {\n LocationDebugLayerId: 'location-debug-id',\n LocationDebugLayerSource: 'location-debug-source',\n LocationFillLayerId: 'location-fill-id',\n LocationFillLayerSource: 'location-fill-source',\n LocationLineLayerId: 'location-line-id',\n LocationLineLayerSource: 'location-line-source',\n}\n\nexport const LocationHeatMapLayerBuilder = (color: string, alternateColor = '#000') => {\n const {\n LocationFillLayerId,\n LocationFillLayerSource,\n LocationLineLayerId,\n LocationLineLayerSource,\n LocationDebugLayerId,\n LocationDebugLayerSource,\n } = MapHeatConstants\n\n const fillLayerConfig = HeatMapFillLayerConfig(color)\n const lineLayerConfig = HeatMapLineLayerConfig(color)\n const debugLayerConfig = HeatMapSymbolLayerConfig(alternateColor)\n\n const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig)\n const lineLayer = new LineLayerBuilder(LocationLineLayerId, LocationLineLayerSource, lineLayerConfig)\n const debugLayer = new SymbolLayerBuilder(LocationDebugLayerId, LocationDebugLayerSource, debugLayerConfig)\n\n return [fillLayer, lineLayer, debugLayer]\n}\n","import { HeatMapFillLayerConfig } from '../Configs'\nimport { FillLayerBuilder } from '../FillLayer'\n\nconst MapHeatConstants = (index: number, type: string) => ({\n LocationDebugLayerId: `location-${type}-debug-id-${index}`,\n LocationDebugLayerSource: `location-${type}-debug-source-${index}`,\n LocationFillLayerId: `location-${type}-fill-id-${index}`,\n LocationFillLayerSource: `location-${type}-fill-source-${index}`,\n LocationLineLayerId: `location-${type}-line-id-${index}`,\n LocationLineLayerSource: `location-${type}-line-source-${index}`,\n})\n\nexport const LocationHeatMapLayerBuilderAnimated = (color: string, index: number, type = '') => {\n const { LocationFillLayerId, LocationFillLayerSource } = MapHeatConstants(index, type)\n\n const fillLayerConfig = HeatMapFillLayerConfig(color)\n\n const fillLayer = new FillLayerBuilder(LocationFillLayerId, LocationFillLayerSource, fillLayerConfig)\n\n return fillLayer\n}\n","import { LayerBase } from '@xyo-network/sdk-geo'\n// eslint-disable-next-line no-restricted-imports\nimport { CircleLayer } from 'mapbox-gl'\n\nexport class CircleLayerBuilder extends LayerBase<CircleLayer> {\n CircleLayerOptions: Partial<CircleLayer>\n\n // ensures this class passes for `AnyLayer` type in MapBox\n type: 'circle' = 'circle' as const\n\n constructor(id: string, source: string, CircleLayerOptions?: Partial<CircleLayer>) {\n super(id, source)\n this.CircleLayerOptions = CircleLayerOptions || { id: this.id, source: this.source, type: 'circle' }\n }\n buildLayer(): CircleLayer {\n return {\n filter: ['==', '$type', 'Point'],\n layout: {},\n paint: {\n 'circle-color': '#ff0000',\n 'circle-radius': 6,\n },\n type: this.type,\n ...this.CircleLayerOptions,\n id: this.id,\n source: this.source,\n }\n }\n}\n","import { CircleLayerBuilder } from '../CircleLayer'\nimport { LocationPointLayerConfig } from '../Configs'\n\nexport const MapPointsConstants = {\n LocationDotsLayerId: 'location-dots',\n LocationDotsLayerSource: 'location-dots-source',\n}\n\nexport const LocationPointsMapLayerBuilder = (color: string, circleRadius = 6, circleOpacity = 0.8) => {\n const { LocationDotsLayerId, LocationDotsLayerSource } = MapPointsConstants\n\n const dotLayerConfig = LocationPointLayerConfig(color, circleRadius, circleOpacity)\n\n const dotLayer = new CircleLayerBuilder(LocationDotsLayerId, LocationDotsLayerSource, dotLayerConfig)\n\n return [dotLayer]\n}\n"],"mappings":";AAEO,IAAM,yBAAgE,CAAC,WAAW;AAAA,EACvF,OAAO;AAAA,IACL,cAAc;AAAA,IACd,gBAAgB;AAAA,MACd;AAAA,MACA;AAAA,MACA,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK;AAAA,MACnD,CAAC,eAAe,CAAC,QAAQ,GAAG,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GAAG,IAAI;AAAA,IAClF;AAAA,EACF;AACF;;;ACVO,IAAM,yBAAgE,CAAC,WAAW;AAAA,EACvF,QA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,IAAI,KAAK;AAAA,MACT,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;;;ACzBO,IAAM,qBAAqB;AAAA,EAChC,qBAAqB;AAAA,EACrB,yBAAyB;AAC3B;AAEO,IAAM,gCAAgC,CAAC,OAAe,eAAe,GAAG,gBAAgB,QAAQ;AACrG,QAAM,EAAE,qBAAqB,wBAAwB,IAAI;AAEzD,QAAM,iBAAiB,yBAAyB,OAAO,cAAc,aAAa;AAElF,QAAM,WAAW,IAAI,mBAAmB,qBAAqB,yBAAyB,cAAc;AAEpG,SAAO,CAAC,QAAQ;AAClB;","names":["LayerBase","LayerBase","MapHeatConstants","LayerBase"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// src/MapBoxClasses/MapBase.ts
|
|
1
2
|
import { assertEx } from "@xylabs/assert";
|
|
2
3
|
import { GeoJson } from "@xyo-network/sdk-geo";
|
|
3
|
-
|
|
4
|
+
var MapBase = class {
|
|
4
5
|
_config;
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this._config = { requestLocation: true, zoom: 2, ...config };
|
|
@@ -23,7 +24,7 @@ class MapBase {
|
|
|
23
24
|
layer.update(this._config.map, true);
|
|
24
25
|
return this;
|
|
25
26
|
}
|
|
26
|
-
}
|
|
27
|
+
};
|
|
27
28
|
export {
|
|
28
29
|
MapBase
|
|
29
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/MapBoxClasses/MapBase.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Geometry } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { GeoJSONSource, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\n\nexport interface MapBaseConfig<T extends Geometry> {\n features: Feature<T>[]\n map: Map\n requestLocation?: boolean\n zoom?: number\n}\n\nexport abstract class MapBase<T extends Geometry> {\n private _config: MapBaseConfig<T>\n\n constructor(config: MapBaseConfig<T>) {\n this._config = { requestLocation: true, zoom: 2, ...config }\n }\n\n get isMapReady() {\n return !!this._config.map\n }\n\n initializeMapSource(layer: MapLayer) {\n const getSource = () => {\n const featuresCollection = GeoJson.featureCollection(this._config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n const existingSource = this._config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource()\n if (existingSource) {\n existingSource.setData(assertEx(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>))\n } else {\n this._config.map.addSource(layer.source as string, source)\n }\n layer.update(this._config.map, true)\n\n return this\n }\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAcjB,
|
|
1
|
+
{"version":3,"sources":["../../../src/MapBoxClasses/MapBase.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Geometry } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { GeoJSONSource, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\n\nexport interface MapBaseConfig<T extends Geometry> {\n features: Feature<T>[]\n map: Map\n requestLocation?: boolean\n zoom?: number\n}\n\nexport abstract class MapBase<T extends Geometry> {\n private _config: MapBaseConfig<T>\n\n constructor(config: MapBaseConfig<T>) {\n this._config = { requestLocation: true, zoom: 2, ...config }\n }\n\n get isMapReady() {\n return !!this._config.map\n }\n\n initializeMapSource(layer: MapLayer) {\n const getSource = () => {\n const featuresCollection = GeoJson.featureCollection(this._config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n const existingSource = this._config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource()\n if (existingSource) {\n existingSource.setData(assertEx(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>))\n } else {\n this._config.map.addSource(layer.source as string, source)\n }\n layer.update(this._config.map, true)\n\n return this\n }\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAcjB,IAAe,UAAf,MAA2C;AAAA,EACxC;AAAA,EAER,YAAY,QAA0B;AACpC,SAAK,UAAU,EAAE,iBAAiB,MAAM,MAAM,GAAG,GAAG,OAAO;AAAA,EAC7D;AAAA,EAEA,IAAI,aAAa;AACf,WAAO,CAAC,CAAC,KAAK,QAAQ;AAAA,EACxB;AAAA,EAEA,oBAAoB,OAAiB;AACnC,UAAM,YAAY,MAAM;AACtB,YAAM,qBAAqB,QAAQ,kBAAkB,KAAK,QAAQ,QAAQ;AAC1E,aAAO,QAAQ,eAAe,kBAAkB;AAAA,IAClD;AAEA,UAAM,iBAAiB,KAAK,QAAQ,IAAI,UAAU,MAAM,MAAgB;AACxE,UAAM,SAAS,UAAU;AACzB,QAAI,gBAAgB;AAClB,qBAAe,QAAQ,SAAS,OAAO,IAAuF,CAAC;AAAA,IACjI,OAAO;AACL,WAAK,QAAQ,IAAI,UAAU,MAAM,QAAkB,MAAM;AAAA,IAC3D;AACA,UAAM,OAAO,KAAK,QAAQ,KAAK,IAAI;AAEnC,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
// src/MapBoxClasses/MapHeat.ts
|
|
2
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
2
3
|
import { delay } from "@xylabs/delay";
|
|
3
4
|
import { forget } from "@xylabs/forget";
|
|
4
|
-
import { GeoJson } from "@xyo-network/sdk-geo";
|
|
5
|
+
import { GeoJson as GeoJson2 } from "@xyo-network/sdk-geo";
|
|
5
6
|
import { LngLatBounds } from "mapbox-gl";
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// src/MapBoxClasses/MapBase.ts
|
|
9
|
+
import { assertEx } from "@xylabs/assert";
|
|
10
|
+
import { GeoJson } from "@xyo-network/sdk-geo";
|
|
11
|
+
var MapBase = class {
|
|
12
|
+
_config;
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this._config = { requestLocation: true, zoom: 2, ...config };
|
|
15
|
+
}
|
|
16
|
+
get isMapReady() {
|
|
17
|
+
return !!this._config.map;
|
|
18
|
+
}
|
|
19
|
+
initializeMapSource(layer) {
|
|
20
|
+
const getSource = () => {
|
|
21
|
+
const featuresCollection = GeoJson.featureCollection(this._config.features);
|
|
22
|
+
return GeoJson.featuresSource(featuresCollection);
|
|
23
|
+
};
|
|
24
|
+
const existingSource = this._config.map.getSource(layer.source);
|
|
25
|
+
const source = getSource();
|
|
26
|
+
if (existingSource) {
|
|
27
|
+
existingSource.setData(assertEx(source.data));
|
|
28
|
+
} else {
|
|
29
|
+
this._config.map.addSource(layer.source, source);
|
|
30
|
+
}
|
|
31
|
+
layer.update(this._config.map, true);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/MapBoxClasses/MapHeat.ts
|
|
37
|
+
var MapHeat = class extends MapBase {
|
|
8
38
|
static animationStarted = false;
|
|
9
39
|
config;
|
|
10
40
|
constructor(config) {
|
|
@@ -37,8 +67,8 @@ class MapHeat extends MapBase {
|
|
|
37
67
|
let layerTick = 0;
|
|
38
68
|
let sourceTick = 0;
|
|
39
69
|
const sources = featureSet.map((feature) => {
|
|
40
|
-
const featuresCollection =
|
|
41
|
-
return
|
|
70
|
+
const featuresCollection = GeoJson2.featureCollection(feature);
|
|
71
|
+
return GeoJson2.featuresSource(featuresCollection);
|
|
42
72
|
});
|
|
43
73
|
this.updateLayer(map, layers[0], sources[0]);
|
|
44
74
|
this.updateLayer(map, layers[1], sources[1]);
|
|
@@ -81,7 +111,7 @@ class MapHeat extends MapBase {
|
|
|
81
111
|
};
|
|
82
112
|
let started = false;
|
|
83
113
|
const startAnimation = async () => {
|
|
84
|
-
|
|
114
|
+
assertEx2(!started, "Animation Already Started");
|
|
85
115
|
started = true;
|
|
86
116
|
while (this.animationStarted) {
|
|
87
117
|
const upLayer = layerTick % layers.length;
|
|
@@ -117,14 +147,14 @@ class MapHeat extends MapBase {
|
|
|
117
147
|
// Build layers each with the same features
|
|
118
148
|
initializeHeatMapSource(layers) {
|
|
119
149
|
const getSource = (_) => {
|
|
120
|
-
const featuresCollection =
|
|
121
|
-
return
|
|
150
|
+
const featuresCollection = GeoJson2.featureCollection(this.config.features);
|
|
151
|
+
return GeoJson2.featuresSource(featuresCollection);
|
|
122
152
|
};
|
|
123
153
|
layers.forEach((layer, index) => {
|
|
124
154
|
const existingSource = this.config.map.getSource(layer.source);
|
|
125
155
|
const source = getSource(index);
|
|
126
156
|
if (existingSource) {
|
|
127
|
-
existingSource.setData(
|
|
157
|
+
existingSource.setData(assertEx2(source.data));
|
|
128
158
|
} else {
|
|
129
159
|
this.config.map.addSource(layer.source, source);
|
|
130
160
|
}
|
|
@@ -132,7 +162,7 @@ class MapHeat extends MapBase {
|
|
|
132
162
|
});
|
|
133
163
|
return this;
|
|
134
164
|
}
|
|
135
|
-
}
|
|
165
|
+
};
|
|
136
166
|
export {
|
|
137
167
|
MapHeat
|
|
138
168
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/MapBoxClasses/MapHeat.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { delay } from '@xylabs/delay'\nimport { forget } from '@xylabs/forget'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Polygon } from 'geojson'\nimport { FitBoundsOptions, GeoJSONSource, GeoJSONSourceRaw, LngLatBounds, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\nimport { MapBase, MapBaseConfig } from './MapBase'\n\nexport class MapHeat extends MapBase<Polygon> {\n static animationStarted = false\n\n config: MapBaseConfig<Polygon>\n constructor(config: MapBaseConfig<Polygon>) {\n super(config)\n this.config = config\n }\n\n static initialMapPositioning(options: FitBoundsOptions, map: Map, features?: Feature<Polygon>[], initialBounds?: LngLatBounds) {\n if (!features) {\n return\n }\n\n let bounds: LngLatBounds\n\n if (initialBounds) {\n bounds = initialBounds\n } else {\n bounds = new LngLatBounds()\n\n features.forEach((feature: Feature<Polygon>) => {\n feature.geometry.coordinates.forEach((coordinates) => {\n coordinates.forEach((position) => {\n bounds.extend(position as [number, number])\n })\n })\n })\n }\n\n map.setCenter(bounds.getCenter())\n map.fitBounds(bounds, options)\n return this\n }\n\n static async initializeAnimatedHeatMapSource(\n layers: MapLayer[],\n featureSet: Feature<Polygon>[][],\n map: Map,\n startColor?: string,\n endColor?: string,\n ) {\n this.animationStarted = true\n let layerTick = 0\n let sourceTick = 0\n\n const sources = featureSet.map((feature) => {\n const featuresCollection = GeoJson.featureCollection(feature)\n return GeoJson.featuresSource(featuresCollection)\n })\n this.updateLayer(map, layers[0], sources[0])\n this.updateLayer(map, layers[1], sources[1])\n\n layers.forEach((layer) => {\n map.setPaintProperty(layer.id, 'fill-opacity', 0)\n })\n\n const frameLength = 3000\n const initialPad = 0.5\n const factor = 10\n const steps = 30\n const stepLength = frameLength / steps\n const lowUsageColor = startColor ?? '#FFB3B3'\n const highUsageColor = endColor ?? '#FF0000'\n\n // Max density at i=0, min density at i=steps\n const dynamicFillColor = (factor: number, initialPad: number, i: number) => {\n const sinFade = Math.sin(((i / steps) * Math.PI) / 2)\n const cosFade = Math.cos(((i / steps) * Math.PI) / 2)\n // we want the divisor to always be at least 1x the desired factor but will go up to\n // 2x factor to account for combinative effect of the overlay of two layers at once\n const divisor = factor + factor * sinFade\n const offset = initialPad * cosFade\n return [\n 'let',\n 'density',\n ['+', ['/', ['number', ['get', 'value']], divisor], offset],\n ['interpolate', ['linear'], ['var', 'density'], 0, lowUsageColor, 0.5, highUsageColor],\n ]\n }\n\n const fadedIn: boolean[] = layers.map((_) => false)\n\n const fadeIn = async (id: string, index: number) => {\n for (let i = steps; i >= 1; i--) {\n map.setPaintProperty(id, 'fill-color', dynamicFillColor(factor, initialPad, i * (180 / stepLength)))\n await delay(stepLength)\n }\n fadedIn[index] = true\n }\n\n const fadeOut = async (id: string, index: number) => {\n for (let i = 1; i <= steps; i++) {\n map.setPaintProperty(id, 'fill-color', dynamicFillColor(factor, initialPad, i * (180 / stepLength)))\n await delay(stepLength)\n }\n fadedIn[index] = false\n }\n\n let started = false\n const startAnimation = async () => {\n assertEx(!started, 'Animation Already Started')\n started = true\n while (this.animationStarted) {\n const upLayer = layerTick % layers.length\n const downLayer = (layerTick + 1) % layers.length\n\n const incomingSource = sourceTick % featureSet.length\n const outgoingSource = (sourceTick + 1) % featureSet.length\n\n // console.log('incoming / outgoing source', incomingSource, outgoingSource)\n\n // console.log(`animate: [${upLayer}, ${downLayer}]`)\n if (fadedIn[upLayer]) {\n this.updateLayer(map, layers[upLayer], sources[incomingSource])\n forget(fadeOut(layers[upLayer].id, upLayer))\n }\n if (!fadedIn[downLayer]) {\n this.updateLayer(map, layers[downLayer], sources[outgoingSource])\n forget(fadeIn(layers[downLayer].id, downLayer))\n }\n while ((fadedIn[upLayer] || !fadedIn[downLayer]) && this.animationStarted) {\n // console.log(`checking: [${fadedIn[upLayer]}, ${!fadedIn[downLayer]}]`)\n await delay(1000)\n }\n layerTick++\n sourceTick++\n\n // console.log(`this.layerTick: ${layerTick}`)\n // console.log(`this.sourceTick: ${sourceTick}`)\n }\n }\n\n await startAnimation()\n }\n\n private static updateLayer(map: Map, layer: MapLayer, source: GeoJSONSourceRaw) {\n const existingSource = map.getSource(layer.source as string) as GeoJSONSource\n if (existingSource && source.data) {\n existingSource.setData(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>)\n } else if (source) {\n map.addSource(layer.source as string, source)\n }\n layer.update(map, true)\n }\n\n // Build layers each with the same features\n initializeHeatMapSource(layers: MapLayer[]) {\n const getSource = (_: number) => {\n const featuresCollection = GeoJson.featureCollection(this.config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n layers.forEach((layer, index) => {\n const existingSource = this.config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource(index)\n if (existingSource) {\n existingSource.setData(assertEx(source.data) as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>)\n } else {\n this.config.map.addSource(layer.source as string, source)\n }\n layer.update(this.config.map, true)\n })\n\n return this\n }\n}\n"],"mappings":"AAAA,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,eAAe;AAExB,SAA4D,oBAAyB;AAGrF,SAAS,eAA8B;AAEhC,MAAM,gBAAgB,QAAiB;AAAA,EAC5C,OAAO,mBAAmB;AAAA,EAE1B;AAAA,EACA,YAAY,QAAgC;AAC1C,UAAM,MAAM;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,sBAAsB,SAA2B,KAAU,UAA+B,eAA8B;AAC7H,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AAEA,QAAI;AAEJ,QAAI,eAAe;AACjB,eAAS;AAAA,IACX,OAAO;AACL,eAAS,IAAI,aAAa;AAE1B,eAAS,QAAQ,CAAC,YAA8B;AAC9C,gBAAQ,SAAS,YAAY,QAAQ,CAAC,gBAAgB;AACpD,sBAAY,QAAQ,CAAC,aAAa;AAChC,mBAAO,OAAO,QAA4B;AAAA,UAC5C,CAAC;AAAA,QACH,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAEA,QAAI,UAAU,OAAO,UAAU,CAAC;AAChC,QAAI,UAAU,QAAQ,OAAO;AAC7B,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,gCACX,QACA,YACA,KACA,YACA,UACA;AACA,SAAK,mBAAmB;AACxB,QAAI,YAAY;AAChB,QAAI,aAAa;AAEjB,UAAM,UAAU,WAAW,IAAI,CAAC,YAAY;AAC1C,YAAM,qBAAqB,QAAQ,kBAAkB,OAAO;AAC5D,aAAO,QAAQ,eAAe,kBAAkB;AAAA,IAClD,CAAC;AACD,SAAK,YAAY,KAAK,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;AAC3C,SAAK,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kB;AAAA,IAClD;AAEA,WAAO,QAAQ,CAAC,OAAO,UAAU;AAC/B,YAAM,iBAAiB,KAAK,OAAO,IAAI,UAAU,MAAM,MAAgB;AACvE,YAAM,SAAS,UAAU,KAAK;AAC9B,UAAI,gBAAgB;AAClB,uBAAe,QAAQ,SAAS,OAAO,IAAI,CAAoF;AAAA,MACjI,OAAO;AACL,aAAK,OAAO,IAAI,UAAU,MAAM,QAAkB,MAAM;AAAA,MAC1D;AACA,YAAM,OAAO,KAAK,OAAO,KAAK,IAAI;AAAA,IACpC,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":["factor","initialPad"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/MapBoxClasses/MapHeat.ts","../../../src/MapBoxClasses/MapBase.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { delay } from '@xylabs/delay'\nimport { forget } from '@xylabs/forget'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Polygon } from 'geojson'\nimport { FitBoundsOptions, GeoJSONSource, GeoJSONSourceRaw, LngLatBounds, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\nimport { MapBase, MapBaseConfig } from './MapBase'\n\nexport class MapHeat extends MapBase<Polygon> {\n static animationStarted = false\n\n config: MapBaseConfig<Polygon>\n constructor(config: MapBaseConfig<Polygon>) {\n super(config)\n this.config = config\n }\n\n static initialMapPositioning(options: FitBoundsOptions, map: Map, features?: Feature<Polygon>[], initialBounds?: LngLatBounds) {\n if (!features) {\n return\n }\n\n let bounds: LngLatBounds\n\n if (initialBounds) {\n bounds = initialBounds\n } else {\n bounds = new LngLatBounds()\n\n features.forEach((feature: Feature<Polygon>) => {\n feature.geometry.coordinates.forEach((coordinates) => {\n coordinates.forEach((position) => {\n bounds.extend(position as [number, number])\n })\n })\n })\n }\n\n map.setCenter(bounds.getCenter())\n map.fitBounds(bounds, options)\n return this\n }\n\n static async initializeAnimatedHeatMapSource(\n layers: MapLayer[],\n featureSet: Feature<Polygon>[][],\n map: Map,\n startColor?: string,\n endColor?: string,\n ) {\n this.animationStarted = true\n let layerTick = 0\n let sourceTick = 0\n\n const sources = featureSet.map((feature) => {\n const featuresCollection = GeoJson.featureCollection(feature)\n return GeoJson.featuresSource(featuresCollection)\n })\n this.updateLayer(map, layers[0], sources[0])\n this.updateLayer(map, layers[1], sources[1])\n\n layers.forEach((layer) => {\n map.setPaintProperty(layer.id, 'fill-opacity', 0)\n })\n\n const frameLength = 3000\n const initialPad = 0.5\n const factor = 10\n const steps = 30\n const stepLength = frameLength / steps\n const lowUsageColor = startColor ?? '#FFB3B3'\n const highUsageColor = endColor ?? '#FF0000'\n\n // Max density at i=0, min density at i=steps\n const dynamicFillColor = (factor: number, initialPad: number, i: number) => {\n const sinFade = Math.sin(((i / steps) * Math.PI) / 2)\n const cosFade = Math.cos(((i / steps) * Math.PI) / 2)\n // we want the divisor to always be at least 1x the desired factor but will go up to\n // 2x factor to account for combinative effect of the overlay of two layers at once\n const divisor = factor + factor * sinFade\n const offset = initialPad * cosFade\n return [\n 'let',\n 'density',\n ['+', ['/', ['number', ['get', 'value']], divisor], offset],\n ['interpolate', ['linear'], ['var', 'density'], 0, lowUsageColor, 0.5, highUsageColor],\n ]\n }\n\n const fadedIn: boolean[] = layers.map((_) => false)\n\n const fadeIn = async (id: string, index: number) => {\n for (let i = steps; i >= 1; i--) {\n map.setPaintProperty(id, 'fill-color', dynamicFillColor(factor, initialPad, i * (180 / stepLength)))\n await delay(stepLength)\n }\n fadedIn[index] = true\n }\n\n const fadeOut = async (id: string, index: number) => {\n for (let i = 1; i <= steps; i++) {\n map.setPaintProperty(id, 'fill-color', dynamicFillColor(factor, initialPad, i * (180 / stepLength)))\n await delay(stepLength)\n }\n fadedIn[index] = false\n }\n\n let started = false\n const startAnimation = async () => {\n assertEx(!started, 'Animation Already Started')\n started = true\n while (this.animationStarted) {\n const upLayer = layerTick % layers.length\n const downLayer = (layerTick + 1) % layers.length\n\n const incomingSource = sourceTick % featureSet.length\n const outgoingSource = (sourceTick + 1) % featureSet.length\n\n // console.log('incoming / outgoing source', incomingSource, outgoingSource)\n\n // console.log(`animate: [${upLayer}, ${downLayer}]`)\n if (fadedIn[upLayer]) {\n this.updateLayer(map, layers[upLayer], sources[incomingSource])\n forget(fadeOut(layers[upLayer].id, upLayer))\n }\n if (!fadedIn[downLayer]) {\n this.updateLayer(map, layers[downLayer], sources[outgoingSource])\n forget(fadeIn(layers[downLayer].id, downLayer))\n }\n while ((fadedIn[upLayer] || !fadedIn[downLayer]) && this.animationStarted) {\n // console.log(`checking: [${fadedIn[upLayer]}, ${!fadedIn[downLayer]}]`)\n await delay(1000)\n }\n layerTick++\n sourceTick++\n\n // console.log(`this.layerTick: ${layerTick}`)\n // console.log(`this.sourceTick: ${sourceTick}`)\n }\n }\n\n await startAnimation()\n }\n\n private static updateLayer(map: Map, layer: MapLayer, source: GeoJSONSourceRaw) {\n const existingSource = map.getSource(layer.source as string) as GeoJSONSource\n if (existingSource && source.data) {\n existingSource.setData(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>)\n } else if (source) {\n map.addSource(layer.source as string, source)\n }\n layer.update(map, true)\n }\n\n // Build layers each with the same features\n initializeHeatMapSource(layers: MapLayer[]) {\n const getSource = (_: number) => {\n const featuresCollection = GeoJson.featureCollection(this.config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n layers.forEach((layer, index) => {\n const existingSource = this.config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource(index)\n if (existingSource) {\n existingSource.setData(assertEx(source.data) as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>)\n } else {\n this.config.map.addSource(layer.source as string, source)\n }\n layer.update(this.config.map, true)\n })\n\n return this\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Geometry } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { GeoJSONSource, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\n\nexport interface MapBaseConfig<T extends Geometry> {\n features: Feature<T>[]\n map: Map\n requestLocation?: boolean\n zoom?: number\n}\n\nexport abstract class MapBase<T extends Geometry> {\n private _config: MapBaseConfig<T>\n\n constructor(config: MapBaseConfig<T>) {\n this._config = { requestLocation: true, zoom: 2, ...config }\n }\n\n get isMapReady() {\n return !!this._config.map\n }\n\n initializeMapSource(layer: MapLayer) {\n const getSource = () => {\n const featuresCollection = GeoJson.featureCollection(this._config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n const existingSource = this._config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource()\n if (existingSource) {\n existingSource.setData(assertEx(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>))\n } else {\n this._config.map.addSource(layer.source as string, source)\n }\n layer.update(this._config.map, true)\n\n return this\n }\n}\n"],"mappings":";AAAA,SAAS,YAAAA,iBAAgB;AACzB,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,WAAAC,gBAAe;AAExB,SAA4D,oBAAyB;;;ACLrF,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAcjB,IAAe,UAAf,MAA2C;AAAA,EACxC;AAAA,EAER,YAAY,QAA0B;AACpC,SAAK,UAAU,EAAE,iBAAiB,MAAM,MAAM,GAAG,GAAG,OAAO;AAAA,EAC7D;AAAA,EAEA,IAAI,aAAa;AACf,WAAO,CAAC,CAAC,KAAK,QAAQ;AAAA,EACxB;AAAA,EAEA,oBAAoB,OAAiB;AACnC,UAAM,YAAY,MAAM;AACtB,YAAM,qBAAqB,QAAQ,kBAAkB,KAAK,QAAQ,QAAQ;AAC1E,aAAO,QAAQ,eAAe,kBAAkB;AAAA,IAClD;AAEA,UAAM,iBAAiB,KAAK,QAAQ,IAAI,UAAU,MAAM,MAAgB;AACxE,UAAM,SAAS,UAAU;AACzB,QAAI,gBAAg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K,OAAO,IAAI,UAAU,MAAM,MAAgB;AACvE,YAAM,SAAS,UAAU,KAAK;AAC9B,UAAI,gBAAgB;AAClB,uBAAe,QAAQG,UAAS,OAAO,IAAI,CAAoF;AAAA,MACjI,OAAO;AACL,aAAK,OAAO,IAAI,UAAU,MAAM,QAAkB,MAAM;AAAA,MAC1D;AACA,YAAM,OAAO,KAAK,OAAO,KAAK,IAAI;AAAA,IACpC,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":["assertEx","GeoJson","GeoJson","factor","initialPad","assertEx"]}
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
+
// src/MapBoxClasses/MapPoints.ts
|
|
1
2
|
import { LngLatBounds } from "mapbox-gl";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
// src/MapBoxClasses/MapBase.ts
|
|
5
|
+
import { assertEx } from "@xylabs/assert";
|
|
6
|
+
import { GeoJson } from "@xyo-network/sdk-geo";
|
|
7
|
+
var MapBase = class {
|
|
8
|
+
_config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this._config = { requestLocation: true, zoom: 2, ...config };
|
|
11
|
+
}
|
|
12
|
+
get isMapReady() {
|
|
13
|
+
return !!this._config.map;
|
|
14
|
+
}
|
|
15
|
+
initializeMapSource(layer) {
|
|
16
|
+
const getSource = () => {
|
|
17
|
+
const featuresCollection = GeoJson.featureCollection(this._config.features);
|
|
18
|
+
return GeoJson.featuresSource(featuresCollection);
|
|
19
|
+
};
|
|
20
|
+
const existingSource = this._config.map.getSource(layer.source);
|
|
21
|
+
const source = getSource();
|
|
22
|
+
if (existingSource) {
|
|
23
|
+
existingSource.setData(assertEx(source.data));
|
|
24
|
+
} else {
|
|
25
|
+
this._config.map.addSource(layer.source, source);
|
|
26
|
+
}
|
|
27
|
+
layer.update(this._config.map, true);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/MapBoxClasses/MapPoints.ts
|
|
33
|
+
var MapPoints = class extends MapBase {
|
|
4
34
|
config;
|
|
5
35
|
constructor(config) {
|
|
6
36
|
super(config);
|
|
@@ -20,7 +50,7 @@ class MapPoints extends MapBase {
|
|
|
20
50
|
this.config.map.fitBounds(bounds, options);
|
|
21
51
|
return this.config.map;
|
|
22
52
|
}
|
|
23
|
-
}
|
|
53
|
+
};
|
|
24
54
|
export {
|
|
25
55
|
MapPoints
|
|
26
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/MapBoxClasses/MapPoints.ts"],"sourcesContent":["import { Feature, Point } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { FitBoundsOptions, LngLatBounds } from 'mapbox-gl'\n\nimport { MapBase, MapBaseConfig } from './MapBase'\n\nexport interface MapPointsConfig extends MapBaseConfig<Point> {\n features: Feature<Point>[]\n}\n\nexport class MapPoints extends MapBase<Point> {\n private config: MapPointsConfig\n\n constructor(config: MapPointsConfig) {\n super(config)\n this.config = config\n }\n\n initialMapPositioning(options: FitBoundsOptions, initialBounds?: LngLatBounds) {\n let bounds: LngLatBounds\n\n if (initialBounds) {\n bounds = initialBounds\n } else {\n bounds = new LngLatBounds()\n\n this.config.features.forEach((feature: Feature<Point>) => {\n bounds.extend(feature.geometry.coordinates as [number, number])\n })\n }\n\n this.config.map.setCenter(bounds.getCenter())\n this.config.map.fitBounds(bounds, options)\n\n return this.config.map\n }\n}\n"],"mappings":"AAEA,SAA2B,oBAAoB
|
|
1
|
+
{"version":3,"sources":["../../../src/MapBoxClasses/MapPoints.ts","../../../src/MapBoxClasses/MapBase.ts"],"sourcesContent":["import { Feature, Point } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { FitBoundsOptions, LngLatBounds } from 'mapbox-gl'\n\nimport { MapBase, MapBaseConfig } from './MapBase'\n\nexport interface MapPointsConfig extends MapBaseConfig<Point> {\n features: Feature<Point>[]\n}\n\nexport class MapPoints extends MapBase<Point> {\n private config: MapPointsConfig\n\n constructor(config: MapPointsConfig) {\n super(config)\n this.config = config\n }\n\n initialMapPositioning(options: FitBoundsOptions, initialBounds?: LngLatBounds) {\n let bounds: LngLatBounds\n\n if (initialBounds) {\n bounds = initialBounds\n } else {\n bounds = new LngLatBounds()\n\n this.config.features.forEach((feature: Feature<Point>) => {\n bounds.extend(feature.geometry.coordinates as [number, number])\n })\n }\n\n this.config.map.setCenter(bounds.getCenter())\n this.config.map.fitBounds(bounds, options)\n\n return this.config.map\n }\n}\n","import { assertEx } from '@xylabs/assert'\nimport { GeoJson } from '@xyo-network/sdk-geo'\nimport { Feature, Geometry } from 'geojson'\n// eslint-disable-next-line no-restricted-imports\nimport { GeoJSONSource, Map } from 'mapbox-gl'\n\nimport { MapLayer } from '../Layers'\n\nexport interface MapBaseConfig<T extends Geometry> {\n features: Feature<T>[]\n map: Map\n requestLocation?: boolean\n zoom?: number\n}\n\nexport abstract class MapBase<T extends Geometry> {\n private _config: MapBaseConfig<T>\n\n constructor(config: MapBaseConfig<T>) {\n this._config = { requestLocation: true, zoom: 2, ...config }\n }\n\n get isMapReady() {\n return !!this._config.map\n }\n\n initializeMapSource(layer: MapLayer) {\n const getSource = () => {\n const featuresCollection = GeoJson.featureCollection(this._config.features)\n return GeoJson.featuresSource(featuresCollection)\n }\n\n const existingSource = this._config.map.getSource(layer.source as string) as GeoJSONSource\n const source = getSource()\n if (existingSource) {\n existingSource.setData(assertEx(source.data as GeoJSON.Feature<GeoJSON.Geometry> | GeoJSON.FeatureCollection<GeoJSON.Geometry>))\n } else {\n this._config.map.addSource(layer.source as string, source)\n }\n layer.update(this._config.map, true)\n\n return this\n }\n}\n"],"mappings":";AAEA,SAA2B,oBAAoB;;;ACF/C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAcjB,IAAe,UAAf,MAA2C;AAAA,EACxC;AAAA,EAER,YAAY,QAA0B;AACpC,SAAK,UAAU,EAAE,iBAAiB,MAAM,MAAM,GAAG,GAAG,OAAO;AAAA,EAC7D;AAAA,EAEA,IAAI,aAAa;AACf,WAAO,CAAC,CAAC,KAAK,QAAQ;AAAA,EACxB;AAAA,EAEA,oBAAoB,OAAiB;AACnC,UAAM,YAAY,MAAM;AACtB,YAAM,qBAAqB,QAAQ,kBAAkB,KAAK,QAAQ,QAAQ;AAC1E,aAAO,QAAQ,eAAe,kBAAkB;AAAA,IAClD;AAEA,UAAM,iBAAiB,KAAK,QAAQ,IAAI,UAAU,MAAM,MAAgB;AACxE,UAAM,SAAS,UAAU;AACzB,QAAI,gBAAgB;AAClB,qBAAe,QAAQ,SAAS,OAAO,IAAuF,CAAC;AAAA,IACjI,OAAO;AACL,WAAK,QAAQ,IAAI,UAAU,MAAM,QAAkB,MAAM;AAAA,IAC3D;AACA,UAAM,OAAO,KAAK,QAAQ,KAAK,IAAI;AAEnC,WAAO;AAAA,EACT;AACF;;;ADjCO,IAAM,YAAN,cAAwB,QAAe;AAAA,EACpC;AAAA,EAER,YAAY,QAAyB;AACnC,UAAM,MAAM;AACZ,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,sBAAsB,SAA2B,eAA8B;AAC7E,QAAI;AAEJ,QAAI,eAAe;AACjB,eAAS;AAAA,IACX,OAAO;AACL,eAAS,IAAI,aAAa;AAE1B,WAAK,OAAO,SAAS,QAAQ,CAAC,YAA4B;AACxD,eAAO,OAAO,QAAQ,SAAS,WAA+B;AAAA,MAChE,CAAC;AAAA,IACH;AAEA,SAAK,OAAO,IAAI,UAAU,OAAO,UAAU,CAAC;AAC5C,SAAK,OAAO,IAAI,UAAU,QAAQ,OAAO;AAEzC,WAAO,KAAK,OAAO;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// src/MapBoxClasses/MapSettings.ts
|
|
1
2
|
import { GeolocateControl, NavigationControl } from "mapbox-gl";
|
|
2
|
-
|
|
3
|
+
var MapSettings = class _MapSettings {
|
|
3
4
|
static geoLocateControl;
|
|
4
5
|
static mapListeners = {
|
|
5
6
|
logData: (ev, map) => {
|
|
@@ -14,9 +15,9 @@ class MapSettings {
|
|
|
14
15
|
static requestLocation;
|
|
15
16
|
static toggleControls(value, map, zoom, requestLocation) {
|
|
16
17
|
if (value) {
|
|
17
|
-
|
|
18
|
+
_MapSettings.addControls(map, zoom, requestLocation);
|
|
18
19
|
} else {
|
|
19
|
-
|
|
20
|
+
_MapSettings.removeControls(map);
|
|
20
21
|
}
|
|
21
22
|
return this;
|
|
22
23
|
}
|
|
@@ -51,7 +52,7 @@ class MapSettings {
|
|
|
51
52
|
static updateSettings(config) {
|
|
52
53
|
const { settings, map, zoom, requestLocation, debugLayerName = "" } = config;
|
|
53
54
|
const { scrollToZoom, enableControls, debugLayer, debugLogging } = settings;
|
|
54
|
-
|
|
55
|
+
_MapSettings.toggleControls(enableControls?.value, map, zoom, requestLocation).toggleScrollToZoom(scrollToZoom?.value, map).toggleDebugLayer(debugLayer?.value, map, debugLayerName).toggleDebugLogging(debugLogging.value, map);
|
|
55
56
|
}
|
|
56
57
|
// Needs to be static so we ensure controls are only instantiated once
|
|
57
58
|
static addControls(map, zoom, requestLocation) {
|
|
@@ -90,7 +91,7 @@ class MapSettings {
|
|
|
90
91
|
}
|
|
91
92
|
return this;
|
|
92
93
|
}
|
|
93
|
-
}
|
|
94
|
+
};
|
|
94
95
|
export {
|
|
95
96
|
MapSettings
|
|
96
97
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/MapBoxClasses/MapSettings.ts"],"sourcesContent":["import { EventData, GeolocateControl, Map, MapLayerMouseEvent, MapLayerTouchEvent, NavigationControl } from 'mapbox-gl'\n\nimport { MapSetting } from '../Settings'\n\nexport interface MapSettingsConfig {\n debugLayerName?: string\n map: Map\n requestLocation?: boolean\n settings: MapSetting\n zoom?: number\n}\n\n/**\n * Utility class to handle changes in settings\n *\n * Methods are pure functions dedicated to map manipulation\n */\nexport class MapSettings {\n static geoLocateControl: GeolocateControl | undefined\n static mapListeners = {\n logData: (ev?: MapLayerMouseEvent | (MapLayerTouchEvent & EventData), map?: Map) => {\n const target = map || ev?.target\n if (target) {\n console.log('zoom', target.getZoom())\n console.log('center', target.getCenter())\n }\n },\n }\n static navControl: NavigationControl | undefined\n static requestLocation: boolean | undefined\n\n static toggleControls(value: boolean | undefined, map: Map, zoom?: number, requestLocation?: boolean) {\n if (value) {\n MapSettings.addControls(map, zoom, requestLocation)\n } else {\n MapSettings.removeControls(map)\n }\n\n return this\n }\n\n static toggleDebugLayer(value: boolean | undefined, map: Map, layerName: string) {\n const debugLayer = map.getLayer(layerName)\n if (debugLayer) {\n if (value) {\n map.setLayoutProperty(layerName, 'visibility', 'visible')\n } else {\n map.setLayoutProperty(layerName, 'visibility', 'none')\n }\n }\n\n return this\n }\n\n static toggleDebugLogging(value: boolean | undefined, map: Map) {\n const debugEvents = ['resize', 'zoomend', 'dragend']\n if (value) {\n // initial values\n this.mapListeners.logData(undefined, map)\n debugEvents.forEach((event) => map.on(event, this.mapListeners.logData))\n } else {\n debugEvents.forEach((event) => map.off(event, this.mapListeners.logData))\n }\n }\n\n static toggleScrollToZoom(value: boolean | undefined, map: Map) {\n if (value) {\n map.scrollZoom.enable()\n } else {\n map.scrollZoom.disable()\n }\n\n return this\n }\n\n static updateSettings(config: MapSettingsConfig) {\n const { settings, map, zoom, requestLocation, debugLayerName = '' } = config\n const { scrollToZoom, enableControls, debugLayer, debugLogging } = settings\n\n MapSettings.toggleControls(enableControls?.value, map, zoom, requestLocation)\n .toggleScrollToZoom(scrollToZoom?.value, map)\n .toggleDebugLayer(debugLayer?.value, map, debugLayerName)\n .toggleDebugLogging(debugLogging.value, map)\n }\n\n // Needs to be static so we ensure controls are only instantiated once\n private static addControls(map: Map, zoom?: number, requestLocation?: boolean) {\n const geolocateControl = new GeolocateControl({\n fitBoundsOptions: {\n zoom: zoom || 2,\n },\n positionOptions: {\n enableHighAccuracy: true,\n },\n trackUserLocation: true,\n })\n\n const navControl = new NavigationControl({\n showCompass: false,\n })\n\n this.geoLocateControl = this.geoLocateControl || geolocateControl\n this.navControl = this.navControl || navControl\n\n if (!map.hasControl(this.geoLocateControl)) {\n if (requestLocation) {\n map.addControl(this.geoLocateControl)\n }\n }\n\n if (!map.hasControl(this.navControl)) {\n map.addControl(this.navControl, 'top-left')\n }\n\n return this\n }\n\n private static removeControls(map: Map) {\n if (this.geoLocateControl && map.hasControl(this.geoLocateControl)) {\n if (this.requestLocation) {\n map.removeControl(this.geoLocateControl)\n }\n }\n\n if (this.navControl && map.hasControl(this.navControl)) {\n map.removeControl(this.navControl)\n }\n\n return this\n }\n}\n"],"mappings":"AAAA,SAAoB,kBAA+D,yBAAyB;AAiBrG,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../src/MapBoxClasses/MapSettings.ts"],"sourcesContent":["import { EventData, GeolocateControl, Map, MapLayerMouseEvent, MapLayerTouchEvent, NavigationControl } from 'mapbox-gl'\n\nimport { MapSetting } from '../Settings'\n\nexport interface MapSettingsConfig {\n debugLayerName?: string\n map: Map\n requestLocation?: boolean\n settings: MapSetting\n zoom?: number\n}\n\n/**\n * Utility class to handle changes in settings\n *\n * Methods are pure functions dedicated to map manipulation\n */\nexport class MapSettings {\n static geoLocateControl: GeolocateControl | undefined\n static mapListeners = {\n logData: (ev?: MapLayerMouseEvent | (MapLayerTouchEvent & EventData), map?: Map) => {\n const target = map || ev?.target\n if (target) {\n console.log('zoom', target.getZoom())\n console.log('center', target.getCenter())\n }\n },\n }\n static navControl: NavigationControl | undefined\n static requestLocation: boolean | undefined\n\n static toggleControls(value: boolean | undefined, map: Map, zoom?: number, requestLocation?: boolean) {\n if (value) {\n MapSettings.addControls(map, zoom, requestLocation)\n } else {\n MapSettings.removeControls(map)\n }\n\n return this\n }\n\n static toggleDebugLayer(value: boolean | undefined, map: Map, layerName: string) {\n const debugLayer = map.getLayer(layerName)\n if (debugLayer) {\n if (value) {\n map.setLayoutProperty(layerName, 'visibility', 'visible')\n } else {\n map.setLayoutProperty(layerName, 'visibility', 'none')\n }\n }\n\n return this\n }\n\n static toggleDebugLogging(value: boolean | undefined, map: Map) {\n const debugEvents = ['resize', 'zoomend', 'dragend']\n if (value) {\n // initial values\n this.mapListeners.logData(undefined, map)\n debugEvents.forEach((event) => map.on(event, this.mapListeners.logData))\n } else {\n debugEvents.forEach((event) => map.off(event, this.mapListeners.logData))\n }\n }\n\n static toggleScrollToZoom(value: boolean | undefined, map: Map) {\n if (value) {\n map.scrollZoom.enable()\n } else {\n map.scrollZoom.disable()\n }\n\n return this\n }\n\n static updateSettings(config: MapSettingsConfig) {\n const { settings, map, zoom, requestLocation, debugLayerName = '' } = config\n const { scrollToZoom, enableControls, debugLayer, debugLogging } = settings\n\n MapSettings.toggleControls(enableControls?.value, map, zoom, requestLocation)\n .toggleScrollToZoom(scrollToZoom?.value, map)\n .toggleDebugLayer(debugLayer?.value, map, debugLayerName)\n .toggleDebugLogging(debugLogging.value, map)\n }\n\n // Needs to be static so we ensure controls are only instantiated once\n private static addControls(map: Map, zoom?: number, requestLocation?: boolean) {\n const geolocateControl = new GeolocateControl({\n fitBoundsOptions: {\n zoom: zoom || 2,\n },\n positionOptions: {\n enableHighAccuracy: true,\n },\n trackUserLocation: true,\n })\n\n const navControl = new NavigationControl({\n showCompass: false,\n })\n\n this.geoLocateControl = this.geoLocateControl || geolocateControl\n this.navControl = this.navControl || navControl\n\n if (!map.hasControl(this.geoLocateControl)) {\n if (requestLocation) {\n map.addControl(this.geoLocateControl)\n }\n }\n\n if (!map.hasControl(this.navControl)) {\n map.addControl(this.navControl, 'top-left')\n }\n\n return this\n }\n\n private static removeControls(map: Map) {\n if (this.geoLocateControl && map.hasControl(this.geoLocateControl)) {\n if (this.requestLocation) {\n map.removeControl(this.geoLocateControl)\n }\n }\n\n if (this.navControl && map.hasControl(this.navControl)) {\n map.removeControl(this.navControl)\n }\n\n return this\n }\n}\n"],"mappings":";AAAA,SAAoB,kBAA+D,yBAAyB;AAiBrG,IAAM,cAAN,MAAM,aAAY;AAAA,EACvB,OA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