@@ -39,13 +39,13 @@ function Maps(ConfigEndpoint, L, _, CONST) {
39
39
pointToLayer : pointToLayer ,
40
40
getConfig : getConfig ,
41
41
getLayer : getLayer ,
42
- pointIcon : pointIcon
42
+ pointIcon : pointIcon ,
43
+ defaultConfig : defaultConfig
43
44
} ;
44
45
45
46
function createMap ( element ) {
46
47
return getLeafletConfig ( ) . then ( function ( config ) {
47
48
var map = L . map ( element , config ) ;
48
-
49
49
map . attributionControl . setPrefix ( false ) ;
50
50
map . zoomControl . setPosition ( 'bottomleft' ) ;
51
51
map . setMaxBounds ( [ [ - 90 , - 360 ] , [ 90 , 360 ] ] ) ;
@@ -58,6 +58,25 @@ function Maps(ConfigEndpoint, L, _, CONST) {
58
58
59
59
// Add a layer control
60
60
// L.control.layers(getBaseLayersForControl(), {}).addTo(map);
61
+ var iconicSprite = require ( 'ushahidi-platform-pattern-library/assets/img/iconic-sprite.svg' ) ;
62
+ var resetButton = L . easyButton ( {
63
+ id : 'reset-button' ,
64
+ position : 'bottomleft' ,
65
+ type : 'replace' ,
66
+ leafletClasses : true ,
67
+ states :[ {
68
+ // specify different icons and responses for your button
69
+ stateName : 'reset-button' ,
70
+ onClick : function ( ) {
71
+ var defaultview = defaultValues ( config ) ;
72
+ map . setView ( [ defaultview . lat , defaultview . lon ] , defaultview . zoom ) ;
73
+ } ,
74
+ title : 'Reset to default view' ,
75
+ icon : '<svg class="iconic" style="fill:black;"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="' + iconicSprite + '#home"></use></svg>'
76
+ } ]
77
+ } ) ;
78
+
79
+ resetButton . addTo ( map ) ;
61
80
62
81
return map ;
63
82
} ) ;
@@ -112,9 +131,9 @@ function Maps(ConfigEndpoint, L, _, CONST) {
112
131
113
132
function defaultConfig ( ) {
114
133
return {
115
- scrollWheelZoom : false ,
134
+ scrollWheelZoom : true ,
116
135
center : [ - 1.2833 , 36.8167 ] , // Default to centered on Nairobi
117
- zoom : 8 ,
136
+ zoom : 3 ,
118
137
layers : [ L . tileLayer ( layers . baselayers . streets . url , layers . baselayers . streets . layerOptions ) ]
119
138
} ;
120
139
}
@@ -124,7 +143,6 @@ function Maps(ConfigEndpoint, L, _, CONST) {
124
143
icon : pointIcon ( feature . properties [ 'marker-color' ] )
125
144
} ) ;
126
145
}
127
-
128
146
// Icon configuration
129
147
function pointIcon ( color , size , className ) {
130
148
// Test string to make sure that it does not contain injection
@@ -140,4 +158,14 @@ function Maps(ConfigEndpoint, L, _, CONST) {
140
158
popupAnchor : [ 0 , 0 - size [ 1 ] ]
141
159
} ) ;
142
160
}
161
+
162
+ // default view is centered on nairobi
163
+ function defaultValues ( config ) {
164
+ return {
165
+ lat : config . center [ 0 ] ,
166
+ lon : config . center [ 1 ] ,
167
+ zoom : config . zoom
168
+ }
169
+ }
170
+
143
171
}
0 commit comments