Skip to content

Commit

Permalink
Merge pull request #658 from kabalin/GoogleMutant
Browse files Browse the repository at this point in the history
Fix Google map loading issue
  • Loading branch information
kabalin authored Jan 7, 2024
2 parents de5f77c + 4296720 commit cf35afb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions public/js/lib/leaflet/extends/L.Google.js
Original file line number Diff line number Diff line change
Expand Up @@ -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&region=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);
};
Expand Down
5 changes: 2 additions & 3 deletions public/js/lib/leaflet/plugins/Leaflet.GoogleMutant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit cf35afb

Please sign in to comment.