forked from MapComplete/MapComplete
		
	Small refactoring, add 'last edit by'-rendering
This commit is contained in:
		
							parent
							
								
									c6b4ba43fb
								
							
						
					
					
						commit
						95f1bdd797
					
				
					 10 changed files with 76 additions and 29 deletions
				
			
		|  | @ -136,7 +136,7 @@ export default class LayerConfig { | |||
|                 return new TagRenderingConfig(deflt, self.source.osmTags, `${context}.${key}.default value`); | ||||
|             } | ||||
|             if (typeof v === "string") { | ||||
|                 const shared = SharedTagRenderings.SharedTagRendering[v]; | ||||
|                 const shared = SharedTagRenderings.SharedTagRendering.get(v); | ||||
|                 if (shared) { | ||||
|                     return shared; | ||||
|                 } | ||||
|  | @ -166,7 +166,7 @@ export default class LayerConfig { | |||
|                         } | ||||
| 
 | ||||
| 
 | ||||
|                         const shared = SharedTagRenderings.SharedTagRendering[renderingJson]; | ||||
|                         const shared = SharedTagRenderings.SharedTagRendering.get(renderingJson); | ||||
|                         if (shared !== undefined) { | ||||
|                             return shared; | ||||
|                         } | ||||
|  | @ -196,8 +196,8 @@ export default class LayerConfig { | |||
|         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[overlay.then] !== undefined) { | ||||
|                 tr = SharedTagRenderings.SharedIcons[overlay.then]; | ||||
|             if (typeof overlay.then === "string" && SharedTagRenderings.SharedIcons.get(overlay.then) !== undefined) { | ||||
|                 tr = SharedTagRenderings.SharedIcons.get(overlay.then); | ||||
|             } | ||||
|             return { | ||||
|                 if: FromJSON.Tag(overlay.if), | ||||
|  | @ -410,14 +410,20 @@ export default class LayerConfig { | |||
|                 htmlParts.push(badgesComponent) | ||||
|             } | ||||
| 
 | ||||
|             if(sourceParts.length ==0){iconH = 0} | ||||
|             if (sourceParts.length == 0) { | ||||
|                 iconH = 0 | ||||
|             } | ||||
|             try { | ||||
| 
 | ||||
|             const label = self.label.GetRenderValue(tgs)?.Subs(tgs) | ||||
|                 .SetClass("block w-min text-center") | ||||
|                 .SetStyle("margin-top: "+(iconH + 2) +"px") | ||||
|                 const label = self.label?.GetRenderValue(tgs)?.Subs(tgs) | ||||
|                     ?.SetClass("block w-min 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).Render(); | ||||
|         }) | ||||
| 
 | ||||
|  |  | |||
|  | @ -83,8 +83,8 @@ export default class LayoutConfig { | |||
|         this.widenFactor = json.widenFactor ?? 0.05; | ||||
|         this.roamingRenderings = (json.roamingRenderings ?? []).map((tr, i) => { | ||||
|                 if (typeof tr === "string") { | ||||
|                     if (SharedTagRenderings.SharedTagRendering[tr] !== undefined) { | ||||
|                         return SharedTagRenderings.SharedTagRendering[tr]; | ||||
|                     if (SharedTagRenderings.SharedTagRendering.get(tr) !== undefined) { | ||||
|                         return SharedTagRenderings.SharedTagRendering.get(tr); | ||||
|                     } | ||||
|                 } | ||||
|                 return new TagRenderingConfig(tr, undefined, `${this.id}.roaming_renderings[${i}]`); | ||||
|  |  | |||
|  | @ -4,15 +4,15 @@ import * as icons from "../assets/tagRenderings/icons.json"; | |||
| 
 | ||||
| export default class SharedTagRenderings { | ||||
| 
 | ||||
|     public static SharedTagRendering = SharedTagRenderings.generatedSharedFields(); | ||||
|     public static SharedIcons = SharedTagRenderings.generatedSharedFields(true); | ||||
|     public static SharedTagRendering : Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(); | ||||
|     public static SharedIcons : Map<string, TagRenderingConfig> = SharedTagRenderings.generatedSharedFields(true); | ||||
| 
 | ||||
|     private static generatedSharedFields(iconsOnly = false) { | ||||
|         const dict = {} | ||||
|     private static generatedSharedFields(iconsOnly = false) : Map<string, TagRenderingConfig>{ | ||||
|         const dict = new Map<string, TagRenderingConfig>(); | ||||
| 
 | ||||
|         function add(key, store) { | ||||
|             try { | ||||
|                 dict[key] = new TagRenderingConfig(store[key], key) | ||||
|                 dict.set(key, new TagRenderingConfig(store[key], key)) | ||||
|             } catch (e) { | ||||
|                 console.error("BUG: could not parse", key, " from questions.json or icons.json - this error happened during the build step of the SharedTagRenderings", e) | ||||
|             } | ||||
|  |  | |||
|  | @ -9,13 +9,15 @@ export default class Constants { | |||
|         addNewPointsUnlock: 0, | ||||
|         moreScreenUnlock: 1, | ||||
|         personalLayoutUnlock: 15, | ||||
|         historyLinkVisible: 20, | ||||
|         tagsVisibleAt: 25, | ||||
|         mapCompleteHelpUnlock: 50, | ||||
|         tagsVisibleAndWikiLinked: 30, | ||||
|         themeGeneratorReadOnlyUnlock: 50, | ||||
|         themeGeneratorFullUnlock: 500, | ||||
|         addNewPointWithUnreadMessagesUnlock: 500, | ||||
|         minZoomLevelToAddNewPoints: (Constants.isRetina() ? 18 : 19) | ||||
|         minZoomLevelToAddNewPoints: (Constants.isRetina() ? 18 : 19), | ||||
|         | ||||
|     }; | ||||
|     /** | ||||
|      * Used by 'PendingChangesUploader', which waits this amount of seconds to upload changes. | ||||
|  |  | |||
|  | @ -47,9 +47,12 @@ export default class LayerSelection extends UIElement { | |||
|                 .SetClass("single-layer-selection-toggle") | ||||
|                 .SetStyle("opacity:0.2;"); | ||||
| 
 | ||||
|             const name = Translations.WT(layer.layerDef.name).Clone() | ||||
|                 .SetStyle("font-size:large;margin-left: 0.5em;"); | ||||
|             const name = Translations.WT(layer.layerDef.name)?.Clone() | ||||
|                 ?.SetStyle("font-size:large;margin-left: 0.5em;"); | ||||
| 
 | ||||
|             if(name === undefined){ | ||||
|                 continue | ||||
|             } | ||||
| 
 | ||||
|             const zoomStatus = new VariableUiElement(State.state.locationControl.map(location => { | ||||
|                 if (location.zoom < layer.layerDef.minzoom) { | ||||
|  |  | |||
|  | @ -9,6 +9,8 @@ import State from "../../State"; | |||
| import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig"; | ||||
| import ScrollableFullScreen from "../Base/ScrollableFullScreen"; | ||||
| import {Tag} from "../../Logic/Tags/Tag"; | ||||
| import Constants from "../../Models/Constants"; | ||||
| import SharedTagRenderings from "../../Customizations/SharedTagRenderings"; | ||||
| 
 | ||||
| export default class FeatureInfoBox extends ScrollableFullScreen { | ||||
| 
 | ||||
|  | @ -67,6 +69,12 @@ export default class FeatureInfoBox extends ScrollableFullScreen { | |||
|             renderings.push(questionBox); | ||||
|         } | ||||
| 
 | ||||
|         if (State.state.osmConnection.userDetails.data.csCount >= Constants.userJourney.historyLinkVisible || | ||||
|             State.state.featureSwitchIsDebugging.data == true || | ||||
|             State.state.featureSwitchIsTesting.data == true) { | ||||
|             renderings.push(new TagRenderingAnswer( tags, SharedTagRenderings.SharedTagRendering.get("last_edit"))) | ||||
|         } | ||||
| 
 | ||||
|         if (State.state.featureSwitchIsDebugging.data) { | ||||
|             const config: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, new Tag("id", ""), ""); | ||||
|             renderings.push(new TagRenderingAnswer(tags, config)) | ||||
|  |  | |||
|  | @ -73,10 +73,18 @@ export class Translation extends UIElement { | |||
|                 let rtext: string = ""; | ||||
|                 if (typeof (el) === "string") { | ||||
|                     rtext = el; | ||||
|                 } else if(typeof(el) === "number") { | ||||
|                     // HUH? Where did that number come from?
 | ||||
|                 } else if (typeof (el) === "number") { | ||||
|                     // HUH? Where did that number come from? It might be a version number or something calculated
 | ||||
|                     rtext = "" + el; | ||||
|                 }else { | ||||
|                 } else if (el["toISOString"] != undefined) { | ||||
|                     // This is a date, probably the timestamp of the object
 | ||||
|                     // @ts-ignore
 | ||||
|                     const date: Date = el; | ||||
|                     rtext = date.toLocaleString(); | ||||
|                 } else if (el.InnerRender === undefined) { | ||||
|                     console.error("InnerREnder is not defined", el); | ||||
|                     throw "Hmmm, el.InnerRender is not defined?" | ||||
|                 } else { | ||||
|                     Translation.forcedLanguage = lang; // This is a very dirty hack - it'll bite me one day
 | ||||
|                     rtext = el.InnerRender(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -77,5 +77,10 @@ | |||
|       "key": "opening_hours", | ||||
|       "type": "opening_hours" | ||||
|     } | ||||
|   }, | ||||
|   "last_edit": { | ||||
|     "#": "Gives some metainfo about the last edit and who did edit it - rendering only", | ||||
|     "#condition": "_last_edit:contributor~*", | ||||
|     "render": "<div class='subtle' style='font-size: small'><a href='https://www.openStreetMap.org/changeset/{_last_edit:changeset}' target='_blank'>Last edited on {_last_edit:timestamp}</a> by <a href='https://www.openStreetMap.org/user/{_last_edit:contributor}' target='_blank'>{_last_edit:contributor}</a></div>" | ||||
|   } | ||||
| } | ||||
|  | @ -15,7 +15,7 @@ | |||
|   "maintainer": "MapComplete", | ||||
|   "icon": "./assets/layers/play_forest/icon.svg", | ||||
|   "hideFromOverview": true, | ||||
|   "lockLocation": false, | ||||
|   "lockLocation": true, | ||||
|   "version": "0", | ||||
|   "startLat": 51.17174, | ||||
|   "startLon": 4.449462, | ||||
|  | @ -27,7 +27,8 @@ | |||
|     "play_forest", | ||||
|     "playground", | ||||
|     "sport_pitch", | ||||
|     { "builtin": "slow_roads", | ||||
|     { | ||||
|       "builtin": "slow_roads", | ||||
|       "override": { | ||||
|         "calculatedTags": [ | ||||
|           "_part_of_walking_routes=feat.memberships().map(r => \"<a href='#relation/\"+r.relation.id+\"'>\" + r.relation.tags.name + \"</a>\").join(', ')" | ||||
|  | @ -109,7 +110,7 @@ | |||
|             "nl": "Wie beheert deze wandeling en plaatst dus de signalisatiebordjes?" | ||||
|           }, | ||||
|           "render": "Signalisatie geplaatst door {operator}", | ||||
|           "freeform":{ | ||||
|           "freeform": { | ||||
|             "key": "operator" | ||||
|           } | ||||
|         }, | ||||
|  | @ -130,7 +131,7 @@ | |||
|       ], | ||||
|       "color": { | ||||
|         "render": "#6d6", | ||||
|         "mappings":[ | ||||
|         "mappings": [ | ||||
|           { | ||||
|             "if": "color~*", | ||||
|             "then": "{color}" | ||||
|  | @ -140,8 +141,16 @@ | |||
|       "width": { | ||||
|         "render": "3" | ||||
|       } | ||||
|     }, | ||||
|     { | ||||
|       "source": { | ||||
|         "osmTags": { | ||||
|           "or": [] | ||||
|         }, | ||||
|         "geoJson": "https://pietervdvn.github.io/speelplekken-cache.geojson" | ||||
|       }, | ||||
|       "passAllFeatures": true | ||||
|     } | ||||
| 
 | ||||
|   ], | ||||
|   "roamingRenderings": [ | ||||
|     { | ||||
|  |  | |||
|  | @ -283,6 +283,12 @@ li::marker { | |||
|     color: #999; | ||||
| } | ||||
| 
 | ||||
| .link-underline .subtle a { | ||||
|     color: var(--foreground-color); | ||||
|     text-decoration: underline 1px #7193bb88; | ||||
|     color: #7193bb; | ||||
| } | ||||
| 
 | ||||
| .bold { | ||||
|     font-weight: bold; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue