2021-01-02 16:04:16 +01:00
|
|
|
import {UIElement} from "../UIElement";
|
|
|
|
import Link from "../Base/Link";
|
|
|
|
import Svg from "../../Svg";
|
|
|
|
import Combine from "../Base/Combine";
|
|
|
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
|
|
|
import {UserDetails} from "../../Logic/Osm/OsmConnection";
|
|
|
|
import Constants from "../../Models/Constants";
|
|
|
|
import LayoutConfig from "../../Customizations/JSON/LayoutConfig";
|
|
|
|
import Loc from "../../Models/Loc";
|
2021-01-02 21:03:40 +01:00
|
|
|
import * as L from "leaflet"
|
2021-01-02 16:04:16 +01:00
|
|
|
|
|
|
|
export default class Attribution extends UIElement {
|
|
|
|
|
|
|
|
private readonly _location: UIEventSource<Loc>;
|
|
|
|
private readonly _layoutToUse: UIEventSource<LayoutConfig>;
|
|
|
|
private readonly _userDetails: UIEventSource<UserDetails>;
|
2021-01-02 21:03:40 +01:00
|
|
|
private readonly _leafletMap: UIEventSource<L.Map>;
|
2021-01-02 16:04:16 +01:00
|
|
|
|
|
|
|
constructor(location: UIEventSource<Loc>,
|
|
|
|
userDetails: UIEventSource<UserDetails>,
|
|
|
|
layoutToUse: UIEventSource<LayoutConfig>,
|
2021-01-02 21:03:40 +01:00
|
|
|
leafletMap: UIEventSource<L.Map>) {
|
2021-01-02 16:04:16 +01:00
|
|
|
super(location);
|
|
|
|
this._layoutToUse = layoutToUse;
|
|
|
|
this.ListenTo(layoutToUse);
|
|
|
|
this._userDetails = userDetails;
|
2021-01-02 21:03:40 +01:00
|
|
|
this._leafletMap = leafletMap;
|
2021-01-02 16:04:16 +01:00
|
|
|
this.ListenTo(userDetails);
|
|
|
|
this._location = location;
|
|
|
|
this.SetClass("map-attribution");
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
const location : Loc = this._location.data;
|
|
|
|
const userDetails = this._userDetails.data;
|
|
|
|
|
|
|
|
const mapComplete = new Link(`Mapcomplete ${Constants.vNumber}`, 'https://github.com/pietervdvn/MapComplete', true);
|
|
|
|
const reportBug = new Link(Svg.bug_img, "https://github.com/pietervdvn/MapComplete/issues", true);
|
|
|
|
|
|
|
|
const layoutId = this._layoutToUse.data.id;
|
|
|
|
const osmChaLink = `https://osmcha.org/?filters=%7B%22comment%22%3A%5B%7B%22label%22%3A%22%23${layoutId}%22%2C%22value%22%3A%22%23${layoutId}%22%7D%5D%2C%22date__gte%22%3A%5B%7B%22label%22%3A%222020-07-05%22%2C%22value%22%3A%222020-07-05%22%7D%5D%2C%22editor%22%3A%5B%7B%22label%22%3A%22MapComplete%22%2C%22value%22%3A%22MapComplete%22%7D%5D%7D`
|
|
|
|
const stats = new Link(Svg.statistics_img, osmChaLink, true)
|
|
|
|
let editHere: (UIElement | string) = "";
|
|
|
|
if (location !== undefined) {
|
|
|
|
const idLink = `https://www.openstreetmap.org/edit?editor=id#map=${location.zoom}/${location.lat}/${location.lon}`
|
|
|
|
editHere = new Link(Svg.pencil_img, idLink, true);
|
|
|
|
}
|
|
|
|
let editWithJosm: (UIElement | string) = ""
|
|
|
|
if (location !== undefined &&
|
2021-01-02 21:03:40 +01:00
|
|
|
this._leafletMap.data !== undefined &&
|
2021-01-02 16:04:16 +01:00
|
|
|
userDetails.csCount >= Constants.userJourney.tagsVisibleAndWikiLinked) {
|
2021-01-02 21:03:40 +01:00
|
|
|
const bounds = this._leafletMap.data.getBounds();
|
2021-01-02 16:04:16 +01:00
|
|
|
const top = bounds.getNorth();
|
|
|
|
const bottom = bounds.getSouth();
|
|
|
|
const right = bounds.getEast();
|
|
|
|
const left = bounds.getWest();
|
|
|
|
|
|
|
|
const josmLink = `http://127.0.0.1:8111/load_and_zoom?left=${left}&right=${right}&top=${top}&bottom=${bottom}`
|
|
|
|
editWithJosm = new Link(Svg.josm_logo_img, josmLink, true);
|
|
|
|
}
|
|
|
|
return new Combine([mapComplete, reportBug, " | ", stats, " | ", editHere, editWithJosm]).Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|