Skip to content

Commit

Permalink
move markers with similar locations
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejkocylapc committed Dec 11, 2024
1 parent e4f2d14 commit 3885d2f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions app/javascript/packs/data_centers/map_component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { mapGetters } from 'vuex';
import '../mixins/numbers_mixins'
import { MarkerClusterer } from "@googlemaps/markerclusterer";
import { defaultOnClusterClickHandler } from '@googlemaps/markerclusterer';
import { h } from 'vue'
axios.defaults.headers.get["Authorization"] = window.api_authorization;
Expand Down Expand Up @@ -102,8 +102,11 @@ import { defaultOnClusterClickHandler } from '@googlemaps/markerclusterer';
const infoWindow = new google.maps.InfoWindow();
axios.get('/api/v1/data-centers-for-map?network=' + this.network)
.then(response => {
this.data_centers = response.data['data_centers'];
this.data_centers = this.data_centers.filter(data_center => data_center.location_latitude && data_center.location_longitude);
let valid_data_centers = response.data['data_centers'].filter(data_center => data_center.location_latitude && data_center.location_longitude);
valid_data_centers.forEach(data_center => {
let checked_data_center = this.test_unique_data_center(data_center);
this.data_centers.push(checked_data_center);
})
this.data_centers.forEach(data_center => {
let position = { lat: parseFloat(data_center.location_latitude), lng: parseFloat(data_center.location_longitude) };
this.heat_points.push({
Expand Down Expand Up @@ -131,6 +134,20 @@ import { defaultOnClusterClickHandler } from '@googlemaps/markerclusterer';
this.set_up_clusterer(this.marker_list, this.map);
});
},
test_unique_data_center: function(data_center, lv = 0) {
lv = lv + 1;
if (this.data_centers.length == 0) {
return data_center;
}
this.data_centers.forEach(data_center_added => {
if(data_center_added.location_latitude == data_center.location_latitude && data_center_added.location_longitude == data_center.location_longitude) {
data_center.location_longitude = parseFloat(data_center.location_longitude) + 0.0003;
return this.test_unique_data_center(data_center, lv);
}
});
return data_center;
},
set_up_clusterer: function(marker_list, map) {
this.markerClusterer && this.markerClusterer.clearMarkers();
Expand Down Expand Up @@ -162,12 +179,7 @@ import { defaultOnClusterClickHandler } from '@googlemaps/markerclusterer';
zIndex: count,
});
}
},
// onClusterClick: function(event, cluster, map) {
// console.log("Cluster click event", event);
// console.log("Cluster click cluster", cluster);
// console.log("Cluster click map", map);
// }
}
});
},
Expand Down

0 comments on commit 3885d2f

Please sign in to comment.