]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/maplibre/map.js
Merge remote-tracking branch 'upstream/pull/6798'
[rails.git] / app / assets / javascripts / maplibre / map.js
1 //= require maplibre/controls
2 //= require maplibre/dom_util
3
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}`);
7 };
8
9 OSM.MapLibre.Map = class extends maplibregl.Map {
10   constructor({ allowRotation, ...options } = {}) {
11     const rotationOptions = {};
12     if (allowRotation === false) {
13       Object.assign(rotationOptions, {
14         rollEnabled: false,
15         dragRotate: false,
16         pitchWithRotate: false,
17         bearingSnap: 180
18       });
19     }
20     const map = super({
21       // Style validation only affects debug output.
22       // Style errors are usually reported to authors, who should validate the style in CI for better error messages.
23       validateStyle: false,
24       ...rotationOptions,
25       ...options
26     });
27     if (allowRotation === false) {
28       map.touchZoomRotate.disableRotation();
29       map.keyboard.disableRotation();
30     }
31     return map;
32   }
33 };
34
35 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
36   constructor(options = {}) {
37     const defaultHomeZoom = 11;
38     super({
39       container: "map",
40       style: OSM.LAYER_DEFINITIONS[0].style,
41       attributionControl: false,
42       allowRotation: false,
43       maxPitch: 0,
44       center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
45       zoom: OSM.home ? defaultHomeZoom : 0,
46       zoomSnap: 1.0,
47       ...options
48     });
49   }
50 };