]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/maplibre/map.js
Use meta protocol for memcached connections
[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       ...rotationOptions,
23       ...options
24     });
25     if (allowRotation === false) {
26       map.touchZoomRotate.disableRotation();
27       map.keyboard.disableRotation();
28     }
29     return map;
30   }
31 };
32
33 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
34   constructor(options = {}) {
35     const defaultHomeZoom = 11;
36     super({
37       container: "map",
38       style: OSM.MapLibre.Styles.Mapnik(),
39       attributionControl: false,
40       allowRotation: false,
41       maxPitch: 0,
42       center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
43       zoom: OSM.home ? defaultHomeZoom : 0,
44       zoomSnap: 1.0,
45       ...options
46     });
47   }
48 };