-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
97 lines (81 loc) · 2.88 KB
/
main.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
94
95
96
97
fetch('./data/spielplaetze_flensburg.geojson', {
method: 'GET'
})
.then((response) => {
return response.json()
})
.then((data) => {
marker(data)
})
.catch(function (error) {
console.log(error)
})
const map = L.map('map').setView([54.7836, 9.4321], 13)
L.tileLayer('https://tiles.oklabflensburg.de/sgm/{z}/{x}/{y}.png', {
maxZoom: 20,
tileSize: 256,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map)
let geocoder = L.Control.Geocoder.nominatim()
if (typeof URLSearchParams !== 'undefined' && location.search) {
// parse /?geocoder=nominatim from URL
let params = new URLSearchParams(location.search)
let geocoderString = params.get('geocoder')
if (geocoderString && L.Control.Geocoder[geocoderString]) {
console.log('Using geocoder', geocoderString)
geocoder = L.Control.Geocoder[geocoderString]()
} else if (geocoderString) {
console.warn('Unsupported geocoder', geocoderString)
}
}
const osmGeocoder = new L.Control.geocoder({
query: 'Flensburg',
position: 'topright',
placeholder: 'Adresse oder Ort',
defaultMarkGeocode: false
}).addTo(map)
osmGeocoder.on('markgeocode', e => {
const bounds = L.latLngBounds(e.geocode.bbox._southWest, e.geocode.bbox._northEast)
map.fitBounds(bounds)
})
const defaultIcon = L.icon({
iconUrl: './static/marker-icon-blue.png',
shadowUrl: './static/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
tooltipAnchor: [2, -41],
shadowSize: [45, 41]
})
function marker(data) {
let markers = L.markerClusterGroup({
zoomToBoundsOnClick: true,
disableClusteringAtZoom: 18
})
const geojsonGroup = L.geoJSON(data, {
onEachFeature: function (feature, layer) {
layer.on('click', function (e) {
document.getElementById('filter').scrollTo({
top: 0,
left: 0
})
map.setView(e.latlng, 19)
let details = e.target.feature.properties.details
let address = e.target.feature.properties.address.replace(', ', '<br>')
let place = e.target.feature.properties.place
document.getElementById('details').classList.remove('hidden')
document.getElementById('features').innerHTML = details
document.getElementById('address').innerHTML = address
document.getElementById('place').innerHTML = place
})
},
pointToLayer: function (feature, latlng) {
let label = String(feature.properties.place)
return L.marker(latlng, {icon: defaultIcon}).bindTooltip(label, {
permanent: false,
direction: 'top'
}).openTooltip()
}
})
markers.addLayer(geojsonGroup)
map.addLayer(markers)
}