def refreshtiles_get(self, canvasextent, canvascrs, widthpx, forcedownload=False, cancelledcallback=None): extll = osm.unproject(canvasextent, canvascrs) zoom = self.zoom(widthpx, extll) if zoom is None or self.tiletype is None: return list(self.loadedlayers.keys()), [], [] tiles = osm.tiles(extll.xMinimum(), extll.xMaximum(), extll.yMinimum(), extll.yMaximum(), zoom) if forcedownload: tilestoclean = list(self.loadedlayers.keys()) tilestoload = tiles else: loadedtiles = set(self.loadedlayers.keys()) tilestoclean = loadedtiles.difference(set(tiles)) tilestoload = list(set(tiles).difference(loadedtiles)) #calculate file names and urls cachedir = qosmsettings.get(qosmsettings.CACHE_DIRECTORY) tilefiles = [tm.filename(cachedir, self.tiletype, tile, zoom) for tile in tilestoload] tileurls = [tm.tileurl(self.tiletype, tile, zoom) for tile in tilestoload] if qosmsettings.get(qosmsettings.AUTODOWNLOAD): #download (keep on same thread for now) if not cancelledcallback: cancelledcallback = lambda: False dlerrors = [] downloader.download(tileurls, tilefiles, overwrite=forcedownload, errorhandler=dlerrors.append, cancelledcallback=cancelledcallback) if dlerrors: self.rendererrors += 1 return tilestoclean, tilestoload, tilefiles
def run(self): log("ensuring %s tiles are downloaded" % len(self.tilelist)) cachedir = qosmsettings.get(qosmsettings.CACHE_DIRECTORY) tilefiles = [tm.filename(cachedir, self.tiletype, tile[0:2], tile[2]) for tile in self.tilelist] tileurls = [tm.tileurl(self.tiletype, tile[0:2], tile[2]) for tile in self.tilelist] if not self.overwrite: #remove existing files indicies = [] for i in range(len(tilefiles)): if os.path.exists(tilefiles[i]): indicies.append(i) log("removing %s tiles that already exist" % len(indicies)) for i in reversed(indicies): tilefiles.pop(i) tileurls.pop(i) downloader.download(tileurls, tilefiles, self.overwrite, errorhandler=self.emiterror, progresshandler=self.emitprogress, cancelledcallback=self.isCancelled)