locations corresponds to markers
This commit is contained in:
@@ -25,7 +25,8 @@ function mp_get_coordinates($id) {
|
|||||||
|
|
||||||
// get coordinates from google maps api
|
// get coordinates from google maps api
|
||||||
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
|
$geolocation = 'https://maps.googleapis.com/maps/api/geocode/json'
|
||||||
. '?address=' . urlencode($address)
|
. '?language=fr'
|
||||||
|
. '&address=' . urlencode($address)
|
||||||
. '&key=' . $mp_api_key;
|
. '&key=' . $mp_api_key;
|
||||||
$jsoncontent = file_get_contents($geolocation);
|
$jsoncontent = file_get_contents($geolocation);
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ function mp_already_in_menu(&$menu, $name) {
|
|||||||
return null;
|
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) {
|
function mp_fill_name($fields, $name, &$menu, $index) {
|
||||||
@@ -24,11 +27,13 @@ function mp_fill_name($fields, $name, &$menu, $index) {
|
|||||||
return;
|
return;
|
||||||
if (strlen($fields[$name]) == 0)
|
if (strlen($fields[$name]) == 0)
|
||||||
return;
|
return;
|
||||||
|
// menu_item, ex: for menu "countries" -> france
|
||||||
$menu_item = mp_already_in_menu($menu, $fields[$name]);
|
$menu_item = mp_already_in_menu($menu, $fields[$name]);
|
||||||
if ($menu_item != null) {
|
if ($menu_item != null) {
|
||||||
// no need to add name if already exist
|
// add to this menu item, eg "Austria", the infos of this
|
||||||
// add to lists of event info (cities, countries, ...)
|
// event, like "city" or "category", if not there already
|
||||||
foreach ($fields as $key_field => $value) {
|
foreach ($fields as $key_field => $value) {
|
||||||
|
// no need to add name if already exist
|
||||||
if ($key_field == $name)
|
if ($key_field == $name)
|
||||||
continue;
|
continue;
|
||||||
if (! isset($menu_item->$key_field) )
|
if (! isset($menu_item->$key_field) )
|
||||||
@@ -38,10 +43,15 @@ function mp_fill_name($fields, $name, &$menu, $index) {
|
|||||||
array_push($menu_item->$key_field, $value);
|
array_push($menu_item->$key_field, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add to list of location index
|
// add location index, if not there already
|
||||||
if (! in_array($index, $menu_item->indexes) )
|
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);
|
array_push($menu_item->indexes, $index);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
$menu_item = (object)[];
|
$menu_item = (object)[];
|
||||||
$menu_item->_name = $fields[$name];
|
$menu_item->_name = $fields[$name];
|
||||||
@@ -54,8 +64,11 @@ function mp_fill_name($fields, $name, &$menu, $index) {
|
|||||||
array_push($menu_item->$key_field, $value);
|
array_push($menu_item->$key_field, $value);
|
||||||
}
|
}
|
||||||
// add list of location index
|
// add list of location index
|
||||||
$menu_item->indexes = [];
|
mp_console_log("add index:");
|
||||||
array_push($menu_item->indexes, $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
|
// and add this item to list of menu
|
||||||
array_push($menu, $menu_item);
|
array_push($menu, $menu_item);
|
||||||
@@ -68,11 +81,13 @@ function mp_get_filters(&$events) {
|
|||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
$fields = array(
|
$fields = array(
|
||||||
"pays" => $event->location->country,
|
"pays" => $event->location->country,
|
||||||
"villes" => $event->location->city,
|
|
||||||
"categories" => $event->categorie,
|
"categories" => $event->categorie,
|
||||||
"mode" => ($event->irl)? "En présentiel" : "En ligne",
|
"mode" => ($event->irl)? "En présentiel" : "En ligne",
|
||||||
);
|
);
|
||||||
$index = $event->index;
|
$index = $event->index;
|
||||||
|
mp_console_log(" ");
|
||||||
|
mp_console_log("EVENT:");
|
||||||
|
mp_console_log($event);
|
||||||
foreach ($fields as $key => $value) {
|
foreach ($fields as $key => $value) {
|
||||||
if (! isset($filters->$key))
|
if (! isset($filters->$key))
|
||||||
$filters->$key = [];
|
$filters->$key = [];
|
||||||
@@ -91,13 +106,12 @@ function mp_get_filters(&$events) {
|
|||||||
{ }
|
{ }
|
||||||
{ [ ] }
|
{ [ ] }
|
||||||
filters: { - countries : [ { - _name : "" } ] }
|
filters: { - countries : [ { - _name : "" } ] }
|
||||||
{ [ { - cities : [] } ] }
|
|
||||||
{ [ { - categories: [] } ] }
|
{ [ { - categories: [] } ] }
|
||||||
{ [ { - indexes : [] }, ... ] }
|
{ [ { - indexes : [] }, ... ] }
|
||||||
{ [ ] }
|
{ [ ] }
|
||||||
{ }
|
{ }
|
||||||
{ - cities : }
|
|
||||||
{ - categories: }
|
{ - categories: }
|
||||||
|
{ - modes : }
|
||||||
{ }
|
{ }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ function mp_coord_already_exist(&$coordinates, &$locations) {
|
|||||||
|
|
||||||
function mp_sort_n_insert(&$event, &$locations) {
|
function mp_sort_n_insert(&$event, &$locations) {
|
||||||
$coordinates = $event->location->coordinates;
|
$coordinates = $event->location->coordinates;
|
||||||
|
if ($coordinates == null)
|
||||||
|
return;
|
||||||
|
|
||||||
$already_exist = mp_coord_already_exist($coordinates, $locations);
|
$already_exist = mp_coord_already_exist($coordinates, $locations);
|
||||||
if ($already_exist) {
|
if ($already_exist) {
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ function create_markers(map, locations, infowindow) {
|
|||||||
let markers = [];
|
let markers = [];
|
||||||
for (loc of locations) {
|
for (loc of locations) {
|
||||||
|
|
||||||
if (loc.coordinates == null) {
|
if (loc.coordinates == null)
|
||||||
//console.log("coordinates == null");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
let count = loc.events.length;
|
let count = loc.events.length;
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
*/
|
*/
|
||||||
function filter_show_only_selection(indexes, show_only = true) {
|
function filter_show_only_selection(indexes, show_only = true) {
|
||||||
|
|
||||||
|
console.log("indexes:");
|
||||||
|
console.log(indexes);
|
||||||
|
|
||||||
let indexes_count = indexes.length;
|
let indexes_count = indexes.length;
|
||||||
if (indexes_count === 0)
|
if (indexes_count === 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ function mp_init_map() {
|
|||||||
* - let cluster_size_factor = Number
|
* - let cluster_size_factor = Number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//console.log("locations:");
|
console.log("locations:");
|
||||||
//console.log(locations);
|
console.log(locations);
|
||||||
console.log("filters:");
|
console.log("filters:");
|
||||||
console.log(filters);
|
console.log(filters);
|
||||||
|
|
||||||
@@ -58,6 +58,8 @@ function mp_init_map() {
|
|||||||
|
|
||||||
g_map = create_map(map_div);
|
g_map = create_map(map_div);
|
||||||
g_markers = create_markers(g_map, locations, infowindow);
|
g_markers = create_markers(g_map, locations, infowindow);
|
||||||
|
console.log("markers:");
|
||||||
|
console.log(g_markers);
|
||||||
g_marker_cluster = draw_clusters(g_map, g_markers);
|
g_marker_cluster = draw_clusters(g_map, g_markers);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user