Skip to content

Commit 0d419b3

Browse files
create OSM.MapLibre.defaultSecondaryMapOptions to share the map style between the secondary maps
1 parent 7a8134e commit 0d419b3

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

app/assets/javascripts/dashboard.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
//= require maplibre.map
2-
//= require maplibre.i18n
32
//= require maplibre.combinedcontrolgroup
43

54
$(function () {
6-
const defaultHomeZoom = 11;
75
let map;
86

97
if ($("#map").length) {
10-
map = new maplibregl.Map({
11-
container: "map",
12-
style: OSM.MapLibre.Styles.Mapnik,
13-
attributionControl: false,
14-
locale: OSM.MapLibre.Locale,
15-
rollEnabled: false,
16-
dragRotate: false,
17-
pitchWithRotate: false,
18-
bearingSnap: 180,
19-
maxPitch: 0,
20-
center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
21-
zoom: OSM.home ? defaultHomeZoom : 0
22-
});
8+
map = new maplibregl.Map(OSM.MapLibre.defaultSecondaryMapOptions);
239

2410
const position = $("html").attr("dir") === "rtl" ? "top-left" : "top-right";
2511
const navigationControl = new maplibregl.NavigationControl({ showCompass: false });

app/assets/javascripts/maplibre.map.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//= require maplibre-gl/dist/maplibre-gl
2+
//= require maplibre.i18n
23

34
OSM.MapLibre.Styles.Mapnik = {
45
version: 8,
@@ -21,6 +22,20 @@ OSM.MapLibre.Styles.Mapnik = {
2122
]
2223
};
2324

25+
OSM.MapLibre.defaultSecondaryMapOptions = {
26+
container: "map",
27+
style: OSM.MapLibre.Styles.Mapnik,
28+
attributionControl: false,
29+
locale: OSM.MapLibre.Locale,
30+
rollEnabled: false,
31+
dragRotate: false,
32+
pitchWithRotate: false,
33+
bearingSnap: 180,
34+
maxPitch: 0,
35+
center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
36+
zoom: OSM.home ? 11 : 0,
37+
};
38+
2439
// Helper function to create Leaflet style (SVG comes from Leaflet) markers for MapLibre
2540
// new maplibregl.Marker({ color: color }) is simpler, but does not have the exact same gradient
2641
OSM.MapLibre.getMarker = function ({ icon = "dot", color = "var(--marker-red)", ...options }) {

app/assets/javascripts/user.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
//= require maplibre.map
2-
//= require maplibre.i18n
32
//= require maplibre.combinedcontrolgroup
43
//= require ./home_location_name-endpoint
54

65
$(function () {
7-
const defaultHomeZoom = 11;
86
let map, marker, deleted_lat, deleted_lon, deleted_home_name, homeLocationNameGeocoder, savedLat, savedLon;
97

108
if ($("#social_links").length) {
@@ -52,19 +50,7 @@ $(function () {
5250
}
5351

5452
if ($("#map").length) {
55-
map = new maplibregl.Map({
56-
container: "map",
57-
style: OSM.MapLibre.Styles.Mapnik,
58-
attributionControl: false,
59-
locale: OSM.MapLibre.Locale,
60-
rollEnabled: false,
61-
dragRotate: false,
62-
pitchWithRotate: false,
63-
bearingSnap: 180,
64-
maxPitch: 0,
65-
center: OSM.home ? [OSM.home.lon, OSM.home.lat] : [0, 0],
66-
zoom: OSM.home ? defaultHomeZoom : 0
67-
});
53+
map = new maplibregl.Map(OSM.MapLibre.defaultSecondaryMapOptions);
6854

6955
savedLat = $("#home_lat").val();
7056
savedLon = $("#home_lon").val();

0 commit comments

Comments
 (0)