locations corresponds to markers

This commit is contained in:
lenovo
2022-11-12 17:22:28 +01:00
parent cda936deb7
commit 07694a71f0
6 changed files with 39 additions and 19 deletions

View File

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

View File

@@ -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 : }
{ }
*/

View File

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

View File

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

View File

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

View File

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