]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/maplibre/map.js
Extend MapLibre Map class
[rails.git] / app / assets / javascripts / maplibre / map.js
1 OSM.MapLibre.Map = class extends maplibregl.Map {
2   constructor({ allowRotation, ...options } = {}) {
3     const rotationOptions = {};
4     if (allowRotation === false) {
5       Object.assign(rotationOptions, {
6         rollEnabled: false,
7         dragRotate: false,
8         pitchWithRotate: false,
9         bearingSnap: 180
10       });
11     }
12     const map = super({
13       ...rotationOptions,
14       ...options
15     });
16     if (allowRotation === false) {
17       map.touchZoomRotate.disableRotation();
18       map.keyboard.disableRotation();
19     }
20     return map;
21   }
22 };
23
24 OSM.MapLibre.SecondaryMap = class extends OSM.MapLibre.Map {
25   constructor(options = {}) {
26     const defaultHomeZoom = 11;
27     super({
28       container: "map",
29       style: OSM.MapLibre.Styles.Mapnik,
30       attributionControl: false,
31       locale: OSM.MapLibre.Locale,
32       allowRotation: false,
33       maxPitch: 0,
34       center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
35       zoom: OSM.home ? defaultHomeZoom : 0,
36       ...options
37     });
38   }
39 };