Open Infrastructure Map, a view of infrastructure data in OpenStreetMap
Circuit inspector
Russ Garrett0520f5cc13ff
diff --git a/web/locales/en/translation.json b/web/locales/en/translation.jsonindex 9036742..dd73308 100644--- a/web/locales/en/translation.json+++ b/web/locales/en/translation.json@@ -132,6 +132,7 @@"usage": "Usage","location": "Location","design": "Design",+ "voltage": "Voltage","material": "Material","line-attachment": "Line attachment","line-management": "Line management",diff --git a/web/public/openinframap.svg b/web/public/openinframap.svgnew file mode 100644index 0000000..324b4c2--- /dev/null+++ b/web/public/openinframap.svg@@ -0,0 +1,16 @@+<?xml version="1.0" encoding="UTF-8"?>+<svg id="a" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" width="40mm" height="40mm" viewBox="0 0 113.38583 113.38583">+ <defs>+ <style>+ .b {+ fill: #003232;+ }++ .c {+ fill: lime;+ }+ </style>+ </defs>+ <path class="c" d="M105.89172,7.24232c-.34717-.21973-.78223-.24805-1.15283-.07422l-23.71191,11.10059-23.71191-11.10059c-.32227-.15039-.69531-.15039-1.01758,0l-23.71191,11.10059L8.87366,7.1681c-.37207-.17432-.80566-.14551-1.15283.07422-.34619.22021-.55615.60254-.55615,1.0127v85.43066c0,.46582.26953.88916.69141,1.08691l24.2207,11.33887c.32227.15039.69531.15039,1.01758,0l23.71191-11.10059,23.71191,11.10059c.16113.0752.33496.11328.50879.11328s.34766-.03809.50879-.11328l24.2207-11.33887c.42188-.19775.69141-.62109.69141-1.08691V8.25501c0-.41016-.20996-.79248-.55615-1.0127Z"/>+ <path class="b" d="M105.8916,7.29541c-.34717-.21973-.78223-.24805-1.15283-.07422l-23.71191,11.10059-23.71191-11.10059c-.32227-.15039-.69531-.15039-1.01758,0l-23.71191,11.10059L8.87354,7.22119c-.37207-.17432-.80566-.14551-1.15283.07422-.34619.22021-.55615.60254-.55615,1.0127v85.43066c0,.46582.26953.88916.69141,1.08691l24.2207,11.33887c.32227.15039.69531.15039,1.01758,0l23.71191-11.10059,23.71191,11.10059c.16113.0752.33496.11328.50879.11328s.34766-.03809.50879-.11328l24.2207-11.33887c.42188-.19775.69141-.62109.69141-1.08691V8.30811c0-.41016-.20996-.79248-.55615-1.0127ZM9.56494,92.97559V10.19482l22.51172,10.53906c.16119.0752.33508.11273.50897.11273v82.90576l-.00018.00006-23.02051-10.77686ZM57.31494,92.65186c-.16107-.0752-.3349-.11328-.50867-.11328V9.63336l23.71179,11.10052c.08936.04169.18713.04401.2821.06256v82.84985l-23.48523-10.99445Z"/>+</svg>\ No newline at end of filediff --git a/web/src/api.ts b/web/src/api.tsnew file mode 100644index 0000000..afbeb24--- /dev/null+++ b/web/src/api.ts@@ -0,0 +1,23 @@+export class OpenInfraMapAPI {+ url: string++ constructor(url: string) {+ this.url = url+ }++ async fetch(path: string) {+ return fetch(this.url + path).then((response) => {+ if (response.status == 200) {+ return response.json()+ }+ })+ }++ async fetchWikidata(qid: string) {+ return this.fetch(`/wikidata/${qid}`)+ }++ async circuitDetail(circuitId: number) {+ return this.fetch(`/api/circuit/${circuitId}`)+ }+}diff --git a/web/src/circuit/circuitinspector.css b/web/src/circuit/circuitinspector.cssnew file mode 100644index 0000000..bb1a5b6--- /dev/null+++ b/web/src/circuit/circuitinspector.css@@ -0,0 +1,70 @@+div.circuit-inspector {+ overflow: hidden;+ position: absolute;+ bottom: 7em;+ right: 1em;+ background-color: var(--oim-content-background);+ min-width: 15em;+ min-height: 5em;+ border: 1px solid #eee;+ max-width: 25em;+ border-radius: 3px;+ box-shadow: 3px 3px 4px rgba(0, 0, 0, 0.2);+}++@media (max-width: 800px) {+ div.circuit-inspector {+ width: 100vw;+ max-width: 100vw;+ bottom: 0;+ right: 0;+ z-index: 1000;+ }+}++div.circuit-inspector-header {+ display: flex;+ gap: 1em;+ padding-left: 1em;+ padding-bottom: 0.5em;+ background: var(--oim-popup-header-info-background);++ h3 {+ flex: 1;+ margin: 0;+ margin-top: 0.2em;+ }+}++div.circuit-inspector-body {+ margin: 0.1em 0.5em 0.5em 0.5em;++ h4 {+ font-size: 1.1em;+ font-weight: bold;+ color: var(--oim-text-color);+ margin-top: 0.2em;+ margin-left: 0;+ margin-bottom: 0;+ }+}++div.circuit-legacy {+ font-size: 0.9em;+ background-color: var(--warning);+ border: 1px solid var(--Grey200);+ border-radius: 5px;+ padding: 0.5em;+ text-align: center;+}++div.circuit-info {+ display: flex;+ flex-direction: row;+ font-size: 0.9em;++ * {+ flex: 1;+ text-align: center;+ }+}diff --git a/web/src/circuit/circuitinspector.ts b/web/src/circuit/circuitinspector.tsnew file mode 100644index 0000000..ad87a6e--- /dev/null+++ b/web/src/circuit/circuitinspector.ts@@ -0,0 +1,183 @@+import './circuitinspector.css'+import i18next, { t } from 'i18next'+import { URLHash } from '@russss/maplibregl-layer-switcher'+import { el, mount, unmount } from 'redom'+import { OpenInfraMapAPI } from '../api'+import { GeoJSONSource } from 'maplibre-gl'+import { circuitName } from '../popup/infopopup'+import { formatFrequency, formatVoltage } from '../l10n'+import ExternalLinks from '../elements/external-links'++class InspectorComponent {+ el: HTMLElement+ inspector: CircuitInspector+ constructor(data: any, inspector: CircuitInspector) {+ this.inspector = inspector++ const external_links = new ExternalLinks(data['id'], false)++ if (data.wikidata) {+ inspector._api.fetchWikidata(data['wikidata']).then((response) => {+ external_links.updateWikidata(data['wikidata'], response)+ })+ }++ this.el = el(+ 'div.oim-popup.circuit-inspector',+ el(+ 'div.circuit-inspector-header',+ el('h3', 'Selected circuit'),+ el('button', '×', { onclick: () => inspector.hide() })+ ),+ el(+ 'div.oim-popup-content.circuit-inspector-body',+ el('div.circuit-subhead', this.name(data), this.info(data)),+ this.substations(data['substations']),+ el(+ 'div.oim-info-footer',+ external_links,+ el('button.oim-button', 'Zoom', { onclick: () => inspector.zoom() })+ )+ )+ )+ }++ name(data: any) {+ const lang = i18next.language.split('-')[0]+ if (data['local_names'][lang]) {+ return [el('h4', data['local_names'][lang]), el('div.main_name', data['name'])]+ }+ if (data['name']) {+ return [el('h4', data['name'])]+ }+ return []+ }++ info(data: any) {+ if (data['type'] == 'power') {+ return el(+ 'div.circuit-info',+ el('span', `${data['length']} km`),+ el('span', formatVoltage(data['voltage'])),+ el('span', formatFrequency(data['frequency']))+ )+ }+ return el(+ 'div.circuit-legacy',+ el(+ 'p',+ el('strong', `Legacy ${data['type']} relation`),+ ': Consider upgrading to a power=circuit relation.'+ )+ )+ }++ substations(data: Array<any>) {+ if (data.length > 0) {+ return [+ el('h4', 'Substations'),+ el(+ 'ul',+ data.map((sub) =>+ el(+ 'li',+ el('a', circuitName(sub), {+ href: 'javascript:void(0)',+ onclick: () => {+ this.inspector._map.flyTo({+ center: sub['location'],+ zoom: 15+ })+ }+ })+ )+ )+ )+ ]+ }+ return []+ }+}++export class CircuitInspector {+ _map: maplibregl.Map+ _url_hash: URLHash+ _container?: InspectorComponent+ _api: OpenInfraMapAPI+ _bbox?: number[]++ constructor(map: maplibregl.Map, url_hash: URLHash, api: OpenInfraMapAPI) {+ this._map = map+ this._url_hash = url_hash+ this._api = api+ url_hash.registerHandler('circuit', (value) => {+ this.hashChange(value)+ })+ }++ updateData(data: GeoJSON.GeoJSON) {+ if (!this._map.loaded()) {+ this._map.on('load', () => {+ this.updateData(data)+ })+ }+ this._bbox = data['bbox']+ const source: GeoJSONSource = this._map.getSource('circuit_highlight')!+ source.setData(data)+ }++ zoom() {+ if (!this._bbox) return++ const x_padding = (this._bbox[2] - this._bbox[0]) * 0.05+ const y_padding = (this._bbox[3] - this._bbox[1]) * 0.05++ this._map.fitBounds([+ [this._bbox[0] - x_padding, this._bbox[1] - y_padding],+ [this._bbox[2] + x_padding, this._bbox[3] + y_padding]+ ])+ }++ async show(circuitId: number) {+ if (this._container) {+ unmount(this._map.getContainer(), this._container)+ this._container = undefined+ }+ const data = await this._api.circuitDetail(circuitId)+ if (!data) {+ return+ }++ this.updateData(data.geometry)++ this._container = new InspectorComponent(data, this)+ mount(this._map.getContainer(), this._container)+ this._url_hash.setParameter('circuit', circuitId.toString())+ }++ hide() {+ if (this._container) {+ unmount(this._map.getContainer(), this._container)+ this._container = undefined+ }+ this._url_hash.setParameter('circuit', null)+ this.updateData({+ type: 'FeatureCollection',+ features: []+ })+ }++ hashChange(param: string | null) {+ if (!param) {+ this.hide()+ }++ const id = parseInt(param!)++ if (id) {+ this.show(id)+ } else {+ this.hide()+ }+ }+}diff --git a/web/src/elements/external-links.ts b/web/src/elements/external-links.tsnew file mode 100644index 0000000..ec618b0--- /dev/null+++ b/web/src/elements/external-links.ts@@ -0,0 +1,106 @@+import i18next, { t } from 'i18next'+import { el, mount } from 'redom'++function osmLink(id: number, is_node: boolean) {+ let url+ let value+ if (id > 0) {+ if (is_node) {+ url = `https://openstreetmap.org/node/${id}`+ value = `Node ${id}`+ } else {+ url = `https://openstreetmap.org/way/${id}`+ value = `Way ${id}`+ }+ } else {+ url = `https://openstreetmap.org/relation/${-id}`+ value = `Relation ${-id}`+ }+ return el('a', value, {+ href: url,+ target: '_blank'+ })+}++export default class ExternalLinks {+ el: HTMLElement++ constructor(osm_id: number | undefined, is_node: boolean) {+ this.el = el('div.infobox-external-links')++ if (osm_id) {+ mount(+ this.el,+ el('a', el('div.ext_link.osm_link'), {+ href: osmLink(osm_id, is_node),+ target: '_blank',+ title: t('info.view-openstreetmap', 'View on OpenStreetMap')+ })+ )+ }+ }++ updateWikidata(id: string, data: any) {+ if (!data) {+ return+ }+ for (const lang of [i18next.language.split('-')[0], 'en']) {+ if (data['sitelinks'][`${lang}wiki`]) {+ const url =+ `https://${lang}.wikipedia.org/wiki/` + encodeURI(data['sitelinks'][`${lang}wiki`]['title'])+ mount(+ this.el,+ el('a', el('div.ext_link.wikipedia_link'), {+ href: url,+ target: '_blank',+ title: t('wikipedia', 'Wikipedia')+ })+ )+ break+ }+ }++ if (data['sitelinks']['commonswiki']) {+ const url = `https://commons.wikimedia.org/wiki/` + encodeURI(data['sitelinks']['commonswiki']['title'])+ mount(+ this.el,+ el('a', el('div.ext_link.commons_link'), {+ href: url,+ target: '_blank',+ title: t('wikimedia-commons', 'Wikimedia Commons')+ })+ )+ }++ if (data['gem_id']) {+ mount(+ this.el,+ el('a', el('div.ext_link.gem_link'), {+ href: `https://www.gem.wiki/${data['gem_id']}`,+ target: '_blank',+ title: 'Global Energy Monitor'+ })+ )+ }++ if (data['peeringdb_facility_id']) {+ mount(+ this.el,+ el('a', el('div.ext_link.peeringdb_link'), {+ href: `https://www.peeringdb.com/fac/${data['peeringdb_facility_id']}`,+ target: '_blank',+ title: 'PeeringDB'+ })+ )+ }++ mount(+ this.el,+ el('a', el('div.ext_link.wikidata_link'), {+ href: `https://wikidata.org/wiki/${id}`,+ target: '_blank',+ title: t('wikidata', 'Wikidata')+ })+ )+ }+}diff --git a/web/src/icons/power_substation_traction.svg b/web/src/icons/power_substation_traction.svgnew file mode 100644index 0000000..90405ea--- /dev/null+++ b/web/src/icons/power_substation_traction.svg@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<svg width="100%" height="100%" viewBox="0 0 35 35" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">+ <g transform="matrix(0.81851,-0.00579528,0.00579528,0.81851,-10.3932,-8.12126)">+ <path d="M33.855,14.049L49.004,22.795L49.004,40.289L33.855,49.035L18.705,40.289L18.705,22.795L33.855,14.049Z" style="fill:white;stroke:black;stroke-width:3.05px;"/>+ </g>+</svg>diff --git a/web/src/index.css b/web/src/index.cssindex 1db32cc..ac67006 100644--- a/web/src/index.css+++ b/web/src/index.css@@ -6,20 +6,35 @@ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono','Ubuntu Mono', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Consolas', 'Courier New', monospace;+ --Grey100: rgb(247, 242, 239);+ --Grey200: rgb(226, 209, 199);+ --Grey300: rgb(197, 164, 144);+ --Grey400: rgb(148, 119, 102);+ --Grey500: rgb(109, 87, 75);+ --Grey600: rgb(73, 58, 50);+ --Green100: rgb(237, 244, 232);+ --Green200: rgb(192, 219, 185);+ --Green300: rgb(133, 184, 125);+ --Green400: rgb(67, 140, 65);+ --Green500: rgb(16, 107, 27);+ --Green600: rgb(0, 72, 2);++ --warning: rgb(255, 240, 240);+--oim-content-background: rgb(252, 252, 252);--oim-text-color: #333;--oim-text-color-light: #666;--oim-text-color-dark: #000;- --oim-light-grey: #f3f3f3;- --oim-grey: #ddd;- --oim-dark-grey: #888;+ --oim-light-grey: var(--Grey100);+ --oim-grey: var(--Grey200);+ --oim-dark-grey: var(--Grey400);--oim-radius-large: 6px;--oim-radius-small: 3px;- --oim-popup-header-info-background: #e0f6f6;- --oim-popup-header-validation-background: #f9e2e4;+ --oim-popup-header-info-background: var(--Green100);+ --oim-popup-header-validation-background: var(--Grey100);--oim-drop-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);--oim-blur: blur(3px) saturate(80%);diff --git a/web/src/l10n.ts b/web/src/l10n.tsindex 20ad8f7..0cae64b 100644--- a/web/src/l10n.ts+++ b/web/src/l10n.ts@@ -35,6 +35,10 @@ export function local_name_tags(): string[] {}export function formatVoltage(value: number | number[]): string {+ if (!value) {+ return ''+ }+if (!Array.isArray(value)) {value = [value]}diff --git a/web/src/openinframap.ts b/web/src/openinframap.tsindex 6f557fe..f466e8f 100644--- a/web/src/openinframap.ts+++ b/web/src/openinframap.ts@@ -10,11 +10,13 @@ import KeyControl from './key/key.js'import WarningBox from './warning-box/warning-box.js'import OIMSearch from './search/search.ts'-import { getStyle, getLayers } from './style/style.js'+import { getStyle, getPrimaryLayers } from './style/style.js'import { ValidationErrorPopup } from './popup/validation-error-popup.js'import { SymbolLoader } from './symbol-loader.ts'import { ClickRouter } from './click-router.js'+import { CircuitInspector } from './circuit/circuitinspector.ts'+import { OpenInfraMapAPI } from './api.ts'export default class OpenInfraMap {map?: maplibregl.Map@@ -79,11 +81,12 @@ export default class OpenInfraMap {t('layers.title', 'Layers'))const url_hash = new URLHash(layer_switcher)-const map_style = getStyle()layer_switcher.setInitialVisibility(map_style)+ const api = new OpenInfraMapAPI('https://openinframap.org')+const map = new maplibregl.Map(url_hash.init({container: 'map',@@ -97,6 +100,7 @@ export default class OpenInfraMap {const clickRouter = new ClickRouter(map, map_style.layers)new SymbolLoader(map)+ const circuit_inspector = new CircuitInspector(map, url_hash, api)map.dragRotate.disable()map.touchZoomRotate.disableRotation()@@ -118,10 +122,12 @@ export default class OpenInfraMap {map.addControl(layer_switcher, 'top-right')map.addControl(new EditButton(), 'bottom-right')map.addControl(new OIMSearch(), 'top-left')- new InfoPopup(- getLayers().map((layer: { [x: string]: any }) => layer['id']),- 6- ).add(map, clickRouter)+ new InfoPopup({+ layers: getPrimaryLayers().map((layer: { [x: string]: any }) => layer['id']),+ min_zoom: 6,+ api,+ circuit_inspector+ }).add(map, clickRouter)new ValidationErrorPopup(map, clickRouter)clickRouter.register()diff --git a/web/src/popup/infopopup.css b/web/src/popup/infopopup.cssindex aad84fb..c4909c6 100644--- a/web/src/popup/infopopup.css+++ b/web/src/popup/infopopup.css@@ -9,30 +9,11 @@margin-right: 0.3em;}-table.item_info {- width: 100%;- border-collapse: collapse;- border: 1px solid var(--oim-light-grey);- border-radius: 4px;-}--table.item_info td,-table.item_info th {- padding: 0.1em 0.5em;-}--table.item_info th {- text-align: left;- text-wrap: nowrap;-}--table.item_info td {- width: 100%;- overflow: hidden;-}--table.item_info tr:nth-child(odd) {- background-color: #f9f9f9;+.oim-popup-info h4 {+ font-weight: bold;+ color: inherit;+ margin-block-end: 0.2em;+ margin-left: 0.2em;}.wikidata_image {@@ -61,6 +42,23 @@ table.item_info tr:nth-child(odd) {display: block;}+#circuits {+ max-height: 40vh;+ overflow-y: auto;+}++.circuits-table {+ font-size: 0.9em;++ td {+ vertical-align: middle;+ }++ button {+ margin-top: auto;+ }+}+div.ext_link {display: block;height: 30px;diff --git a/web/src/popup/infopopup.ts b/web/src/popup/infopopup.tsindex 6324d34..ab2770b 100644--- a/web/src/popup/infopopup.ts+++ b/web/src/popup/infopopup.ts@@ -8,6 +8,9 @@ import friendlyNames from '../friendlynames.ts'import friendlyIcons from '../friendlyicons.ts'import { el, mount, setChildren, RedomElement } from 'redom'import { ClickRouter } from '../click-router.ts'+import { OpenInfraMapAPI } from '../api.ts'+import { CircuitInspector } from '../circuit/circuitinspector.ts'+import ExternalLinks from '../elements/external-links.ts'const hidden_keys = ['osm_id',@@ -111,6 +114,18 @@ function fieldValue(key: string, value: any): any {return titleCase(value)}+export function circuitName(data) {+ const lang = i18next.language.split('-')[0]++ if (lang in data['local_names']) {+ return data['local_names'][lang]+ }+ if (data['name']) {+ return data['name']+ }+ return `-`+}+function truncateUrl(urlString: string, length: number): string {// Trim trailing slashurlString = urlString.replace(/\/$/, '')@@ -152,18 +167,29 @@ function truncateUrl(urlString: string, length: number): string {return [parsed.host, ...pathPartsReturnValue.reverse()].join('/')}+interface InfoPopupOptions {+ layers: string[]+ min_zoom: number+ api: OpenInfraMapAPI+ circuit_inspector: CircuitInspector+}+class InfoPopup {layers: string[]min_zoom: anypopup_obj: Popup | null_map!: maplibregl.MapfriendlyNames: { [key: string]: string }+ api: OpenInfraMapAPI+ circuit_inspector: CircuitInspector- constructor(layers: string[], min_zoom: number) {- this.layers = layers- this.min_zoom = min_zoom+ constructor(options: InfoPopupOptions) {+ this.api = options.api+ this.layers = options.layers+ this.min_zoom = options.min_zoomthis.popup_obj = nullthis.friendlyNames = friendlyNames()+ this.circuit_inspector = options.circuit_inspector}add(map: maplibregl.Map, clickRouter: ClickRouter) {@@ -300,6 +326,8 @@ class InfoPopup {}async popupHtml(feature: MapGeoJSONFeature) {+ const layer_id = feature.layer.id+const attrs_table = el('table', { class: 'item_info' })const renderedProperties = Object.keys(feature.properties).sort()@@ -312,38 +340,49 @@ class InfoPopup {if (feature.properties['voltage'] || feature.properties['voltage_primary']) {mount(content, this.voltageField(feature))}-- const links_container = el('div.infobox-external-links')const image_container = el('div.infobox-image')++ const external_links = new ExternalLinks(feature.properties['osm_id'], feature.properties['is_node'])+if (feature.properties['wikidata']) {- // Start wikidata fetching asynchronously- this.fetch_wikidata(feature.properties['wikidata'], image_container, links_container)- } else {- const wp_link = this.wp_link(feature.properties['wikipedia'])- if (wp_link) {- mount(links_container, wp_link)- }+ this.api.fetchWikidata(feature.properties['wikidata']).then((data) => {+ external_links.updateWikidata(feature.properties['wikidata'], data)+ if (data && data['thumbnail']) {+ mount(+ image_container,+ el(+ 'a',+ el('img.wikidata_image', {+ src: data['thumbnail']+ }),+ {+ href: `https://commons.wikimedia.org/wiki/File:${data['image']}`,+ target: '_blank'+ }+ )+ )+ }+ })}mount(content, image_container)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: t('info.view-openstreetmap', 'View on OpenStreetMap')- })- )+ if (layer_id.startsWith('power_substation') || layer_id.startsWith('power_converter')) {+ const circuits_container = await this.fetch_substation_circuits(feature.properties['osm_id'])+ circuits_container.forEach((e) => mount(content, e))+ }++ if (layer_id.startsWith('power_line')) {+ const circuits_container = await this.fetch_line_circuits(feature.properties['osm_id'])+ circuits_container.forEach((e) => mount(content, e))}const footer = el('div.oim-info-footer')mount(content, footer)- mount(footer, links_container)+ mount(footer, external_links)- if (feature.layer.id.startsWith('power_plant')) {+ if (layer_id.startsWith('power_plant')) {mount(footer,el('a.oim-button', t('more_info', 'More info'), {@@ -372,97 +411,44 @@ class InfoPopup {.addClassName('oim-popup-info')}- async fetch_wikidata(id: string, imageContainer: RedomElement, linksContainer: RedomElement) {- const data = await fetch(`https://openinframap.org/wikidata/${id}`).then((response) => {- return response.json()- })-- if (data['thumbnail']) {- mount(- imageContainer,- el(- 'a',- el('img.wikidata_image', {- src: data['thumbnail']- }),- {- href: `https://commons.wikimedia.org/wiki/File:${data['image']}`,- target: '_blank'- }+ circuits_table(circuits: Array<object>) {+ return el(+ 'table.circuits-table',+ el('tr', el('th', t('info.name')), el('th', t('info.voltage')), el('th', '')),+ circuits+ .sort((a, b) => b['circuit']['voltage'] - a['circuit']['voltage'])+ .map((c) =>+ el(+ 'tr',+ el('td', circuitName(c['circuit'])),+ el('td', formatVoltage(c['circuit']['voltage'])),+ el('button', 'view', {+ onclick: () => {+ this.circuit_inspector.show(c['circuit']['id'])+ this.popup_obj?.remove()+ }+ })+ ))- )- }-- for (const lang of [i18next.language.split('-')[0], 'en']) {- if (data['sitelinks'][`${lang}wiki`]) {- mount(- linksContainer,- el('a', el('div.ext_link.wikipedia_link'), {- href: data['sitelinks'][`${lang}wiki`]['url'],- target: '_blank',- title: t('wikipedia', 'Wikipedia')- })- )- break- }- }+ )+ }- if (data['sitelinks']['commonswiki']) {- mount(- linksContainer,- el('a', el('div.ext_link.commons_link'), {- href: data['sitelinks']['commonswiki']['url'],- target: '_blank',- title: t('wikimedia-commons', 'Wikimedia Commons')- })- )+ async circuits_section(response) {+ if (response.circuits.length == 0) {+ return []}- if (data['gem_id']) {- mount(- linksContainer,- el('a', el('div.ext_link.gem_link'), {- href: `https://www.gem.wiki/${data['gem_id']}`,- target: '_blank',- title: 'Global Energy Monitor'- })- )- }-- if (data['peeringdb_facility_id']) {- mount(- linksContainer,- el('a', el('div.ext_link.peeringdb_link'), {- href: `https://www.peeringdb.com/fac/${data['peeringdb_facility_id']}`,- target: '_blank',- title: 'PeeringDB'- })- )- }+ return [el('h4', t('info.circuits')), el('div#circuits', this.circuits_table(response.circuits))]+ }- mount(- linksContainer,- el('a', el('div.ext_link.wikidata_link'), {- href: `https://wikidata.org/wiki/${id}`,- target: '_blank',- title: t('wikidata', 'Wikidata')- })- )+ async fetch_substation_circuits(id: string) {+ const response = await this.api.fetch(`/api/substation/${id}`)+ return this.circuits_section(response)}- wp_link(value: string) {- if (!value) {- return null- }- const parts = value.split(':', 2)- if (parts.length > 1) {- const url = `https://${parts[0]}.wikipedia.org/wiki/${parts[1]}`- return el('a', el('div.ext_link.wikipedia_link'), {- href: url,- target: '_blank',- title: t('wikipedia', 'Wikipedia')- })- }+ async fetch_line_circuits(id: string) {+ const response = await this.api.fetch(`/api/line/${id}`)+ return this.circuits_section(response)}}diff --git a/web/src/popup/popup.css b/web/src/popup/popup.cssindex 67ed75c..b3ae6e1 100644--- a/web/src/popup/popup.css+++ b/web/src/popup/popup.css@@ -12,7 +12,7 @@}.oim-popup-content > * + * {- margin-block-start: 0.5em;+ margin-block-start: 0.6em;}.oim-popup .oim-popup-header {@@ -29,7 +29,6 @@.oim-popup h4 {font-weight: normal;color: var(--oim-text-color-light);- margin: 0.1em 0 0 0;}.oim-popup .maplibregl-popup-close-button {@@ -45,3 +44,34 @@color: var(--oim-text-color-light);background-color: var(--oim-grey);}++.oim-popup table {+ width: 100%;+ border-collapse: collapse;+ border: 1px solid var(--oim-light-grey);+ border-radius: 4px;+}++.oim-popup table td,+.oim-popup table th {+ padding: 0.1em 0.5em;+}++.oim-popup table th {+ text-align: left;+ text-wrap: nowrap;+}++.oim-popup table td {+ width: 100%;+ overflow: hidden;+}++.oim-popup table tr:nth-child(odd) {+ background-color: #f9f9f9;+}++.oim-popup ul {+ margin: 0;+ padding-left: 1.5em;+}diff --git a/web/src/style/style.ts b/web/src/style/style.tsindex bd5c180..f8e5521 100644--- a/web/src/style/style.ts+++ b/web/src/style/style.ts@@ -9,6 +9,8 @@ import style_oim_water from './style_oim_water.js'import style_oim_other_pipelines from './style_oim_other_pipelines.js'import style_osmose from './style_osmose.js'import { StyleSpecification } from 'maplibre-gl'+import { interpolate, zoom } from './stylehelpers.js'+import { LayerSpecificationWithZIndex } from './types.js'const oim_attribution ='<a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="https://openinframap.org/copyright">Open Infrastructure Map</a>'@@ -110,13 +112,20 @@ const style: StyleSpecification = {tiles: ['https://osmose.openstreetmap.fr/api/0.3/issues/{z}/{x}/{y}.mvt?tags=power'],maxzoom: 17,minzoom: 11+ },+ circuit_highlight: {+ type: 'geojson',+ data: {+ type: 'FeatureCollection',+ features: []+ }}},glyphs: '/fonts/{fontstack}/{range}.pbf',layers: []}-export function getLayers() {+export function getPrimaryLayers() {return [...style_oim_power(),...style_oim_power_heatmap,@@ -128,8 +137,31 @@ export function getLayers() {]}+const circuit_highlight_layer: LayerSpecificationWithZIndex = {+ zorder: 59,+ id: 'circuit_highlight',+ type: 'line',+ source: 'circuit_highlight',+ paint: {+ 'line-opacity': interpolate(zoom, [+ [5, 1],+ [20, 0.8]+ ]),+ 'line-blur': 3,+ 'line-color': '#fdef32',+ 'line-width': interpolate(zoom, [+ [5, 10],+ [20, 30]+ ])+ },+ layout: {+ 'line-join': 'round',+ 'line-cap': 'round'+ }+}+export function getStyle() {- const oim_layers = [...getLayers(), ...style_labels(i18next.language)]+ const oim_layers = [circuit_highlight_layer, ...getPrimaryLayers(), ...style_labels(i18next.language)]oim_layers.sort((a, b) => {if (!a.zorder || !b.zorder) {