2021-07-23 15:56:22 +02:00
import { Translation } from "../../UI/i18n/Translation" ;
2021-03-20 23:45:52 +01:00
import SourceConfig from "./SourceConfig" ;
2021-08-07 23:11:34 +02:00
import TagRenderingConfig from "./TagRenderingConfig" ;
2021-12-04 21:49:17 +01:00
import PresetConfig , { PreciseInput } from "./PresetConfig" ;
2021-08-07 23:11:34 +02:00
import { LayerConfigJson } from "./Json/LayerConfigJson" ;
import Translations from "../../UI/i18n/Translations" ;
import { TagUtils } from "../../Logic/Tags/TagUtils" ;
2021-07-22 11:29:09 +02:00
import FilterConfig from "./FilterConfig" ;
2021-08-07 23:11:34 +02:00
import { Unit } from "../Unit" ;
import DeleteConfig from "./DeleteConfig" ;
2021-10-14 03:46:09 +02:00
import MoveConfig from "./MoveConfig" ;
2021-10-19 02:31:32 +02:00
import PointRenderingConfig from "./PointRenderingConfig" ;
import WithContextLoader from "./WithContextLoader" ;
2021-10-20 02:01:27 +02:00
import LineRenderingConfig from "./LineRenderingConfig" ;
import PointRenderingConfigJson from "./Json/PointRenderingConfigJson" ;
import LineRenderingConfigJson from "./Json/LineRenderingConfigJson" ;
2021-10-22 18:53:07 +02:00
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" ;
2021-10-31 02:08:39 +01:00
import { UIEventSource } from "../../Logic/UIEventSource" ;
import BaseUIElement from "../../UI/BaseUIElement" ;
2021-11-08 02:36:01 +01:00
import Combine from "../../UI/Base/Combine" ;
import Title from "../../UI/Base/Title" ;
import List from "../../UI/Base/List" ;
import Link from "../../UI/Base/Link" ;
2021-11-08 03:00:58 +01:00
import { Utils } from "../../Utils" ;
2021-11-10 08:34:29 +01:00
import * as icons from "../../assets/tagRenderings/icons.json"
2021-04-10 23:53:13 +02:00
2021-10-22 18:53:07 +02:00
export default class LayerConfig extends WithContextLoader {
2021-07-23 15:56:22 +02:00
2021-12-04 21:49:17 +01:00
public readonly id : string ;
public readonly name : Translation ;
public readonly description : Translation ;
public readonly source : SourceConfig ;
public readonly calculatedTags : [ string , string ] [ ] ;
public readonly doNotDownload : boolean ;
public readonly passAllFeatures : boolean ;
public readonly isShown : TagRenderingConfig ;
public readonly minzoom : number ;
public readonly minzoomVisible : number ;
public readonly maxzoom : number ;
public readonly title? : TagRenderingConfig ;
public readonly titleIcons : TagRenderingConfig [ ] ;
2021-10-22 18:53:07 +02:00
2021-10-19 02:31:32 +02:00
public readonly mapRendering : PointRenderingConfig [ ]
2021-10-20 02:01:27 +02:00
public readonly lineRendering : LineRenderingConfig [ ]
2021-10-19 02:31:32 +02:00
2021-07-23 15:56:22 +02:00
public readonly units : Unit [ ] ;
public readonly deletion : DeleteConfig | null ;
2021-10-14 03:46:09 +02:00
public readonly allowMove : MoveConfig | null
2021-07-15 20:47:28 +02:00
public readonly allowSplit : boolean
2021-12-03 02:29:25 +01:00
public readonly shownByDefault : boolean ;
2021-10-25 20:38:57 +02:00
/ * *
* In seconds
* /
public readonly maxAgeOfCache : number
2021-07-23 15:56:22 +02:00
2021-12-04 21:49:17 +01:00
public readonly presets : PresetConfig [ ] ;
2020-11-17 02:22:48 +01:00
2021-12-04 21:49:17 +01:00
public readonly tagRenderings : TagRenderingConfig [ ] ;
public readonly filters : FilterConfig [ ] ;
2021-07-22 11:29:09 +02:00
2021-07-23 15:56:22 +02:00
constructor (
json : LayerConfigJson ,
context? : string ,
official : boolean = true
) {
context = context + "." + json . id ;
2021-10-19 02:31:32 +02:00
super ( json , context )
2021-07-23 15:56:22 +02:00
this . id = json . id ;
2021-10-29 01:41:37 +02:00
if ( json . source === undefined ) {
2021-10-31 02:08:39 +01:00
throw "Layer " + this . id + " does not define a source section (" + context + ")"
2021-03-20 23:45:52 +01:00
}
2021-10-25 20:38:57 +02:00
2021-10-29 01:41:37 +02:00
if ( json . source . osmTags === undefined ) {
2021-10-31 02:08:39 +01:00
throw "Layer " + this . id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")"
2021-07-23 15:56:22 +02:00
2021-10-29 01:41:37 +02:00
}
2021-07-23 15:56:22 +02:00
2021-10-29 01:41:37 +02:00
this . maxAgeOfCache = json . source . maxCacheAge ? ? 24 * 60 * 60 * 30
2021-07-23 15:56:22 +02:00
2021-10-29 01:41:37 +02:00
const osmTags = TagUtils . Tag (
json . source . osmTags ,
context + "source.osmTags"
) ;
2021-09-18 02:32:40 +02:00
2021-10-29 01:41:37 +02:00
if ( json . source [ "geoJsonSource" ] !== undefined ) {
throw context + "Use 'geoJson' instead of 'geoJsonSource'" ;
}
if ( json . source [ "geojson" ] !== undefined ) {
throw context + "Use 'geoJson' instead of 'geojson' (the J is a capital letter)" ;
2021-03-24 01:25:57 +01:00
}
2021-10-29 01:41:37 +02:00
this . source = new SourceConfig (
{
osmTags : osmTags ,
geojsonSource : json.source [ "geoJson" ] ,
geojsonSourceLevel : json.source [ "geoJsonZoomLevel" ] ,
overpassScript : json.source [ "overpassScript" ] ,
isOsmCache : json.source [ "isOsmCache" ] ,
mercatorCrs : json.source [ "mercatorCrs" ]
} ,
json . id
) ;
2021-10-19 02:31:32 +02:00
this . allowSplit = json . allowSplit ? ? false ;
this . name = Translations . T ( json . name , context + ".name" ) ;
this . units = ( json . units ? ? [ ] ) . map ( ( ( unitJson , i ) = > Unit . fromJson ( unitJson , ` ${ context } .unit[ ${ i } ] ` ) ) )
if ( json . description !== undefined ) {
if ( Object . keys ( json . description ) . length === 0 ) {
json . description = undefined ;
}
}
this . description = Translations . T (
json . description ,
context + ".description"
) ;
2021-07-23 15:56:22 +02:00
this . calculatedTags = undefined ;
if ( json . calculatedTags !== undefined ) {
if ( ! official ) {
console . warn (
` Unofficial theme ${ this . id } with custom javascript! This is a security risk `
) ;
2021-01-08 03:57:18 +01:00
}
2021-07-23 15:56:22 +02:00
this . calculatedTags = [ ] ;
for ( const kv of json . calculatedTags ) {
const index = kv . indexOf ( "=" ) ;
const key = kv . substring ( 0 , index ) ;
const code = kv . substring ( index + 1 ) ;
2021-01-08 03:57:18 +01:00
2021-10-14 03:46:09 +02:00
try {
new Function ( "feat" , "return " + code + ";" ) ;
} catch ( e ) {
throw ` Invalid function definition: code ${ code } is invalid: ${ e } (at ${ context } ) `
2021-09-18 02:32:40 +02:00
}
2021-07-23 15:56:22 +02:00
this . calculatedTags . push ( [ key , code ] ) ;
2020-10-27 01:01:34 +01:00
}
2021-07-23 15:56:22 +02:00
}
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
this . doNotDownload = json . doNotDownload ? ? false ;
this . passAllFeatures = json . passAllFeatures ? ? false ;
this . minzoom = json . minzoom ? ? 0 ;
2021-07-27 19:39:57 +02:00
this . minzoomVisible = json . minzoomVisible ? ? this . minzoom ;
2021-12-03 02:29:25 +01:00
this . shownByDefault = json . shownByDefault ? ? true ;
2021-10-14 03:46:09 +02:00
if ( json . presets !== undefined && json . presets ? . map === undefined ) {
throw "Presets should be a list of items (at " + context + ")"
2021-09-22 20:44:53 +02:00
}
2021-07-14 00:17:15 +02:00
this . presets = ( json . presets ? ? [ ] ) . map ( ( pr , i ) = > {
2021-12-04 21:49:17 +01:00
let preciseInput : PreciseInput = {
2021-10-16 00:43:53 +02:00
preferredBackground : [ "photo" ] ,
snapToLayers : undefined ,
maxSnapDistance : undefined
2021-10-15 19:58:02 +02:00
} ;
2021-08-07 23:11:34 +02:00
if ( pr . preciseInput !== undefined ) {
2021-08-07 21:19:01 +02:00
if ( pr . preciseInput === true ) {
pr . preciseInput = {
preferredBackground : undefined
}
}
2021-12-04 21:49:17 +01:00
2021-08-07 21:19:01 +02:00
let snapToLayers : string [ ] ;
if ( typeof pr . preciseInput . snapToLayer === "string" ) {
snapToLayers = [ pr . preciseInput . snapToLayer ]
} else {
snapToLayers = pr . preciseInput . snapToLayer
}
2021-08-07 23:11:34 +02:00
let preferredBackground : string [ ]
2021-08-07 21:19:01 +02:00
if ( typeof pr . preciseInput . preferredBackground === "string" ) {
preferredBackground = [ pr . preciseInput . preferredBackground ]
} else {
preferredBackground = pr . preciseInput . preferredBackground
}
preciseInput = {
preferredBackground : preferredBackground ,
2021-12-04 21:49:17 +01:00
snapToLayers ,
2021-08-07 21:19:01 +02:00
maxSnapDistance : pr.preciseInput.maxSnapDistance ? ? 10
2021-07-14 00:17:15 +02:00
}
}
2021-08-07 23:11:34 +02:00
const config : PresetConfig = {
2021-03-13 19:08:31 +01:00
title : Translations.T ( pr . title , ` ${ context } .presets[ ${ i } ].title ` ) ,
2021-08-07 23:11:34 +02:00
tags : pr.tags.map ( ( t ) = > TagUtils . SimpleTag ( t ) ) ,
2021-07-14 00:17:15 +02:00
description : Translations.T ( pr . description , ` ${ context } .presets[ ${ i } ].description ` ) ,
2021-08-07 21:19:01 +02:00
preciseInput : preciseInput ,
2021-07-24 02:32:33 +02:00
}
2021-08-07 21:19:01 +02:00
return config ;
2021-07-24 02:32:33 +02:00
} ) ;
2021-07-23 15:56:22 +02:00
2021-10-22 18:53:07 +02:00
if ( json . mapRendering === undefined ) {
throw "MapRendering is undefined in " + context
2021-10-21 01:26:20 +02:00
}
2021-09-09 20:26:12 +02:00
2021-11-09 18:22:05 +01:00
if ( json . mapRendering === null ) {
this . mapRendering = [ ]
this . lineRendering = [ ]
} else {
2021-11-09 19:45:26 +01:00
this . mapRendering = Utils . NoNull ( json . mapRendering )
2021-11-09 18:22:05 +01:00
. filter ( r = > r [ "location" ] !== undefined )
. map ( ( r , i ) = > new PointRenderingConfig ( < PointRenderingConfigJson > r , context + ".mapRendering[" + i + "]" ) )
2021-10-20 02:01:27 +02:00
2021-11-09 19:45:26 +01:00
this . lineRendering = Utils . NoNull ( json . mapRendering )
2021-11-09 18:22:05 +01:00
. filter ( r = > r [ "location" ] === undefined )
. map ( ( r , i ) = > new LineRenderingConfig ( < LineRenderingConfigJson > r , context + ".mapRendering[" + i + "]" ) )
const hasCenterRendering = this . mapRendering . some ( r = > r . location . has ( "centroid" ) || r . location . has ( "start" ) || r . location . has ( "end" ) )
if ( this . lineRendering . length === 0 && this . mapRendering . length === 0 ) {
console . log ( json . mapRendering )
throw ( "The layer " + this . id + " does not have any maprenderings defined and will thus not show up on the map at all. If this is intentional, set maprenderings to 'null' instead of '[]'" )
} else if ( ! hasCenterRendering && this . lineRendering . length === 0 ) {
throw "The layer " + this . id + " might not render ways. This might result in dropped information"
}
}
2021-10-20 02:01:27 +02:00
2021-10-23 00:31:41 +02:00
const missingIds = json . tagRenderings ? . filter ( tr = > typeof tr !== "string" && tr [ "builtin" ] === undefined && tr [ "id" ] === undefined && tr [ "rewrite" ] === undefined ) ? ? [ ] ;
2021-11-08 03:00:58 +01:00
if ( missingIds ? . length > 0 && official ) {
2021-10-14 03:46:09 +02:00
console . error ( "Some tagRenderings of" , this . id , "are missing an id:" , missingIds )
throw "Missing ids in tagrenderings"
}
2021-11-11 17:14:03 +01:00
this . tagRenderings = this . ExtractLayerTagRenderings ( json , official )
if ( official ) {
2021-11-08 03:00:58 +01:00
const emptyIds = this . tagRenderings . filter ( tr = > tr . id === "" ) ;
if ( emptyIds . length > 0 ) {
throw ` Some tagrendering-ids are empty or have an emtpy string; this is not allowed (at ${ context } ) `
}
const duplicateIds = Utils . Dupicates ( this . tagRenderings . map ( f = > f . id ) . filter ( id = > id !== "questions" ) )
if ( duplicateIds . length > 0 ) {
throw ` Some tagRenderings have a duplicate id: ${ duplicateIds } (at ${ context } .tagRenderings) `
}
}
2021-07-23 15:56:22 +02:00
this . filters = ( json . filter ? ? [ ] ) . map ( ( option , i ) = > {
return new FilterConfig ( option , ` ${ context } .filter-[ ${ i } ] ` )
} ) ;
2021-10-14 03:46:09 +02:00
2021-11-08 03:00:58 +01:00
{
const duplicateIds = Utils . Dupicates ( this . filters . map ( f = > f . id ) )
if ( duplicateIds . length > 0 ) {
throw ` Some filters have a duplicate id: ${ duplicateIds } (at ${ context } .filters) `
}
}
2021-10-14 03:46:09 +02:00
if ( json [ "filters" ] !== undefined ) {
throw "Error in " + context + ": use 'filter' instead of 'filters'"
}
2021-07-23 15:56:22 +02:00
const titleIcons = [ ] ;
2021-11-10 08:34:29 +01:00
const defaultIcons = icons . defaultIcons ;
2021-07-23 15:56:22 +02:00
for ( const icon of json . titleIcons ? ? defaultIcons ) {
if ( icon === "defaults" ) {
titleIcons . push ( . . . defaultIcons ) ;
} else {
titleIcons . push ( icon ) ;
}
}
2020-11-16 01:59:30 +01:00
2021-11-11 17:14:03 +01:00
this . titleIcons = this . ParseTagRenderings ( titleIcons , {
readOnlyMode : true
} ) ;
2021-03-15 16:23:04 +01:00
2021-10-19 02:31:32 +02:00
this . title = this . tr ( "title" , undefined ) ;
this . isShown = this . tr ( "isShown" , "yes" ) ;
2021-10-22 18:53:07 +02:00
2021-07-23 15:56:22 +02:00
this . deletion = null ;
if ( json . deletion === true ) {
json . deletion = { } ;
}
if ( json . deletion !== undefined && json . deletion !== false ) {
this . deletion = new DeleteConfig ( json . deletion , ` ${ context } .deletion ` ) ;
}
2021-03-15 16:23:04 +01:00
2021-10-14 03:46:09 +02:00
this . allowMove = null
if ( json . allowMove === false ) {
this . allowMove = null ;
} else if ( json . allowMove === true ) {
this . allowMove = new MoveConfig ( { } , context + ".allowMove" )
} else if ( json . allowMove !== undefined && json . allowMove !== false ) {
this . allowMove = new MoveConfig ( json . allowMove , context + ".allowMove" )
}
2021-07-23 15:56:22 +02:00
if ( json [ "showIf" ] !== undefined ) {
throw (
"Invalid key on layerconfig " +
this . id +
": showIf. Did you mean 'isShown' instead?"
) ;
}
2021-01-08 03:57:18 +01:00
}
2021-11-07 16:34:51 +01:00
public defaultIcon ( ) : BaseUIElement | undefined {
2021-11-11 17:14:03 +01:00
if ( this . mapRendering === undefined || this . mapRendering === null ) {
2021-11-09 19:45:26 +01:00
return undefined ;
}
2021-10-31 02:08:39 +01:00
const mapRendering = this . mapRendering . filter ( r = > r . location . has ( "point" ) ) [ 0 ]
if ( mapRendering === undefined ) {
return undefined
}
const defaultTags = new UIEventSource ( TagUtils . changeAsProperties ( this . source . osmTags . asChange ( { id : "node/-1" } ) ) )
return mapRendering . GenerateLeafletStyle ( defaultTags , false , { noSize : true } ) . html
}
2021-11-11 17:14:03 +01:00
public ExtractLayerTagRenderings ( json : LayerConfigJson , official : boolean ) : TagRenderingConfig [ ] {
2021-10-22 18:53:07 +02:00
if ( json . tagRenderings === undefined ) {
return [ ]
}
const normalTagRenderings : ( string | { builtin : string , override : any } | TagRenderingConfigJson ) [ ] = [ ]
2021-10-23 00:31:41 +02:00
2021-10-29 01:41:37 +02:00
const renderingsToRewrite : ( {
rewrite : {
2021-10-23 00:31:41 +02:00
sourceString : string ,
into : string [ ]
2021-10-29 01:41:37 +02:00
} , renderings : ( string | { builtin : string , override : any } | TagRenderingConfigJson ) [ ]
} ) [ ] = [ ]
2021-10-22 18:53:07 +02:00
for ( let i = 0 ; i < json . tagRenderings . length ; i ++ ) {
const tr = json . tagRenderings [ i ] ;
2021-10-23 00:31:41 +02:00
const rewriteDefined = tr [ "rewrite" ] !== undefined
2021-10-22 18:53:07 +02:00
const renderingsDefined = tr [ "renderings" ]
2021-10-23 00:31:41 +02:00
if ( ! rewriteDefined && ! renderingsDefined ) {
2021-10-22 18:53:07 +02:00
// @ts-ignore
normalTagRenderings . push ( tr )
continue
}
2021-10-23 00:31:41 +02:00
if ( rewriteDefined && renderingsDefined ) {
2021-10-22 18:53:07 +02:00
// @ts-ignore
2021-10-23 00:31:41 +02:00
renderingsToRewrite . push ( tr )
2021-10-22 18:53:07 +02:00
continue
}
2021-10-23 00:31:41 +02:00
throw ` Error in ${ this . _context } .tagrenderings[ ${ i } ]: got a value which defines either \` rewrite \` or \` renderings \` , but not both. Either define both or move the \` renderings \` out of this scope `
2021-10-22 18:53:07 +02:00
}
2021-11-11 17:14:03 +01:00
const allRenderings = this . ParseTagRenderings ( normalTagRenderings ,
{
requiresId : official
} ) ;
2021-10-22 18:53:07 +02:00
2021-10-29 01:41:37 +02:00
if ( renderingsToRewrite . length === 0 ) {
2021-10-22 18:53:07 +02:00
return allRenderings
}
2021-10-29 01:41:37 +02:00
2021-11-11 17:14:03 +01:00
/* Used for left|right group creation and replacement */
2021-10-29 01:41:37 +02:00
function prepConfig ( keyToRewrite : string , target : string , tr : TagRenderingConfigJson ) {
function replaceRecursive ( transl : string | any ) {
if ( typeof transl === "string" ) {
2021-10-23 00:31:41 +02:00
return transl . replace ( keyToRewrite , target )
2021-10-22 18:53:07 +02:00
}
2021-10-29 01:41:37 +02:00
if ( transl . map !== undefined ) {
2021-10-22 18:53:07 +02:00
return transl . map ( o = > replaceRecursive ( o ) )
}
transl = { . . . transl }
for ( const key in transl ) {
transl [ key ] = replaceRecursive ( transl [ key ] )
}
return transl
}
2021-10-29 01:41:37 +02:00
2021-10-22 18:53:07 +02:00
const orig = tr ;
tr = replaceRecursive ( tr )
2021-10-29 01:41:37 +02:00
tr . id = target + "-" + orig . id
2021-10-22 18:53:07 +02:00
tr . group = target
return tr
}
2021-10-23 00:31:41 +02:00
const rewriteGroups : Map < string , TagRenderingConfig [ ] > = new Map < string , TagRenderingConfig [ ] > ( )
for ( const rewriteGroup of renderingsToRewrite ) {
2021-10-29 01:41:37 +02:00
2021-10-23 00:31:41 +02:00
const tagRenderings = rewriteGroup . renderings
const textToReplace = rewriteGroup . rewrite . sourceString
const targets = rewriteGroup . rewrite . into
for ( const target of targets ) {
2021-11-11 17:14:03 +01:00
const parsedRenderings = this . ParseTagRenderings ( tagRenderings , {
prepConfig : tr = > prepConfig ( textToReplace , target , tr )
} )
2021-10-29 01:41:37 +02:00
if ( ! rewriteGroups . has ( target ) ) {
2021-10-23 00:31:41 +02:00
rewriteGroups . set ( target , [ ] )
}
2021-10-29 01:41:37 +02:00
rewriteGroups . get ( target ) . push ( . . . parsedRenderings )
2021-10-23 00:31:41 +02:00
}
2021-10-22 18:53:07 +02:00
}
2021-10-29 01:41:37 +02:00
2021-10-23 00:31:41 +02:00
rewriteGroups . forEach ( ( group , groupName ) = > {
group . push ( new TagRenderingConfig ( {
2021-10-29 01:41:37 +02:00
id : "questions" ,
group : groupName
2021-10-23 00:31:41 +02:00
} ) )
} )
2021-10-29 01:41:37 +02:00
2021-10-23 00:31:41 +02:00
rewriteGroups . forEach ( group = > {
allRenderings . push ( . . . group )
} )
2021-10-22 18:53:07 +02:00
return allRenderings ;
}
2021-12-05 02:06:14 +01:00
public GenerateDocumentation ( usedInThemes : string [ ] , layerIsNeededBy : Map < string , string [ ] > , dependencies : {
context? : string ;
reason : string ;
neededLayer : string ;
} [ ] , addedByDefault = false , canBeIncluded = true ) : BaseUIElement {
2021-11-08 02:36:01 +01:00
const extraProps = [ ]
if ( canBeIncluded ) {
2021-11-09 18:22:05 +01:00
if ( addedByDefault ) {
extraProps . push ( "**This layer is included automatically in every theme. This layer might contain no points**" )
2021-11-08 14:18:45 +01:00
}
2021-12-07 18:18:24 +01:00
if ( this . shownByDefault === false ) {
extraProps . push ( 'This layer is not visible by default and must be enabled in the filter by the user. ' )
}
2021-11-08 02:36:01 +01:00
if ( this . title === undefined ) {
2021-12-07 18:18:24 +01:00
extraProps . push ( "This layer cannot be toggled in the filter view. If you import this layer in your theme, override `title` to make this toggleable." )
}
if ( this . title === undefined && this . shownByDefault === false ) {
extraProps . push ( "This layer is not visible by default and the visibility cannot be toggled, effectively resulting in a fully hidden layer. This can be useful, e.g. to calculate some metatags. If you want to render this layer (e.g. for debugging), enable it by setting the URL-parameter layer-<id>=true" )
2021-11-08 02:36:01 +01:00
}
if ( this . name === undefined ) {
extraProps . push ( "Not visible in the layer selection by default. If you want to make this layer toggable, override `name`" )
}
if ( this . mapRendering . length === 0 ) {
extraProps . push ( "Not rendered on the map by default. If you want to rendering this on the map, override `mapRenderings`" )
}
} else {
extraProps . push ( "This layer can **not** be included in a theme. It is solely used by [special renderings](SpecialRenderings.md) showing a minimap with custom data." )
}
let usingLayer : BaseUIElement [ ] = [ ]
if ( usedInThemes ? . length > 0 && ! addedByDefault ) {
usingLayer = [ new Title ( "Themes using this layer" , 4 ) ,
new List ( ( usedInThemes ? ? [ ] ) . map ( id = > new Link ( id , "https://mapcomplete.osm.be/" + id ) ) )
]
}
2021-12-05 02:06:14 +01:00
for ( const dep of dependencies ) {
extraProps . push ( new Combine ( [ "This layer will automatically load " , new Link ( dep . neededLayer , "#" + dep . neededLayer ) , " into the layout as it depends on it: " , dep . reason , "(" + dep . context + ")" ] ) )
}
for ( const revDep of layerIsNeededBy ? . get ( this . id ) ? ? [ ] ) {
extraProps . push ( new Combine ( [ "This layer is needed as dependency for layer" , new Link ( revDep , "#" + revDep ) ] ) )
2021-12-04 21:49:17 +01:00
}
2021-11-08 02:36:01 +01:00
return new Combine ( [
new Title ( this . id , 3 ) ,
this . description ,
2021-11-09 18:22:05 +01:00
2021-11-08 14:18:45 +01:00
new Link ( "Go to the source code" , ` ../assets/layers/ ${ this . id } / ${ this . id } .json ` ) ,
2021-11-08 02:36:01 +01:00
new List ( extraProps ) ,
. . . usingLayer
2021-11-08 14:18:45 +01:00
] ) . SetClass ( "flex flex-col" )
2021-11-08 02:36:01 +01:00
}
2021-07-23 15:56:22 +02:00
public CustomCodeSnippets ( ) : string [ ] {
if ( this . calculatedTags === undefined ) {
return [ ] ;
}
return this . calculatedTags . map ( ( code ) = > code [ 1 ] ) ;
2021-07-22 11:29:09 +02:00
}
2021-12-05 02:06:14 +01:00
AllTagRenderings ( ) : TagRenderingConfig [ ] {
return Utils . NoNull ( [ . . . this . tagRenderings , . . . this . titleIcons , this . title , this . isShown ] )
}
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
public ExtractImages ( ) : Set < string > {
const parts : Set < string > [ ] = [ ] ;
parts . push ( . . . this . tagRenderings ? . map ( ( tr ) = > tr . ExtractImages ( false ) ) ) ;
parts . push ( . . . this . titleIcons ? . map ( ( tr ) = > tr . ExtractImages ( true ) ) ) ;
for ( const preset of this . presets ) {
parts . push ( new Set < string > ( preset . description ? . ExtractImages ( false ) ) ) ;
2020-11-16 01:59:30 +01:00
}
2021-10-19 02:31:32 +02:00
for ( const pointRenderingConfig of this . mapRendering ) {
parts . push ( pointRenderingConfig . ExtractImages ( ) )
}
2021-07-23 15:56:22 +02:00
const allIcons = new Set < string > ( ) ;
for ( const part of parts ) {
part ? . forEach ( allIcons . add , allIcons ) ;
}
2021-04-09 02:57:06 +02:00
2021-07-23 15:56:22 +02:00
return allIcons ;
}
2021-10-22 18:53:07 +02:00
public isLeftRightSensitive ( ) : boolean {
2021-10-22 14:01:40 +02:00
return this . lineRendering . some ( lr = > lr . leftRightSensitive )
}
2021-12-04 21:49:17 +01:00
2021-08-07 23:11:34 +02:00
}