@@ -10,12 +10,19 @@ var Session = require('./session.js');
10
10
var BuildingService = require ( './buildingservice.js' ) ;
11
11
var LoadingStatus = require ( './loadingstatus.js' ) ;
12
12
13
+ require ( 'leaflet-easybutton' ) ;
14
+
13
15
require ( 'leaflet/dist/leaflet.css' ) ;
16
+ require ( 'leaflet/dist/images/marker-icon.png' ) ;
17
+ require ( 'leaflet/dist/images/marker-icon-2x.png' ) ;
18
+ require ( 'leaflet/dist/images/marker-shadow.png' ) ;
19
+ require ( 'leaflet-easybutton/src/easy-button.css' ) ;
20
+ require ( 'font-awesome/css/font-awesome.css' ) ;
14
21
require ( './style.css' ) ;
15
22
16
23
// since leaflet is bundled into the browserify package it won't be able to detect where the images
17
24
// solution is to point it to where you host the the leaflet images yourself
18
- // L.Icon.Default.imagePath = 'http://cdn.leafletjs.com/leaflet-0.7.3/images';
25
+ L . Icon . Default . imagePath = 'http://cdn.leafletjs.com/leaflet-0.7.3/images' ;
19
26
20
27
$ ( "body" ) . append ( "<div id='wrapper'></div>" ) ;
21
28
var wrapper = $ ( "body" ) . children ( "#wrapper" ) ;
@@ -38,6 +45,7 @@ wrapper.children("#footer").append(
38
45
39
46
var _username = undefined ;
40
47
var _map = undefined ;
48
+ var _recenterButton = undefined ;
41
49
var _buildingPolygon = undefined ;
42
50
var _session = new Session ( ) ;
43
51
var _loadingStatus = new LoadingStatus ( ) ;
@@ -93,8 +101,6 @@ function fetchUserName(callback) {
93
101
} ) ;
94
102
} ;
95
103
96
- _loadingStatus . addListener ( updateButtons ) ;
97
-
98
104
function updateButtons ( )
99
105
{
100
106
var loading = _loadingStatus . isLoading ;
@@ -106,6 +112,12 @@ function updateButtons()
106
112
if ( _session . currentIndex <= 0 ) {
107
113
$ ( "#previous-building" ) . prop ( 'disabled' , true ) ;
108
114
}
115
+
116
+ if ( _session . currentIndex < 0 ) {
117
+ _recenterButton . disable ( ) ;
118
+ } else {
119
+ _recenterButton . enable ( ) ;
120
+ }
109
121
}
110
122
111
123
function updateConnectionStatusDisplay ( ) {
@@ -120,9 +132,6 @@ function updateConnectionStatusDisplay() {
120
132
}
121
133
}
122
134
123
- updateConnectionStatusDisplay ( ) ;
124
- updateButtons ( ) ;
125
-
126
135
if ( auth . authenticated ( ) ) {
127
136
$ ( "#connection-status" ) . text ( "Connected, retrieving username..." ) ;
128
137
fetchUserName ( ) ;
@@ -210,8 +219,35 @@ document.getElementById('next-building').onclick = function() {
210
219
displayNextBuilding ( ) ;
211
220
} ;
212
221
213
- var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ;
214
- var osmAttrib = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' ;
215
- var osm = new L . TileLayer ( osmUrl , { minZoom : 0 , maxZoom : 18 , attribution : osmAttrib } ) ;
216
- _map = L . map ( 'map' ) . setView ( [ 46.935 , 2.780 ] , 7 ) ;
217
- _map . addLayer ( osm ) ;
222
+ function init ( ) {
223
+ var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ;
224
+ var osmAttrib = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors' ;
225
+ var osm = new L . TileLayer ( osmUrl , { minZoom : 0 , maxZoom : 18 , attribution : osmAttrib } ) ;
226
+ _map = L . map ( 'map' ) . setView ( [ 46.935 , 2.780 ] , 7 ) ;
227
+ _map . addLayer ( osm ) ;
228
+
229
+ _recenterButton = L . easyButton (
230
+ 'fa-crosshairs fa-lg' ,
231
+ function ( button , map ) {
232
+ if ( defined ( _buildingPolygon ) ) {
233
+ _map . fitBounds ( _buildingPolygon . getBounds ( ) ) ;
234
+ }
235
+ } ,
236
+ '' , // title
237
+ 'recenter-button' // id
238
+ ) ;
239
+ _recenterButton . addTo ( _map ) ;
240
+ _recenterButton . disable ( ) ;
241
+
242
+ // Set the title here and not in the button constructor because when set by
243
+ // the constructor, the title is only displayable when the button is active.
244
+ // With this alternative way its always displayable.
245
+ $ ( "#recenter-button" ) . closest ( ".leaflet-control" ) . prop ( "title" , "Recenter on building" ) ;
246
+
247
+ _loadingStatus . addListener ( updateButtons ) ;
248
+
249
+ updateConnectionStatusDisplay ( ) ;
250
+ updateButtons ( ) ;
251
+ }
252
+
253
+ init ( ) ;
0 commit comments