diff --git a/Logic/State/MapState.ts b/Logic/State/MapState.ts index 319c3547a4..9f9c331b13 100644 --- a/Logic/State/MapState.ts +++ b/Logic/State/MapState.ts @@ -55,7 +55,8 @@ export default class MapState extends UserRelatedState { */ public historicalUserLocations: FeatureSourceForLayer & Tiled; /** - * The number of seconds that the GPS-locations are stored in memory + * The number of seconds that the GPS-locations are stored in memory. + * Time in seconds */ public gpsLocationHistoryRetentionTime = new UIEventSource(7 * 24 * 60 * 60, "gps_location_retention") public historicalUserLocationsTrack: FeatureSourceForLayer & Tiled; @@ -199,7 +200,7 @@ export default class MapState extends UserRelatedState { const now = new Date().getTime() features.data = features.data .map(ff => ({feature: ff.feature, freshness: new Date(ff.freshness)})) - .filter(ff => (now - ff.freshness.getTime()) < this.gpsLocationHistoryRetentionTime.data) + .filter(ff => (now - ff.freshness.getTime()) < 1000 * this.gpsLocationHistoryRetentionTime.data) features.ping() const self = this; let i = 0 diff --git a/Models/ThemeConfig/LegacyJsonConvert.ts b/Models/ThemeConfig/LegacyJsonConvert.ts index 5a691e0a29..4128e6d919 100644 --- a/Models/ThemeConfig/LegacyJsonConvert.ts +++ b/Models/ThemeConfig/LegacyJsonConvert.ts @@ -1,4 +1,5 @@ import LineRenderingConfigJson from "./Json/LineRenderingConfigJson"; +import PointRenderingConfig from "./PointRenderingConfig"; export default class LegacyJsonConvert { @@ -29,22 +30,26 @@ export default class LegacyJsonConvert { } if (config.mapRendering === undefined && config.id !== "sidewalks") { + config.mapRendering = [] // This is a legacy format, lets create a pointRendering let location: ("point" | "centroid")[] = ["point"] let wayHandling: number = config["wayHandling"] ?? 0 if (wayHandling !== 0) { location = ["point", "centroid"] } - config.mapRendering = [ - { - icon: config["icon"], - iconBadges: config["iconOverlays"], - label: config["label"], - iconSize: config["iconSize"], - location, - rotation: config["rotation"] - } - ] + if(config["icon"] ?? config["label"] !== undefined){ + + const pointConfig = { + icon: config["icon"], + iconBadges: config["iconOverlays"], + label: config["label"], + iconSize: config["iconSize"], + location, + rotation: config["rotation"] + } + config.mapRendering.push(pointConfig) + } + if (wayHandling !== 1) { const lineRenderConfig = { @@ -56,6 +61,9 @@ export default class LegacyJsonConvert { config.mapRendering.push(lineRenderConfig) } } + if(config.mapRendering.length === 0){ + throw "Could not convert the legacy theme into a new theme: no renderings defined for layer "+config.id + } } diff --git a/test/LegacyThemeLoader.spec.ts b/test/LegacyThemeLoader.spec.ts new file mode 100644 index 0000000000..96eda96232 --- /dev/null +++ b/test/LegacyThemeLoader.spec.ts @@ -0,0 +1,158 @@ +import T from "./TestHelper"; +import LegacyJsonConvert from "../Models/ThemeConfig/LegacyJsonConvert"; +import LayoutConfig from "../Models/ThemeConfig/LayoutConfig"; + +export default class LegacyThemeLoaderSpec extends T { + + private static readonly walking_node_theme = { + "id": "walkingnodenetworks", + "title": { + "en": "Walking node networks" + }, + "maintainer": "L'imaginaire", + "icon": "https://upload.wikimedia.org/wikipedia/commons/3/30/Man_walking_icon_1410105361.svg", + "description": { + "en": "This map shows walking node networks" + }, + "language": [ + "en" + ], + "version": "2021-10-02", + "startLat": 51.1599, + "startLon": 3.34750, + "startZoom": 12, + "clustering": { + "maxZoom": 12 + }, + "layers": [ + { + "id": "node2node", + "name": { + "en": "node to node links" + }, + "source": { + "osmTags": { + "and": [ + "network=rwn", + "network:type=node_network" + ] + } + }, + "minzoom": 12, + "title": { + "render": { + "en": "node to node link" + }, + "mappings": [ + { + "if": "ref~*", + "then": { + "en": "node to node link {ref}" + } + } + ] + }, + "width": { + "render": "4" + }, + "color": { + "render": "#8b1e20" + }, + "tagRenderings": [ + { + "question": { + "en": "When was this node to node link last surveyed?" + }, + "render": { + "en": "This node to node link was last surveyed on {survey:date}" + }, + "freeform": { + "key": "survey:date", + "type": "date" + }, + "mappings": [ + { + "if": "survey:date:={_now:date}", + "then": "Surveyed today!" + } + ] + } + ] + }, + { + "id": "node", + "name": { + "en": "nodes" + }, + "source": { + "osmTags": "rwn_ref~*" + }, + "minzoom": 12, + "title": { + "render": { + "en": "walking node {rwn_ref}" + } + }, + "label": { + "mappings": [ + { + "if": "rwn_ref~*", + "then": "
{rwn_ref}
" + } + ] + }, + "tagRenderings": [ + { + "question": { + "en": "When was this walking node last surveyed?" + }, + "render": { + "en": "This walking node was last surveyed on {survey:date}" + }, + "freeform": { + "key": "survey:date", + "type": "date" + }, + "mappings": [ + { + "if": "survey:date:={_now:date}", + "then": "Surveyed today!" + } + ] + }, + { + "question": { + "en": "How many other walking nodes does this node link to?" + }, + "render": { + "en": "This node links to {expected_rwn_route_relations} other walking nodes." + }, + "freeform": { + "key": "expected_rwn_route_relations", + "type": "int" + } + }, + "images" + ] + } + ] + } + + constructor() { + super("LegacyThemeLoader", + + [ + ["Walking_node_theme", () => { + + const config = LegacyThemeLoaderSpec.walking_node_theme + LegacyJsonConvert.fixThemeConfig(config) + // @ts-ignore + const theme = new LayoutConfig(config) + + }] + ] + ); + } + + +} \ No newline at end of file diff --git a/test/TestAll.ts b/test/TestAll.ts index e6dc4f9e7c..f53e1beb46 100644 --- a/test/TestAll.ts +++ b/test/TestAll.ts @@ -14,6 +14,7 @@ import WikidataSpecTest from "./Wikidata.spec.test"; import ImageProviderSpec from "./ImageProvider.spec"; import ActorsSpec from "./Actors.spec"; import ReplaceGeometrySpec from "./ReplaceGeometry.spec"; +import LegacyThemeLoaderSpec from "./LegacyThemeLoader.spec"; ScriptUtils.fixUtils() @@ -31,7 +32,8 @@ const allTests = [ new WikidataSpecTest(), new ImageProviderSpec(), new ActorsSpec(), - new ReplaceGeometrySpec() + new ReplaceGeometrySpec(), + new LegacyThemeLoaderSpec() ] Utils.externalDownloadFunction = async (url) => {