From 03bfc6214a6e325655d85bf51adff367f0e28c5f Mon Sep 17 00:00:00 2001 From: lenovo Date: Fri, 11 Nov 2022 22:25:50 +0100 Subject: [PATCH] wip try to modify zoom level with filters --- srcs/plugins/map_prof/mp_create_div.php | 4 +- .../plugins/map_prof/scripts/mp_create_map.js | 1 + .../map_prof/scripts/mp_filter_events.js | 38 ++++++++++++++++++- srcs/plugins/map_prof/scripts/mp_init_map.js | 21 +++++----- srcs/plugins/map_prof/styles/mp__style.css | 8 ++++ 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/srcs/plugins/map_prof/mp_create_div.php b/srcs/plugins/map_prof/mp_create_div.php index a37a82d..f1a7f5a 100644 --- a/srcs/plugins/map_prof/mp_create_div.php +++ b/srcs/plugins/map_prof/mp_create_div.php @@ -13,11 +13,11 @@ function mp_create_div(&$filters) {

'.$key.'

-

TOUT DESELECTIONNER

+

TOUT DESELECTIONNER

'; foreach ($filter as $value) { $mp_map_div .= ' -

'.$value->_name.'

+

'.$value->_name.'

'; } $mp_map_div .= ' diff --git a/srcs/plugins/map_prof/scripts/mp_create_map.js b/srcs/plugins/map_prof/scripts/mp_create_map.js index 467ddfe..26eef1c 100644 --- a/srcs/plugins/map_prof/scripts/mp_create_map.js +++ b/srcs/plugins/map_prof/scripts/mp_create_map.js @@ -1,6 +1,7 @@ function create_map(map_div) { // default map center to france let map_center = coordinates_default; + // map_center = {lat:-2.515748362923059, lng:32.93366215464864}; let world_bound = { north: 80, south: -80, diff --git a/srcs/plugins/map_prof/scripts/mp_filter_events.js b/srcs/plugins/map_prof/scripts/mp_filter_events.js index 45df123..60be9ec 100644 --- a/srcs/plugins/map_prof/scripts/mp_filter_events.js +++ b/srcs/plugins/map_prof/scripts/mp_filter_events.js @@ -1,4 +1,38 @@ -function mp_filter_selection(indexes) { - console.log(indexes); +// 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 + +function filter_show_only_selection(indexes) { + console.log("filter_show_only_selection"); + + marker_cluster.clearMarkers(true); + //marker_cluster.removeMarkers(markers, true); + + let current_bounds = map.getBounds(); + console.log("current_bounds:"); + console.log(current_bounds); + let bounds = new google.maps.LatLngBounds(current_bounds); + console.log("bounds:"); + console.log(bounds); + //for (let index of indexes) + + for (let index of indexes) { + let marker = markers[index]; + let position = marker.getPosition(); + console.log(position); + console.log(bounds.contains(position)); + + marker_cluster.addMarker(marker, true); + } + 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 152a9b7..2e34519 100644 --- a/srcs/plugins/map_prof/scripts/mp_init_map.js +++ b/srcs/plugins/map_prof/scripts/mp_init_map.js @@ -1,3 +1,9 @@ + +let map = {}; +let markers = []; +let marker_cluster = {}; +//let bounds = {}; + function mp_init_map() { /* @@ -39,28 +45,21 @@ 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 */ - let map = create_map(map_div); - let markers = create_markers(map, locations, infowindow); - let marker_cluster = draw_clusters(map, markers); + map = create_map(map_div); + markers = create_markers(map, locations, infowindow); + marker_cluster = draw_clusters(map, markers); - //let toggle = true; // add listener to close infowindow at any click on map map.addListener('click', function() { infowindow.close(); - //console.log(toggle); - ////markers[index].setMap(null); - //if (toggle === true) - // marker_cluster.removeMarker(markers[25]); - //else - // marker_cluster.addMarker(markers[25]); - //toggle = (toggle === true)? false : true ; }); } diff --git a/srcs/plugins/map_prof/styles/mp__style.css b/srcs/plugins/map_prof/styles/mp__style.css index e894a4d..c3ff528 100644 --- a/srcs/plugins/map_prof/styles/mp__style.css +++ b/srcs/plugins/map_prof/styles/mp__style.css @@ -16,4 +16,12 @@ color: blue; } +/* TMP */ +.et_pb_module.et_pb_image.et_pb_image_0_tb_header { + display: none; +} +.et-l.et-l--header { + display: none; +} +