|
@ -1,22 +1,21 @@ |
|
|
|
|
|
/* globals map:true, overpassFrontend:true, currentPath:true, options:true, baseCategory:true, overpassUrl:true */ |
|
|
|
|
|
|
|
|
var LeafletGeoSearch = require('leaflet-geosearch') |
|
|
var LeafletGeoSearch = require('leaflet-geosearch') |
|
|
|
|
|
|
|
|
var OverpassLayer = require('overpass-layer') |
|
|
|
|
|
var OverpassLayerList = require('overpass-layer').List |
|
|
|
|
|
var OverpassFrontend = require('overpass-frontend') |
|
|
var OverpassFrontend = require('overpass-frontend') |
|
|
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') |
|
|
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') |
|
|
var state = require('./state') |
|
|
var state = require('./state') |
|
|
var hash = require('sheet-router/hash') |
|
|
var hash = require('sheet-router/hash') |
|
|
var queryString = require('query-string') |
|
|
|
|
|
window.OpenStreetBrowserLoader = OpenStreetBrowserLoader |
|
|
|
|
|
|
|
|
global.OpenStreetBrowserLoader = OpenStreetBrowserLoader |
|
|
|
|
|
|
|
|
require('./CategoryIndex') |
|
|
require('./CategoryIndex') |
|
|
require('./CategoryOverpass') |
|
|
require('./CategoryOverpass') |
|
|
|
|
|
|
|
|
global.map |
|
|
|
|
|
window.baseCategory |
|
|
|
|
|
window.overpassUrl |
|
|
|
|
|
window.overpassFrontend |
|
|
|
|
|
window.currentPath = null |
|
|
|
|
|
|
|
|
global.map = null |
|
|
|
|
|
global.baseCategory = null |
|
|
|
|
|
global.overpassUrl = null |
|
|
|
|
|
global.overpassFrontend = null |
|
|
|
|
|
global.currentPath = null |
|
|
var lastPopupClose = 0 |
|
|
var lastPopupClose = 0 |
|
|
|
|
|
|
|
|
// Optional modules
|
|
|
// Optional modules
|
|
@ -29,7 +28,7 @@ require('./mapLayers') |
|
|
require('./twigFunctions') |
|
|
require('./twigFunctions') |
|
|
require('./categories') |
|
|
require('./categories') |
|
|
|
|
|
|
|
|
window.onload = function() { |
|
|
|
|
|
|
|
|
window.onload = function () { |
|
|
var initState = {} |
|
|
var initState = {} |
|
|
|
|
|
|
|
|
map = L.map('map') |
|
|
map = L.map('map') |
|
@ -54,9 +53,9 @@ function onload2 (initState) { |
|
|
drawCircle: false, |
|
|
drawCircle: false, |
|
|
drawMarker: false, |
|
|
drawMarker: false, |
|
|
showPopup: false |
|
|
showPopup: false |
|
|
}).addTo(map); |
|
|
|
|
|
|
|
|
}).addTo(map) |
|
|
|
|
|
|
|
|
if (typeof overpassUrl === 'undefined') { |
|
|
|
|
|
|
|
|
if (!overpassUrl) { |
|
|
overpassUrl = config.overpassUrl |
|
|
overpassUrl = config.overpassUrl |
|
|
if (Array.isArray(overpassUrl) && overpassUrl.length) { |
|
|
if (Array.isArray(overpassUrl) && overpassUrl.length) { |
|
|
overpassUrl = overpassUrl[0] |
|
|
overpassUrl = overpassUrl[0] |
|
@ -98,17 +97,19 @@ function onload2 (initState) { |
|
|
map.on('popupopen', function (e) { |
|
|
map.on('popupopen', function (e) { |
|
|
if (e.popup.object) { |
|
|
if (e.popup.object) { |
|
|
var url = e.popup.object.layer_id + '/' + e.popup.object.id |
|
|
var url = e.popup.object.layer_id + '/' + e.popup.object.id |
|
|
if (location.hash.substr(1) !== url && location.hash.substr(1, url.length + 1) !== url + '/' ) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (location.hash.substr(1) !== url && location.hash.substr(1, url.length + 1) !== url + '/') { |
|
|
currentPath = url |
|
|
currentPath = url |
|
|
// only push state, when last popup close happened >1sec earlier
|
|
|
// only push state, when last popup close happened >1sec earlier
|
|
|
state.update(null, Date.now() - lastPopupClose > 1000) |
|
|
state.update(null, Date.now() - lastPopupClose > 1000) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
OpenStreetBrowserLoader.getCategory(e.popup.object.layer_id, function (err, category) { |
|
|
OpenStreetBrowserLoader.getCategory(e.popup.object.layer_id, function (err, category) { |
|
|
category.notifyPopupOpen(e.popup.object, e.popup) |
|
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
alert(err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
category.notifyPopupOpen(e.popup.object, e.popup) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -160,12 +161,12 @@ function show (id, options, callback) { |
|
|
id = id.split('/') |
|
|
id = id.split('/') |
|
|
|
|
|
|
|
|
if (id.length < 2) { |
|
|
if (id.length < 2) { |
|
|
return callback('unknown request') |
|
|
|
|
|
|
|
|
return callback(new Error('unknown request')) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
OpenStreetBrowserLoader.getCategory(id[0], function (err, category) { |
|
|
OpenStreetBrowserLoader.getCategory(id[0], function (err, category) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
return callback('error loading category "' + id[0] + '": ' + err) |
|
|
|
|
|
|
|
|
return callback(new Error('error loading category "' + id[0] + '": ' + err)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!category.parentDom) { |
|
|
if (!category.parentDom) { |
|
@ -178,7 +179,7 @@ function show (id, options, callback) { |
|
|
}, |
|
|
}, |
|
|
function (err, data) { |
|
|
function (err, data) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
return callback('error loading object "' + id[0] + '/' + id[1] +'": ' + err) |
|
|
|
|
|
|
|
|
return callback(new Error('error loading object "' + id[0] + '/' + id[1] + '": ' + err)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!map._popup || map._popup !== data.popup) { |
|
|
if (!map._popup || map._popup !== data.popup) { |
|
@ -198,58 +199,61 @@ function show (id, options, callback) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function showDetails (data, category) { |
|
|
function showDetails (data, category) { |
|
|
|
|
|
var div, h, dt, dd |
|
|
|
|
|
var k |
|
|
var dom = document.getElementById('contentDetails') |
|
|
var dom = document.getElementById('contentDetails') |
|
|
|
|
|
|
|
|
dom.innerHTML = '' |
|
|
dom.innerHTML = '' |
|
|
|
|
|
|
|
|
var div = document.createElement('h1') |
|
|
|
|
|
|
|
|
div = document.createElement('h1') |
|
|
div.className = 'title' |
|
|
div.className = 'title' |
|
|
div.innerHTML = data.data.title |
|
|
div.innerHTML = data.data.title |
|
|
dom.appendChild(div) |
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
|
|
|
|
|
div = document.createElement('div') |
|
|
div.className = 'description' |
|
|
div.className = 'description' |
|
|
div.innerHTML = data.data.description |
|
|
div.innerHTML = data.data.description |
|
|
dom.appendChild(div) |
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
|
|
|
|
|
div = document.createElement('div') |
|
|
div.className = 'body' |
|
|
div.className = 'body' |
|
|
div.innerHTML = data.data.body |
|
|
div.innerHTML = data.data.body |
|
|
dom.appendChild(div) |
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
|
|
|
|
|
div = document.createElement('div') |
|
|
div.className = 'body' |
|
|
div.className = 'body' |
|
|
dom.appendChild(div) |
|
|
dom.appendChild(div) |
|
|
category.renderTemplate(data, 'detailsBody', function (div, err, result) { |
|
|
category.renderTemplate(data, 'detailsBody', function (div, err, result) { |
|
|
div.innerHTML = result |
|
|
div.innerHTML = result |
|
|
}.bind(this, div)) |
|
|
}.bind(this, div)) |
|
|
|
|
|
|
|
|
var h = document.createElement('h3') |
|
|
|
|
|
|
|
|
h = document.createElement('h3') |
|
|
h.innerHTML = 'Attributes' |
|
|
h.innerHTML = 'Attributes' |
|
|
dom.appendChild(h) |
|
|
dom.appendChild(h) |
|
|
|
|
|
|
|
|
var div = document.createElement('dl') |
|
|
|
|
|
|
|
|
div = document.createElement('dl') |
|
|
div.className = 'tags' |
|
|
div.className = 'tags' |
|
|
for (var k in data.object.tags) { |
|
|
|
|
|
var dt = document.createElement('dt') |
|
|
|
|
|
|
|
|
for (k in data.object.tags) { |
|
|
|
|
|
dt = document.createElement('dt') |
|
|
dt.appendChild(document.createTextNode(k)) |
|
|
dt.appendChild(document.createTextNode(k)) |
|
|
div.appendChild(dt) |
|
|
div.appendChild(dt) |
|
|
var dd = document.createElement('dd') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dd = document.createElement('dd') |
|
|
dd.appendChild(document.createTextNode(data.object.tags[k])) |
|
|
dd.appendChild(document.createTextNode(data.object.tags[k])) |
|
|
div.appendChild(dd) |
|
|
div.appendChild(dd) |
|
|
} |
|
|
} |
|
|
dom.appendChild(div) |
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
|
var h = document.createElement('h3') |
|
|
|
|
|
|
|
|
h = document.createElement('h3') |
|
|
h.innerHTML = 'OSM Meta' |
|
|
h.innerHTML = 'OSM Meta' |
|
|
dom.appendChild(h) |
|
|
dom.appendChild(h) |
|
|
|
|
|
|
|
|
var div = document.createElement('dl') |
|
|
|
|
|
|
|
|
div = document.createElement('dl') |
|
|
div.className = 'meta' |
|
|
div.className = 'meta' |
|
|
var dt = document.createElement('dt') |
|
|
|
|
|
|
|
|
dt = document.createElement('dt') |
|
|
dt.appendChild(document.createTextNode('id')) |
|
|
dt.appendChild(document.createTextNode('id')) |
|
|
div.appendChild(dt) |
|
|
div.appendChild(dt) |
|
|
var dd = document.createElement('dd') |
|
|
|
|
|
|
|
|
dd = document.createElement('dd') |
|
|
var a = document.createElement('a') |
|
|
var a = document.createElement('a') |
|
|
a.appendChild(document.createTextNode(data.object.type + '/' + data.object.osm_id)) |
|
|
a.appendChild(document.createTextNode(data.object.type + '/' + data.object.osm_id)) |
|
|
a.href = 'https://openstreetmap.org/' + data.object.type + '/' + data.object.osm_id |
|
|
a.href = 'https://openstreetmap.org/' + data.object.type + '/' + data.object.osm_id |
|
@ -257,11 +261,12 @@ function showDetails (data, category) { |
|
|
|
|
|
|
|
|
dd.appendChild(a) |
|
|
dd.appendChild(a) |
|
|
div.appendChild(dd) |
|
|
div.appendChild(dd) |
|
|
for (var k in data.object.meta) { |
|
|
|
|
|
var dt = document.createElement('dt') |
|
|
|
|
|
|
|
|
for (k in data.object.meta) { |
|
|
|
|
|
dt = document.createElement('dt') |
|
|
dt.appendChild(document.createTextNode(k)) |
|
|
dt.appendChild(document.createTextNode(k)) |
|
|
div.appendChild(dt) |
|
|
div.appendChild(dt) |
|
|
var dd = document.createElement('dd') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dd = document.createElement('dd') |
|
|
dd.appendChild(document.createTextNode(data.object.meta[k])) |
|
|
dd.appendChild(document.createTextNode(data.object.meta[k])) |
|
|
div.appendChild(dd) |
|
|
div.appendChild(dd) |
|
|
} |
|
|
} |
|
|