Skip to content

Commit 2882a65

Browse files
committed
Merge remote-tracking branch 'upstream/pull/5349'
2 parents 257f467 + 126a987 commit 2882a65

File tree

3 files changed

+91
-102
lines changed

3 files changed

+91
-102
lines changed

app/assets/javascripts/leaflet.map.js

+17-102
Original file line numberDiff line numberDiff line change
@@ -15,108 +15,24 @@ L.OSM.Map = L.Map.extend({
1515
initialize: function (id, options) {
1616
L.Map.prototype.initialize.call(this, id, options);
1717

18-
const layerCredits = {
19-
mapnik: {
20-
id: "make_a_donation",
21-
href: "https://supporting.openstreetmap.org",
22-
donate: true
23-
},
24-
cyclosm: {
25-
id: "cyclosm_credit",
26-
children: {
27-
cyclosm_link: {
28-
id: "cyclosm_name",
29-
href: "https://www.cyclosm.org"
30-
},
31-
osm_france_link: {
32-
id: "osm_france",
33-
href: "https://openstreetmap.fr/"
34-
}
35-
}
36-
},
37-
thunderforest: {
38-
id: "thunderforest_credit",
39-
children: {
40-
thunderforest_link: {
41-
id: "andy_allan",
42-
href: "https://www.thunderforest.com/"
43-
}
44-
}
45-
},
46-
tracestrack: {
47-
id: "tracestrack_credit",
48-
children: {
49-
tracestrack_link: {
50-
id: "tracestrack",
51-
href: "https://www.tracestrack.com/"
52-
}
53-
}
54-
},
55-
hotosm: {
56-
id: "hotosm_credit",
57-
children: {
58-
hotosm_link: {
59-
id: "hotosm_name",
60-
href: "https://www.hotosm.org/"
61-
},
62-
osm_france_link: {
63-
id: "osm_france",
64-
href: "https://openstreetmap.fr/"
65-
}
66-
}
67-
}
68-
};
69-
7018
this.baseLayers = [];
7119

72-
this.baseLayers.push(new L.OSM.Mapnik({
73-
attribution: makeAttribution("mapnik"),
74-
code: "M",
75-
keyid: "mapnik",
76-
name: I18n.t("javascripts.map.base.standard")
77-
}));
78-
79-
this.baseLayers.push(new L.OSM.CyclOSM({
80-
attribution: makeAttribution("cyclosm"),
81-
code: "Y",
82-
keyid: "cyclosm",
83-
name: I18n.t("javascripts.map.base.cyclosm")
84-
}));
85-
86-
if (OSM.THUNDERFOREST_KEY) {
87-
this.baseLayers.push(new L.OSM.CycleMap({
88-
attribution: makeAttribution("thunderforest"),
89-
apikey: OSM.THUNDERFOREST_KEY,
90-
code: "C",
91-
keyid: "cyclemap",
92-
name: I18n.t("javascripts.map.base.cycle_map")
93-
}));
94-
95-
this.baseLayers.push(new L.OSM.TransportMap({
96-
attribution: makeAttribution("thunderforest"),
97-
apikey: OSM.THUNDERFOREST_KEY,
98-
code: "T",
99-
keyid: "transportmap",
100-
name: I18n.t("javascripts.map.base.transport_map")
101-
}));
102-
}
20+
for (const layerDefinition of OSM.LAYER_DEFINITIONS) {
21+
if (layerDefinition.apiKeyId && !OSM[layerDefinition.apiKeyId]) continue;
10322

104-
if (OSM.TRACESTRACK_KEY) {
105-
this.baseLayers.push(new L.OSM.TracestrackTopo({
106-
attribution: makeAttribution("tracestrack"),
107-
apikey: OSM.TRACESTRACK_KEY,
108-
code: "P",
109-
keyid: "tracestracktopo",
110-
name: I18n.t("javascripts.map.base.tracestracktop_topo")
111-
}));
112-
}
23+
const layerOptions = {
24+
attribution: makeAttribution(layerDefinition.credit),
25+
code: layerDefinition.code,
26+
keyid: layerDefinition.keyId,
27+
name: I18n.t(`javascripts.map.base.${layerDefinition.nameId}`)
28+
};
29+
if (layerDefinition.apiKeyId) {
30+
layerOptions.apikey = OSM[layerDefinition.apiKeyId];
31+
}
11332

114-
this.baseLayers.push(new L.OSM.HOT({
115-
attribution: makeAttribution("hotosm"),
116-
code: "H",
117-
keyid: "hot",
118-
name: I18n.t("javascripts.map.base.hot")
119-
}));
33+
const layer = new L.OSM[layerDefinition.leafletOsmId](layerOptions);
34+
this.baseLayers.push(layer);
35+
}
12036

12137
this.noteLayer = new L.FeatureGroup();
12238
this.noteLayer.options = { code: "N" };
@@ -135,8 +51,7 @@ L.OSM.Map = L.Map.extend({
13551
}
13652
});
13753

138-
function makeAttribution(id) {
139-
const layerCredit = layerCredits[id];
54+
function makeAttribution(credit) {
14055
let attribution = "";
14156

14257
attribution += I18n.t("javascripts.map.copyright_text", {
@@ -146,8 +61,8 @@ L.OSM.Map = L.Map.extend({
14661
}).prop("outerHTML")
14762
});
14863

149-
attribution += layerCredit.donate ? " ♥ " : ". ";
150-
attribution += makeCredit(layerCredit);
64+
attribution += credit.donate ? " ♥ " : ". ";
65+
attribution += makeCredit(credit);
15166
attribution += ". ";
15267

15368
attribution += $("<a>", {

app/assets/javascripts/osm.js.erb

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//= depend_on settings.yml
22
//= depend_on settings.local.yml
3+
//= depend_on layers.yml
34
//= depend_on key.yml
45
//= require qs/dist/qs
56

@@ -30,6 +31,7 @@ OSM = {
3031
TRACESTRACK_KEY: <%= Settings.tracestrack_key.to_json %>,
3132
<% end %>
3233

34+
LAYER_DEFINITIONS: <%= YAML.load_file(Rails.root.join("config/layers.yml")).to_json %>,
3335
LAYERS_WITH_MAP_KEY: <%= YAML.load_file(Rails.root.join("config/key.yml")).keys.to_json %>,
3436

3537
MARKER_GREEN: <%= image_path("marker-green.png").to_json %>,

config/layers.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
- leafletOsmId: "Mapnik"
2+
code: "M"
3+
keyId: "mapnik"
4+
nameId: "standard"
5+
credit:
6+
id: "make_a_donation"
7+
href: "https://supporting.openstreetmap.org"
8+
donate: true
9+
10+
- leafletOsmId: "CyclOSM"
11+
code: "Y"
12+
keyId: "cyclosm"
13+
nameId: "cyclosm"
14+
credit:
15+
id: "cyclosm_credit"
16+
children:
17+
cyclosm_link:
18+
id: "cyclosm_name"
19+
href: "https://www.cyclosm.org"
20+
osm_france_link:
21+
id: "osm_france"
22+
href: "https://openstreetmap.fr/"
23+
24+
- leafletOsmId: "CycleMap"
25+
code: "C"
26+
keyId: "cyclemap"
27+
nameId: "cycle_map"
28+
apiKeyId: "THUNDERFOREST_KEY"
29+
credit:
30+
id: "thunderforest_credit"
31+
children:
32+
thunderforest_link:
33+
id: "andy_allan"
34+
href: "https://www.thunderforest.com/"
35+
36+
- leafletOsmId: "TransportMap"
37+
code: "T"
38+
keyId: "transportmap"
39+
nameId: "transport_map"
40+
apiKeyId: "THUNDERFOREST_KEY"
41+
credit:
42+
id: "thunderforest_credit"
43+
children:
44+
thunderforest_link:
45+
id: "andy_allan"
46+
href: "https://www.thunderforest.com/"
47+
48+
- leafletOsmId: "TracestrackTopo"
49+
code: "P"
50+
keyId: "tracestracktopo"
51+
nameId: "tracestracktop_topo"
52+
apiKeyId: "TRACESTRACK_KEY"
53+
credit:
54+
id: "tracestrack_credit"
55+
children:
56+
tracestrack_link:
57+
id: "tracestrack"
58+
href: "https://www.tracestrack.com/"
59+
60+
- leafletOsmId: "HOT"
61+
code: "H"
62+
keyId: "hot"
63+
nameId: "hot"
64+
credit:
65+
id: "hotosm_credit"
66+
children:
67+
hotosm_link:
68+
id: "hotosm_name"
69+
href: "https://www.hotosm.org/"
70+
osm_france_link:
71+
id: "osm_france"
72+
href: "https://openstreetmap.fr/"

0 commit comments

Comments
 (0)