File tree 4 files changed +23
-22
lines changed
4 files changed +23
-22
lines changed Original file line number Diff line number Diff line change @@ -18,19 +18,13 @@ L.OSM.Map = L.Map.extend({
18
18
this . baseLayers = [ ] ;
19
19
20
20
for ( const layerDefinition of OSM . LAYER_DEFINITIONS ) {
21
- if ( layerDefinition . apiKeyId && ! OSM [ layerDefinition . apiKeyId ] ) continue ;
22
-
23
- const layerOptions = {
21
+ const layer = new L . OSM [ layerDefinition . leafletOsmId ] ( {
24
22
attribution : makeAttribution ( layerDefinition . credit ) ,
25
23
code : layerDefinition . code ,
26
24
keyid : layerDefinition . keyId ,
27
- name : I18n . t ( `javascripts.map.base.${ layerDefinition . nameId } ` )
28
- } ;
29
- if ( layerDefinition . apiKeyId ) {
30
- layerOptions . apikey = OSM [ layerDefinition . apiKeyId ] ;
31
- }
32
-
33
- const layer = new L . OSM [ layerDefinition . leafletOsmId ] ( layerOptions ) ;
25
+ name : I18n . t ( `javascripts.map.base.${ layerDefinition . nameId } ` ) ,
26
+ apikey : layerDefinition . apiKey
27
+ } ) ;
34
28
this . baseLayers . push ( layer ) ;
35
29
}
36
30
Original file line number Diff line number Diff line change @@ -23,15 +23,7 @@ OSM = {
23
23
FOSSGIS_VALHALLA_URL: < %= Settings . fossgis_valhalla_url . to_json % > ,
24
24
DEFAULT_LOCALE: < %= I18n . default_locale . to_json % > ,
25
25
26
- < % if Settings . key ?( :thunderforest_key ) % >
27
- THUNDERFOREST_KEY: < %= Settings . thunderforest_key . to_json % > ,
28
- < % end % >
29
-
30
- < % if Settings . key ?( :tracestrack_key ) % >
31
- TRACESTRACK_KEY: < %= Settings . tracestrack_key . to_json % > ,
32
- < % end % >
33
-
34
- LAYER_DEFINITIONS: < %= YAML . load_file ( Rails . root . join ( "config / layers . yml ") ) . to_json % > ,
26
+ LAYER_DEFINITIONS: < %= MapLayers ::definitions ( "config / layers . yml ") . to_json % > ,
35
27
LAYERS_WITH_MAP_KEY: < %= YAML . load_file ( Rails . root . join ( "config / key . yml ") ) . keys . to_json % > ,
36
28
37
29
MARKER_GREEN: < %= image_path ( "marker-green . png ") . to_json % > ,
Original file line number Diff line number Diff line change 25
25
code : " C"
26
26
keyId : " cyclemap"
27
27
nameId : " cycle_map"
28
- apiKeyId : " THUNDERFOREST_KEY "
28
+ apiKeyId : " thunderforest_key "
29
29
credit :
30
30
id : " thunderforest_credit"
31
31
children :
37
37
code : " T"
38
38
keyId : " transportmap"
39
39
nameId : " transport_map"
40
- apiKeyId : " THUNDERFOREST_KEY "
40
+ apiKeyId : " thunderforest_key "
41
41
credit :
42
42
id : " thunderforest_credit"
43
43
children :
49
49
code : " P"
50
50
keyId : " tracestracktopo"
51
51
nameId : " tracestracktop_topo"
52
- apiKeyId : " TRACESTRACK_KEY "
52
+ apiKeyId : " tracestrack_key "
53
53
credit :
54
54
id : " tracestrack_credit"
55
55
children :
Original file line number Diff line number Diff line change
1
+ module MapLayers
2
+ def self . definitions ( layers_filename )
3
+ YAML . load_file ( Rails . root . join ( layers_filename ) ) . filter_map do |layer |
4
+ if layer [ "apiKeyId" ]
5
+ if Settings . key? ( layer [ "apiKeyId" ] . to_sym )
6
+ layer [ "apiKey" ] = Settings [ layer [ "apiKeyId" ] ]
7
+ layer . delete "apiKeyId"
8
+ layer
9
+ end
10
+ else
11
+ layer
12
+ end
13
+ end
14
+ end
15
+ end
You can’t perform that action at this time.
0 commit comments