Skip to content

Commit 3aa7d53

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

File tree

3 files changed

+19
-31
lines changed

3 files changed

+19
-31
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: 16 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,21 @@ OSM.MapLibre.Styles.Mapnik = {
2122
]
2223
};
2324

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

app/assets/javascripts/user.js

Lines changed: 2 additions & 16 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();
@@ -132,7 +118,7 @@ $(function () {
132118
const lat = $("#home_lat").val(),
133119
lon = $("#home_lon").val();
134120

135-
map.flyTo({ center: [lon, lat], zoom: defaultHomeZoom });
121+
map.flyTo({ center: [lon, lat], zoom: OSM.MapLibre.defaultHomeZoom });
136122
});
137123

138124
$("#home_delete").click(function () {

0 commit comments

Comments
 (0)