Fix page title rendering
This commit is contained in:
parent
0d51015cc8
commit
2606a27f60
2 changed files with 25 additions and 22 deletions
|
@ -14,38 +14,40 @@ class TitleElement extends UIElement {
|
||||||
|
|
||||||
constructor(layoutToUse: UIEventSource<LayoutConfig>,
|
constructor(layoutToUse: UIEventSource<LayoutConfig>,
|
||||||
selectedFeature: UIEventSource<any>,
|
selectedFeature: UIEventSource<any>,
|
||||||
allElementsStorage : ElementStorage) {
|
allElementsStorage: ElementStorage) {
|
||||||
super(layoutToUse);
|
super(layoutToUse);
|
||||||
this._layoutToUse = layoutToUse;
|
this._layoutToUse = layoutToUse;
|
||||||
this._selectedFeature = selectedFeature;
|
this._selectedFeature = selectedFeature;
|
||||||
this._allElementsStorage = allElementsStorage;
|
this._allElementsStorage = allElementsStorage;
|
||||||
this.ListenTo(Locale.language);
|
this.ListenTo(Locale.language);
|
||||||
|
this.ListenTo(this._selectedFeature)
|
||||||
this.dumbMode = false;
|
this.dumbMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InnerRender(): string {
|
InnerRender(): string {
|
||||||
|
|
||||||
const defaultTitle = Translations.WT(this._layoutToUse.data?.title)?.txt ?? "MapComplete"
|
const defaultTitle = Translations.WT(this._layoutToUse.data?.title)?.txt ?? "MapComplete"
|
||||||
|
console.log("Default title: ", defaultTitle)
|
||||||
const feature = this._selectedFeature.data;
|
const feature = this._selectedFeature.data;
|
||||||
|
|
||||||
if(feature === undefined){
|
if (feature === undefined) {
|
||||||
return defaultTitle;
|
return defaultTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const layout = this._layoutToUse.data;
|
const layout = this._layoutToUse.data;
|
||||||
const properties = this._selectedFeature.data.properties;
|
const properties = this._selectedFeature.data.properties;
|
||||||
for (const layer of layout.layers) {
|
for (const layer of layout.layers) {
|
||||||
if(layer.title === undefined){
|
if (layer.title === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (layer.overpassTags.matchesProperties(properties)) {
|
if (layer.overpassTags.matchesProperties(properties)) {
|
||||||
|
|
||||||
const title = new TagRenderingAnswer(
|
const title = new TagRenderingAnswer(
|
||||||
this._allElementsStorage.getEventSourceFor(feature),
|
this._allElementsStorage.getEventSourceFor(feature),
|
||||||
layer.title
|
layer.title
|
||||||
)
|
)
|
||||||
return new Combine([defaultTitle," | ", title]).Render();
|
return new Combine([defaultTitle, " | ", title]).Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return defaultTitle;
|
return defaultTitle;
|
||||||
|
@ -56,17 +58,18 @@ class TitleElement extends UIElement {
|
||||||
export default class TitleHandler {
|
export default class TitleHandler {
|
||||||
constructor(layoutToUse: UIEventSource<LayoutConfig>,
|
constructor(layoutToUse: UIEventSource<LayoutConfig>,
|
||||||
selectedFeature: UIEventSource<any>,
|
selectedFeature: UIEventSource<any>,
|
||||||
allElementsStorage : ElementStorage) {
|
allElementsStorage: ElementStorage) {
|
||||||
|
|
||||||
new TitleElement(layoutToUse, selectedFeature, allElementsStorage)
|
console.log("Titlehandler inited")
|
||||||
.addCallbackAndRun(contents => {
|
selectedFeature.addCallbackAndRun(_ => {
|
||||||
|
const title = new TitleElement(layoutToUse, selectedFeature, allElementsStorage)
|
||||||
const d = document.createElement('div');
|
const d = document.createElement('div');
|
||||||
d.innerHTML = contents;
|
const contents = title.InnerRender()
|
||||||
// We pass everything into a div to strip out images etc...
|
d.innerHTML = contents;
|
||||||
document.title = (d.textContent || d.innerText);
|
console.log("Setting title to ", d.innerText, contents)
|
||||||
|
// We pass everything into a div to strip out images etc...
|
||||||
});
|
document.title = (d.textContent || d.innerText);
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ import { Utils } from "../Utils";
|
||||||
|
|
||||||
export default class Constants {
|
export default class Constants {
|
||||||
|
|
||||||
public static vNumber = "0.5.14";
|
public static vNumber = "0.5.15";
|
||||||
|
|
||||||
// The user journey states thresholds when a new feature gets unlocked
|
// The user journey states thresholds when a new feature gets unlocked
|
||||||
public static userJourney = {
|
public static userJourney = {
|
||||||
|
|
Loading…
Reference in a new issue