diff --git a/srcs/plugins/map_prof/map_prof_hooks.php b/srcs/plugins/map_prof/map_prof_hooks.php index 16ca840..187c657 100644 --- a/srcs/plugins/map_prof/map_prof_hooks.php +++ b/srcs/plugins/map_prof/map_prof_hooks.php @@ -59,6 +59,7 @@ function mp_ljdp_map() { wp_enqueue_script('mp_errors_map', plugins_url('scripts/mp_errors_map.js', __FILE__), '', '', false); wp_enqueue_script('mp_create_filters', plugins_url('scripts/mp_create_filters.js', __FILE__), '', '', false); wp_enqueue_script('mp_create_markers', plugins_url('scripts/mp_create_markers.js', __FILE__), '', '', false); + wp_enqueue_script('mp_create_map', plugins_url('scripts/mp_create_map.js', __FILE__), '', '', false); wp_enqueue_script('mp_draw_clusters', plugins_url('scripts/mp_draw_clusters.js', __FILE__), '', '', false); wp_enqueue_script('mp_filter_events', plugins_url('scripts/mp_filter_events.js', __FILE__), '', '', false); @@ -80,6 +81,11 @@ function mp_ljdp_map() { //mp_console_log("php locations:"); //mp_console_log($locations); + mp_console_log("php events:"); + mp_console_log($events); + mp_console_log("php locations:"); + mp_console_log($locations); + $filters = mp_get_filters($events); //mp_console_log("php filters:"); //mp_console_log($filters); diff --git a/srcs/plugins/map_prof/mp_get_events.php b/srcs/plugins/map_prof/mp_get_events.php index a2100be..1bb0f7b 100644 --- a/srcs/plugins/map_prof/mp_get_events.php +++ b/srcs/plugins/map_prof/mp_get_events.php @@ -177,4 +177,30 @@ function mp_get_published_events() { return $events; } +/* + event : {} + - heure_de_debut : ""; + - heure_de_fin : ""; + - categorie : ""; + - date : ""; + - pays : ""; + - ville : ""; + - adresse : ""; + - prenom : ""; + - nom : ""; + - irl : bool; + - id : x; + - title : ""; + - location : {} + - street : ""; + - city : ""; + - country : ""; + - address : ""; + - approximate : bool; + - coordinates : {} + - lat : x; + - lng : x; +*/ + + ?> diff --git a/srcs/plugins/map_prof/mp_get_filters.php b/srcs/plugins/map_prof/mp_get_filters.php index 9130221..8507e66 100644 --- a/srcs/plugins/map_prof/mp_get_filters.php +++ b/srcs/plugins/map_prof/mp_get_filters.php @@ -51,7 +51,7 @@ function mp_fill_name($fields, $name, &$menu) { } } -function mp_get_filters($events) { +function mp_get_filters(&$events) { $filters = (object)[]; foreach ($events as $event) { diff --git a/srcs/plugins/map_prof/mp_sort_events.php b/srcs/plugins/map_prof/mp_sort_events.php index f95c85a..7a473f4 100644 --- a/srcs/plugins/map_prof/mp_sort_events.php +++ b/srcs/plugins/map_prof/mp_sort_events.php @@ -14,6 +14,9 @@ function mp_sort_n_insert(&$event, &$locations) { $already_exist = mp_coord_already_exist($coordinates, $locations); if ($already_exist) { + // add index to the event + $index = $already_exist->index; + $event->index = $index; // add event to events[] array_push($already_exist->events, $event); } @@ -22,6 +25,10 @@ function mp_sort_n_insert(&$event, &$locations) { $location = (object)[]; $location->events = []; + // add index to the location and event + $index = count($locations); + $location->index = $index; + $event->index = $index; // add coordinates to the location $location->coordinates = $coordinates; // add first event to events[] @@ -31,7 +38,7 @@ function mp_sort_n_insert(&$event, &$locations) { } } -function mp_sort_events($events) { +function mp_sort_events(&$events) { $locations = []; foreach ($events as $event) { @@ -41,4 +48,17 @@ function mp_sort_events($events) { return $locations; } +/* + + locations = [ + { + index : x + coordinates: {} + events : [{}, ...] + }, + ... + ] + +*/ + ?> diff --git a/srcs/plugins/map_prof/scripts/mp_create_map.js b/srcs/plugins/map_prof/scripts/mp_create_map.js new file mode 100644 index 0000000..467ddfe --- /dev/null +++ b/srcs/plugins/map_prof/scripts/mp_create_map.js @@ -0,0 +1,30 @@ +function create_map(map_div) { + // default map center to france + let map_center = coordinates_default; + let world_bound = { + north: 80, + south: -80, + west: -180, + east: 180, + }; + let map_options = { + /* map options : https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions */ + disableDefaultUI: true, + zoomControl: true, + scaleControl: true, + zoom: 2, + gestureHandling: "cooperative", + //gestureHandling: "greedy", + //gestureHandling: "none", + //gestureHandling: "auto", + //disableDoubleClickZoom: "false", //deprecated + //draggable: "true", //deprecated + center: map_center, + restriction: { + latLngBounds: world_bound, + strictBounds: true, + }, + } + + return new google.maps.Map(map_div, map_options); +} diff --git a/srcs/plugins/map_prof/scripts/mp_init_map.js b/srcs/plugins/map_prof/scripts/mp_init_map.js index 16a7634..bd05dcb 100644 --- a/srcs/plugins/map_prof/scripts/mp_init_map.js +++ b/srcs/plugins/map_prof/scripts/mp_init_map.js @@ -23,7 +23,6 @@ function mp_init_map() { * { - mode : ... } * { } * - * - let filters * - let coordinates_default = {lat: ,lng: } * - let icon_color = "" * - let icon_color_back = "" @@ -36,45 +35,19 @@ function mp_init_map() { console.log("filters:"); console.log(filters); - // default map center to france - let map_center = coordinates_default; - let world_bound = { - north: 80, - south: -80, - west: -180, - east: 180, - }; - let map_options = { - /* map options : https://developers.google.com/maps/documentation/javascript/reference/map#MapOptions */ - disableDefaultUI: true, - zoomControl: true, - scaleControl: true, - zoom: 2, - gestureHandling: "cooperative", - //gestureHandling: "greedy", - //gestureHandling: "none", - //gestureHandling: "auto", - //disableDoubleClickZoom: "false", //deprecated - //draggable: "true", //deprecated - center: map_center, - restriction: { - latLngBounds: world_bound, - strictBounds: true, - }, - } let map_div = document.getElementById("ljdp_map"); + //let filters_div = document.getElementById("ljdp_map_filters"); let infowindow = new google.maps.InfoWindow(); + /* * DRAW MAP */ - let map = new google.maps.Map(map_div, map_options); + let map = create_map(map_div); let markers = create_markers(map, locations, infowindow); let marker_cluster = draw_clusters(map, markers); - let filters_div = document.getElementById("ljdp_map_filters"); - //fill_filters(filters_div); // add listener to close infowindow at any click on map let toggle = true;