1 //= require maplibre/controls
2 //= require maplibre/marker
3 //= require maplibre/popup
5 maplibregl.Map.prototype._getUIString = function (key) {
6 const snakeCaseKey = key.replaceAll(/(?<=\w)[A-Z]/g, "_$&").toLowerCase();
7 return OSM.i18n.t(`javascripts.map.${snakeCaseKey}`);
10 OSM.MapLibre.showWebGLError = function (container) {
11 const containerElement =
12 typeof container === "string" ? document.getElementById(container) : container;
14 if (containerElement) {
15 fetch("/panes/webgl_error")
16 .then(response => response.text())
17 .then(html => containerElement.innerHTML = html);
21 OSM.MapLibre.Map = class extends maplibregl.Map {
22 constructor({ allowRotation, ...options } = {}) {
23 const rotationOptions = {};
24 if (allowRotation === false) {
25 Object.assign(rotationOptions, {
28 pitchWithRotate: false,
36 // Style validation only affects debug output.
37 // Style errors are usually reported to authors, who should validate the style in CI for better error messages.
43 const structuredError = JSON.parse(error.message);
44 if (structuredError.type === "webglcontextcreationerror") {
45 OSM.MapLibre.showWebGLError(options.container);
47 // the constructor panicked => we need to re-throw
50 if (allowRotation === false) {
51 map.touchZoomRotate.disableRotation();
52 map.keyboard.disableRotation();
58 // Convert MapLibre's 512px based zoom to OSM's 256px based zoom.
59 return super.getZoom() + 1;
62 setZoom(zoom, ...args) {
63 return super.setZoom(zoom - 1, ...args);
66 zoomTo(zoom, ...args) {
67 return super.zoomTo(zoom - 1, ...args);
71 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
72 constructor(options = {}) {
73 const defaultHomeZoom = 11;
76 style: OSM.LAYER_DEFINITIONS[0].style,
77 attributionControl: false,
80 center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
81 zoom: OSM.home ? defaultHomeZoom : 0,