added location indexes to events

This commit is contained in:
lenovo
2022-11-11 17:53:22 +01:00
parent b5c73fc039
commit 9024a3472b
6 changed files with 87 additions and 32 deletions

View File

@@ -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);

View File

@@ -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;
*/
?>

View File

@@ -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) {

View File

@@ -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 : [{}, ...]
},
...
]
*/
?>

View File

@@ -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);
}

View File

@@ -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;