wip try to modify zoom level with filters

This commit is contained in:
lenovo
2022-11-11 22:25:50 +01:00
parent 9332c05274
commit 03bfc6214a
5 changed files with 57 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
function create_map(map_div) {
// default map center to france
let map_center = coordinates_default;
// map_center = {lat:-2.515748362923059, lng:32.93366215464864};
let world_bound = {
north: 80,
south: -80,

View File

@@ -1,4 +1,38 @@
function mp_filter_selection(indexes) {
console.log(indexes);
// https://googlemaps.github.io/js-markerclusterer/classes/MarkerClusterer.html
// add true for noDraw
// bounds : https://stackoverflow.com/questions/19304574/center-set-zoom-of-map-to-cover-all-visible-markers/19304625#19304625
function filter_show_only_selection(indexes) {
console.log("filter_show_only_selection");
marker_cluster.clearMarkers(true);
//marker_cluster.removeMarkers(markers, true);
let current_bounds = map.getBounds();
console.log("current_bounds:");
console.log(current_bounds);
let bounds = new google.maps.LatLngBounds(current_bounds);
console.log("bounds:");
console.log(bounds);
//for (let index of indexes)
for (let index of indexes) {
let marker = markers[index];
let position = marker.getPosition();
console.log(position);
console.log(bounds.contains(position));
marker_cluster.addMarker(marker, true);
}
marker_cluster.render();
}
function filter_show_all() {
console.log("filter_show_all");
marker_cluster.addMarkers(markers);
}
function filter_zoom_on_selection(indexes) {
marker_cluster.addMarkers(markers);
}

View File

@@ -1,3 +1,9 @@
let map = {};
let markers = [];
let marker_cluster = {};
//let bounds = {};
function mp_init_map() {
/*
@@ -39,28 +45,21 @@ function mp_init_map() {
let map_div = document.getElementById("ljdp_map");
//let filters_div = document.getElementById("ljdp_map_filters");
let infowindow = new google.maps.InfoWindow();
//bounds = new google.maps.LatLngBounds();
/*
* DRAW MAP
*/
let map = create_map(map_div);
let markers = create_markers(map, locations, infowindow);
let marker_cluster = draw_clusters(map, markers);
map = create_map(map_div);
markers = create_markers(map, locations, infowindow);
marker_cluster = draw_clusters(map, markers);
//let toggle = true;
// add listener to close infowindow at any click on map
map.addListener('click', function() {
infowindow.close();
//console.log(toggle);
////markers[index].setMap(null);
//if (toggle === true)
// marker_cluster.removeMarker(markers[25]);
//else
// marker_cluster.addMarker(markers[25]);
//toggle = (toggle === true)? false : true ;
});
}