-
Notifications
You must be signed in to change notification settings - Fork 2
WebGL: Warnung wenn deaktiviert #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "93-deaktivertes-webgl-sollte-zu-einer-klaren-und-verst\u00E4ndlichen-fehlermeldung-f\u00FChren"
Changes from 8 commits
e1dae97
746c8ff
af46d41
482000d
05c033a
eb1c2f1
bdc779c
4c1b9ab
8228b2f
7977bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,84 +8,96 @@ import { | |
| } from "./lib/internal/mapUtils.js"; | ||
| import { createSearchControl } from "./lib/internal/search.js"; | ||
|
|
||
| const basemapConfig = { | ||
| de: { | ||
| displayName: "deutscher Stil", | ||
| tiles: ["https://tile.openstreetmap.de/{z}/{x}/{y}.png"], | ||
| attribution: "Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "osmde.png", | ||
| }, | ||
| standard: { | ||
| displayName: "Standard", | ||
| tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"], | ||
| attribution: "Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "osmorg.png", | ||
| }, | ||
| oepnv: { | ||
| displayName: "ÖPNV", | ||
| tiles: [ | ||
| "https://tile.geofabrik.de/25ab8b065d8149bd90c1876384259ebf/{z}/{x}/{y}.png", | ||
| ], | ||
| attribution: | ||
| "ÖPNV Kartenstil von memomaps.de CC-BY-SA, Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "oepnv.png", | ||
| }, | ||
| }; | ||
| const setupMap = () => { | ||
| const basemapConfig = { | ||
| de: { | ||
| displayName: "deutscher Stil", | ||
| tiles: ["https://tile.openstreetmap.de/{z}/{x}/{y}.png"], | ||
| attribution: "Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "osmde.png", | ||
| }, | ||
| standard: { | ||
| displayName: "Standard", | ||
| tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"], | ||
| attribution: "Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "osmorg.png", | ||
| }, | ||
| oepnv: { | ||
| displayName: "ÖPNV", | ||
| tiles: [ | ||
| "https://tile.geofabrik.de/25ab8b065d8149bd90c1876384259ebf/{z}/{x}/{y}.png", | ||
| ], | ||
| attribution: | ||
| "ÖPNV Kartenstil von memomaps.de CC-BY-SA, Kartendaten © OpenStreetMap Mitwirkende", | ||
| thumbnail: "oepnv.png", | ||
| }, | ||
| }; | ||
|
|
||
| const map = new maplibregl.Map({ | ||
| container: "map", | ||
| hash: "map", | ||
| maplibreLogo: false, | ||
| dragRotate: false, | ||
| center: [11, 51.5], // center Germany | ||
| zoom: 5, | ||
| // prevent users changing pitch with keyboard shortcuts | ||
| maxPitch: 0, | ||
| attributionControl: true, | ||
| maxZoom: 19, | ||
| locale: { | ||
| "AttributionControl.ToggleAttribution": "Quellenangabe ein-/ausblenden", | ||
| "GeolocateControl.FindMyLocation": "Meinen Standort finden", | ||
| "GeolocateControl.LocationNotAvailable": "Standort nicht verfügbar", | ||
| "NavigationControl.ZoomIn": "Hineinzoomen", | ||
| "NavigationControl.ZoomOut": "Herauszoomen", | ||
| }, | ||
| }); | ||
|
|
||
| // on desktop: prevent keyboard rotating using "shift" + arrow keys | ||
| map.keyboard.disableRotation(); | ||
|
|
||
| // on mobile: prevent rotation and pitch, but leave zoom | ||
| map.touchZoomRotate.disableRotation(); | ||
| map.touchPitch.disable(); | ||
|
|
||
| // set basemaps | ||
| Object.entries(basemapConfig).forEach(([id, config]) => { | ||
| const { tiles, attribution } = config; | ||
| map.addSource(id, { | ||
| type: "raster", | ||
| tileSize: 256, | ||
| attribution, | ||
| tiles, | ||
| const map = new maplibregl.Map({ | ||
| container: "map", | ||
| hash: "map", | ||
| maplibreLogo: false, | ||
| dragRotate: false, | ||
| center: [11, 51.5], // center Germany | ||
| zoom: 5, | ||
| // prevent users changing pitch with keyboard shortcuts | ||
| maxPitch: 0, | ||
| attributionControl: true, | ||
| maxZoom: 19, | ||
| locale: { | ||
| "AttributionControl.ToggleAttribution": "Quellenangabe ein-/ausblenden", | ||
| "GeolocateControl.FindMyLocation": "Meinen Standort finden", | ||
| "GeolocateControl.LocationNotAvailable": "Standort nicht verfügbar", | ||
| "NavigationControl.ZoomIn": "Hineinzoomen", | ||
| "NavigationControl.ZoomOut": "Herauszoomen", | ||
| }, | ||
| }); | ||
|
|
||
| // on desktop: prevent keyboard rotating using "shift" + arrow keys | ||
| map.keyboard.disableRotation(); | ||
|
|
||
| // on mobile: prevent rotation and pitch, but leave zoom | ||
| map.touchZoomRotate.disableRotation(); | ||
| map.touchPitch.disable(); | ||
|
|
||
| // set basemaps | ||
| Object.entries(basemapConfig).forEach(([id, config]) => { | ||
| const { tiles, attribution } = config; | ||
| map.addSource(id, { | ||
| type: "raster", | ||
| tileSize: 256, | ||
| attribution, | ||
| tiles, | ||
| }); | ||
| map.addLayer({ id, source: id, type: "raster" }); | ||
| }); | ||
| map.addLayer({ id, source: id, type: "raster" }); | ||
| }); | ||
|
|
||
| map.addControl(createSearchControl(maplibregl)); | ||
| map.addControl(createSearchControl(maplibregl)); | ||
|
|
||
| map.addControl(new maplibregl.NavigationControl({ showCompass: false })); | ||
| map.addControl(new maplibregl.NavigationControl({ showCompass: false })); | ||
|
|
||
| map.addControl(new maplibregl.ScaleControl(), "bottom-right"); | ||
| map.addControl(new maplibregl.ScaleControl(), "bottom-right"); | ||
|
|
||
| map.addControl(new maplibregl.GeolocateControl()); | ||
| map.addControl(new maplibregl.GeolocateControl()); | ||
|
|
||
| map.addControl(new maplibregl.GlobeControl(), "top-right"); | ||
| map.addControl(new maplibregl.GlobeControl(), "top-right"); | ||
|
|
||
| setGlobePermalinkUpdate(map); | ||
| setGlobePermalinkUpdate(map); | ||
|
|
||
| setupLinkUpdate(map); | ||
| const basemapSwitcher = new BasemapSwitcher(basemapConfig); | ||
| map.addControl(basemapSwitcher); | ||
| setupLinkUpdate(map); | ||
| const basemapSwitcher = new BasemapSwitcher(basemapConfig); | ||
| map.addControl(basemapSwitcher); | ||
| }; | ||
|
|
||
| /** | ||
| * Checks if browser supports WebGL | ||
| * Inspired by: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example/Detect_WebGL | ||
| */ | ||
| function isWebGlActivated() { | ||
| const canvas = document.createElement("canvas"); | ||
| const gl = canvas.getContext("webgl"); | ||
| return gl instanceof WebGLRenderingContext; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Die Funktion ist schon ganz schön verbose für den kleinen Check, den sie macht. Wir liefern das JS ja nachher so aus, da lohnt es sich schon, darauf ein bischen zu achten. Und das Kommentar könte auch weg und stattdessen in die commit msg.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ich habe die Funktion jetzt möglichst klein gemacht. Wobei ich nicht weiß ob das wirklich ins Gewicht schlägt. Unsere beiden externen Libs haben zusammen schon 1MB Speicher. Ein paar Zeilen mehr Kommentar sind da glaub ich nicht so dramatisch |
||
|
|
||
| /** | ||
| * Make menu of website interactive | ||
|
|
@@ -151,3 +163,11 @@ const setupMenu = () => { | |
|
|
||
| // setup menu after page is loaded | ||
| document.addEventListener("DOMContentLoaded", setupMenu); | ||
|
|
||
| if (isWebGlActivated()) { | ||
| setupMap(); | ||
| } else { | ||
| // show warning that WebGL is not available | ||
| const warningNoWebGL = document.getElementById("warning-no-webgl"); | ||
| warningNoWebGL.style.display = "flex"; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kann das nicht eine normale Funktion sein?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
könnte schon, aber in dem Fall ist es egal.
const setupMenu = () => {}ist auch schon so definiert. Dann würde ich eher die Funktion die WebGL check auch als Arrow Funktoin machen damit es einheitlich ist