Files
vue-google-maps-community-fork/utils/center-markers.js
Fawad Mirzad 23c0ac636c Fix small bug
2021-01-27 11:55:07 +01:00

15 lines
653 B
JavaScript

export function fitMapToMarkers(geoCoordinates, mapInstance) {
/* eslint-disable no-undef */
const bounds = new google.maps.LatLngBounds();
if (geoCoordinates.length === 1) {
mapInstance.setCenter({lat: geoCoordinates[0].position.lat, lng: geoCoordinates[0].position.lng});
mapInstance.setZoom(16);
} else if (geoCoordinates.length > 0) {
geoCoordinates.forEach(geoCoordinate => {
if (geoCoordinate.location.lat && geoCoordinate.location.lng)
bounds.extend({lat: geoCoordinate.location.lat, lng: geoCoordinate.location.lng});
});
mapInstance.fitBounds(bounds);
}
}