Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Re-enable WebGL warning and refactor

Russ Garrett0a5b1563609f
diff --git a/web/src/index.css b/web/src/index.css
index 4f39108..ff6ada1 100644
--- a/web/src/index.css
+++ b/web/src/index.css
@@ -68,36 +68,6 @@ a:hover {
color: #000;
}
-.infobox {
- display: block;
- position: absolute;
- bottom: 40px;
- min-width: 60px;
- max-width: 300px;
- left: 5%;
- background-color: white;
- padding: 5px;
- border: 1px solid #999;
- border-radius: 4px;
-}
-
-.infobox-header {
- font-weight: bold;
- padding-bottom: 5px;
- border-bottom: 1px solid #bbb;
- margin-bottom: 4px;
-}
-
-.infobox-header a {
- cursor: pointer;
- float: right;
- margin-top: -3px;
-}
-
-.infobox-content {
- clear: both;
-}
-
.maplibregl-popup-content {
box-shadow: 3px 3px 4px rgba(0, 0, 0, 0.2);
}
diff --git a/web/src/index.ts b/web/src/index.ts
index 3aa43c7..cfd2dea 100644
--- a/web/src/index.ts
+++ b/web/src/index.ts
@@ -1,5 +1,6 @@
import './index.css'
import maplibregl from 'maplibre-gl'
+import { mount } from 'redom'
import LayerSwitcher from '@russss/maplibregl-layer-switcher'
import URLHash from '@russss/maplibregl-layer-switcher/urlhash'
@@ -7,6 +8,7 @@ import URLHash from '@russss/maplibregl-layer-switcher/urlhash'
import EditButton from './editbutton.js'
import InfoPopup from './infopopup.js'
import KeyControl from './key/key.js'
+import WarningBox from './warning-box/warning-box.js'
import map_style from './style/style.js'
import style_base from './style/style_base.js'
@@ -19,16 +21,36 @@ import style_oim_water from './style/style_oim_water.js'
import loadIcons from './loadIcons.js'
import { LayerSpecificationWithZIndex } from './style/types.js'
+function isWebglSupported() {
+ if (window.WebGLRenderingContext) {
+ const canvas = document.createElement('canvas')
+ try {
+ const context =
+ canvas.getContext('webgl2', { failIfMajorPerformanceCaveat: true }) ||
+ canvas.getContext('webgl', { failIfMajorPerformanceCaveat: true })
+ if (context && typeof context.getParameter == 'function') {
+ return true
+ }
+ } catch (e) {
+ // WebGL is supported, but disabled
+ }
+ return false
+ }
+ // WebGL not supported
+ return false
+}
+
function init() {
- // if (!maplibregl.supported({ failIfMajorPerformanceCaveat: true })) {
- // const infobox = new InfoBox("Warning");
- // infobox.update(
- // "Your browser may have performance or functionality issues with OpenInfraMap.<br/>" +
- // '<a href="http://webglreport.com">WebGL</a> with hardware acceleration is required for this site ' +
- // "to perform well."
- // );
- // mount(document.body, infobox);
- // }
+ if (!isWebglSupported()) {
+ const infobox = new WarningBox('Warning')
+ infobox.update(
+ '<p>Your browser may have performance or functionality issues with Open Infrastructure Map.</p>' +
+ '<p><a href="http://webglreport.com">WebGL</a> with hardware acceleration is required for this site ' +
+ 'to perform well.</p>' +
+ '<p>If your browser supports WebGL, you may need to disable browser fingerprinting protection for this site.</p>'
+ )
+ mount(document.body, infobox)
+ }
const oim_layers: LayerSpecificationWithZIndex[] = [
...style_oim_power,
diff --git a/web/src/infobox.ts b/web/src/infobox.ts
deleted file mode 100644
index 5edb3fd..0000000
--- a/web/src/infobox.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { el, unmount } from 'redom'
-
-class InfoBox {
- content: HTMLDivElement
- el: HTMLDivElement
- constructor(title: string) {
- this.content = el('div', { class: 'infobox-content' })
- const closeButton = el('a', '×')
- const header = el('div', title, closeButton, { class: 'infobox-header' })
-
- this.el = el('div', header, this.content, { class: 'infobox' })
-
- closeButton.onclick = (e: MouseEvent) => {
- unmount(document.body, this.el)
- e.preventDefault()
- }
- }
-
- update(data: string) {
- this.content.innerHTML = data
- }
-}
-
-export default InfoBox
diff --git a/web/src/warning-box/warning-box.css b/web/src/warning-box/warning-box.css
new file mode 100644
index 0000000..864ab92
--- /dev/null
+++ b/web/src/warning-box/warning-box.css
@@ -0,0 +1,40 @@
+.infobox-container {
+ position: fixed;
+ top: 0;
+ left: 0;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ width: 100vw;
+ z-index: 1000;
+ background-color: rgba(0, 0, 0, 0.3);
+}
+
+.infobox {
+ min-width: 60px;
+ max-width: 400px;
+ background-color: white;
+ padding: 5px;
+ border: 1px solid #999;
+ border-radius: 4px;
+ box-shadow: 10px 10px 15px rgba(0, 0, 0, 0.3);
+}
+
+.infobox-header {
+ font-weight: bold;
+ padding-bottom: 5px;
+ border-bottom: 1px solid #bbb;
+ margin-bottom: 4px;
+}
+
+.infobox-header a {
+ cursor: pointer;
+ float: right;
+ margin-top: -3px;
+}
+
+.infobox-content {
+ clear: both;
+ padding: 0px 5px;
+}
diff --git a/web/src/warning-box/warning-box.ts b/web/src/warning-box/warning-box.ts
new file mode 100644
index 0000000..95f94e7
--- /dev/null
+++ b/web/src/warning-box/warning-box.ts
@@ -0,0 +1,28 @@
+import './warning-box.css'
+import { el, unmount } from 'redom'
+
+class WarningBox {
+ content: HTMLDivElement
+ el: HTMLDivElement
+ constructor(title: string) {
+ this.content = el('div', { class: 'infobox-content' })
+ const closeButton = el('a', '×')
+ const header = el('div', title, closeButton, { class: 'infobox-header' })
+
+ this.el = el('div', el('div', header, this.content, { class: 'infobox' }), { class: 'infobox-container' })
+
+ closeButton.onclick = (e) => this.closeHandler(e)
+ this.el.onclick = (e) => this.closeHandler(e)
+ }
+
+ closeHandler(e: MouseEvent) {
+ unmount(document.body, this.el)
+ e.preventDefault()
+ }
+
+ update(data: string) {
+ this.content.innerHTML = data
+ }
+}
+
+export default WarningBox