From 95c379e7865db65879f629f4cf109d65e18e3f1d Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 22 Nov 2017 11:59:50 +0100
Subject: [PATCH] imgae tiles that don't exist are not fetched by google maps
 api anymore

---
 .../src/main/js/map/AbstractCustomMap.js      | 26 ++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/frontend-js/src/main/js/map/AbstractCustomMap.js b/frontend-js/src/main/js/map/AbstractCustomMap.js
index 78f7c7216d..abf9eedc13 100644
--- a/frontend-js/src/main/js/map/AbstractCustomMap.js
+++ b/frontend-js/src/main/js/map/AbstractCustomMap.js
@@ -157,27 +157,35 @@ AbstractCustomMap.prototype.createMapOptions = function () {
  */
 AbstractCustomMap.prototype.createTypeOptions = function (param) {
   var self = this;
-  var result = {
+  return {
     // this is a function that will retrieve valid url to png images for
     // tiles on different zoom levels
     getTileUrl: function (coord, zoom) {
       // we have 1 tile on self.getConfiguration().MIN_ZOOM and
       // therefore must limit tails according to this
       /* jshint bitwise: false */
-      var tileRange = 1 << (zoom - self.getMinZoom());
-      if (coord.y < 0 || coord.y >= tileRange || coord.x < 0 || coord.x >= tileRange) {
+      var maxTileRange = 1 << (zoom - self.getMinZoom());
+      var maxTileXRange = maxTileRange;
+      var maxTileYRange = maxTileRange;
+
+      var width = self.getModel().getWidth();
+      var height = self.getModel().getHeight();
+      if (width > height) {
+        maxTileYRange = height / width * maxTileRange;
+      } else if (width < height) {
+        maxTileXRange = width / height * maxTileRange;
+      }
+      if (coord.y < 0 || coord.y >= maxTileYRange || coord.x < 0 || coord.x >= maxTileXRange) {
         return null;
       }
-      var addr = "../map_images/" + param.getDirectory() + "/" + zoom + "/" + coord.x + "/" + coord.y + ".PNG";
-      return addr;
+      return "../map_images/" + param.getDirectory() + "/" + zoom + "/" + coord.x + "/" + coord.y + ".PNG";
     },
-    tileSize: new google.maps.Size(this.getTileSize(), this.getTileSize()),
-    maxZoom: this.getMaxZoom(),
-    minZoom: this.getMinZoom(),
+    tileSize: new google.maps.Size(self.getTileSize(), self.getTileSize()),
+    maxZoom: self.getMaxZoom(),
+    minZoom: self.getMinZoom(),
     radius: 360,
     name: param.name
   };
-  return result;
 };
 
 /**
-- 
GitLab