Extract codegrid to seperate module, heatup the codegrid caches

This commit is contained in:
Pieter Vander Vennet 2020-10-11 18:41:45 +02:00
parent 7c52ace770
commit 4db1997ed6
3 changed files with 28 additions and 6 deletions

View file

@ -5,8 +5,9 @@ import {Layer} from "leaflet"
import {GeoOperations} from "./GeoOperations";
import {UIElement} from "../UI/UIElement";
import {LayerDefinition} from "../Customizations/LayerDefinition";
import codegrid from "codegrid-js";
import State from "../State";
import CodeGrid from "./Web/CodeGrid";
/***
* A filtered layer is a layer which offers a 'set-data' function
@ -44,8 +45,6 @@ export class FilteredLayer {
private _showOnPopup: (tags: UIEventSource<any>, feature: any) => UIElement;
private static readonly grid = codegrid.CodeGrid("./tiles/");
constructor(
layerDef: LayerDefinition,
showOnPopup: ((tags: UIEventSource<any>, feature: any) => UIElement)
@ -118,7 +117,7 @@ export class FilteredLayer {
feature.properties["_lon"] = "" + lat; // We expect a string here for lat/lon
feature.properties["_lat"] = "" + lon;
// But the codegrid SHOULD be a number!
FilteredLayer.grid.getCode(lat, lon, (error, code) => {
CodeGrid.grid.getCode(lat, lon, (error, code) => {
if (error === null) {
feature.properties["_country"] = code;
} else {

18
Logic/Web/CodeGrid.ts Normal file
View file

@ -0,0 +1,18 @@
import codegrid from "codegrid-js";
export default class CodeGrid {
public static readonly grid = CodeGrid.InitGrid();
private static InitGrid(): any {
const grid = codegrid.CodeGrid("./tiles/");
// Heat up the caches
grid.getCode(50.2, 3.2, (error, code) => {
});
grid.getCode(52.5072, 13.4248, (error, code) => {
});
grid.getCode(40.4781, -3.7034, () => {
});
return grid;
}
}

View file

@ -56,9 +56,14 @@ export default class Translation extends UIElement {
const argument = matched[2];
const partAfter = matched[3];
const element = knownSpecial.constr(argument).Render();
try {
template = partBefore + element + partAfter;
const element = knownSpecial.constr(argument).Render();
template = partBefore + element + partAfter;
} catch (e) {
console.error(e);
template = partBefore + partAfter;
}
}
newTranslations[lang] = template;
}