Extract codegrid to seperate module, heatup the codegrid caches
This commit is contained in:
parent
7c52ace770
commit
4db1997ed6
3 changed files with 28 additions and 6 deletions
|
@ -5,8 +5,9 @@ import {Layer} from "leaflet"
|
||||||
import {GeoOperations} from "./GeoOperations";
|
import {GeoOperations} from "./GeoOperations";
|
||||||
import {UIElement} from "../UI/UIElement";
|
import {UIElement} from "../UI/UIElement";
|
||||||
import {LayerDefinition} from "../Customizations/LayerDefinition";
|
import {LayerDefinition} from "../Customizations/LayerDefinition";
|
||||||
import codegrid from "codegrid-js";
|
|
||||||
import State from "../State";
|
import State from "../State";
|
||||||
|
import CodeGrid from "./Web/CodeGrid";
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* A filtered layer is a layer which offers a 'set-data' function
|
* 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 _showOnPopup: (tags: UIEventSource<any>, feature: any) => UIElement;
|
||||||
|
|
||||||
|
|
||||||
private static readonly grid = codegrid.CodeGrid("./tiles/");
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
layerDef: LayerDefinition,
|
layerDef: LayerDefinition,
|
||||||
showOnPopup: ((tags: UIEventSource<any>, feature: any) => UIElement)
|
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["_lon"] = "" + lat; // We expect a string here for lat/lon
|
||||||
feature.properties["_lat"] = "" + lon;
|
feature.properties["_lat"] = "" + lon;
|
||||||
// But the codegrid SHOULD be a number!
|
// But the codegrid SHOULD be a number!
|
||||||
FilteredLayer.grid.getCode(lat, lon, (error, code) => {
|
CodeGrid.grid.getCode(lat, lon, (error, code) => {
|
||||||
if (error === null) {
|
if (error === null) {
|
||||||
feature.properties["_country"] = code;
|
feature.properties["_country"] = code;
|
||||||
} else {
|
} else {
|
||||||
|
|
18
Logic/Web/CodeGrid.ts
Normal file
18
Logic/Web/CodeGrid.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,9 +56,14 @@ export default class Translation extends UIElement {
|
||||||
const argument = matched[2];
|
const argument = matched[2];
|
||||||
const partAfter = matched[3];
|
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;
|
newTranslations[lang] = template;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue