// // Map Locators Management // LocatorManager.strokeOpacity = 0.8; LocatorManager.fillOpacity = 0.35; LocatorManager.allRectangles = function() { return true; }; function LocatorManager() { // Current rectangles this.rectangles = {}; // Current color allocations this.colorKeys = {}; // The color scale used this.colorScale = chroma.scale(['red', 'blue', 'green']).mode('hsl'); // Current coloring mode this.colorMode = 'byband'; // Current filter this.rectangleFilter = LocatorManager.allRectangles; } LocatorManager.prototype.filter = function(data) { return this.rectangleFilter(data); } LocatorManager.prototype.find = function(id) { return id in this.rectangles? this.rectangles[id] : null; }; LocatorManager.prototype.add = function(id, rectangle) { this.rectangles[id] = rectangle; }; LocatorManager.prototype.ageAll = function() { var now = new Date().getTime(); var data = this.rectangles; $.each(data, function(id, x) { if (!x.age(now - x.lastseen)) delete data[id]; }); }; LocatorManager.prototype.clear = function() { // Remove all rectangles from the map $.each(this.rectangles, function(_, x) { x.setMap(); }); // Delete all rectangles this.rectangles = {}; }; LocatorManager.prototype.setFilter = function(map, filterBy = null) { if (!filterBy) { this.rectangleFilter = LocatorManager.allRectangles; } else { var key = this.colorMode.slice(2); this.rectangleFilter = function(x) { return x[key] === filterBy; }; } var filter = this.rectangleFilter; $.each(this.rectangles, function(_, x) { x.setMap(filter(x) ? map : undefined); }); }; LocatorManager.prototype.reColor = function() { var self = this; $.each(this.rectangles, function(_, x) { x.setColor(self.getColor(x)); }); }; LocatorManager.prototype.updateLegend = function() { if (!this.colorKeys) return; var filter = this.rectangleFilter; var mode = this.colorMode.slice(2); var list = $.map(this.colorKeys, function(value, key) { // Fake rectangle to test if the filter would match var fakeRectangle = Object.fromEntries([[mode, key]]); var disabled = filter(fakeRectangle) ? '' : ' disabled'; return '