diff --git a/srcs/plugins/map_prof/mp_get_coordinates.php b/srcs/plugins/map_prof/mp_get_coordinates.php index 040749c..911dbc7 100644 --- a/srcs/plugins/map_prof/mp_get_coordinates.php +++ b/srcs/plugins/map_prof/mp_get_coordinates.php @@ -25,7 +25,8 @@ function mp_get_coordinates($id) { // get coordinates from google maps api $geolocation = 'https://maps.googleapis.com/maps/api/geocode/json' - . '?address=' . urlencode($address) + . '?language=fr' + . '&address=' . urlencode($address) . '&key=' . $mp_api_key; $jsoncontent = file_get_contents($geolocation); diff --git a/srcs/plugins/map_prof/mp_get_filters.php b/srcs/plugins/map_prof/mp_get_filters.php index d94af02..888bed1 100644 --- a/srcs/plugins/map_prof/mp_get_filters.php +++ b/srcs/plugins/map_prof/mp_get_filters.php @@ -12,10 +12,13 @@ function mp_already_in_menu(&$menu, $name) { return null; } -/* - menu: [ { _name:"", field_1:[], field_2:[] }, ... ] - fields: [ countries:"", cities:"", categories:"", ... ] -*/ + +/** + * fields: [ countries:"", cities:"", categories:"", ... ] + * name : field's values -> countries, cities, categories, ... + * menu : [ { _name:"", field_1:[], field_2:[] }, ... ] + * index : index of this event in locations[] array + */ function mp_fill_name($fields, $name, &$menu, $index) { if ($fields[$name] == null) @@ -24,11 +27,13 @@ function mp_fill_name($fields, $name, &$menu, $index) { return; if (strlen($fields[$name]) == 0) return; + // menu_item, ex: for menu "countries" -> france $menu_item = mp_already_in_menu($menu, $fields[$name]); if ($menu_item != null) { - // no need to add name if already exist - // add to lists of event info (cities, countries, ...) + // add to this menu item, eg "Austria", the infos of this + // event, like "city" or "category", if not there already foreach ($fields as $key_field => $value) { + // no need to add name if already exist if ($key_field == $name) continue; if (! isset($menu_item->$key_field) ) @@ -38,9 +43,14 @@ function mp_fill_name($fields, $name, &$menu, $index) { array_push($menu_item->$key_field, $value); } } - // add to list of location index - if (! in_array($index, $menu_item->indexes) ) + // add location index, if not there already + if (! in_array($index, $menu_item->indexes) ) { + mp_console_log("add index:"); + mp_console_log($index); + mp_console_log("to menu_item:"); + mp_console_log($menu_item); array_push($menu_item->indexes, $index); + } } else { $menu_item = (object)[]; @@ -54,8 +64,11 @@ function mp_fill_name($fields, $name, &$menu, $index) { array_push($menu_item->$key_field, $value); } // add list of location index - $menu_item->indexes = []; - array_push($menu_item->indexes, $index); + mp_console_log("add index:"); + mp_console_log($index); + mp_console_log("to menu_item:"); + mp_console_log($menu_item); + $menu_item->indexes = [$index]; // and add this item to list of menu array_push($menu, $menu_item); @@ -68,11 +81,13 @@ function mp_get_filters(&$events) { foreach ($events as $event) { $fields = array( "pays" => $event->location->country, - "villes" => $event->location->city, "categories" => $event->categorie, "mode" => ($event->irl)? "En présentiel" : "En ligne", ); $index = $event->index; + mp_console_log(" "); + mp_console_log("EVENT:"); + mp_console_log($event); foreach ($fields as $key => $value) { if (! isset($filters->$key)) $filters->$key = []; @@ -91,13 +106,12 @@ function mp_get_filters(&$events) { { } { [ ] } filters: { - countries : [ { - _name : "" } ] } - { [ { - cities : [] } ] } { [ { - categories: [] } ] } { [ { - indexes : [] }, ... ] } { [ ] } { } - { - cities : } { - categories: } + { - modes : } { } */ diff --git a/srcs/plugins/map_prof/mp_sort_events.php b/srcs/plugins/map_prof/mp_sort_events.php index 7a473f4..8ff65e5 100644 --- a/srcs/plugins/map_prof/mp_sort_events.php +++ b/srcs/plugins/map_prof/mp_sort_events.php @@ -11,6 +11,8 @@ function mp_coord_already_exist(&$coordinates, &$locations) { function mp_sort_n_insert(&$event, &$locations) { $coordinates = $event->location->coordinates; + if ($coordinates == null) + return; $already_exist = mp_coord_already_exist($coordinates, $locations); if ($already_exist) { diff --git a/srcs/plugins/map_prof/scripts/mp_create_markers.js b/srcs/plugins/map_prof/scripts/mp_create_markers.js index 5b80856..42a4d4e 100644 --- a/srcs/plugins/map_prof/scripts/mp_create_markers.js +++ b/srcs/plugins/map_prof/scripts/mp_create_markers.js @@ -21,10 +21,8 @@ function create_markers(map, locations, infowindow) { let markers = []; for (loc of locations) { - if (loc.coordinates == null) { - //console.log("coordinates == null"); + if (loc.coordinates == null) continue; - } let count = loc.events.length; diff --git a/srcs/plugins/map_prof/scripts/mp_filter_events.js b/srcs/plugins/map_prof/scripts/mp_filter_events.js index 74e0a09..e231db8 100644 --- a/srcs/plugins/map_prof/scripts/mp_filter_events.js +++ b/srcs/plugins/map_prof/scripts/mp_filter_events.js @@ -10,6 +10,9 @@ */ function filter_show_only_selection(indexes, show_only = true) { + console.log("indexes:"); + console.log(indexes); + let indexes_count = indexes.length; if (indexes_count === 0) return; diff --git a/srcs/plugins/map_prof/scripts/mp_init_map.js b/srcs/plugins/map_prof/scripts/mp_init_map.js index 41f9a4f..854c95a 100644 --- a/srcs/plugins/map_prof/scripts/mp_init_map.js +++ b/srcs/plugins/map_prof/scripts/mp_init_map.js @@ -42,8 +42,8 @@ function mp_init_map() { * - let cluster_size_factor = Number */ - //console.log("locations:"); - //console.log(locations); + console.log("locations:"); + console.log(locations); console.log("filters:"); console.log(filters); @@ -58,6 +58,8 @@ function mp_init_map() { g_map = create_map(map_div); g_markers = create_markers(g_map, locations, infowindow); + console.log("markers:"); + console.log(g_markers); g_marker_cluster = draw_clusters(g_map, g_markers);