diff --git a/Logic/FilteredLayer.ts b/Logic/FilteredLayer.ts index cad504f..e654c93 100644 --- a/Logic/FilteredLayer.ts +++ b/Logic/FilteredLayer.ts @@ -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, feature: any) => UIElement; - private static readonly grid = codegrid.CodeGrid("./tiles/"); - constructor( layerDef: LayerDefinition, showOnPopup: ((tags: UIEventSource, 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 { diff --git a/Logic/Web/CodeGrid.ts b/Logic/Web/CodeGrid.ts new file mode 100644 index 0000000..ade7cc8 --- /dev/null +++ b/Logic/Web/CodeGrid.ts @@ -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; + } +} \ No newline at end of file diff --git a/UI/i18n/Translation.ts b/UI/i18n/Translation.ts index 5c6011c..1ee96c1 100644 --- a/UI/i18n/Translation.ts +++ b/UI/i18n/Translation.ts @@ -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; }