
// https://googlemaps.github.io/js-markerclusterer/classes/MarkerClusterer.html
// add true for noDraw
// bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625

/**
 * if show_only is true:
 *   erase all other markers from the map,
 *   else, they stay visible
 */
function filter_show_only_selection(indexes, show_only = true) {

	let indexes_count = indexes.length;
	if (indexes_count === 0)
		return;

	if (show_only)
		g_marker_cluster.clearMarkers(true);

	let marker = g_markers[0];
	let position = marker.getPosition();
	let current_bounds = g_map.getBounds();
	console.log("current_bounds:");
	console.log(current_bounds);
	let bounds = new google.maps.LatLngBounds(position);
	console.log("bounds:");
	console.log(bounds);

	let outside_bounds = false;
	for (let index of indexes) {
		marker = g_markers[index];
		position = marker.getPosition();
		if (! current_bounds.contains(position))
			outside_bounds = true;
		bounds.extend(position);

		if (show_only)
			g_marker_cluster.addMarker(marker, true);
	}
	if ( show_only == false || (show_only && outside_bounds) ) {
		if (indexes_count === 1) {
			g_map.setCenter(position);
			g_map.setZoom(5);
		}
		else if (indexes_count > 1)
			g_map.fitBounds(bounds);
	}
	if (show_only)
		g_marker_cluster.render();

}

function filter_show_all() {
	g_marker_cluster.addMarkers(g_markers);
	g_map.fitBounds(g_init_bounds);
}
