Skip to content

Commit

Permalink
mp_tile.py: use If-Modified-Since to try to reuse tile data
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Sep 27, 2024
1 parent 9019faf commit 8670e99
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions MAVProxy/modules/mavproxy_map/mp_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import math
import threading
import os
import pathlib
import string
import time
import cv2
Expand Down Expand Up @@ -284,11 +285,28 @@ def downloader(self):
print("Downloading %s [%u left]" % (url, len(keys)))
req = url_request(url)
req.add_header('User-Agent', 'MAVProxy')

# try to re-use our cached data:
try:
mtime = os.path.getmtime(path)
req.add_header('If-Modified-Since', time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(mtime)))
except Exception:
pass

if url.find('google') != -1:
req.add_header('Referer', 'https://maps.google.com/')
resp = url_open(req)
headers = resp.info()
except url_error as e:
try:
if e.getcode() == 304:
# cache hit; touch the file to reset its refresh time
pathlib.Path(path).touch()
self._download_pending.pop(key)
continue
except Exception as ex:
pass

#print('Error loading %s' % url)
if not key in self._tile_cache:
self._tile_cache[key] = self._unavailable
Expand Down

0 comments on commit 8670e99

Please sign in to comment.