1 //= require maplibre/controls
2 //= require maplibre/dom_util
4 maplibregl.Map.prototype._getUIString = function (key) {
5 const snakeCaseKey = key.replaceAll(/(?<=\w)[A-Z]/g, "_$&").toLowerCase();
6 return OSM.i18n.t(`javascripts.map.${snakeCaseKey}`);
9 OSM.MapLibre.showWebGLError = function (container) {
10 const containerElement =
11 typeof container === "string" ? document.getElementById(container) : container;
13 if (containerElement) {
14 fetch("/panes/webgl_error")
15 .then(response => response.text())
16 .then(html => containerElement.innerHTML = html);
20 OSM.MapLibre.Map = class extends maplibregl.Map {
21 constructor({ allowRotation, ...options } = {}) {
22 const rotationOptions = {};
23 if (allowRotation === false) {
24 Object.assign(rotationOptions, {
27 pitchWithRotate: false,
35 // Style validation only affects debug output.
36 // Style errors are usually reported to authors, who should validate the style in CI for better error messages.
42 const structuredError = JSON.parse(error.message);
43 if (structuredError.type === "webglcontextcreationerror") {
44 OSM.MapLibre.showWebGLError(options.container);
46 // the constructor panicked => we need to re-throw
49 if (allowRotation === false) {
50 map.touchZoomRotate.disableRotation();
51 map.keyboard.disableRotation();
57 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
58 constructor(options = {}) {
59 const defaultHomeZoom = 11;
62 style: OSM.LAYER_DEFINITIONS[0].style,
63 attributionControl: false,
66 center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
67 zoom: OSM.home ? defaultHomeZoom : 0,