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