s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
186 lines • 10 kB
JavaScript
import { GTFSRealtimeEntitySelector, GTFSRealtimeTranslatedString } from '.';
/** Severity of this alert. */
export var GTFSRealtimeSeverityLevel;
(function (GTFSRealtimeSeverityLevel) {
GTFSRealtimeSeverityLevel[GTFSRealtimeSeverityLevel["UNKNOWN_SEVERITY"] = 1] = "UNKNOWN_SEVERITY";
GTFSRealtimeSeverityLevel[GTFSRealtimeSeverityLevel["INFO"] = 2] = "INFO";
GTFSRealtimeSeverityLevel[GTFSRealtimeSeverityLevel["WARNING"] = 3] = "WARNING";
GTFSRealtimeSeverityLevel[GTFSRealtimeSeverityLevel["SEVERE"] = 4] = "SEVERE";
})(GTFSRealtimeSeverityLevel || (GTFSRealtimeSeverityLevel = {}));
/**
* What is the effect of this problem on the affected entity. If effect_detail is included, then
* Effect must also be included.
*/
export var GTFSRealtimeEffect;
(function (GTFSRealtimeEffect) {
GTFSRealtimeEffect[GTFSRealtimeEffect["NO_SERVICE"] = 1] = "NO_SERVICE";
GTFSRealtimeEffect[GTFSRealtimeEffect["REDUCED_SERVICE"] = 2] = "REDUCED_SERVICE";
// We don't care about INsignificant delays: they are hard to detect, have
// little impact on the user, and would clutter the results as they are too
// frequent.
GTFSRealtimeEffect[GTFSRealtimeEffect["SIGNIFICANT_DELAYS"] = 3] = "SIGNIFICANT_DELAYS";
GTFSRealtimeEffect[GTFSRealtimeEffect["DETOUR"] = 4] = "DETOUR";
GTFSRealtimeEffect[GTFSRealtimeEffect["ADDITIONAL_SERVICE"] = 5] = "ADDITIONAL_SERVICE";
GTFSRealtimeEffect[GTFSRealtimeEffect["MODIFIED_SERVICE"] = 6] = "MODIFIED_SERVICE";
GTFSRealtimeEffect[GTFSRealtimeEffect["OTHER_EFFECT"] = 7] = "OTHER_EFFECT";
GTFSRealtimeEffect[GTFSRealtimeEffect["UNKNOWN_EFFECT"] = 8] = "UNKNOWN_EFFECT";
GTFSRealtimeEffect[GTFSRealtimeEffect["STOP_MOVED"] = 9] = "STOP_MOVED";
GTFSRealtimeEffect[GTFSRealtimeEffect["NO_EFFECT"] = 10] = "NO_EFFECT";
GTFSRealtimeEffect[GTFSRealtimeEffect["ACCESSIBILITY_ISSUE"] = 11] = "ACCESSIBILITY_ISSUE";
})(GTFSRealtimeEffect || (GTFSRealtimeEffect = {}));
/** Cause of this alert. If cause_detail is included, then Cause must also be included. */
export var GTFSRealtimeCause;
(function (GTFSRealtimeCause) {
GTFSRealtimeCause[GTFSRealtimeCause["UNKNOWN_CAUSE"] = 1] = "UNKNOWN_CAUSE";
GTFSRealtimeCause[GTFSRealtimeCause["OTHER_CAUSE"] = 2] = "OTHER_CAUSE";
GTFSRealtimeCause[GTFSRealtimeCause["TECHNICAL_PROBLEM"] = 3] = "TECHNICAL_PROBLEM";
GTFSRealtimeCause[GTFSRealtimeCause["STRIKE"] = 4] = "STRIKE";
GTFSRealtimeCause[GTFSRealtimeCause["DEMONSTRATION"] = 5] = "DEMONSTRATION";
GTFSRealtimeCause[GTFSRealtimeCause["ACCIDENT"] = 6] = "ACCIDENT";
GTFSRealtimeCause[GTFSRealtimeCause["HOLIDAY"] = 7] = "HOLIDAY";
GTFSRealtimeCause[GTFSRealtimeCause["WEATHER"] = 8] = "WEATHER";
GTFSRealtimeCause[GTFSRealtimeCause["MAINTENANCE"] = 9] = "MAINTENANCE";
GTFSRealtimeCause[GTFSRealtimeCause["CONSTRUCTION"] = 10] = "CONSTRUCTION";
GTFSRealtimeCause[GTFSRealtimeCause["POLICE_ACTIVITY"] = 11] = "POLICE_ACTIVITY";
GTFSRealtimeCause[GTFSRealtimeCause["MEDICAL_EMERGENCY"] = 12] = "MEDICAL_EMERGENCY";
})(GTFSRealtimeCause || (GTFSRealtimeCause = {}));
/** An alert, indicating some sort of incident in the public transit network. */
export class GTFSRealtimeAlert {
/**
* Time when the alert should be shown to the user. If missing, the
* alert will be shown as long as it appears in the feed.
* If multiple ranges are given, the alert will be shown during all of them.
*/
activePeriods = []; // 1 [repeated message]
/** Entities whose users we should notify of this alert. */
informedEntities = []; // 5 [repeated message]
/** Cause of this alert. If cause_detail is included, then Cause must also be included. */
cause = GTFSRealtimeCause.UNKNOWN_CAUSE; // 6 [enum]
/**
* What is the effect of this problem on the affected entity. If effect_detail is included, then
* Effect must also be included.
*/
effect = GTFSRealtimeEffect.UNKNOWN_EFFECT; // 7 [enum]
/** The URL which provides additional information about the alert. */
url; // 8 [message]
/** Alert header. Contains a short summary of the alert text as plain-text. */
headerText; // 10 [message]
/**
* Full description for the alert as plain-text. The information in the
* description should add to the information of the header.
*/
descriptionText; // 11 [message]
/**
* Text for alert header to be used in text-to-speech implementations. This field is the
* text-to-speech version of header_text.
*/
ttsHeaderText; // 12 [message]
/**
* Text for full description for the alert to be used in text-to-speech implementations.
* This field is the text-to-speech version of description_text.
*/
ttsDescriptionText; // 13 [message]
/** Severity of this alert. */
severityLevel = GTFSRealtimeSeverityLevel.UNKNOWN_SEVERITY; // 14 [enum]
/**
* TranslatedImage to be displayed along the alert text. Used to explain visually the alert effect of a detour, station closure, etc. The image must enhance the understanding of the alert. Any essential information communicated within the image must also be contained in the alert text.
* The following types of images are discouraged : image containing mainly text, marketing or branded images that add no additional information.
* NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
*/
image; // 15 [message]
/**
* Text describing the appearance of the linked image in the `image` field (e.g., in case the image can't be displayed
* or the user can't see the image for accessibility reasons). See the HTML spec for alt image text - https://html.spec.whatwg.org/#alt.
* NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future
*/
imageAlternativeText; // 16 [message]
/**
* Description of the cause of the alert that allows for agency-specific language; more specific than the Cause. If cause_detail is included, then Cause must also be included.
* NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
*/
causeDetail; // 17 [message]
/**
* Description of the effect of the alert that allows for agency-specific language; more specific than the Effect. If effect_detail is included, then Effect must also be included.
* NOTE: This field is still experimental, and subject to change. It may be formally adopted in the future.
*/
effectDetail; // 18 [message]
/**
* @param pbf - The Protobuf object to read from
* @param end - The end position of the message in the buffer
*/
constructor(pbf, end) {
pbf.readFields(this.#readAlert, this, end);
}
/**
* @param tag - The tag of the message
* @param alert - The alert to mutate
* @param pbf - The Protobuf object to read from
*/
#readAlert(tag, alert, pbf) {
if (tag === 1)
alert.activePeriods.push(new GTFSRealtimeTimeRange(pbf, pbf.readVarint() + pbf.pos));
else if (tag === 5)
alert.informedEntities.push(new GTFSRealtimeEntitySelector(pbf, pbf.readVarint() + pbf.pos));
else if (tag === 6)
alert.cause = pbf.readVarint();
else if (tag === 7)
alert.effect = pbf.readVarint();
else if (tag === 8)
alert.url = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 10)
alert.headerText = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 11)
alert.descriptionText = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 12)
alert.ttsHeaderText = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 13)
alert.ttsDescriptionText = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 14)
alert.severityLevel = pbf.readVarint();
else if (tag === 15)
alert.image = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 16)
alert.imageAlternativeText = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 17)
alert.causeDetail = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else if (tag === 18)
alert.effectDetail = new GTFSRealtimeTranslatedString(pbf, pbf.readVarint() + pbf.pos);
else
throw new Error('GTFSRealtimeAlert: unknown tag: ' + tag);
}
}
/**
* A time interval. The interval is considered active at time 't' if 't' is
* greater than or equal to the start time and less than the end time.
*/
export class GTFSRealtimeTimeRange {
// Start time, in POSIX time (i.e., number of seconds since January 1st 1970
// 00:00:00 UTC).
// If missing, the interval starts at minus infinity.
start; // 1 [uint64]
// End time, in POSIX time (i.e., number of seconds since January 1st 1970
// 00:00:00 UTC).
// If missing, the interval ends at plus infinity.
end; // 2 [uint64]
/**
* @param pbf - The Protobuf object to read from
* @param end - The end position of the message in the buffer
*/
constructor(pbf, end) {
pbf.readFields(this.#readTimeRange, this, end);
}
/**
* @param tag - The tag of the message
* @param timeRange - The timeRange to mutate
* @param pbf - The Protobuf object to read from
*/
#readTimeRange(tag, timeRange, pbf) {
if (tag === 1)
timeRange.start = new Date(pbf.readVarint() * 1000);
else if (tag === 2)
timeRange.end = new Date(pbf.readVarint() * 1000);
else
throw new Error('GTFSRealtimeTimeRange: unknown tag: ' + tag);
}
}
//# sourceMappingURL=alert.js.map