add panTo-method to center view on marker-click

This commit is contained in:
Tim Herbst 2020-12-27 15:46:43 +01:00
parent b484857746
commit 9afb135d91

View File

@ -63,10 +63,11 @@ export class MapService {
for (const station of data) { for (const station of data) {
const marker = L.marker([station.lat, station.lon], {icon: createIcon}); const marker = L.marker([station.lat, station.lon], {icon: createIcon});
markerClusters.addLayer(marker); markerClusters.addLayer(marker);
marker.on('click', e => e.target marker.on('click', e => {
.bindPopup(this.popUpService.makeAvailabilityPopUp(station), {maxWidth: 'auto'}) e.target.bindPopup(this.popUpService.makeAvailabilityPopUp(station), {maxWidth: 'auto'})
.openPopup() .openPopup();
); this.map.panTo(e.target.getLatLng());
});
marker.on('popupclose', e => e.target.unbindPopup()); marker.on('popupclose', e => e.target.unbindPopup());
} }
}).catch((error) => { }).catch((error) => {