Browse Source

State: Bugfix initial view

master
parent
commit
a06d49395b
  1. 8
      src/index.js
  2. 6
      src/location.js

8
src/index.js

@ -29,7 +29,7 @@ require('./twigFunctions')
require('./categories')
window.onload = function () {
var initState = {}
initState = config.defaultView
map = L.map('map')
@ -77,8 +77,10 @@ function onload2 (initState) {
}
// make sure the map has an initial location
if (!('map' in newState)) {
newState.map = initState.map
if (!('zoom' in newState) && !('lat' in newState) && !('lon' in newState)) {
newState.zoom = initState.zoom
newState.lat = initState.lat
newState.lon = initState.lon
}
state.apply(newState)

6
src/location.js

@ -1,15 +1,15 @@
var ipLocation = require('./ip-location')
register_hook('init_callback', function (initState, callback) {
initState.map = ('zoom' in config.defaultView ? config.defaultView.zoom : 14) + '/' + config.defaultView.lat + '/' + config.defaultView.lon
if ('checkIpLocation' in config && !config.checkIpLocation) {
return callback()
}
ipLocation('', function (err, ipLoc) {
if (typeof ipLoc === 'object' && 'latitude' in ipLoc) {
initState.map = '14/' + ipLoc.latitude + '/' + ipLoc.longitude
initState.zoom = 14
initState.lat = ipLoc.latitude
initState.lon = ipLoc.longitude
}
callback(err)

Loading…
Cancel
Save