filters intersection works well
This commit is contained in:
13
README.md
13
README.md
@@ -2,10 +2,19 @@
|
|||||||
|
|
||||||
#### todo
|
#### todo
|
||||||
- [/] copy recent site version
|
- [/] copy recent site version
|
||||||
- [ ] create links
|
- [/] create links
|
||||||
- [ ] make links having map
|
- [/] make links having map
|
||||||
- [ ] transform filter list in select
|
- [ ] transform filter list in select
|
||||||
- [ ] make two infowindow size
|
- [ ] make two infowindow size
|
||||||
|
- ne pas ouvrir sur un nouvel onglet
|
||||||
|
- responsive
|
||||||
|
- pays
|
||||||
|
- categories
|
||||||
|
- irl / online
|
||||||
|
- effacer -> bouton carre, fond violet, ecriture blanche, en capitale, arrondis de 3px sur les coins
|
||||||
|
- sur ordi carte hauteur 600px, sur telephone 500px
|
||||||
|
- "reinitialiser" avec accents, ou "effacer", "Pays" et "Categories" avec les accents
|
||||||
|
- enlever le bandeau de scroll des menus
|
||||||
if time:
|
if time:
|
||||||
- [ ] deal with error double event irl and online
|
- [ ] deal with error double event irl and online
|
||||||
- [ ] deal with multiplication of filters
|
- [ ] deal with multiplication of filters
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ function mp_ljdp_map() {
|
|||||||
if (is_event_post()) {
|
if (is_event_post()) {
|
||||||
$mp_zoom = $mp_zoom_set[1];
|
$mp_zoom = $mp_zoom_set[1];
|
||||||
|
|
||||||
$location = get_field(location);
|
$location = get_field("location");
|
||||||
$coordinates = $location->coordinates;
|
$coordinates = $location->coordinates;
|
||||||
|
|
||||||
$mp_coordinates_default = $coordinates;
|
$mp_coordinates_default = $coordinates;
|
||||||
|
|||||||
@@ -15,14 +15,8 @@ function mp_filter_drop_down($key, &$filter) {
|
|||||||
<div class="filter_menu_drop_items" tabindex=0>
|
<div class="filter_menu_drop_items" tabindex=0>
|
||||||
';
|
';
|
||||||
foreach ($filter as $value) {
|
foreach ($filter as $value) {
|
||||||
/*
|
|
||||||
<p id="'.$value->_name. '" onblur="filter_show_only_selection('.json_encode($value->indexes).')">'.$value->_name.'</p>
|
|
||||||
<p id="'.$value->_name. '" onfocus="filter_show_only_selection('.json_encode($value->indexes).')">'.$value->_name.'</p>
|
|
||||||
<p id="'.$value->_name. '" onfocusin="filter_show_only_selection('.json_encode($value->indexes).')">'.$value->_name.'</p>
|
|
||||||
<p id="'.$value->_name.'" onfocusout="filter_show_only_selection('.json_encode($value->indexes).')">'.$value->_name.'</p>
|
|
||||||
*/
|
|
||||||
$content .= '
|
$content .= '
|
||||||
<p id="'.$value->_name. '" onclick="filter_show_only_selection(this, '.json_encode($value->indexes).')">'.$value->_name.'</p>
|
<p onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".')">'.$value->_name.'</p>
|
||||||
';
|
';
|
||||||
}
|
}
|
||||||
$content .= '
|
$content .= '
|
||||||
@@ -40,7 +34,7 @@ function mp_filter_buttons($key, &$filter) {
|
|||||||
$content = '';
|
$content = '';
|
||||||
foreach ($filter as $value) {
|
foreach ($filter as $value) {
|
||||||
$content .= '
|
$content .= '
|
||||||
<input id="checkbox_'.$value->_name.'" class="filter_menu_checkbox" type="checkbox" style="display:none;" onclick="filter_show_only_selection(this, '.json_encode($value->indexes).')">
|
<input id="checkbox_'.$value->_name.'" class="filter_menu_checkbox" type="checkbox" style="display:none;" onclick="filter_show_only_selection(this, '.json_encode($value->indexes).', '."'".$key."'".', true)">
|
||||||
<label for="checkbox_'.$value->_name.'" class="filter_menu_checkbox filter_menu">
|
<label for="checkbox_'.$value->_name.'" class="filter_menu_checkbox filter_menu">
|
||||||
<div class="filter_menu_title filter_menu_checkbox_title" tabindex=0>
|
<div class="filter_menu_title filter_menu_checkbox_title" tabindex=0>
|
||||||
<p>'.$value->_name.'</p>
|
<p>'.$value->_name.'</p>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ function mp_url_api() {
|
|||||||
foreach ($mp_url as $url_key => $url_value) {
|
foreach ($mp_url as $url_key => $url_value) {
|
||||||
if ($url_key === 'src') {
|
if ($url_key === 'src') {
|
||||||
$mp_src .= $url_value;
|
$mp_src .= $url_value;
|
||||||
if (count($mp_url > 1))
|
if (count($mp_url) > 1)
|
||||||
$mp_src .= "?";
|
$mp_src .= "?";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -9,12 +9,15 @@ function create_map(map_div) {
|
|||||||
zoomControl: true,
|
zoomControl: true,
|
||||||
scaleControl: true,
|
scaleControl: true,
|
||||||
zoom: map_zoom,
|
zoom: map_zoom,
|
||||||
gestureHandling: "cooperative",
|
|
||||||
//gestureHandling: "greedy",
|
//gestureHandling: "cooperative",
|
||||||
|
gestureHandling: "greedy",
|
||||||
//gestureHandling: "none",
|
//gestureHandling: "none",
|
||||||
//gestureHandling: "auto",
|
//gestureHandling: "auto",
|
||||||
//disableDoubleClickZoom: "false", //deprecated
|
|
||||||
//draggable: "true", //deprecated
|
//disableDoubleClickZoom: "false", // deprecated
|
||||||
|
//draggable: "true", // deprecated
|
||||||
|
|
||||||
center: map_center,
|
center: map_center,
|
||||||
restriction: {
|
restriction: {
|
||||||
latLngBounds: world_bound,
|
latLngBounds: world_bound,
|
||||||
|
|||||||
@@ -4,29 +4,85 @@
|
|||||||
// bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625
|
// bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return intersection of both arrays : indexes and g_indexes
|
|
||||||
*/
|
|
||||||
|
|
||||||
function filter_selection_indexes(indexes, invert) {
|
function array_first_not_in_second(first, second) {
|
||||||
// if g_indexes empty, just fill it with indexes
|
let temp_array = [];
|
||||||
// because it's like intersection of indexes and g_indexes if g_indexes was the list of all markers
|
for (let index of first) {
|
||||||
if (g_indexes.length == 0) {
|
if (second.indexOf(index) == -1) {
|
||||||
// deep copy of indexes
|
temp_array.push(index);
|
||||||
g_indexes = [].concat(indexes);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
let intersection = [];
|
|
||||||
for (let index of indexes) {
|
|
||||||
if (g_indexes.indexOf(index) != -1)
|
|
||||||
intersection.push(index);
|
|
||||||
}
|
|
||||||
// if no intersection found, the filter shouldn't be selectable, so this shouldn't happen
|
|
||||||
if (intersection.length)
|
|
||||||
g_indexes = intersection;
|
|
||||||
}
|
}
|
||||||
|
return temp_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
function filter_selection_indexes(menu, indexes, reverse, add) {
|
||||||
|
|
||||||
|
// if reverse is true, delete all indexes in g_indexes.menu
|
||||||
|
if (reverse) {
|
||||||
|
// https://stackoverflow.com/questions/5113374/javascript-check-if-variable-exists-is-defined-initialized
|
||||||
|
if ( typeof(g_indexes[menu]) !== "undefined" && g_indexes[menu] !== null ) {
|
||||||
|
// creates an array with all values of g_indexes[menu] minus indexes
|
||||||
|
let temp_array = array_first_not_in_second(g_indexes[menu], indexes);
|
||||||
|
if (temp_array.length === 0)
|
||||||
|
delete g_indexes[menu];
|
||||||
|
else
|
||||||
|
g_indexes[menu] = [].concat(temp_array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (add && typeof(g_indexes[menu]) !== "undefined") {
|
||||||
|
// add array of menus to g_indexes{}
|
||||||
|
// creates an array with all values of indexes that are not in g_indexes[menu] already
|
||||||
|
let temp_array = array_first_not_in_second(indexes, g_indexes[menu]);
|
||||||
|
g_indexes[menu] = g_indexes[menu].concat(temp_array);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// replace or create array of menu in g_indexes{}
|
||||||
|
g_indexes[menu] = [].concat(indexes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop through all arrays of g_indexes to find intersection
|
||||||
|
// take first one as comparison
|
||||||
|
let keys = Object.keys(g_indexes);
|
||||||
|
let intersection = [];
|
||||||
|
let compare = [];
|
||||||
|
keys.forEach((key, i) => {
|
||||||
|
if (i == 0) {
|
||||||
|
intersection = g_indexes[key];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let temp = [];
|
||||||
|
compare = g_indexes[key];
|
||||||
|
for (let index of intersection) {
|
||||||
|
if (compare.indexOf(index) != -1)
|
||||||
|
temp.push(index);
|
||||||
|
}
|
||||||
|
intersection = [].concat(temp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return intersection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function is_element_unchecked(element) {
|
||||||
|
if (typeof(element) === "undefined")
|
||||||
|
return false;
|
||||||
|
if (typeof(element.attributes) === "undefined")
|
||||||
|
return false;
|
||||||
|
if (typeof(element.attributes.type) === "undefined")
|
||||||
|
return false;
|
||||||
|
value = element.attributes.type.value;
|
||||||
|
if (value === "checkbox") {
|
||||||
|
return ! element.checked;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if zoom_in is true:
|
* if zoom_in is true:
|
||||||
@@ -34,29 +90,18 @@ function filter_selection_indexes(indexes, invert) {
|
|||||||
* even if already visible in current view
|
* even if already visible in current view
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function filter_show_only_selection(element, indexes, zoom_in = false) {
|
function filter_show_only_selection(element, indexes, menu, add = false, zoom_in = false) {
|
||||||
//console.log("element:");
|
|
||||||
//console.log(element);
|
|
||||||
//console.log("element.checked:");
|
|
||||||
//console.log(element.checked);
|
|
||||||
//console.log("element.attributes.type:");
|
|
||||||
//console.log(element.attributes.type);
|
|
||||||
//console.log("element.attributes.type.value:");
|
|
||||||
//console.log(element.attributes.type.value);
|
|
||||||
|
|
||||||
let type = element.attributes.type;
|
let reverse = is_element_unchecked(element);
|
||||||
let invert = false;
|
|
||||||
if (type != null)
|
|
||||||
type = type.value;
|
|
||||||
if (type === "checkbox")
|
|
||||||
invert = true;
|
|
||||||
// if checkbox is unchecked, re-add filters
|
|
||||||
filter_selection_indexes(indexes, invert);
|
|
||||||
|
|
||||||
let indexes_count = g_indexes.length;
|
let index_array = filter_selection_indexes(menu, indexes, reverse, add);
|
||||||
if (indexes_count === 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
let indexes_count = index_array.length;
|
||||||
|
|
||||||
|
// if there is no indexes,
|
||||||
|
// if object is not empty, just render zero markers
|
||||||
|
// if object is empty, shall all markers
|
||||||
|
if (indexes_count !== 0) {
|
||||||
g_marker_cluster.clearMarkers(true);
|
g_marker_cluster.clearMarkers(true);
|
||||||
|
|
||||||
let marker = g_markers[0];
|
let marker = g_markers[0];
|
||||||
@@ -65,7 +110,7 @@ function filter_show_only_selection(element, indexes, zoom_in = false) {
|
|||||||
let bounds = new google.maps.LatLngBounds(position);
|
let bounds = new google.maps.LatLngBounds(position);
|
||||||
|
|
||||||
let outside_bounds = false;
|
let outside_bounds = false;
|
||||||
for (let index of g_indexes) {
|
for (let index of index_array) {
|
||||||
marker = g_markers[index];
|
marker = g_markers[index];
|
||||||
position = marker.getPosition();
|
position = marker.getPosition();
|
||||||
if (! current_bounds.contains(position))
|
if (! current_bounds.contains(position))
|
||||||
@@ -82,12 +127,20 @@ function filter_show_only_selection(element, indexes, zoom_in = false) {
|
|||||||
else if (indexes_count > 1)
|
else if (indexes_count > 1)
|
||||||
g_map.fitBounds(bounds);
|
g_map.fitBounds(bounds);
|
||||||
}
|
}
|
||||||
g_marker_cluster.render();
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if ( Object.keys(g_indexes).length === 0 ) { // object is empty, there are no filters
|
||||||
|
g_marker_cluster.addMarkers(g_markers, true);
|
||||||
|
}
|
||||||
|
else { // filters intersection lets no markers on the map
|
||||||
|
g_marker_cluster.clearMarkers(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_marker_cluster.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter_show_all() {
|
function filter_show_all() {
|
||||||
g_indexes = [];
|
g_indexes = {};
|
||||||
g_marker_cluster.addMarkers(g_markers);
|
g_marker_cluster.addMarkers(g_markers);
|
||||||
//g_map.fitBounds(g_init_bounds);
|
//g_map.fitBounds(g_init_bounds);
|
||||||
g_map.setCenter(coordinates_default);
|
g_map.setCenter(coordinates_default);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const g_init_bounds = {
|
|||||||
west: -180,
|
west: -180,
|
||||||
east: 180,
|
east: 180,
|
||||||
};
|
};
|
||||||
let g_indexes = [];
|
let g_indexes = {};
|
||||||
|
|
||||||
function mp_init_map() {
|
function mp_init_map() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user