filters multiple selection intersect well

This commit is contained in:
lenovo
2022-11-13 11:01:18 +01:00
parent 36a55260fe
commit d34d18e88d
4 changed files with 68 additions and 30 deletions

View File

@@ -4,6 +4,30 @@
// 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) {
// if g_indexes empty, just fill it with indexes
// because it's like intersection of indexes and g_indexes if g_indexes was the list of all markers
if (g_indexes.length == 0) {
// deep copy of indexes
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;
}
}
/**
* if zoom_in is true:
* zoom to new selection,
@@ -12,11 +36,9 @@
function filter_show_only_selection(indexes, zoom_in = false) {
console.log(" ");
console.log("indexes:");
console.log(indexes);
filter_selection_indexes(indexes);
let indexes_count = indexes.length;
let indexes_count = g_indexes.length;
if (indexes_count === 0)
return;
@@ -25,14 +47,10 @@ console.log(indexes);
let marker = g_markers[0];
let position = marker.getPosition();
let current_bounds = g_map.getBounds();
console.log("current_bounds:");
console.log(current_bounds);
let bounds = new google.maps.LatLngBounds(position);
console.log("bounds:");
console.log(bounds);
let outside_bounds = false;
for (let index of indexes) {
for (let index of g_indexes) {
marker = g_markers[index];
position = marker.getPosition();
if (! current_bounds.contains(position))
@@ -54,6 +72,7 @@ console.log(bounds);
}
function filter_show_all() {
g_indexes = [];
g_marker_cluster.addMarkers(g_markers);
//g_map.fitBounds(g_init_bounds);
g_map.setCenter(coordinates_default);

View File

@@ -8,6 +8,7 @@ const g_init_bounds = {
west: -180,
east: 180,
};
let g_indexes = [];
function mp_init_map() {