From e7a88cc68abea23924566efec418179e20444928 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Sun, 30 Jul 2023 12:34:26 -0400 Subject: [PATCH] Performance issue with GMap rectangles solved. --- htdocs/lib/LocatorManager.js | 24 ++++++++++++++---------- htdocs/map.js | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/htdocs/lib/LocatorManager.js b/htdocs/lib/LocatorManager.js index 11d5eedb..28bdaf01 100644 --- a/htdocs/lib/LocatorManager.js +++ b/htdocs/lib/LocatorManager.js @@ -45,7 +45,7 @@ LocatorManager.prototype.ageAll = function() { LocatorManager.prototype.clear = function() { // Remove all rectangles from the map - $.each(this.markers, function(_, x) { x.setMap(); }); + $.each(this.rectangles, function(_, x) { x.setMap(); }); // Delete all rectangles this.rectangles = {}; }; @@ -196,12 +196,18 @@ Locator.prototype.update = function(update) { // GoogleMaps-Specific Locators (derived from generic locators) // -function GLocator() { $.extend(this, new Locator()); } +function GLocator() { + this.rect = new google.maps.Rectangle(); +} -GLocator.prototype = new google.maps.Rectangle(); +GLocator.prototype = new Locator(); GLocator.prototype.setOptions = function(options) { - google.maps.Rectangle.prototype.setOptions.apply(this, arguments); + this.rect.setOptions(options); +}; + +GLocator.prototype.setMap = function(map) { + this.rect.setMap(map); }; GLocator.prototype.setCenter = function(lat, lon) { @@ -218,12 +224,10 @@ GLocator.prototype.setCenter = function(lat, lon) { GLocator.prototype.age = function(age) { if (age <= retention_time) { var scale = Marker.getOpacityScale(age); - var stroke = LocatorManager.strokeOpacity * scale; - var fill = LocatorManager.fillOpacity * scale; -// this.setOptions({ -// strokeOpacity : stroke, -// fillOpacity : fill -// }); + this.setOptions({ + strokeOpacity : LocatorManager.strokeOpacity * scale, + fillOpacity : LocatorManager.fillOpacity * scale + }); return true; } else { this.setMap(); diff --git a/htdocs/map.js b/htdocs/map.js index 65310a43..095951fa 100644 --- a/htdocs/map.js +++ b/htdocs/map.js @@ -165,8 +165,8 @@ $(function(){ if (!rectangle) { rectangle = new GLocator(); locmanager.add(update.callsign, rectangle); - rectangle.addListener('click', function() { - showLocatorInfoWindow(this.locator, this.center); + rectangle.rect.addListener('click', function() { + showLocatorInfoWindow(rectangle.locator, rectangle.center); }); }