@@ -15,108 +15,24 @@ 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
- 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
-
70
18
this . baseLayers = [ ] ;
71
19
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 ;
103
22
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
+ }
113
32
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
+ }
120
36
121
37
this . noteLayer = new L . FeatureGroup ( ) ;
122
38
this . noteLayer . options = { code : "N" } ;
@@ -135,8 +51,7 @@ L.OSM.Map = L.Map.extend({
135
51
}
136
52
} ) ;
137
53
138
- function makeAttribution ( id ) {
139
- const layerCredit = layerCredits [ id ] ;
54
+ function makeAttribution ( credit ) {
140
55
let attribution = "" ;
141
56
142
57
attribution += I18n . t ( "javascripts.map.copyright_text" , {
@@ -146,8 +61,8 @@ L.OSM.Map = L.Map.extend({
146
61
} ) . prop ( "outerHTML" )
147
62
} ) ;
148
63
149
- attribution += layerCredit . donate ? " ♥ " : ". " ;
150
- attribution += makeCredit ( layerCredit ) ;
64
+ attribution += credit . donate ? " ♥ " : ". " ;
65
+ attribution += makeCredit ( credit ) ;
151
66
attribution += ". " ;
152
67
153
68
attribution += $ ( "<a>" , {
0 commit comments