forked from MapComplete/MapComplete
Add test for legacy theme conversion, fix legacy theme conversion
This commit is contained in:
parent
04e4ba769f
commit
756106afc3
4 changed files with 182 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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 = <LineRenderingConfigJson>{
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
158
test/LegacyThemeLoader.spec.ts
Normal file
158
test/LegacyThemeLoader.spec.ts
Normal file
|
@ -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 <strong>{ref}</strong>"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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 <strong>{rwn_ref}</strong>"
|
||||
}
|
||||
},
|
||||
"label": {
|
||||
"mappings": [
|
||||
{
|
||||
"if": "rwn_ref~*",
|
||||
"then": "<div style='position: absolute; top: 10px; right: 10px; color: white; background-color: #8b1e20; width: 20px; height: 20px; border-radius: 100%'>{rwn_ref}</div>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"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)
|
||||
|
||||
}]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in a new issue