@atmosx/event-product-parser 3.0.63 → 3.0.75
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/.github/docs/docs-functions.md +1 -1
- package/.github/docs/docs-general-configurations.md +1 -11
- package/.github/docs/docs-integrations.md +3 -2
- package/README.md +4 -4
- package/dist/cjs/index.cjs +3590 -623
- package/dist/esm/index.mjs +3589 -624
- package/package.json +11 -4
- package/src/bootstrap.ts +50 -33
- package/src/{@building → building}/CreateEvent.ts +10 -10
- package/src/{@building → building}/GetCleanedEvent.ts +2 -2
- package/src/{@building → building}/GetEventAttachments.ts +12 -10
- package/src/building/GetEventDirection.ts +28 -0
- package/src/{@building → building}/GetEventEnhancedName.ts +5 -6
- package/src/{@building → building}/GetEventGeometry.ts +19 -13
- package/src/{@building → building}/GetEventHeader.ts +4 -4
- package/src/{@building → building}/GetEventNodes.ts +16 -14
- package/src/{@building → building}/GetEventOffice.ts +5 -5
- package/src/building/GetEventPopulation.ts +58 -0
- package/src/{@building → building}/GetEventProperties.ts +23 -18
- package/src/{@building → building}/GetEventSignature.ts +8 -8
- package/src/{@building → building}/GetEventTags.ts +3 -3
- package/src/{@core/CreateListener.ts → building/GetEventTheme.ts} +8 -6
- package/src/{@building → building}/GetEventTracking.ts +6 -6
- package/src/{@modules/@eas/GenerateEASMessage.ts → components/audio/GenerateAudioMessage.ts} +32 -33
- package/src/{@modules/@eas → components/audio/components}/GetCleanDescription.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetFloatPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetMergedPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetPCMToFloat.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetSampledPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/GetTTS.ts +5 -3
- package/src/{@modules/@eas → components/audio/components}/GetWavPCM16.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/SetAFSK.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/SetAsciiToBits.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/SetAttentionTone.ts +2 -2
- package/src/{@modules/@eas → components/audio/components}/SetNoise.ts +4 -4
- package/src/{@modules/@eas → components/audio/components}/SetRadioEffect.ts +4 -4
- package/src/{@modules/@eas → components/audio/components}/SetSameHeader.ts +5 -5
- package/src/{@modules/@utilities/SetWarning.ts → components/database/CreateQuery.ts} +18 -13
- package/src/{@modules/@database → components/database}/GetCachedEvents.ts +14 -9
- package/src/components/database/ImportBoundaries.ts +168 -0
- package/src/{@modules/@database → components/database}/ImportBroadcastify.ts +8 -17
- package/src/components/database/ImportCities.ts +87 -0
- package/src/{@modules/@database → components/database}/ImportShapefiles.ts +14 -16
- package/src/{@modules/@database → components/database}/ImportStanza.ts +13 -17
- package/src/components/database/InitializeDatabase.ts +71 -0
- package/src/components/images/GenerateGraphic.ts +242 -0
- package/src/components/images/components/CreateRectangle.ts +22 -0
- package/src/components/images/components/CreateText.ts +22 -0
- package/src/components/images/modules/CreateSVG.ts +37 -0
- package/src/components/images/modules/GetGeographicalBoundaries.ts +72 -0
- package/src/components/images/modules/GetGeographicalCities.ts +58 -0
- package/src/components/images/modules/GetGeographicalEvents.ts +48 -0
- package/src/components/images/modules/GetGeometryBounds.ts +82 -0
- package/src/components/images/modules/GetParsedBoundary.ts +58 -0
- package/src/components/images/modules/GetSVGPath.ts +53 -0
- package/src/components/images/modules/NormalizePolygon.ts +57 -0
- package/src/{@modules/@stanza → components/stanza}/GetAwipsType.ts +4 -4
- package/src/{@modules/@stanza → components/stanza}/ValidateStanza.ts +6 -6
- package/src/{@modules/@utilities → components/utilities}/CreateHttp.ts +2 -2
- package/src/{@parsers/@text → components/utilities}/GetEmbededText.ts +6 -4
- package/src/{@modules/@utilities → components/utilities}/GetFormattedTime.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/GetLatestIssuance.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/GetMatched.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/GetShapeNearestPoint.ts +2 -2
- package/src/{@parsers/@text → components/utilities}/GetStringText.ts +7 -7
- package/src/components/utilities/GetUnionPolygon.ts +36 -0
- package/src/{@modules/@utilities → components/utilities}/QueueManager.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/SetCronSchedule.ts +37 -25
- package/src/{@modules/@utilities → components/utilities}/SetDebug.ts +4 -4
- package/src/{@modules/@utilities → components/utilities}/SetEventEmit.ts +8 -7
- package/src/{@modules/@utilities → components/utilities}/SetSettings.ts +4 -4
- package/src/{@modules/@utilities → components/utilities}/SetSleep.ts +2 -2
- package/src/{@modules/@utilities → components/utilities}/SetTimeoutAction.ts +3 -3
- package/src/components/utilities/SetWarning.ts +47 -0
- package/src/{@modules/@xmpp → components/xmpp}/DeployXMPP.ts +12 -12
- package/src/{@modules/@xmpp → components/xmpp}/ErrorXMPP.ts +3 -3
- package/src/{@modules/@xmpp → components/xmpp}/OfflineXMPP.ts +4 -4
- package/src/{@modules/@xmpp → components/xmpp}/OnlineXMPP.ts +5 -5
- package/src/{@modules/@xmpp → components/xmpp}/ReconnectXMPP.ts +6 -6
- package/src/{@modules/@xmpp → components/xmpp}/StanzaXMPP.ts +8 -8
- package/src/{@core → core}/ClearEvents.ts +4 -4
- package/src/{@core → core}/GetEvents.ts +3 -3
- package/src/{@core → core}/GetNodes.ts +3 -3
- package/src/{@core → core}/GetRandomEvent.ts +3 -3
- package/src/{@core → core}/GetVersion.ts +3 -3
- package/src/{@core → core}/ManualEvent.ts +6 -6
- package/src/{@core → core}/QueryStanza.ts +9 -8
- package/src/{@core → core}/SetNode.ts +5 -5
- package/src/{@core → core}/StartService.ts +13 -12
- package/src/{@core → core}/StopService.ts +3 -3
- package/src/{@enums → enums}/AWIPS.ts +2 -2
- package/src/{@enums → enums}/Actions.ts +2 -2
- package/src/{@enums → enums}/Cancellation.ts +2 -2
- package/src/{@enums → enums}/Causes.ts +2 -2
- package/src/{@enums → enums}/Correlations.ts +2 -2
- package/src/{@enums → enums}/Enhanced.ts +4 -3
- package/src/{@enums → enums}/Events.ts +2 -2
- package/src/{@enums → enums}/Expressions.ts +2 -2
- package/src/{@enums → enums}/GlobalFilter.ts +2 -2
- package/src/{@enums → enums}/Hail.ts +2 -2
- package/src/{@enums → enums}/ICAO.ts +2 -2
- package/src/{@enums → enums}/Matches.ts +8 -3
- package/src/{@enums → enums}/Products.ts +2 -2
- package/src/{@enums → enums}/Records.ts +2 -2
- package/src/{@enums → enums}/Severity.ts +2 -2
- package/src/{@enums → enums}/Shapefiles.ts +2 -2
- package/src/{@enums → enums}/States.ts +68 -4
- package/src/{@enums → enums}/Status.ts +2 -2
- package/src/{@enums → enums}/Strings.ts +2 -2
- package/src/{@enums → enums}/Tags.ts +8 -3
- package/src/{@enums → enums}/Testing.ts +2 -2
- package/src/enums/Themes.ts +70 -0
- package/src/{@events → events}/ParseAPI.ts +28 -17
- package/src/{@events → events}/ParseText.ts +13 -11
- package/src/{@events → events}/ParseUGC.ts +15 -14
- package/src/{@events → events}/ParseVTEC.ts +18 -16
- package/src/index.ts +49 -32
- package/src/{@manager → manager}/MakeEvents.ts +16 -28
- package/src/{@manager → manager}/RemoveEvent.ts +9 -9
- package/src/{@manager → manager}/SetHash.ts +5 -5
- package/src/{@manager → manager}/UpdateEvents.ts +6 -6
- package/src/{@manager → manager}/UpdateNode.ts +6 -6
- package/src/{@manager → manager}/ValidateEvents.ts +31 -20
- package/src/{@parsers/@hvtec → parsers/hvtec}/HVExtract.ts +7 -7
- package/src/{@parsers/@text → parsers/text}/GetDescriptionFromProduct.ts +3 -3
- package/src/parsers/text/GetPolygonFromProduct.ts +71 -0
- package/src/{@parsers/@text → parsers/text}/GetTextFromProduct.ts +2 -2
- package/src/{@parsers/@ugc → parsers/ugc}/GetCache.ts +4 -4
- package/src/{@parsers/@ugc → parsers/ugc}/GetExpiry.ts +2 -2
- package/src/{@parsers/@ugc → parsers/ugc}/GetHeader.ts +3 -3
- package/src/{@parsers/@ugc → parsers/ugc}/GetLocations.ts +9 -9
- package/src/parsers/ugc/GetZonePolygon.ts +73 -0
- package/src/{@parsers/@ugc → parsers/ugc}/GetZones.ts +2 -2
- package/src/{@parsers/@ugc → parsers/ugc}/SetCache.ts +4 -4
- package/src/{@parsers/@ugc → parsers/ugc}/UGCExtract.ts +9 -9
- package/src/{@parsers/@vtec → parsers/vtec}/GetExpiry.ts +2 -2
- package/src/{@parsers/@vtec → parsers/vtec}/VTECExtract.ts +9 -9
- package/src/{@types-lower → static}/Attributes.ts +2 -3
- package/src/{@types-lower → static}/Event.ts +7 -6
- package/src/{@types-lower → static}/Properties.ts +17 -4
- package/src/{@types-lower → static}/Stanza.ts +3 -3
- package/src/{@tasks → tasks}/CreateTasks.ts +40 -34
- package/src/{@tasks → tasks}/TaskGenerateJSON.ts +2 -2
- package/src/{@tasks → tasks}/TaskGenerateText.ts +2 -2
- package/src/{@tasks → tasks}/TaskSendNTFY.ts +29 -25
- package/src/{@tasks → tasks}/TaskSendWebhook.ts +22 -15
- package/src/{@types → types}/Actions.ts +3 -3
- package/src/{@types → types}/HVTEC.ts +2 -2
- package/src/{@types → types}/Hash.ts +2 -2
- package/src/types/Nodes.ts +29 -0
- package/src/{@types → types}/Settings.ts +17 -8
- package/src/{@types → types}/StanzaCompiled.ts +3 -3
- package/src/{@types → types}/UGC.ts +2 -2
- package/src/{@types → types}/VTEC.ts +2 -2
- package/tools/build.js +2 -0
- package/tsconfig.json +25 -18
- package/src/@modules/@database/InitializeDatabase.ts +0 -59
- package/src/@modules/@utilities/GetSettings.ts +0 -25
- package/src/@modules/@utilities/SetListener.ts +0 -30
- package/src/@parsers/@text/GetPolygonFromProduct.ts +0 -53
- package/src/@parsers/@text/GetXML.ts +0 -61
- package/src/@parsers/@ugc/GetZonePolygon.ts +0 -111
- package/src/@tasks/TaskGenerateAudio.ts +0 -34
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { EnumStates, EnumZones } from "@Enums/States"
|
|
21
|
+
import { TypeEvent } from "StaticTypes/Event"
|
|
22
|
+
import { Bootstrap } from "@Bootstrap"
|
|
23
|
+
import { GetStringText } from "@Utilities/GetStringText"
|
|
24
|
+
import { GetEventGeometry } from "@Building/GetEventGeometry"
|
|
25
|
+
import { GetGeographicalEvents } from "@ImageModules/GetGeographicalEvents"
|
|
26
|
+
import { GetUnionPolygon } from "@Utilities/GetUnionPolygon"
|
|
27
|
+
import { GetGeographicalBoundaries } from "@ImageModules/GetGeographicalBoundaries"
|
|
28
|
+
import { GetGeographicalCities } from "@ImageModules/GetGeographicalCities"
|
|
29
|
+
import { GetParsedBoundary } from "@ImageModules/GetParsedBoundary"
|
|
30
|
+
import { GetSVGPath } from "@ImageModules/GetSVGPath"
|
|
31
|
+
import { CreateSVG } from "@ImageModules/CreateSVG"
|
|
32
|
+
import { GetGeometryBounds } from "@ImageModules/GetGeometryBounds"
|
|
33
|
+
import { geoBounds, geoMercator, geoPath } from "d3-geo"
|
|
34
|
+
import { mkdir, readFile } from "fs/promises"
|
|
35
|
+
import { join } from "path";
|
|
36
|
+
import sharp from "sharp"
|
|
37
|
+
|
|
38
|
+
interface GenerateGraphicOptions {
|
|
39
|
+
Regions?: string[]
|
|
40
|
+
IgnoredRegions?: string[]
|
|
41
|
+
Event?: TypeEvent
|
|
42
|
+
File?: {
|
|
43
|
+
Directory?: string
|
|
44
|
+
Name?: string
|
|
45
|
+
}
|
|
46
|
+
MaxMiles?: number
|
|
47
|
+
Width?: number
|
|
48
|
+
Height?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const GenerateGraphic = async ({ File, Regions, Event, MaxMiles = 350, Width = 1200, Height = 675 }: GenerateGraphicOptions): Promise<string> => {
|
|
52
|
+
let polygons: GeoJSON.Polygon | GeoJSON.MultiPolygon | null
|
|
53
|
+
let icon: string | null;
|
|
54
|
+
let renders: any = {
|
|
55
|
+
cities: null,
|
|
56
|
+
states: null,
|
|
57
|
+
counties: null,
|
|
58
|
+
};
|
|
59
|
+
let pathing: any = {
|
|
60
|
+
cities: null,
|
|
61
|
+
events: null,
|
|
62
|
+
counties: null,
|
|
63
|
+
states: null,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const A = [EnumStates, EnumZones].reduce((acc, obj) => ({ ...acc, ...obj }), {});
|
|
67
|
+
const B = [`HI`, `AK`];
|
|
68
|
+
const { coordinates } = Event?.geometry ?? {};
|
|
69
|
+
const { properties } = Event ?? {};
|
|
70
|
+
const { regions, theme, event } = properties ?? {};
|
|
71
|
+
const inConus = Event ? regions?.every(state => A[state] && !B.includes(state)) : true;
|
|
72
|
+
const R = (Regions ?? null)?.length
|
|
73
|
+
? [...new Set(Regions ?? null)]
|
|
74
|
+
: null;
|
|
75
|
+
const E = GetGeographicalEvents({ Regions: R, Event: Event });
|
|
76
|
+
if (inConus || !Event) {
|
|
77
|
+
const boundaries = GetGeographicalBoundaries({ Regions: R });
|
|
78
|
+
const cities = GetGeographicalCities({ Regions: R });
|
|
79
|
+
renders.cities = cities.cities.filter(city => city.population >= 5e3).sort((a, b) => b.population - a.population).filter((city, index, cities) => {
|
|
80
|
+
return !cities.slice(0, index).some(other => {
|
|
81
|
+
const dist = Math.sqrt(
|
|
82
|
+
Math.pow(city.lat - other.lat, 2) +
|
|
83
|
+
Math.pow(city.lon - other.lon, 2)
|
|
84
|
+
);
|
|
85
|
+
return dist < (Event || Regions ? 0.4 : 3);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
renders.states = GetParsedBoundary(boundaries.states);
|
|
89
|
+
renders.counties = GetParsedBoundary(boundaries.counties);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (Event) {
|
|
93
|
+
polygons = (coordinates.length > 0) ? Event.geometry : await GetEventGeometry({ Event });
|
|
94
|
+
if (polygons.coordinates.length == 0) { return null; }
|
|
95
|
+
if (inConus) {
|
|
96
|
+
const eBounds = GetGeometryBounds({ Geometry: polygons, Padding: MaxMiles });
|
|
97
|
+
renders.counties = renders?.counties?.filter((county: GeoJSON.Feature<GeoJSON.Polygon>) => {
|
|
98
|
+
const cBounds = GetGeometryBounds({ Geometry: county.geometry, Padding: MaxMiles });
|
|
99
|
+
return ( cBounds.Bounds.minLon <= eBounds.Search.maxLon && cBounds.Bounds.maxLon >= eBounds.Search.minLon && cBounds.Bounds.minLat <= eBounds.Search.maxLat && cBounds.Bounds.maxLat >= eBounds.Search.minLat );
|
|
100
|
+
});
|
|
101
|
+
renders.states = renders?.states?.filter((state: GeoJSON.Feature<GeoJSON.Polygon>) => {
|
|
102
|
+
const sBounds = GetGeometryBounds({ Geometry: state.geometry, Padding: MaxMiles });
|
|
103
|
+
return ( sBounds.Bounds.minLon <= eBounds.Search.maxLon && sBounds.Bounds.maxLon >= eBounds.Search.minLon && sBounds.Bounds.minLat <= eBounds.Search.maxLat && sBounds.Bounds.maxLat >= eBounds.Search.minLat );
|
|
104
|
+
});
|
|
105
|
+
renders.cities = renders?.cities?.filter((city: { lat: number; lon: number }) => {
|
|
106
|
+
return ( city.lat >= eBounds.Search.minLat && city.lat <= eBounds.Search.maxLat && city.lon >= eBounds.Search.minLon && city.lon <= eBounds.Search.maxLon );
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const iMode = geoMercator();
|
|
112
|
+
const iPath = geoPath().projection(iMode);
|
|
113
|
+
const jFeatures: GeoJSON.Feature[] = [...renders?.states ?? [], ...renders?.counties ?? []];
|
|
114
|
+
const jCollection: GeoJSON.FeatureCollection = { type: `FeatureCollection`, features: jFeatures };
|
|
115
|
+
const events = (await Promise.all(
|
|
116
|
+
E.map(async (event: TypeEvent) => {
|
|
117
|
+
const zones = event.properties?.geocode?.ugc ?? [];
|
|
118
|
+
if (zones?.length === 0) return null;
|
|
119
|
+
return {event, polygon: await GetUnionPolygon({
|
|
120
|
+
Polygons: polygons ? [polygons.coordinates] : [await GetEventGeometry({ Event: event }).coordinates],
|
|
121
|
+
})};
|
|
122
|
+
})
|
|
123
|
+
)).filter(Boolean);
|
|
124
|
+
|
|
125
|
+
if (polygons) {
|
|
126
|
+
let geometry = polygons;
|
|
127
|
+
const geo = {
|
|
128
|
+
type: "FeatureCollection",
|
|
129
|
+
features: [{ type: "Feature", geometry, properties: {} }]
|
|
130
|
+
};
|
|
131
|
+
const bounds = geoBounds(geo as any);
|
|
132
|
+
if (bounds[0][0] === -180 && bounds[0][1] === -90 && bounds[1][0] === 180 && bounds[1][1] === 90) {
|
|
133
|
+
if (geometry.type === "Polygon") {
|
|
134
|
+
geometry = { ...geometry, coordinates: geometry.coordinates.map((ring) => [...ring].reverse())};
|
|
135
|
+
} else if (geometry.type === "MultiPolygon") {
|
|
136
|
+
geometry = {...geometry, coordinates: geometry.coordinates.map((polygon) => polygon.map((ring) => [...ring].reverse()))};
|
|
137
|
+
}
|
|
138
|
+
geo.features[0].geometry = geometry;
|
|
139
|
+
}
|
|
140
|
+
iMode.fitExtent([[150, 150], [Width - 150, Height - 150]], geo as any);
|
|
141
|
+
} else {
|
|
142
|
+
iMode.fitExtent( [[60, 60], [Width - 60, Height - 60]], jCollection);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pathing.events = events?.map(({ event, polygon: polys }) => {
|
|
146
|
+
const color = event?.properties?.theme ?? theme ?? `rgb(56, 72, 88)`;
|
|
147
|
+
return GetSVGPath({
|
|
148
|
+
Polygons: polys,
|
|
149
|
+
IPath: iPath,
|
|
150
|
+
Map: false,
|
|
151
|
+
Settings: { BorderColor: `${color}`, BorderWidth: 2, FillColor: `${color}`, FillOpacity: 0.1 }
|
|
152
|
+
});
|
|
153
|
+
}).filter(Boolean).join(``);
|
|
154
|
+
|
|
155
|
+
pathing.counties = renders?.counties?.map((polygon: GeoJSON.Feature) => GetSVGPath({
|
|
156
|
+
Polygons: polygon.geometry as GeoJSON.Polygon | GeoJSON.MultiPolygon,
|
|
157
|
+
IPath: iPath,
|
|
158
|
+
Map: true,
|
|
159
|
+
Settings: { BorderColor: `darkgray`, BorderWidth: 0.5, FillColor: `black`, FillOpacity: 1 }
|
|
160
|
+
})).filter(Boolean).join(``);
|
|
161
|
+
|
|
162
|
+
pathing.states = renders?.states?.map((polygon: GeoJSON.Feature) => GetSVGPath({
|
|
163
|
+
Polygons: polygon.geometry as GeoJSON.Polygon | GeoJSON.MultiPolygon,
|
|
164
|
+
IPath: iPath,
|
|
165
|
+
Map: false,
|
|
166
|
+
Settings: { BorderColor: `white`, BorderWidth: 1, FillColor: `#ffffff`, FillOpacity: 0 }
|
|
167
|
+
})).filter(Boolean).join(``);
|
|
168
|
+
|
|
169
|
+
pathing.cities = renders?.cities?.map((city: { lat: number; lon: number; name: string; population: number }) => {
|
|
170
|
+
const point = iMode([city.lon, city.lat]);
|
|
171
|
+
const [x, y] = point;
|
|
172
|
+
const radius = 2 * Math.max(0.75, Math.min(1.5, Width / 1000));
|
|
173
|
+
return `
|
|
174
|
+
<circle cx="${x}" cy="${y}" r="${radius}" fill="#ffffff" />
|
|
175
|
+
<text x="${x}" y="${y + radius + 9}" fill="#ffffff" font-size="${Math.max(10, Math.min(10, Width / 140))}px" font-family="Arial, sans-serif" font-weight="500" text-anchor="middle" dominant-baseline="middle" stroke="#000000" stroke-width="2.5" stroke-opacity="0.7" paint-order="stroke" >${city.name}</text>
|
|
176
|
+
`;
|
|
177
|
+
}).join(``);
|
|
178
|
+
|
|
179
|
+
const title = Event
|
|
180
|
+
? (event ?? `Event`)
|
|
181
|
+
: (R?.length > 0 ? `Region: ${R.map(state => EnumStates[state] ?? state).join(`, `)}` : `Contiguous United States`);
|
|
182
|
+
const subtitleLines = Event
|
|
183
|
+
? GetStringText(Event).split(`\n`).filter(line => line.trim().length > 0).slice(0, 10)
|
|
184
|
+
: [`Last Updated: ${new Date().toLocaleString()}`];
|
|
185
|
+
const scale = Math.max(0.75, Math.min(1.0, Width / 1000));
|
|
186
|
+
const titleSize = Math.round(17 * scale);
|
|
187
|
+
const lineSize = Math.round(13 * scale);
|
|
188
|
+
const lineHeight = Math.round(15 * scale);
|
|
189
|
+
const paddingX = Math.round(16 * scale);
|
|
190
|
+
const paddingTop = Math.round(16 * scale);
|
|
191
|
+
const paddingBottom = Math.round(16 * scale);
|
|
192
|
+
const accentWidth = Math.max(4, Math.round(5 * scale));
|
|
193
|
+
const iconSize = Math.round(Math.min(122, Math.max(48, Width * 0.07)) * scale);
|
|
194
|
+
const hasIcon = Boolean(Bootstrap?.Settings?.GlobalSettings?.ArchiveSettings?.Logo);
|
|
195
|
+
|
|
196
|
+
if (hasIcon) {
|
|
197
|
+
const buffer = await readFile(Bootstrap.Settings.GlobalSettings.ArchiveSettings.Logo);
|
|
198
|
+
icon = `data:image/png;base64,${Buffer.from(buffer).toString(`base64`)}`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const boxWidth = Math.min(Math.round(Width * 0.4), Width - Math.round(28 * scale));
|
|
202
|
+
const textStartX = paddingX + accentWidth + Math.round(6 * scale);
|
|
203
|
+
const textEndPadding = hasIcon ? iconSize + Math.round(20 * scale) : Math.round(16 * scale);
|
|
204
|
+
const availableTextWidth = boxWidth - textStartX - textEndPadding;
|
|
205
|
+
const maxTitleChars = Math.max(20, Math.floor(availableTextWidth / (titleSize * 0.52)));
|
|
206
|
+
const maxLineChars = Math.max(24, Math.floor(availableTextWidth / (lineSize * 0.52)));
|
|
207
|
+
|
|
208
|
+
const titleY = paddingTop + titleSize;
|
|
209
|
+
const firstLineY = titleY + Math.round(22 * scale);
|
|
210
|
+
const contentHeight = firstLineY + (subtitleLines.length * lineHeight) + paddingBottom;
|
|
211
|
+
const boxHeight = Math.max(contentHeight, hasIcon ? paddingTop + iconSize + paddingBottom : contentHeight);
|
|
212
|
+
|
|
213
|
+
const iconX = boxWidth - iconSize - Math.round(5 * scale);
|
|
214
|
+
const iconY = paddingTop;
|
|
215
|
+
|
|
216
|
+
const SVG = CreateSVG({
|
|
217
|
+
Width, Height,
|
|
218
|
+
MapFeatures: !inConus ? [pathing.events] : [pathing.counties, pathing.states, pathing.events, pathing.cities],
|
|
219
|
+
Features: [
|
|
220
|
+
`<rect x="${Math.round(9 * scale)}" y="${Math.round(10 * scale)}" width="${boxWidth}" height="${boxHeight}" fill="rgba(0, 0, 0, 0.57)" />`,
|
|
221
|
+
`<rect x="${Math.round(6 * scale)}" y="${Math.round(7 * scale)}" width="${boxWidth}" height="${boxHeight}" fill="rgba(16, 18, 24, 0.36)" stroke="rgba(255,255,255,0.12)" stroke-width="${Math.max(1, scale)}" />`,
|
|
222
|
+
`<rect x="${Math.round(6 * scale)}" y="${Math.round(7 * scale)}" width="${accentWidth}" height="${boxHeight}" fill="${theme ?? `rgb(56, 72, 88)`}" />`,
|
|
223
|
+
hasIcon && icon
|
|
224
|
+
? `<image href="${icon}" x="${iconX}" y="${iconY}" width="${iconSize}" height="${iconSize}" preserveAspectRatio="xMidYMid meet" opacity="0.95" />`
|
|
225
|
+
: ``,
|
|
226
|
+
`<text x="${textStartX}" y="${titleY}" text-anchor="start" font-family="Arial, sans-serif" font-size="${titleSize}" font-weight="700" fill="white">${title.length > maxTitleChars ? title.slice(0, maxTitleChars - 3) + `...` : title}</text>`,
|
|
227
|
+
...subtitleLines.map((line, i) =>
|
|
228
|
+
`<text x="${textStartX}" y="${firstLineY + (i * lineHeight)}" text-anchor="start" font-family="Arial, sans-serif" font-size="${lineSize}" fill="rgba(255,255,255,0.82)">${line.length > maxLineChars ? line.slice(0, maxLineChars - 3) + `...` : line.replace(/</g, "<").replace(/>/g, ">")}</text>`
|
|
229
|
+
),
|
|
230
|
+
`<text x="${textStartX}" y="${boxHeight - Math.round(5 * scale)}" text-anchor="start" font-family="Arial, sans-serif" font-size="${Math.max(8, Math.min(8, Width / 140))}px" fill="rgba(255,255,255,0.82)" >This graphic was created by AtmosphericX and is not an official NOAA graphic.</text>`
|
|
231
|
+
]
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const { Directory, Name } = File ?? {};
|
|
235
|
+
const dir = Directory ?? Bootstrap.Settings?.GlobalSettings?.ArchiveSettings?.ImageDirectory;
|
|
236
|
+
const name = Name ?? event ?? `img`;
|
|
237
|
+
await mkdir(dir, { recursive: true });
|
|
238
|
+
await sharp(Buffer.from(SVG))
|
|
239
|
+
.png()
|
|
240
|
+
.toFile(join(dir, `${name}${name.includes(`.png`) ? `` : `.png`}`));
|
|
241
|
+
return dir + `/${name}${name.includes(`.png`) ? `` : `.png`}`;
|
|
242
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface CreateRectangleOptions {}
|
|
21
|
+
|
|
22
|
+
export const CreateRectangle = ({}: CreateRectangleOptions): void => {}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface CreateTextOptions {}
|
|
21
|
+
|
|
22
|
+
export const CreateText = ({}: CreateTextOptions): void => {}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface CreateSVGOptions {
|
|
21
|
+
MapFeatures: string[];
|
|
22
|
+
Features: string[];
|
|
23
|
+
Width: number;
|
|
24
|
+
Height: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const CreateSVG = ({ MapFeatures, Features, Width, Height }: CreateSVGOptions): string => {
|
|
28
|
+
return `
|
|
29
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${Width}" height="${Height}" viewBox="0 0 ${Width} ${Height}">
|
|
30
|
+
<rect width="${Width}" height="${Height}" fill="black"/>
|
|
31
|
+
<g fill-rule="evenodd" clip-rule="evenodd">
|
|
32
|
+
${MapFeatures.join(`\n`)}
|
|
33
|
+
${Features.join(`\n`)}
|
|
34
|
+
</g>
|
|
35
|
+
</svg>
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { EnumStateFIPS } from "@Enums/States"
|
|
21
|
+
import { CreateQuery } from "@Database/CreateQuery"
|
|
22
|
+
|
|
23
|
+
interface GetGeographicalBoundariesOptions {
|
|
24
|
+
Regions: string[] | null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface GeographicalBoundariesResponse {
|
|
28
|
+
states: any[]
|
|
29
|
+
counties: any[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const GetGeographicalBoundaries = ({ Regions }: GetGeographicalBoundariesOptions): GeographicalBoundariesResponse => {
|
|
33
|
+
const states = []
|
|
34
|
+
const counties = []
|
|
35
|
+
if (!Regions) {
|
|
36
|
+
const stateBoundaries = CreateQuery({
|
|
37
|
+
Query: `SELECT * FROM boundaries WHERE type = 'state' AND state NOT IN ('AK', 'HI')`,
|
|
38
|
+
})
|
|
39
|
+
const countyBoundaries = CreateQuery({
|
|
40
|
+
Query: `SELECT * FROM boundaries WHERE type = 'county' AND state NOT IN ('AK', 'HI')`,
|
|
41
|
+
})
|
|
42
|
+
states.push(...stateBoundaries)
|
|
43
|
+
counties.push(...countyBoundaries)
|
|
44
|
+
return { states, counties }
|
|
45
|
+
}
|
|
46
|
+
for (const region of Regions) {
|
|
47
|
+
const match = region.match(/^([A-Z]{2})[CZ](\d{3})$/i) ?? null
|
|
48
|
+
if (!match) {
|
|
49
|
+
const children = CreateQuery({
|
|
50
|
+
Query: `SELECT * FROM boundaries WHERE type = 'county' AND state = ?`,
|
|
51
|
+
Parameters: [region]
|
|
52
|
+
})
|
|
53
|
+
const parent = CreateQuery({
|
|
54
|
+
Query: `SELECT * FROM boundaries WHERE type = 'state' AND state = ?`,
|
|
55
|
+
Parameters: [region]
|
|
56
|
+
})
|
|
57
|
+
for (const child of children) {
|
|
58
|
+
counties.push(child)
|
|
59
|
+
}
|
|
60
|
+
states.push(...parent)
|
|
61
|
+
} else {
|
|
62
|
+
const [, state, county] = match
|
|
63
|
+
const fips = Object.entries(EnumStateFIPS).find(([, value]) => value === state)?.[0]
|
|
64
|
+
const child = CreateQuery({
|
|
65
|
+
Query: `SELECT * FROM boundaries WHERE type = 'county' AND id = ?`,
|
|
66
|
+
Parameters: [fips + county]
|
|
67
|
+
})
|
|
68
|
+
counties.push(...child);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { states, counties }
|
|
72
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { CreateQuery } from "@Database/CreateQuery"
|
|
21
|
+
|
|
22
|
+
interface GetGeographicalCitiesOptions {
|
|
23
|
+
Regions: string[] | null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface GeographicalCitiesResponse {
|
|
27
|
+
cities: {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
state: string;
|
|
31
|
+
county: string;
|
|
32
|
+
population: number;
|
|
33
|
+
lat: number;
|
|
34
|
+
lon: number
|
|
35
|
+
}[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const GetGeographicalCities = ({ Regions }: GetGeographicalCitiesOptions): GeographicalCitiesResponse => {
|
|
39
|
+
const cities = []
|
|
40
|
+
if (!Regions) {
|
|
41
|
+
const cityBoundaries = CreateQuery({
|
|
42
|
+
Query: `SELECT * FROM cities WHERE state NOT IN ('AK', 'HI')`,
|
|
43
|
+
})
|
|
44
|
+
cities.push(...cityBoundaries)
|
|
45
|
+
return { cities }
|
|
46
|
+
}
|
|
47
|
+
for (const region of Regions) {
|
|
48
|
+
const match = region.match(/^([A-Z]{2})[CZ](\d{3})$/i) ?? null
|
|
49
|
+
if (!match) {
|
|
50
|
+
const parent = CreateQuery({
|
|
51
|
+
Query: `SELECT * FROM cities WHERE state = ?`,
|
|
52
|
+
Parameters: [region]
|
|
53
|
+
})
|
|
54
|
+
cities.push(...parent)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { cities }
|
|
58
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { TypeEvent } from "StaticTypes/Event"
|
|
21
|
+
import { Bootstrap } from "@Bootstrap"
|
|
22
|
+
|
|
23
|
+
interface GetGeographicalEventsOptions {
|
|
24
|
+
Regions: string[] | null
|
|
25
|
+
Event?: TypeEvent
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const GetGeographicalEvents = ({ Regions, Event }: GetGeographicalEventsOptions): TypeEvent[] => {
|
|
29
|
+
const events = Bootstrap.Cache.Events.features
|
|
30
|
+
if (Event) { return [Event] }
|
|
31
|
+
if (!Regions) { return events }
|
|
32
|
+
return events.filter(event => {
|
|
33
|
+
const ugcs = event.properties?.geocode?.ugc ?? []
|
|
34
|
+
return Regions.some(region => {
|
|
35
|
+
const normalized = region.trim().toUpperCase()
|
|
36
|
+
const ugcMatch = normalized.match(/^([A-Z]{2})[CZ](\d{3})$/)
|
|
37
|
+
if (ugcMatch) {
|
|
38
|
+
return ugcs.some(ugc => ugc.trim().toUpperCase() === normalized)
|
|
39
|
+
}
|
|
40
|
+
const stateMatch = normalized.match(/^[A-Z]{2}$/)
|
|
41
|
+
if (stateMatch) {
|
|
42
|
+
return ugcs.some(ugc => ugc.trim().toUpperCase().startsWith(`${normalized}Z`) || ugc.trim().toUpperCase().startsWith(`${normalized}C`))
|
|
43
|
+
}
|
|
44
|
+
return false
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface GetGeometryBoundsOptions {
|
|
21
|
+
Geometry: GeoJSON.Geometry
|
|
22
|
+
Padding: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface GeometryBounds {
|
|
26
|
+
Bounds: {
|
|
27
|
+
minLon: number
|
|
28
|
+
minLat: number
|
|
29
|
+
maxLon: number
|
|
30
|
+
maxLat: number
|
|
31
|
+
}
|
|
32
|
+
Search: {
|
|
33
|
+
minLon: number
|
|
34
|
+
minLat: number
|
|
35
|
+
maxLon: number
|
|
36
|
+
maxLat: number
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const GetGeometryBounds = ({ Geometry, Padding }: GetGeometryBoundsOptions): GeometryBounds => {
|
|
41
|
+
let minLon = Infinity;
|
|
42
|
+
let minLat = Infinity;
|
|
43
|
+
let maxLon = -Infinity;
|
|
44
|
+
let maxLat = -Infinity;
|
|
45
|
+
const ProcessCoordinate = (coordinate: GeoJSON.Position): void => {
|
|
46
|
+
const [lon, lat] = coordinate;
|
|
47
|
+
if (!Number.isFinite(lon) || !Number.isFinite(lat)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
minLon = Math.min(minLon, lon);
|
|
51
|
+
minLat = Math.min(minLat, lat);
|
|
52
|
+
maxLon = Math.max(maxLon, lon);
|
|
53
|
+
maxLat = Math.max(maxLat, lat);
|
|
54
|
+
};
|
|
55
|
+
const ProcessRing = (ring: GeoJSON.Position[]): void => {
|
|
56
|
+
for (const coordinate of ring) {
|
|
57
|
+
ProcessCoordinate(coordinate);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (Geometry.type === `Polygon`) {
|
|
61
|
+
for (const ring of Geometry.coordinates) {
|
|
62
|
+
ProcessRing(ring);
|
|
63
|
+
}
|
|
64
|
+
} else if (Geometry.type === `MultiPolygon`) {
|
|
65
|
+
for (const polygon of Geometry.coordinates) {
|
|
66
|
+
for (const ring of polygon) {
|
|
67
|
+
ProcessRing(ring);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const centerLat = (minLat + maxLat) / 2;
|
|
72
|
+
const latPadding = Padding / 69;
|
|
73
|
+
const lonPadding = Padding / (69 * Math.cos(centerLat * Math.PI / 180));
|
|
74
|
+
const searchMinLon = minLon - lonPadding;
|
|
75
|
+
const searchMaxLon = maxLon + lonPadding;
|
|
76
|
+
const searchMinLat = minLat - latPadding;
|
|
77
|
+
const searchMaxLat = maxLat + latPadding;
|
|
78
|
+
return {
|
|
79
|
+
Search: { minLon: searchMinLon, minLat: searchMinLat, maxLon: searchMaxLon, maxLat: searchMaxLat },
|
|
80
|
+
Bounds: { minLon, minLat, maxLon, maxLat }
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
_ _ _ __ __
|
|
3
|
+
/\ | | | | (_) \ \ / /
|
|
4
|
+
/ \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
|
|
5
|
+
/ /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
|
|
6
|
+
/ ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
|
|
7
|
+
/_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
|
|
8
|
+
| |
|
|
9
|
+
|_|
|
|
10
|
+
|
|
11
|
+
Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
|
|
12
|
+
Discord: https://atmosphericx-discord.scriptkitty.cafe
|
|
13
|
+
Ko-Fi: https://ko-fi.com/k3yomi
|
|
14
|
+
Documentation: https://atmosphericx.scriptkitty.cafe/documentation
|
|
15
|
+
|
|
16
|
+
Independent Package: @atmosx/event-product-parser
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface BoundaryRow {
|
|
21
|
+
id: string
|
|
22
|
+
type: `state` | `county`
|
|
23
|
+
state: string
|
|
24
|
+
name: string
|
|
25
|
+
geometry: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type BoundaryProperties = {
|
|
29
|
+
state: string
|
|
30
|
+
name: string
|
|
31
|
+
id?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type BoundaryFeature = GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon, BoundaryProperties>
|
|
35
|
+
|
|
36
|
+
export const GetParsedBoundary = (rows: BoundaryRow[]): BoundaryFeature[] => {
|
|
37
|
+
const features: BoundaryFeature[] = []
|
|
38
|
+
for (const row of rows) {
|
|
39
|
+
try {
|
|
40
|
+
const geometry = JSON.parse(row.geometry) as GeoJSON.Geometry
|
|
41
|
+
if ( !geometry || typeof geometry !== `object` || (geometry.type !== `Polygon` && geometry.type !== `MultiPolygon`) ) {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
features.push({
|
|
45
|
+
type: `Feature`,
|
|
46
|
+
properties: {
|
|
47
|
+
state: row.state,
|
|
48
|
+
name: row.name,
|
|
49
|
+
...(row.type === `county` ? { id: row.id } : {})
|
|
50
|
+
},
|
|
51
|
+
geometry
|
|
52
|
+
})
|
|
53
|
+
} catch {
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return features
|
|
58
|
+
}
|