Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Info popup tweaks
Russ Garrett6fc9a86d8ba4
diff --git a/web/src/infopopup.css b/web/src/infopopup.cssindex 0064615..5dba1f7 100644--- a/web/src/infopopup.css+++ b/web/src/infopopup.css@@ -2,28 +2,20 @@ table.item_info th {text-align: left;}-.maplibregl-popup {- max-width: 350px !important;-}--.maplibregl-popup .nameContainer {- margin-bottom: 5px;-}--.maplibregl-popup h3 {+.oim-info h3 {margin-top: 0px;margin-bottom: 0px;}-.maplibregl-popup h4::before {+.oim-info h4::before {content: "("}-.maplibregl-popup h4::after {+.oim-info h4::after {content: ")"}-.maplibregl-popup h4 {+.oim-info h4 {font-weight: normal;margin-top: 0px;margin-bottom: 0px;@@ -40,6 +32,10 @@ div.ext_link {background-size: 30px 30px;}+span.voltages {+ font-size: 1.05em;+}+div.wikidata_link {background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='156' width='156'%3E%3Ccircle r='70' stroke='%23FFF' cy='78' cx='78' stroke-width='12' fill='%23E6E6E6'/%3E%3Ccircle cy='78' cx='78' r='56' fill='%23FFF'/%3E%3Cpath d='M32 107h3V49h-3v58zm7 0h10V49H39v58zm13-58v58h10V49H52z' fill='%23900'/%3E%3Cpath d='M114 107h3V49h-3v58zm7-58v58h3V49h-3zm-55 58h3V49h-3v58zm7-58v58h3V49h-3z' fill='%23396'/%3E%3Cpath d='M80 107h10V49H80v58zm13 0h4V49h-4v58zm7-58v58h10V49h-10z' fill='%23069'/%3E%3C/svg%3E");}diff --git a/web/src/infopopup.ts b/web/src/infopopup.tsindex 9e8cb29..7f9ebfd 100644--- a/web/src/infopopup.ts+++ b/web/src/infopopup.ts@@ -18,7 +18,8 @@ const hidden_keys = ['is_node','area','gid',- 'ref_len'+ 'ref_len',+ 'frequency']class InfoPopup {@@ -77,10 +78,7 @@ class InfoPopup {}renderKey(key: string, value: any) {- if (hidden_keys.includes(key) || key.startsWith('name_')) {- return null- }- if (!value) {+ if (hidden_keys.includes(key) || key.startsWith('name_') || key.startsWith('voltage') || !value) {return null}@@ -143,6 +141,27 @@ class InfoPopup {return container}+ voltageField(feature: MapGeoJSONFeature): RedomElement {+ const voltages = new Set(+ Object.keys(feature.properties)+ .filter((key) => key.startsWith('voltage'))+ .map((key) => parseFloat(feature.properties[key]))+ )++ let text = [...voltages]+ .sort()+ .reverse()+ .map((val) => val.toString())+ .join('/')+ text += ' kV'++ if (feature.properties['frequency']) {+ text += ` ${feature.properties['frequency'].replace(';', '/')} Hz`+ }++ return el('span.voltages', text)+ }+popupHtml(feature: MapGeoJSONFeature) {const attrs_table = el('table', { class: 'item_info' })const renderedProperties = Object.keys(feature.properties)@@ -151,19 +170,15 @@ class InfoPopup {.filter((x) => x !== null) as HTMLTableRowElement[]setChildren(attrs_table, renderedProperties)- const links_container = el('div')+ console.log(feature.properties)- if (feature.properties['osm_id']) {- mount(- links_container,- el('a', el('div.ext_link.osm_link'), {- href: this.osmLink(feature.properties['osm_id'], feature.properties['is_node']),- target: '_blank',- title: 'OpenStreetMap'- })- )+ const content = el('div', this.nameTags(feature))++ if (feature.properties['voltage']) {+ mount(content, this.voltageField(feature))}+ const links_container = el('div')const wikidata_div = el('div')if (feature.properties['wikidata']) {this.fetch_wikidata(feature.properties['wikidata'], wikidata_div, links_container)@@ -174,7 +189,20 @@ class InfoPopup {}}- const content = el('div', this.nameTags(feature), links_container, wikidata_div, attrs_table)+ mount(content, wikidata_div)+ mount(content, attrs_table)++ if (feature.properties['osm_id']) {+ mount(+ links_container,+ el('a', el('div.ext_link.osm_link'), {+ href: this.osmLink(feature.properties['osm_id'], feature.properties['is_node']),+ target: '_blank',+ title: 'OpenStreetMap'+ })+ )+ }+ mount(content, links_container)if (feature.layer.id.startsWith('power_plant')) {mount(@@ -200,7 +228,9 @@ class InfoPopup {this.popup_obj = new maplibregl.Popup().setLngLat(e.lngLat).setDOMContent(this.popupHtml(e.features[0]))+ .setMaxWidth('350px').addTo(this._map)+ this.popup_obj.addClassName('oim-info')}fetch_wikidata(id: string, container: RedomElement, links_container: RedomElement) {