forked from codeforberlin/trees-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
93 lines (77 loc) · 3.01 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var _map = null, _marker = null, _names = {};
$(document).ready(function() {
_map = L.map('map');
var view = {
"center": [52.51,13.37628],
"zoom": 15
};
var base = {
'Open Street Map': L.tileLayer("https://trees.codefor.de/tiles/osm/{z}/{x}/{y}.png", {
"attribution": "Map data © 2012 OpenStreetMap contributors",
"minZoom": 8,
"maxZoom": 20
})
};
var overlay = {
'Alle Bäume': L.tileLayer("https://trees.codefor.de/tiles/trees/{z}/{x}/{y}.png", {
"attribution": "Geoportal Berlin / Baumbestand Berlin",
"minZoom": 8,
"maxZoom": 20
})
};
base['Open Street Map'].addTo(_map);
overlay['Alle Bäume'].addTo(_map);
L.control.layers(base, overlay, { collapsed: false }).addTo(_map);
_map.setView(view.center, view.zoom);
_map.on('click', function(e) {
_map.clicked = true;
setTimeout(function(){
if (_map.clicked){
$.ajax({
url: 'https://trees.codefor.de/api/trees/',
data: {
dist: 10,
point: e.latlng.lng + ',' + e.latlng.lat
},
success: function(response) {
if (response.count > 0) {
var feature = response.features[0];
var lat = feature.geometry.coordinates[1],
lon = feature.geometry.coordinates[0];
var headline;
var list = [];
$.each(feature.properties, function(key, value) {
if (key === 'species_german') {
headline = value;
} else {
var string = '<td><strong>' + _names[key].label.de + '</strong></td>';
string += '<td>' + value + '</td>';
list.push(string);
}
});
var html = '<h4>' + headline + '</h4>';
html += '<table><tr>';
html += list.join('</tr><tr>');
html += '</tr></table>';
if (_marker !== null) {
_map.removeLayer(_marker);
}
_marker = L.marker([lat, lon]).addTo(_map);
_marker.bindPopup(html).openPopup();
}
}
});
}
}, 300);
});
_map.on('dblclick', function(event){
_map.clicked = false;
_map.zoomIn();
});
$.ajax({
url: 'https://trees.codefor.de/names/column-names.json',
success: function(response) {
_names = response;
}
});
});