@@ -15,83 +15,85 @@ L.OSM.Map = L.Map.extend({
15
15
initialize : function ( id , options ) {
16
16
L . Map . prototype . initialize . call ( this , id , options ) ;
17
17
18
- var copyright_link = $ ( "<a>" , {
19
- href : "/copyright" ,
20
- text : I18n . t ( "javascripts.map.openstreetmap_contributors" )
21
- } ) . prop ( "outerHTML" ) ;
22
- var copyright = I18n . t ( "javascripts.map.copyright_text" , { copyright_link : copyright_link } ) ;
23
-
24
- var donate = $ ( "<a>" , {
25
- "href" : "https://supporting.openstreetmap.org" ,
26
- "class" : "donate-attr" ,
27
- "text" : I18n . t ( "javascripts.map.make_a_donation" )
28
- } ) . prop ( "outerHTML" ) ;
29
-
30
- var terms = $ ( "<a>" , {
31
- href : "https://wiki.osmfoundation.org/wiki/Terms_of_Use" ,
32
- text : I18n . t ( "javascripts.map.website_and_api_terms" )
33
- } ) . prop ( "outerHTML" ) ;
34
-
35
- var cyclosm_link = $ ( "<a>" , {
36
- href : "https://www.cyclosm.org" ,
37
- target : "_blank" ,
38
- text : I18n . t ( "javascripts.map.cyclosm_name" )
39
- } ) . prop ( "outerHTML" ) ;
40
- var osm_france_link = $ ( "<a>" , {
41
- href : "https://openstreetmap.fr/" ,
42
- target : "_blank" ,
43
- text : I18n . t ( "javascripts.map.osm_france" )
44
- } ) . prop ( "outerHTML" ) ;
45
- var cyclosm = I18n . t ( "javascripts.map.cyclosm_credit" , { cyclosm_link : cyclosm_link , osm_france_link : osm_france_link } ) ;
46
-
47
- var thunderforest_link = $ ( "<a>" , {
48
- href : "https://www.thunderforest.com/" ,
49
- target : "_blank" ,
50
- text : I18n . t ( "javascripts.map.andy_allan" )
51
- } ) . prop ( "outerHTML" ) ;
52
- var thunderforest = I18n . t ( "javascripts.map.thunderforest_credit" , { thunderforest_link : thunderforest_link } ) ;
53
-
54
- var tracestrack_link = $ ( "<a>" , {
55
- href : "https://www.tracestrack.com/" ,
56
- target : "_blank" ,
57
- text : I18n . t ( "javascripts.map.tracestrack" )
58
- } ) . prop ( "outerHTML" ) ;
59
- var tracestrack = I18n . t ( "javascripts.map.tracestrack_credit" , { tracestrack_link : tracestrack_link } ) ;
60
-
61
- var hotosm_link = $ ( "<a>" , {
62
- href : "https://www.hotosm.org/" ,
63
- target : "_blank" ,
64
- text : I18n . t ( "javascripts.map.hotosm_name" )
65
- } ) . prop ( "outerHTML" ) ;
66
- var hotosm = I18n . t ( "javascripts.map.hotosm_credit" , { hotosm_link : hotosm_link , osm_france_link : osm_france_link } ) ;
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
+ } ;
67
69
68
70
this . baseLayers = [ ] ;
69
71
70
72
this . baseLayers . push ( new L . OSM . Mapnik ( {
71
- attribution : copyright + " ♥ " + donate + ". " + terms ,
73
+ attribution : makeAttribution ( "mapnik" ) ,
72
74
code : "M" ,
73
75
keyid : "mapnik" ,
74
76
name : I18n . t ( "javascripts.map.base.standard" )
75
77
} ) ) ;
76
78
77
79
this . baseLayers . push ( new L . OSM . CyclOSM ( {
78
- attribution : copyright + ". " + cyclosm + ". " + terms ,
80
+ attribution : makeAttribution ( " cyclosm" ) ,
79
81
code : "Y" ,
80
82
keyid : "cyclosm" ,
81
83
name : I18n . t ( "javascripts.map.base.cyclosm" )
82
84
} ) ) ;
83
85
84
86
if ( OSM . THUNDERFOREST_KEY ) {
85
87
this . baseLayers . push ( new L . OSM . CycleMap ( {
86
- attribution : copyright + ". " + thunderforest + ". " + terms ,
88
+ attribution : makeAttribution ( " thunderforest" ) ,
87
89
apikey : OSM . THUNDERFOREST_KEY ,
88
90
code : "C" ,
89
91
keyid : "cyclemap" ,
90
92
name : I18n . t ( "javascripts.map.base.cycle_map" )
91
93
} ) ) ;
92
94
93
95
this . baseLayers . push ( new L . OSM . TransportMap ( {
94
- attribution : copyright + ". " + thunderforest + ". " + terms ,
96
+ attribution : makeAttribution ( " thunderforest" ) ,
95
97
apikey : OSM . THUNDERFOREST_KEY ,
96
98
code : "T" ,
97
99
keyid : "transportmap" ,
@@ -101,7 +103,7 @@ L.OSM.Map = L.Map.extend({
101
103
102
104
if ( OSM . TRACESTRACK_KEY ) {
103
105
this . baseLayers . push ( new L . OSM . TracestrackTopo ( {
104
- attribution : copyright + ". " + tracestrack + ". " + terms ,
106
+ attribution : makeAttribution ( " tracestrack" ) ,
105
107
apikey : OSM . TRACESTRACK_KEY ,
106
108
code : "P" ,
107
109
keyid : "tracestracktopo" ,
@@ -110,7 +112,7 @@ L.OSM.Map = L.Map.extend({
110
112
}
111
113
112
114
this . baseLayers . push ( new L . OSM . HOT ( {
113
- attribution : copyright + ". " + hotosm + ". " + terms ,
115
+ attribution : makeAttribution ( " hotosm" ) ,
114
116
code : "H" ,
115
117
keyid : "hot" ,
116
118
name : I18n . t ( "javascripts.map.base.hot" )
@@ -132,6 +134,51 @@ L.OSM.Map = L.Map.extend({
132
134
this . setMaxZoom ( event . layer . options . maxZoom ) ;
133
135
}
134
136
} ) ;
137
+
138
+ function makeAttribution ( id ) {
139
+ const layerCredit = layerCredits [ id ] ;
140
+ let attribution = "" ;
141
+
142
+ attribution += I18n . t ( "javascripts.map.copyright_text" , {
143
+ copyright_link : $ ( "<a>" , {
144
+ href : "/copyright" ,
145
+ text : I18n . t ( "javascripts.map.openstreetmap_contributors" )
146
+ } ) . prop ( "outerHTML" )
147
+ } ) ;
148
+
149
+ attribution += layerCredit . donate ? " ♥ " : ". " ;
150
+ attribution += makeCredit ( layerCredit ) ;
151
+ attribution += ". " ;
152
+
153
+ attribution += $ ( "<a>" , {
154
+ href : "https://wiki.osmfoundation.org/wiki/Terms_of_Use" ,
155
+ text : I18n . t ( "javascripts.map.website_and_api_terms" )
156
+ } ) . prop ( "outerHTML" ) ;
157
+
158
+ return attribution ;
159
+ }
160
+
161
+ function makeCredit ( credit ) {
162
+ const children = { } ;
163
+ for ( const childId in credit . children ) {
164
+ children [ childId ] = makeCredit ( credit . children [ childId ] ) ;
165
+ }
166
+ const text = I18n . t ( `javascripts.map.${ credit . id } ` , children ) ;
167
+ if ( credit . href ) {
168
+ const link = $ ( "<a>" , {
169
+ href : credit . href ,
170
+ text : text
171
+ } ) ;
172
+ if ( credit . donate ) {
173
+ link . addClass ( "donate-attr" ) ;
174
+ } else {
175
+ link . attr ( "target" , "_blank" ) ;
176
+ }
177
+ return link . prop ( "outerHTML" ) ;
178
+ } else {
179
+ return text ;
180
+ }
181
+ }
135
182
} ,
136
183
137
184
updateLayers : function ( layerParam ) {
0 commit comments