Styling tweak

Add mapillary link to nearby_images

Fix licenses

Add missing assets

First version of nearby-images
This commit is contained in:
Pieter Vander Vennet 2022-05-06 12:41:24 +02:00
parent a4f2fa63a5
commit 7559f9259b
52 changed files with 674 additions and 207 deletions

View file

@ -163,6 +163,11 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
{
"id": "add_image",
"render": "{add_image_to_note()}"
},
{
"id":"nearby_images",
render: tr(t.nearbyImagesIntro)
}
],
"mapRendering": [

View file

@ -8,6 +8,7 @@ import Translations from "../../../UI/i18n/Translations";
import {Translation} from "../../../UI/i18n/Translation";
import * as tagrenderingconfigmeta from "../../../assets/tagrenderingconfigmeta.json"
import {AddContextToTranslations} from "./AddContextToTranslations";
import spec = Mocha.reporters.spec;
class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | { builtin: string | string[], override: any }, TagRenderingConfigJson[]> {
private readonly _state: DesugaringContext;
@ -302,11 +303,6 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
/**
* Converts a 'special' translation into a regular translation which uses parameters
* E.g.
*
* const tr = <TagRenderingJson> {
* "special":
* }
*/
export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
constructor() {
@ -330,6 +326,11 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
* const r = RewriteSpecial.convertIfNeeded(spec, [], "test")
* r // => {"en": "{image_upload(,Add a picture to this object)}", "nl": "{image_upload(,Voeg een afbeelding toe)}" }
*
* // should handle special case with a prefix and postfix
* const spec = {"special": {"type":"image_upload" }, before: {"en": "PREFIX "}, after: {"en": " POSTFIX", nl: " Achtervoegsel"} }
* const r = RewriteSpecial.convertIfNeeded(spec, [], "test")
* r // => {"en": "PREFIX {image_upload(,)} POSTFIX", "nl": "PREFIX {image_upload(,)} Achtervoegsel" }
*
* // should warn for unexpected keys
* const errors = []
* RewriteSpecial.convertIfNeeded({"special": {type: "image_carousel"}, "en": "xyz"}, errors, "test") // => {'*': "{image_carousel()}"}
@ -352,7 +353,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
return input
}
for (const wrongKey of Object.keys(input).filter(k => k !== "special")) {
for (const wrongKey of Object.keys(input).filter(k => k !== "special" && k !== "before" && k !== "after")) {
errors.push(`At ${context}: Unexpected key in a special block: ${wrongKey}`)
}
@ -400,6 +401,16 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
}
}
const before = Translations.T(input.before)
const after = Translations.T(input.after)
for (const ln of Object.keys(before?.translations??{})) {
foundLanguages.add(ln)
}
for (const ln of Object.keys(after?.translations??{})) {
foundLanguages.add(ln)
}
if(foundLanguages.size === 0){
const args= argNamesList.map(nm => special[nm] ?? "").join(",")
return {'*': `{${type}(${args})}`
@ -419,7 +430,9 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
args.push(v)
}
}
result[ln] = `{${type}(${args.join(",")})}`
const beforeText = before?.textFor(ln) ?? ""
const afterText = after?.textFor(ln) ?? ""
result[ln] = `${beforeText}{${type}(${args.join(",")})}${afterText}`
}
return result
}
@ -437,6 +450,13 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
* const result = new RewriteSpecial().convert(tr,"test").result
* const expected = {render: {'*': "{image_carousel(image)}"}, mappings: [{if: "other_image_key", then: {'*': "{image_carousel(other_image_key)}"}} ]}
* result // => expected
*
* const tr = {
* render: {special: {type: "image_carousel", image_key: "image"}, before: {en: "Some introduction"} },
* }
* const result = new RewriteSpecial().convert(tr,"test").result
* const expected = {render: {'en': "Some introduction{image_carousel(image)}"}}
* result // => expected
*/
convert(json: TagRenderingConfigJson, context: string): { result: TagRenderingConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
const errors = []

View file

@ -170,7 +170,13 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
super("For every layer in the 'layers'-list, create a new layer which'll import notes. (Note that priviliged layers and layers which have a geojson-source set are ignored)", ["layers"], "AddImportLayers");
}
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors: string[] } {
convert(json: LayoutConfigJson, context: string): { result: LayoutConfigJson; errors?: string[], warnings?: string[] } {
if (!(json.enableNoteImports ?? true)) {
return {
warnings: ["Not creating a note import layers for theme "+json.id+" as they are disabled"],
result: json
};
}
const errors = []
json = {...json}
@ -178,39 +184,37 @@ class AddImportLayers extends DesugaringStep<LayoutConfigJson> {
json.layers = [...json.layers]
if (json.enableNoteImports ?? true) {
const creator = new CreateNoteImportLayer()
for (let i1 = 0; i1 < allLayers.length; i1++) {
const layer = allLayers[i1];
if (Constants.priviliged_layers.indexOf(layer.id) >= 0) {
// Priviliged layers are skipped
continue
}
const creator = new CreateNoteImportLayer()
for (let i1 = 0; i1 < allLayers.length; i1++) {
const layer = allLayers[i1];
if (Constants.priviliged_layers.indexOf(layer.id) >= 0) {
// Priviliged layers are skipped
continue
}
if (layer.source["geoJson"] !== undefined) {
// Layer which don't get their data from OSM are skipped
continue
}
if (layer.source["geoJson"] !== undefined) {
// Layer which don't get their data from OSM are skipped
continue
}
if (layer.title === undefined || layer.name === undefined) {
// Anonymous layers and layers without popup are skipped
continue
}
if (layer.title === undefined || layer.name === undefined) {
// Anonymous layers and layers without popup are skipped
continue
}
if (layer.presets === undefined || layer.presets.length == 0) {
// A preset is needed to be able to generate a new point
continue;
}
if (layer.presets === undefined || layer.presets.length == 0) {
// A preset is needed to be able to generate a new point
continue;
}
try {
try {
const importLayerResult = creator.convert(layer, context + ".(noteimportlayer)[" + i1 + "]")
if (importLayerResult.result !== undefined) {
json.layers.push(importLayerResult.result)
}
} catch (e) {
errors.push("Could not generate an import-layer for " + layer.id + " due to " + e)
const importLayerResult = creator.convert(layer, context + ".(noteimportlayer)[" + i1 + "]")
if (importLayerResult.result !== undefined) {
json.layers.push(importLayerResult.result)
}
} catch (e) {
errors.push("Could not generate an import-layer for " + layer.id + " due to " + e)
}
}
@ -255,6 +259,7 @@ export class AddMiniMap extends DesugaringStep<LayerConfigJson> {
if (!translation.hasOwnProperty(key)) {
continue
}
const template = translation[key]
const parts = SubstitutedTranslation.ExtractSpecialComponents(template)
const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap")

View file

@ -308,6 +308,8 @@ export interface LayoutConfigJson {
/**
* If true, notes will be loaded and parsed. If a note is an import (as created by the import_helper.html-tool from mapcomplete),
* these notes will be shown if a relevant layer is present.
*
* Default is true for official layers and false for unofficial (sideloaded) layers
*/
enableNoteImports?: true | boolean;