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-07-23 15:56:22 +02:00
import { TagsFilter } from "../../Logic/Tags/TagsFilter" ;
2021-08-07 23:11:34 +02:00
import PresetConfig from "./PresetConfig" ;
import { LayerConfigJson } from "./Json/LayerConfigJson" ;
import Translations from "../../UI/i18n/Translations" ;
import { TagUtils } from "../../Logic/Tags/TagUtils" ;
import SharedTagRenderings from "../../Customizations/SharedTagRenderings" ;
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson" ;
import { Utils } from "../../Utils" ;
import { UIEventSource } from "../../Logic/UIEventSource" ;
2021-06-10 01:36:20 +02:00
import BaseUIElement from "../../UI/BaseUIElement" ;
2021-08-07 23:11:34 +02:00
import { FixedUiElement } from "../../UI/Base/FixedUiElement" ;
import Combine from "../../UI/Base/Combine" ;
import { VariableUiElement } from "../../UI/Base/VariableUIElement" ;
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-09-06 01:35:08 +02:00
import Svg from "../../Svg" ;
2021-04-10 23:53:13 +02:00
2020-10-27 01:01:34 +01:00
export default class LayerConfig {
2021-07-23 15:56:22 +02:00
static WAYHANDLING_DEFAULT = 0 ;
static WAYHANDLING_CENTER_ONLY = 1 ;
static WAYHANDLING_CENTER_AND_WAY = 2 ;
id : string ;
name : Translation ;
description : Translation ;
source : SourceConfig ;
calculatedTags : [ string , string ] [ ] ;
doNotDownload : boolean ;
passAllFeatures : boolean ;
isShown : TagRenderingConfig ;
minzoom : number ;
2021-07-27 19:39:57 +02:00
minzoomVisible : number ;
2021-08-07 21:19:01 +02:00
maxzoom : number ;
2021-07-23 15:56:22 +02:00
title? : TagRenderingConfig ;
titleIcons : TagRenderingConfig [ ] ;
icon : TagRenderingConfig ;
iconOverlays : { if : TagsFilter ; then : TagRenderingConfig ; badge : boolean } [ ] ;
iconSize : TagRenderingConfig ;
label : TagRenderingConfig ;
rotation : TagRenderingConfig ;
color : TagRenderingConfig ;
width : TagRenderingConfig ;
dashArray : TagRenderingConfig ;
wayHandling : number ;
public readonly units : Unit [ ] ;
public readonly deletion : DeleteConfig | null ;
2021-07-15 20:47:28 +02:00
public readonly allowSplit : boolean
2021-07-23 15:56:22 +02:00
2021-08-07 21:19:01 +02:00
presets : PresetConfig [ ] ;
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
tagRenderings : TagRenderingConfig [ ] ;
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
) {
2021-09-13 01:21:47 +02:00
2021-07-23 15:56:22 +02:00
context = context + "." + json . id ;
const self = this ;
this . id = json . id ;
2021-07-15 20:47:28 +02:00
this . allowSplit = json . allowSplit ? ? false ;
2021-07-23 15:56:22 +02:00
this . name = Translations . T ( json . name , context + ".name" ) ;
2021-09-13 01:21:47 +02:00
this . units = ( json . units ? ? [ ] ) . map ( ( ( unitJson , i ) = > Unit . fromJson ( unitJson , ` ${ context } .unit[ ${ i } ] ` ) ) )
2021-07-23 15:56:22 +02:00
if ( json . description !== undefined ) {
if ( Object . keys ( json . description ) . length === 0 ) {
json . description = undefined ;
}
}
2021-03-20 23:45:52 +01:00
2021-07-23 15:56:22 +02:00
this . description = Translations . T (
json . description ,
context + ".description"
2021-07-22 11:29:09 +02:00
) ;
2021-03-20 23:45:52 +01:00
2021-07-23 15:56:22 +02:00
let legacy = undefined ;
if ( json [ "overpassTags" ] !== undefined ) {
// @ts-ignore
2021-08-07 23:11:34 +02:00
legacy = TagUtils . Tag ( json [ "overpassTags" ] , context + ".overpasstags" ) ;
2021-03-20 23:45:52 +01:00
}
2021-07-23 15:56:22 +02:00
if ( json . source !== undefined ) {
if ( legacy !== undefined ) {
throw (
context +
"Both the legacy 'layer.overpasstags' and the new 'layer.source'-field are defined"
) ;
}
let osmTags : TagsFilter = legacy ;
if ( json . source [ "osmTags" ] ) {
2021-08-07 23:11:34 +02:00
osmTags = TagUtils . Tag (
2021-07-23 15:56:22 +02:00
json . source [ "osmTags" ] ,
context + "source.osmTags"
) ;
}
if ( json . source [ "geoJsonSource" ] !== undefined ) {
throw context + "Use 'geoJson' instead of 'geoJsonSource'" ;
}
this . source = new SourceConfig (
{
osmTags : osmTags ,
geojsonSource : json.source [ "geoJson" ] ,
geojsonSourceLevel : json.source [ "geoJsonZoomLevel" ] ,
overpassScript : json.source [ "overpassScript" ] ,
isOsmCache : json.source [ "isOsmCache" ] ,
} ,
this . id
) ;
} else {
this . source = new SourceConfig ( {
osmTags : legacy ,
} ) ;
2021-03-24 01:25:57 +01:00
}
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-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-07-23 15:56:22 +02:00
this . wayHandling = json . wayHandling ? ? 0 ;
2021-07-14 00:17:15 +02:00
this . presets = ( json . presets ? ? [ ] ) . map ( ( pr , i ) = > {
2021-08-07 23:11:34 +02:00
2021-08-07 21:19:01 +02:00
let preciseInput = undefined ;
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
}
}
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 ,
snapToLayers : snapToLayers ,
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
/ * * G i v e n a k e y , g e t s t h e c o r r e s p o n d i n g p r o p e r t y f r o m t h e j s o n ( o r t h e d e f a u l t i f n o t f o u n d
*
* The found value is interpreted as a tagrendering and fetched / parsed
* * /
function tr ( key : string , deflt ) {
const v = json [ key ] ;
if ( v === undefined || v === null ) {
if ( deflt === undefined ) {
return undefined ;
}
return new TagRenderingConfig (
deflt ,
self . source . osmTags ,
` ${ context } . ${ key } .default value `
) ;
}
if ( typeof v === "string" ) {
const shared = SharedTagRenderings . SharedTagRendering . get ( v ) ;
if ( shared ) {
return shared ;
}
}
return new TagRenderingConfig (
v ,
self . source . osmTags ,
` ${ context } . ${ key } `
2021-07-22 11:29:09 +02:00
) ;
2021-07-23 15:56:22 +02:00
}
2020-11-24 12:52:01 +01:00
2021-07-23 15:56:22 +02:00
/ * *
* Converts a list of tagRenderingCOnfigJSON in to TagRenderingConfig
* A string is interpreted as a name to call
* /
function trs (
2021-09-09 20:26:12 +02:00
tagRenderings ? : ( string | { builtin : string , override : any } | TagRenderingConfigJson ) [ ] ,
2021-07-23 15:56:22 +02:00
readOnly = false
) {
if ( tagRenderings === undefined ) {
return [ ] ;
2020-12-06 00:20:27 +01:00
}
2020-10-27 01:01:34 +01:00
2021-07-23 15:56:22 +02:00
return Utils . NoNull (
tagRenderings . map ( ( renderingJson , i ) = > {
if ( typeof renderingJson === "string" ) {
2021-09-09 20:26:12 +02:00
renderingJson = { builtin : renderingJson , override : undefined }
}
if ( renderingJson [ "builtin" ] !== undefined ) {
const renderingId = renderingJson [ "builtin" ]
if ( renderingId === "questions" ) {
2021-07-23 15:56:22 +02:00
if ( readOnly ) {
throw ` A tagrendering has a question, but asking a question does not make sense here: is it a title icon or a geojson-layer? ${ context } . The offending tagrendering is ${ JSON . stringify (
renderingJson
) } ` ;
}
return new TagRenderingConfig ( "questions" , undefined ) ;
}
2021-09-09 20:26:12 +02:00
if ( renderingJson [ "override" ] !== undefined ) {
const sharedJson = SharedTagRenderings . SharedTagRenderingJson . get ( renderingId )
return new TagRenderingConfig (
Utils . Merge ( renderingJson [ "override" ] , sharedJson ) ,
self . source . osmTags ,
` ${ context } .tagrendering[ ${ i } ]+override `
) ;
2021-07-23 15:56:22 +02:00
}
2021-09-09 20:26:12 +02:00
const shared = SharedTagRenderings . SharedTagRendering . get ( renderingId ) ;
2021-07-23 15:56:22 +02:00
2021-09-09 20:26:12 +02:00
if ( shared !== undefined ) {
return shared ;
}
2021-07-23 15:56:22 +02:00
if ( Utils . runningFromConsole ) {
return undefined ;
}
2021-09-09 20:26:12 +02:00
const keys = Array . from (
SharedTagRenderings . SharedTagRendering . keys ( )
) ;
throw ` Predefined tagRendering ${ renderingId } not found in ${ context } . \ n Try one of ${ keys . join (
2021-07-23 15:56:22 +02:00
", "
) } \ n If you intent to output this text literally , use { \ "render\": <your text>} instead" } ` ;
}
2021-09-09 20:26:12 +02:00
2021-07-23 15:56:22 +02:00
return new TagRenderingConfig (
2021-09-09 20:26:12 +02:00
< TagRenderingConfigJson > renderingJson ,
2021-07-23 15:56:22 +02:00
self . source . osmTags ,
` ${ context } .tagrendering[ ${ i } ] `
) ;
} )
) ;
}
2020-11-16 01:59:30 +01:00
2021-07-23 15:56:22 +02:00
this . tagRenderings = trs ( json . tagRenderings , false ) ;
this . filters = ( json . filter ? ? [ ] ) . map ( ( option , i ) = > {
return new FilterConfig ( option , ` ${ context } .filter-[ ${ i } ] ` )
} ) ;
const titleIcons = [ ] ;
const defaultIcons = [
"phonelink" ,
"emaillink" ,
"wikipedialink" ,
"osmlink" ,
"sharelink" ,
] ;
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-07-23 15:56:22 +02:00
this . titleIcons = trs ( titleIcons , true ) ;
2021-03-15 16:23:04 +01:00
2021-07-23 15:56:22 +02:00
this . title = tr ( "title" , undefined ) ;
this . icon = tr ( "icon" , "" ) ;
this . iconOverlays = ( json . iconOverlays ? ? [ ] ) . map ( ( overlay , i ) = > {
let tr = new TagRenderingConfig (
overlay . then ,
self . source . osmTags ,
` iconoverlays. ${ i } `
) ;
if (
typeof overlay . then === "string" &&
SharedTagRenderings . SharedIcons . get ( overlay . then ) !== undefined
) {
tr = SharedTagRenderings . SharedIcons . get ( overlay . then ) ;
}
return {
2021-08-07 23:11:34 +02:00
if : TagUtils . Tag ( overlay . if ) ,
2021-07-23 15:56:22 +02:00
then : tr ,
badge : overlay.badge ? ? false ,
} ;
} ) ;
const iconPath = this . icon . GetRenderValue ( { id : "node/-1" } ) . txt ;
if ( iconPath . startsWith ( Utils . assets_path ) ) {
const iconKey = iconPath . substr ( Utils . assets_path . length ) ;
if ( Svg . All [ iconKey ] === undefined ) {
throw "Builtin SVG asset not found: " + iconPath ;
}
}
this . isShown = tr ( "isShown" , "yes" ) ;
this . iconSize = tr ( "iconSize" , "40,40,center" ) ;
this . label = tr ( "label" , "" ) ;
this . color = tr ( "color" , "#0000ff" ) ;
this . width = tr ( "width" , "7" ) ;
this . rotation = tr ( "rotation" , "0" ) ;
this . dashArray = tr ( "dashArray" , "" ) ;
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-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-07-23 15:56:22 +02:00
public CustomCodeSnippets ( ) : string [ ] {
if ( this . calculatedTags === undefined ) {
return [ ] ;
}
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
return this . calculatedTags . map ( ( code ) = > code [ 1 ] ) ;
2021-07-22 11:29:09 +02:00
}
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
public AddRoamingRenderings ( addAll : {
tagRenderings : TagRenderingConfig [ ] ;
titleIcons : TagRenderingConfig [ ] ;
iconOverlays : {
if : TagsFilter ;
then : TagRenderingConfig ;
badge : boolean ;
} [ ] ;
} ) : LayerConfig {
let insertionPoint = this . tagRenderings
. map ( ( tr ) = > tr . IsQuestionBoxElement ( ) )
. indexOf ( true ) ;
if ( insertionPoint < 0 ) {
// No 'questions' defined - we just add them all to the end
insertionPoint = this . tagRenderings . length ;
}
this . tagRenderings . splice ( insertionPoint , 0 , . . . addAll . tagRenderings ) ;
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
this . iconOverlays . push ( . . . addAll . iconOverlays ) ;
for ( const icon of addAll . titleIcons ) {
this . titleIcons . splice ( 0 , 0 , icon ) ;
}
return this ;
2021-07-22 11:29:09 +02:00
}
2021-01-08 03:57:18 +01:00
2021-07-23 15:56:22 +02:00
public GetRoamingRenderings ( ) : {
tagRenderings : TagRenderingConfig [ ] ;
titleIcons : TagRenderingConfig [ ] ;
iconOverlays : {
if : TagsFilter ;
then : TagRenderingConfig ;
badge : boolean ;
} [ ] ;
} {
const tagRenderings = this . tagRenderings . filter ( ( tr ) = > tr . roaming ) ;
const titleIcons = this . titleIcons . filter ( ( tr ) = > tr . roaming ) ;
const iconOverlays = this . iconOverlays . filter ( ( io ) = > io . then . roaming ) ;
return {
tagRenderings : tagRenderings ,
titleIcons : titleIcons ,
iconOverlays : iconOverlays ,
} ;
2021-01-08 03:57:18 +01:00
}
2021-07-23 15:56:22 +02:00
public GenerateLeafletStyle (
tags : UIEventSource < any > ,
2021-07-27 22:23:42 +02:00
clickable : boolean
2021-07-23 15:56:22 +02:00
) : {
icon : {
html : BaseUIElement ;
iconSize : [ number , number ] ;
iconAnchor : [ number , number ] ;
popupAnchor : [ number , number ] ;
iconUrl : string ;
className : string ;
} ;
color : string ;
weight : number ;
dashArray : number [ ] ;
} {
function num ( str , deflt = 40 ) {
const n = Number ( str ) ;
if ( isNaN ( n ) ) {
return deflt ;
}
return n ;
}
2020-11-16 01:59:30 +01:00
2021-07-23 15:56:22 +02:00
function rendernum ( tr : TagRenderingConfig , deflt : number ) {
const str = Number ( render ( tr , "" + deflt ) ) ;
const n = Number ( str ) ;
if ( isNaN ( n ) ) {
return deflt ;
}
return n ;
}
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
function render ( tr : TagRenderingConfig , deflt? : string ) {
2021-08-07 23:11:34 +02:00
if ( tags === undefined ) {
2021-08-07 21:19:01 +02:00
return deflt
}
2021-07-23 15:56:22 +02:00
const str = tr ? . GetRenderValue ( tags . data ) ? . txt ? ? deflt ;
return Utils . SubstituteKeys ( str , tags . data ) . replace ( /{.*}/g , "" ) ;
}
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
const iconSize = render ( this . iconSize , "40,40,center" ) . split ( "," ) ;
2021-08-07 21:19:01 +02:00
const dashArray = render ( this . dashArray ) ? . split ( " " ) ? . map ( Number ) ;
2021-07-23 15:56:22 +02:00
let color = render ( this . color , "#00f" ) ;
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
if ( color . startsWith ( "--" ) ) {
color = getComputedStyle ( document . body ) . getPropertyValue (
"--catch-detail-color"
) ;
}
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
const weight = rendernum ( this . width , 5 ) ;
2020-11-17 02:22:48 +01:00
2021-07-23 15:56:22 +02:00
const iconW = num ( iconSize [ 0 ] ) ;
let iconH = num ( iconSize [ 1 ] ) ;
const mode = iconSize [ 2 ] ? . trim ( ) ? . toLowerCase ( ) ? ? "center" ;
2020-11-16 01:59:30 +01:00
2021-07-23 15:56:22 +02:00
let anchorW = iconW / 2 ;
let anchorH = iconH / 2 ;
if ( mode === "left" ) {
anchorW = 0 ;
2020-11-16 01:59:30 +01:00
}
2021-07-23 15:56:22 +02:00
if ( mode === "right" ) {
anchorW = iconW ;
2020-11-16 01:59:30 +01:00
}
2021-07-23 15:56:22 +02:00
if ( mode === "top" ) {
anchorH = 0 ;
}
if ( mode === "bottom" ) {
anchorH = iconH ;
2020-11-16 01:59:30 +01:00
}
2021-07-22 11:29:09 +02:00
2021-07-23 15:56:22 +02:00
const iconUrlStatic = render ( this . icon ) ;
const self = this ;
2021-08-07 21:19:01 +02:00
function genHtmlFromString ( sourcePart : string , rotation : string ) : BaseUIElement {
const style = ` width:100%;height:100%;transform: rotate( ${ rotation } );display:block;position: absolute; top: 0; left: 0 ` ;
let html : BaseUIElement = new FixedUiElement (
` <img src=" ${ sourcePart } " style=" ${ style } " /> `
) ;
const match = sourcePart . match ( /([a-zA-Z0-9_]*):([^;]*)/ ) ;
if ( match !== null && Svg . All [ match [ 1 ] + ".svg" ] !== undefined ) {
html = new Combine ( [
( Svg . All [ match [ 1 ] + ".svg" ] as string ) . replace (
/#000000/g ,
match [ 2 ]
) ,
] ) . SetStyle ( style ) ;
2021-07-23 15:56:22 +02:00
}
2021-08-07 21:19:01 +02:00
return html ;
}
2021-07-23 15:56:22 +02:00
2021-08-07 21:19:01 +02:00
const mappedHtml = tags ? . map ( ( tgs ) = > {
2021-07-23 15:56:22 +02:00
// What do you mean, 'tgs' is never read?
// It is read implicitly in the 'render' method
const iconUrl = render ( self . icon ) ;
const rotation = render ( self . rotation , "0deg" ) ;
let htmlParts : BaseUIElement [ ] = [ ] ;
let sourceParts = Utils . NoNull (
iconUrl . split ( ";" ) . filter ( ( prt ) = > prt != "" )
) ;
for ( const sourcePart of sourceParts ) {
2021-08-07 21:19:01 +02:00
htmlParts . push ( genHtmlFromString ( sourcePart , rotation ) ) ;
2021-07-23 15:56:22 +02:00
}
let badges = [ ] ;
for ( const iconOverlay of self . iconOverlays ) {
if ( ! iconOverlay . if . matchesProperties ( tgs ) ) {
continue ;
}
if ( iconOverlay . badge ) {
const badgeParts : BaseUIElement [ ] = [ ] ;
const partDefs = iconOverlay . then
. GetRenderValue ( tgs )
. txt . split ( ";" )
. filter ( ( prt ) = > prt != "" ) ;
for ( const badgePartStr of partDefs ) {
2021-08-07 21:19:01 +02:00
badgeParts . push ( genHtmlFromString ( badgePartStr , "0" ) ) ;
2021-07-23 15:56:22 +02:00
}
const badgeCompound = new Combine ( badgeParts ) . SetStyle (
"display:flex;position:relative;width:100%;height:100%;"
) ;
badges . push ( badgeCompound ) ;
} else {
htmlParts . push (
2021-08-07 21:19:01 +02:00
genHtmlFromString ( iconOverlay . then . GetRenderValue ( tgs ) . txt , "0" )
2021-07-23 15:56:22 +02:00
) ;
}
}
if ( badges . length > 0 ) {
const badgesComponent = new Combine ( badges ) . SetStyle (
"display:flex;height:50%;width:100%;position:absolute;top:50%;left:50%;"
) ;
htmlParts . push ( badgesComponent ) ;
}
if ( sourceParts . length == 0 ) {
iconH = 0 ;
}
try {
const label = self . label
? . GetRenderValue ( tgs )
? . Subs ( tgs )
? . SetClass ( "block text-center" )
? . SetStyle ( "margin-top: " + ( iconH + 2 ) + "px" ) ;
if ( label !== undefined ) {
htmlParts . push (
new Combine ( [ label ] ) . SetClass ( "flex flex-col items-center" )
) ;
}
} catch ( e ) {
console . error ( e , tgs ) ;
}
return new Combine ( htmlParts ) ;
} ) ;
return {
icon : {
2021-08-07 21:19:01 +02:00
html : mappedHtml === undefined ? new FixedUiElement ( self . icon . render . txt ) : new VariableUiElement ( mappedHtml ) ,
2021-07-23 15:56:22 +02:00
iconSize : [ iconW , iconH ] ,
iconAnchor : [ anchorW , anchorH ] ,
popupAnchor : [ 0 , 3 - anchorH ] ,
iconUrl : iconUrlStatic ,
className : clickable
? "leaflet-div-icon"
: "leaflet-div-icon unclickable" ,
} ,
color : color ,
weight : weight ,
dashArray : dashArray ,
} ;
}
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 ) ) ) ;
parts . push ( this . icon ? . ExtractImages ( true ) ) ;
parts . push (
. . . this . iconOverlays ? . map ( ( overlay ) = > overlay . then . ExtractImages ( true ) )
2021-07-22 11:29:09 +02:00
) ;
2021-07-23 15:56:22 +02:00
for ( const preset of this . presets ) {
parts . push ( new Set < string > ( preset . description ? . ExtractImages ( false ) ) ) ;
2020-11-16 01:59:30 +01:00
}
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-08-07 23:11:34 +02:00
}