forked from MapComplete/MapComplete
		
	Add title icons to favourites layer
This commit is contained in:
		
							parent
							
								
									3b9035e3b4
								
							
						
					
					
						commit
						37cdf0f01a
					
				
					 3 changed files with 45 additions and 12 deletions
				
			
		|  | @ -1,5 +1,6 @@ | ||||||
| { | { | ||||||
|   "#":"no-translations", |   "#":"no-translations", | ||||||
|  |   "#dont-translate": "*", | ||||||
|   "pointRendering": [ |   "pointRendering": [ | ||||||
|     { |     { | ||||||
|       "location": [ |       "location": [ | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "wikipedialink", |       "id": "wikipedialink", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "render": "<a href='https://wikipedia.org/wiki/{wikipedia}' target='_blank' rel='noopener'><img src='./assets/svg/wikipedia.svg' textmode='📖' alt='Wikipedia'/></a>", |       "render": "<a href='https://wikipedia.org/wiki/{wikipedia}' target='_blank' rel='noopener'><img src='./assets/svg/wikipedia.svg' textmode='📖' alt='Wikipedia'/></a>", | ||||||
|       "condition": { |       "condition": { | ||||||
|  | @ -69,7 +69,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "phonelink", |       "id": "phonelink", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "render": "<a href='tel:{phone}'><img textmode='📞' alt='phone' src='./assets/layers/questions/phone.svg'/></a>", |       "render": "<a href='tel:{phone}'><img textmode='📞' alt='phone' src='./assets/layers/questions/phone.svg'/></a>", | ||||||
|       "mappings": [ |       "mappings": [ | ||||||
|  | @ -89,7 +89,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "emaillink", |       "id": "emaillink", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "render": "<a href='mailto:{email}'><img textmode='✉️' alt='email' src='./assets/layers/questions/send_email.svg'/></a>", |       "render": "<a href='mailto:{email}'><img textmode='✉️' alt='email' src='./assets/layers/questions/send_email.svg'/></a>", | ||||||
|       "mappings": [ |       "mappings": [ | ||||||
|  | @ -109,7 +109,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "websitelink", |       "id": "websitelink", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "render": "<a href='{website}' target='_blank' rel='noopener'><img textmode='🌐' alt='website' src='./assets/layers/icons/website.svg'/></a>", |       "render": "<a href='{website}' target='_blank' rel='noopener'><img textmode='🌐' alt='website' src='./assets/layers/icons/website.svg'/></a>", | ||||||
|       "condition": "website~*" |       "condition": "website~*" | ||||||
|  | @ -117,7 +117,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "smokingicon", |       "id": "smokingicon", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "mappings": [ |       "mappings": [ | ||||||
|         { |         { | ||||||
|  | @ -171,7 +171,7 @@ | ||||||
|     { |     { | ||||||
|       "id": "dogicon", |       "id": "dogicon", | ||||||
|       "labels": [ |       "labels": [ | ||||||
|         "defaults" |         "defaults", "in_favourite" | ||||||
|       ], |       ], | ||||||
|       "mappings": [ |       "mappings": [ | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -13,7 +13,7 @@ import { TagConfigJson } from "../src/Models/ThemeConfig/Json/TagConfigJson" | ||||||
| import { TagUtils } from "../src/Logic/Tags/TagUtils" | import { TagUtils } from "../src/Logic/Tags/TagUtils" | ||||||
| import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson" | import { TagRenderingConfigJson } from "../src/Models/ThemeConfig/Json/TagRenderingConfigJson" | ||||||
| import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable" | import { Translatable } from "../src/Models/ThemeConfig/Json/Translatable" | ||||||
| 
 | import icons from "../src/assets/generated/layers/icons.json" | ||||||
| export class GenerateFavouritesLayer extends Script { | export class GenerateFavouritesLayer extends Script { | ||||||
|     private readonly layers: LayerConfigJson[] = [] |     private readonly layers: LayerConfigJson[] = [] | ||||||
| 
 | 
 | ||||||
|  | @ -51,10 +51,11 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|             "move-button", |             "move-button", | ||||||
|             "delete-button", |             "delete-button", | ||||||
|             "all-tags", |             "all-tags", | ||||||
|  |             "all_tags", | ||||||
|             ...AddEditingElements.addedElements, |             ...AddEditingElements.addedElements, | ||||||
|         ]) |         ]) | ||||||
| 
 | 
 | ||||||
|         const generateTagRenderings: (string | QuestionableTagRenderingConfigJson)[] = [] |         const generatedTagRenderings: (string | QuestionableTagRenderingConfigJson)[] = [] | ||||||
|         const trPerId = new Map< |         const trPerId = new Map< | ||||||
|             string, |             string, | ||||||
|             { conditions: TagConfigJson[]; tr: QuestionableTagRenderingConfigJson } |             { conditions: TagConfigJson[]; tr: QuestionableTagRenderingConfigJson } | ||||||
|  | @ -68,7 +69,7 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|                     if (blacklistedIds.has(tagRendering)) { |                     if (blacklistedIds.has(tagRendering)) { | ||||||
|                         continue |                         continue | ||||||
|                     } |                     } | ||||||
|                     generateTagRenderings.push(tagRendering) |                     generatedTagRenderings.push(tagRendering) | ||||||
|                     blacklistedIds.add(tagRendering) |                     blacklistedIds.add(tagRendering) | ||||||
|                     continue |                     continue | ||||||
|                 } |                 } | ||||||
|  | @ -97,14 +98,14 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|                         newTr.condition = { |                         newTr.condition = { | ||||||
|                             and: Utils.NoNull([(newTr.condition, layerConfig.source["osmTags"])]), |                             and: Utils.NoNull([(newTr.condition, layerConfig.source["osmTags"])]), | ||||||
|                         } |                         } | ||||||
|                         generateTagRenderings.push(newTr) |                         generatedTagRenderings.push(newTr) | ||||||
|                         blacklistedIds.add(newTr.id) |                         blacklistedIds.add(newTr.id) | ||||||
|                         continue |                         continue | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 if (!trPerId.has(id)) { |                 if (!trPerId.has(id)) { | ||||||
|                     const newTr = <QuestionableTagRenderingConfigJson>Utils.Clone(tagRendering) |                     const newTr = <QuestionableTagRenderingConfigJson>Utils.Clone(tagRendering) | ||||||
|                     generateTagRenderings.push(newTr) |                     generatedTagRenderings.push(newTr) | ||||||
|                     trPerId.set(newTr.id, { tr: newTr, conditions: [] }) |                     trPerId.set(newTr.id, { tr: newTr, conditions: [] }) | ||||||
|                 } |                 } | ||||||
|                 const conditions = trPerId.get(id).conditions |                 const conditions = trPerId.get(id).conditions | ||||||
|  | @ -142,13 +143,43 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|             }, |             }, | ||||||
|         } |         } | ||||||
|         proto.tagRenderings = [ |         proto.tagRenderings = [ | ||||||
|             ...generateTagRenderings, |             "images", | ||||||
|  |             ...generatedTagRenderings, | ||||||
|             ...proto.tagRenderings, |             ...proto.tagRenderings, | ||||||
|             "questions", |             "questions", | ||||||
|             allTags, |             allTags, | ||||||
|         ] |         ] | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     private addTitleIcons(proto: LayerConfigJson) { | ||||||
|  |         proto.titleIcons = [] | ||||||
|  |         const seenTitleIcons = new Set<string>() | ||||||
|  |         for (const layer of this.layers) { | ||||||
|  |             for (const titleIcon of layer.titleIcons) { | ||||||
|  |                 if (typeof titleIcon === "string") { | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 if (titleIcon["labels"]?.indexOf("defaults") >= 0) { | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 if (titleIcon.id === "rating") { | ||||||
|  |                     if (!seenTitleIcons.has("rating")) { | ||||||
|  |                         proto.titleIcons.unshift("icons.rating") | ||||||
|  |                         seenTitleIcons.add("rating") | ||||||
|  |                     } | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 if (seenTitleIcons.has(titleIcon.id)) { | ||||||
|  |                     continue | ||||||
|  |                 } | ||||||
|  |                 seenTitleIcons.add(titleIcon.id) | ||||||
|  |                 console.log("Adding ", titleIcon.id) | ||||||
|  |                 proto.titleIcons.push(titleIcon) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         proto.titleIcons.push("icons.defaults") | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private addTitle(proto: LayerConfigJson) { |     private addTitle(proto: LayerConfigJson) { | ||||||
|         const mappings: MappingConfigJson[] = [] |         const mappings: MappingConfigJson[] = [] | ||||||
|         for (const layer of this.layers) { |         for (const layer of this.layers) { | ||||||
|  | @ -227,6 +258,7 @@ export class GenerateFavouritesLayer extends Script { | ||||||
|         const proto = this.readLayer("favourite/favourite.proto.json") |         const proto = this.readLayer("favourite/favourite.proto.json") | ||||||
|         this.addTagRenderings(proto) |         this.addTagRenderings(proto) | ||||||
|         this.addTitle(proto) |         this.addTitle(proto) | ||||||
|  |         this.addTitleIcons(proto) | ||||||
|         writeFileSync("./assets/layers/favourite/favourite.json", JSON.stringify(proto, null, "  ")) |         writeFileSync("./assets/layers/favourite/favourite.json", JSON.stringify(proto, null, "  ")) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue