|
|
@ -1,22 +1,21 @@ |
|
|
|
/* globals map:true, overpassFrontend:true, currentPath:true, options:true, baseCategory:true, overpassUrl:true */ |
|
|
|
|
|
|
|
var LeafletGeoSearch = require('leaflet-geosearch') |
|
|
|
|
|
|
|
var OverpassLayer = require('overpass-layer') |
|
|
|
var OverpassLayerList = require('overpass-layer').List |
|
|
|
var OverpassFrontend = require('overpass-frontend') |
|
|
|
var OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader') |
|
|
|
var state = require('./state') |
|
|
|
var hash = require('sheet-router/hash') |
|
|
|
var queryString = require('query-string') |
|
|
|
window.OpenStreetBrowserLoader = OpenStreetBrowserLoader |
|
|
|
global.OpenStreetBrowserLoader = OpenStreetBrowserLoader |
|
|
|
|
|
|
|
require('./CategoryIndex') |
|
|
|
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 |
|
|
|
|
|
|
|
// Optional modules
|
|
|
@ -54,9 +53,9 @@ function onload2 (initState) { |
|
|
|
drawCircle: false, |
|
|
|
drawMarker: false, |
|
|
|
showPopup: false |
|
|
|
}).addTo(map); |
|
|
|
}).addTo(map) |
|
|
|
|
|
|
|
if (typeof overpassUrl === 'undefined') { |
|
|
|
if (!overpassUrl) { |
|
|
|
overpassUrl = config.overpassUrl |
|
|
|
if (Array.isArray(overpassUrl) && overpassUrl.length) { |
|
|
|
overpassUrl = overpassUrl[0] |
|
|
@ -99,16 +98,18 @@ function onload2 (initState) { |
|
|
|
if (e.popup.object) { |
|
|
|
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 + '/') { |
|
|
|
|
|
|
|
currentPath = url |
|
|
|
// only push state, when last popup close happened >1sec earlier
|
|
|
|
state.update(null, Date.now() - lastPopupClose > 1000) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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('/') |
|
|
|
|
|
|
|
if (id.length < 2) { |
|
|
|
return callback('unknown request') |
|
|
|
return callback(new Error('unknown request')) |
|
|
|
} |
|
|
|
|
|
|
|
OpenStreetBrowserLoader.getCategory(id[0], function (err, category) { |
|
|
|
if (err) { |
|
|
|
return callback('error loading category "' + id[0] + '": ' + err) |
|
|
|
return callback(new Error('error loading category "' + id[0] + '": ' + err)) |
|
|
|
} |
|
|
|
|
|
|
|
if (!category.parentDom) { |
|
|
@ -178,7 +179,7 @@ function show (id, options, callback) { |
|
|
|
}, |
|
|
|
function (err, data) { |
|
|
|
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) { |
|
|
@ -198,58 +199,61 @@ function show (id, options, callback) { |
|
|
|
} |
|
|
|
|
|
|
|
function showDetails (data, category) { |
|
|
|
var div, h, dt, dd |
|
|
|
var k |
|
|
|
var dom = document.getElementById('contentDetails') |
|
|
|
|
|
|
|
dom.innerHTML = '' |
|
|
|
|
|
|
|
var div = document.createElement('h1') |
|
|
|
div = document.createElement('h1') |
|
|
|
div.className = 'title' |
|
|
|
div.innerHTML = data.data.title |
|
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
div = document.createElement('div') |
|
|
|
div.className = 'description' |
|
|
|
div.innerHTML = data.data.description |
|
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
div = document.createElement('div') |
|
|
|
div.className = 'body' |
|
|
|
div.innerHTML = data.data.body |
|
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
var div = document.createElement('div') |
|
|
|
div = document.createElement('div') |
|
|
|
div.className = 'body' |
|
|
|
dom.appendChild(div) |
|
|
|
category.renderTemplate(data, 'detailsBody', function (div, err, result) { |
|
|
|
div.innerHTML = result |
|
|
|
}.bind(this, div)) |
|
|
|
|
|
|
|
var h = document.createElement('h3') |
|
|
|
h = document.createElement('h3') |
|
|
|
h.innerHTML = 'Attributes' |
|
|
|
dom.appendChild(h) |
|
|
|
|
|
|
|
var div = document.createElement('dl') |
|
|
|
div = document.createElement('dl') |
|
|
|
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)) |
|
|
|
div.appendChild(dt) |
|
|
|
var dd = document.createElement('dd') |
|
|
|
|
|
|
|
dd = document.createElement('dd') |
|
|
|
dd.appendChild(document.createTextNode(data.object.tags[k])) |
|
|
|
div.appendChild(dd) |
|
|
|
} |
|
|
|
dom.appendChild(div) |
|
|
|
|
|
|
|
var h = document.createElement('h3') |
|
|
|
h = document.createElement('h3') |
|
|
|
h.innerHTML = 'OSM Meta' |
|
|
|
dom.appendChild(h) |
|
|
|
|
|
|
|
var div = document.createElement('dl') |
|
|
|
div = document.createElement('dl') |
|
|
|
div.className = 'meta' |
|
|
|
var dt = document.createElement('dt') |
|
|
|
dt = document.createElement('dt') |
|
|
|
dt.appendChild(document.createTextNode('id')) |
|
|
|
div.appendChild(dt) |
|
|
|
var dd = document.createElement('dd') |
|
|
|
dd = document.createElement('dd') |
|
|
|
var a = document.createElement('a') |
|
|
|
a.appendChild(document.createTextNode(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) |
|
|
|
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)) |
|
|
|
div.appendChild(dt) |
|
|
|
var dd = document.createElement('dd') |
|
|
|
|
|
|
|
dd = document.createElement('dd') |
|
|
|
dd.appendChild(document.createTextNode(data.object.meta[k])) |
|
|
|
div.appendChild(dd) |
|
|
|
} |
|
|
|