11import React , { useEffect , useState } from 'react'
22
33import dayjs from 'dayjs'
4+ import relativeTime from 'dayjs/plugin/relativeTime'
45
56import Box from '@mui/material/Box'
67import Fab from '@mui/material/Fab'
@@ -26,6 +27,8 @@ import PostcodeSearch from './PostcodeSearch'
2627
2728import config from './helpers/config.json'
2829
30+ dayjs . extend ( relativeTime )
31+
2932const libraryAuthorityTiles = config . libraryAuthorityTiles
3033const mobileTiles = config . mobileTiles
3134
@@ -147,38 +150,38 @@ const MobileMap = () => {
147150 // The mobile library locations
148151 mobileLocations && mobileLocations . length > 0
149152 ? mobileLocations . map ( l => {
150- if ( ! l . geoX || ! l . geoY ) return null
151- let locationPoint = [ l . geoX , l . geoY ]
152- if ( l . routeSection && l . routeSection . coordinates && l . updated ) {
153- const millisecondsPassed = dayjs ( Date . now ( ) ) . diff ( l . updated )
154- const index = Math . round ( millisecondsPassed / 500 )
155- const coords = l . routeSection . coordinates
156- if ( coords . length > index && index > 0 ) {
157- locationPoint = coords [ index ]
158- }
159- if ( coords . length <= index && index > 0 ) {
160- locationPoint = coords [ coords . length - 1 ]
153+ if ( ! l . geoX || ! l . geoY ) return null
154+ let locationPoint = [ l . geoX , l . geoY ]
155+ if ( l . routeSection && l . routeSection . coordinates && l . updated ) {
156+ const millisecondsPassed = dayjs ( Date . now ( ) ) . diff ( l . updated )
157+ const index = Math . round ( millisecondsPassed / 500 )
158+ const coords = l . routeSection . coordinates
159+ if ( coords . length > index && index > 0 ) {
160+ locationPoint = coords [ index ]
161+ }
162+ if ( coords . length <= index && index > 0 ) {
163+ locationPoint = coords [ coords . length - 1 ]
164+ }
161165 }
162- }
163- const mobile = mobileLookup [ l . mobileId ]
164- const organisation = mobile
165- ? organisationLookup [ mobile . organisationId ]
166- : null
167- return (
168- < Marker
169- key = { 'mkr_' + l . mobileId }
170- longitude = { locationPoint [ 0 ] }
171- latitude = { locationPoint [ 1 ] }
172- anchor = 'bottom'
173- >
174- < MobileAvatar
175- organisation = { organisation }
176- location = { l }
177- zoom = { map ? map . getZoom ( ) : 0 }
178- />
179- </ Marker >
180- )
181- } )
166+ const mobile = mobileLookup [ l . mobileId ]
167+ const organisation = mobile
168+ ? organisationLookup [ mobile . organisationId ]
169+ : null
170+ return (
171+ < Marker
172+ key = { 'mkr_' + l . mobileId }
173+ longitude = { locationPoint [ 0 ] }
174+ latitude = { locationPoint [ 1 ] }
175+ anchor = 'bottom'
176+ >
177+ < MobileAvatar
178+ organisation = { organisation }
179+ location = { l }
180+ zoom = { map ? map . getZoom ( ) : 0 }
181+ />
182+ </ Marker >
183+ )
184+ } )
182185 : null
183186 }
184187 { currentService && currentService . geojson && (
@@ -195,37 +198,33 @@ const MobileMap = () => {
195198 ) }
196199
197200 < Source type = 'vector' tiles = { [ libraryAuthorityTiles ] } >
198- { mapSettings . authorityBoundary
199- ? (
200- < Layer
201- type = 'line'
202- source-layer = 'library_authority_boundaries'
203- minzoom = { 6 }
204- layout = { {
205- 'line-join' : 'round' ,
206- 'line-cap' : 'square'
207- } }
208- paint = { {
209- 'line-color' : '#a7a39b' ,
210- 'line-opacity' : 1 ,
211- 'line-width' : [ 'interpolate' , [ 'linear' ] , [ 'zoom' ] , 6 , 1 , 18 , 4 ]
212- } }
213- />
214- )
215- : null }
216- { mapSettings . authorityBoundary
217- ? (
218- < Layer
219- type = 'fill'
220- source-layer = 'library_authority_boundaries'
221- minzoom = { 6 }
222- paint = { {
223- 'fill-color' : '#ccc' ,
224- 'fill-opacity' : 0.1
225- } }
226- />
227- )
228- : null }
201+ { mapSettings . authorityBoundary ? (
202+ < Layer
203+ type = 'line'
204+ source-layer = 'library_authority_boundaries'
205+ minzoom = { 6 }
206+ layout = { {
207+ 'line-join' : 'round' ,
208+ 'line-cap' : 'square'
209+ } }
210+ paint = { {
211+ 'line-color' : '#a7a39b' ,
212+ 'line-opacity' : 1 ,
213+ 'line-width' : [ 'interpolate' , [ 'linear' ] , [ 'zoom' ] , 6 , 1 , 18 , 4 ]
214+ } }
215+ />
216+ ) : null }
217+ { mapSettings . authorityBoundary ? (
218+ < Layer
219+ type = 'fill'
220+ source-layer = 'library_authority_boundaries'
221+ minzoom = { 6 }
222+ paint = { {
223+ 'fill-color' : '#ccc' ,
224+ 'fill-opacity' : 0.1
225+ } }
226+ />
227+ ) : null }
229228 </ Source >
230229
231230 < Source type = 'vector' tiles = { [ mobileTiles ] } maxzoom = { 14 } >
@@ -353,13 +352,11 @@ const MobileMap = () => {
353352 } }
354353 />
355354 </ Source >
356- { searchPosition && searchPosition . length > 1
357- ? (
358- < Marker longitude = { searchPosition [ 0 ] } latitude = { searchPosition [ 1 ] } >
359- < MeAvatar searchType = { searchType } />
360- </ Marker >
361- )
362- : null }
355+ { searchPosition && searchPosition . length > 1 ? (
356+ < Marker longitude = { searchPosition [ 0 ] } latitude = { searchPosition [ 1 ] } >
357+ < MeAvatar searchType = { searchType } />
358+ </ Marker >
359+ ) : null }
363360 < NavigationControl position = 'bottom-left' />
364361 </ Map >
365362 < Tooltip title = 'Map settings' >
@@ -376,7 +373,8 @@ const MobileMap = () => {
376373 dispatchView ( {
377374 type : 'SetMapSettingsDialog' ,
378375 mapSettingsDialogOpen : true
379- } ) }
376+ } )
377+ }
380378 >
381379 < LayersIcon />
382380 </ Fab >
0 commit comments