From 42967209d0c4fbd9ddc3bf3c8d7349f45267c66b Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Thu, 28 Dec 2023 23:49:11 +0000 Subject: [PATCH] Fix Google map loading issue. Also use Leaflet class hook for google api loading. Fixes #565 --- public/js/lib/leaflet/extends/L.Google.js | 8 +++++--- public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js | 5 ++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/public/js/lib/leaflet/extends/L.Google.js b/public/js/lib/leaflet/extends/L.Google.js index 8468840c2..58e1b7e7f 100644 --- a/public/js/lib/leaflet/extends/L.Google.js +++ b/public/js/lib/leaflet/extends/L.Google.js @@ -4,15 +4,17 @@ */ // Google layer plugin wrapper. Loads Google Maps library with API key included. -define(['Params', 'leaflet', 'leaflet-plugins/lru', 'leaflet-plugins/Leaflet.GoogleMutant'], function (P, L) { +define(['Params', 'leaflet', 'leaflet-plugins/lru', 'leaflet-plugins/Leaflet.GoogleMutant'], function (P, L, lru) { const keyParam = P.settings.publicApiKeys.googleMaps.length ? '&key=' + P.settings.publicApiKeys.googleMaps : ''; const url = 'https://maps.googleapis.com/maps/api/js?v=weekly®ion=RU' + keyParam; // Load Google Maps API library asynchronously. - require(['async!' + url]); - + L.GridLayer.GoogleMutant.addInitHook(function() { + require(['async!' + url]); + }); return function (options) { options = options || {}; + options.lru = new lru.LRUMap(100); // Tile LRU cache. return new L.GridLayer.GoogleMutant(options); }; diff --git a/public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js b/public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js index bff6ddc18..8e2104b6e 100644 --- a/public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js +++ b/public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js @@ -11,8 +11,7 @@ this stuff is worth it, you can buy me a beer in return. */ //import { LRUMap } from "./lru_map.js"; -// We have to use requirejs to load module, ES6 syntax won't work here. -const { LRUMap } = require('leaflet-plugins/lru'); +// LRU is passed in options. function waitForAPI(callback, context) { let checkCounter = 0, @@ -47,7 +46,7 @@ L.GridLayer.GoogleMutant = L.GridLayer.extend({ // Couple data structures indexed by tile key this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected - this._lru = new LRUMap(100); // Tile LRU cache + this._lru = options.lru; // Tile LRU cache this._imagesPerTile = this.options.type === "hybrid" ? 2 : 1;