First version of the OH-input-element

This commit is contained in:
Pieter Vander Vennet 2020-10-08 19:03:00 +02:00
parent b93f25d79c
commit 895ec01213
16 changed files with 532 additions and 248 deletions

View file

@ -1,38 +1,71 @@
import {UIElement} from "./UIElement";
import {UIEventSource} from "../Logic/UIEventSource";
import * as opening_hours from "opening_hours";
import opening_hours from "opening_hours";
export default class OhVisualization extends UIElement {
export default class OpeningHoursVisualization extends UIElement {
constructor(openingHours: UIEventSource<any>) {
super(openingHours);
constructor(tags: UIEventSource<any>) {
super(tags);
}
private static GetRanges(tags: any, from: Date, to: Date): {
isOpen: boolean,
isUnknown: boolean,
comment: string,
startDate: Date
}[] {
const oh = new opening_hours(tags.opening_hours, {
lat: tags._lat,
lon: tags._lon,
address: {
country_code: tags._country
}
});
const values = [];
const iterator = oh.getIterator(from);
while (iterator.advance(to)) {
const value = {
isUnknown: iterator.getUnknown(),
isOpen: iterator.getState(),
comment: iterator.getComment(),
startDate: iterator.getDate()
}
if (value.comment === undefined && !value.isOpen && !value.isUnknown) {
// simply closed, nothing special here
continue;
}
console.log(value)
values.push(value);
}
return values;
}
InnerRender(): string {
const oh = new opening_hours(this._source.data, {});
let nominatim_example = [{
"place_id": 79276782,
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_type": "way",
"osm_id": 4575088,
"boundingbox": ["52.5519288", "52.5541724", "-1.8278941", "-1.8238916"],
"lat": "52.553624",
"lon": "-1.8256057",
"display_name": "Pilkington Avenue, Sutton Coldfield, Birmingham, West Midlands Combined Authority, England, B72, United Kingdom",
"place_rank": 26,
"category": "highway",
"type": "residential",
"importance": 0.4,
"geojson": {
"type": "LineString",
"coordinates": [[-1.8278941, 52.55417], [-1.8277256, 52.5541716], [-1.8276423, 52.5541724], [-1.8267652, 52.5539852], [-1.8261462, 52.5538445], [-1.8258137, 52.5537286], [-1.8256057, 52.553624], [-1.8254024, 52.5534973], [-1.8252343, 52.5533435], [-1.8245486, 52.5526243], [-1.8238916, 52.5519288]]
}
}]
const from = new Date("2019-12-31");
const to = new Date("2020-01-05");
const ranges = OpeningHoursVisualization.GetRanges(this._source.data, from, to);
return "";
let text = "";
for (const range of ranges) {
text += `From${range.startDate} it is${range.isOpen} ${range.comment?? ""}<br/>`
}
return text;
}
}