]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/maplibre/map.js
Merge remote-tracking branch 'upstream/pull/6735'
[rails.git] / app / assets / javascripts / maplibre / map.js
1 //= require maplibre-gl/dist/maplibre-gl
2 //= require maplibre/controls
3 //= require maplibre/dom_util
4 //= require maplibre/styles
5
6 maplibregl.Map.prototype._getUIString = function (key) {
7   const snakeCaseKey = key.replaceAll(/(?<=\w)[A-Z]/g, "_$&").toLowerCase();
8   return OSM.i18n.t(`javascripts.map.${snakeCaseKey}`);
9 };
10
11 OSM.MapLibre.Map = class extends maplibregl.Map {
12   constructor({ allowRotation, ...options } = {}) {
13     const rotationOptions = {};
14     if (allowRotation === false) {
15       Object.assign(rotationOptions, {
16         rollEnabled: false,
17         dragRotate: false,
18         pitchWithRotate: false,
19         bearingSnap: 180
20       });
21     }
22     const map = super({
23       ...rotationOptions,
24       ...options
25     });
26     if (allowRotation === false) {
27       map.touchZoomRotate.disableRotation();
28       map.keyboard.disableRotation();
29     }
30     return map;
31   }
32 };
33
34 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
35   constructor(options = {}) {
36     const defaultHomeZoom = 11;
37     super({
38       container: "map",
39       style: OSM.MapLibre.Styles.Mapnik,
40       attributionControl: false,
41       allowRotation: false,
42       maxPitch: 0,
43       center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
44       zoom: OSM.home ? defaultHomeZoom : 0,
45       ...options
46     });
47   }
48 };