diff --git a/srcs/plugins/map_prof/mp_create_div.php b/srcs/plugins/map_prof/mp_create_div.php index f1a7f5a..af85fec 100644 --- a/srcs/plugins/map_prof/mp_create_div.php +++ b/srcs/plugins/map_prof/mp_create_div.php @@ -17,7 +17,7 @@ function mp_create_div(&$filters) { '; foreach ($filter as $value) { $mp_map_div .= ' -

'.$value->_name.'

+

'.$value->_name.'

'; } $mp_map_div .= ' diff --git a/srcs/plugins/map_prof/scripts/mp_filter_events.js b/srcs/plugins/map_prof/scripts/mp_filter_events.js index 60be9ec..258460f 100644 --- a/srcs/plugins/map_prof/scripts/mp_filter_events.js +++ b/srcs/plugins/map_prof/scripts/mp_filter_events.js @@ -3,36 +3,54 @@ // add true for noDraw // bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625 -function filter_show_only_selection(indexes) { - console.log("filter_show_only_selection"); +/** + * 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) { - marker_cluster.clearMarkers(true); - //marker_cluster.removeMarkers(markers, true); + let indexes_count = indexes.length; + if (indexes_count === 0) + return; - let current_bounds = map.getBounds(); + 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(current_bounds); + let bounds = new google.maps.LatLngBounds(position); console.log("bounds:"); console.log(bounds); - //for (let index of indexes) + let outside_bounds = false; for (let index of indexes) { - let marker = markers[index]; - let position = marker.getPosition(); - console.log(position); - console.log(bounds.contains(position)); + marker = g_markers[index]; + position = marker.getPosition(); + if (! current_bounds.contains(position)) + outside_bounds = true; + bounds.extend(position); - marker_cluster.addMarker(marker, true); + if (show_only) + g_marker_cluster.addMarker(marker, true); } - marker_cluster.render(); + 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() { console.log("filter_show_all"); marker_cluster.addMarkers(markers); } - -function filter_zoom_on_selection(indexes) { - marker_cluster.addMarkers(markers); -} diff --git a/srcs/plugins/map_prof/scripts/mp_init_map.js b/srcs/plugins/map_prof/scripts/mp_init_map.js index 2e34519..c12bfa0 100644 --- a/srcs/plugins/map_prof/scripts/mp_init_map.js +++ b/srcs/plugins/map_prof/scripts/mp_init_map.js @@ -1,8 +1,7 @@ -let map = {}; -let markers = []; -let marker_cluster = {}; -//let bounds = {}; +let g_map = {}; +let g_markers = []; +let g_marker_cluster = {}; function mp_init_map() { @@ -45,20 +44,19 @@ function mp_init_map() { let map_div = document.getElementById("ljdp_map"); //let filters_div = document.getElementById("ljdp_map_filters"); let infowindow = new google.maps.InfoWindow(); - //bounds = new google.maps.LatLngBounds(); /* * DRAW MAP */ - map = create_map(map_div); - markers = create_markers(map, locations, infowindow); - marker_cluster = draw_clusters(map, markers); + g_map = create_map(map_div); + g_markers = create_markers(g_map, locations, infowindow); + g_marker_cluster = draw_clusters(g_map, g_markers); // add listener to close infowindow at any click on map - map.addListener('click', function() { + g_map.addListener('click', function() { infowindow.close(); });