Exemple #1
0
 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 tiles(extll, minzoom, maxzoom=None):
    if maxzoom is None:
        maxzoom = minzoom
    alltiles = []
    for zoom in range(minzoom, maxzoom+1):
        alltiles = alltiles + osm.tiles(extll.xMinimum(), extll.xMaximum(), 
              extll.yMinimum(), extll.yMaximum(), zoom)
    return alltiles
Exemple #3
0
 def zoom(self, widthpx, extll):
     if self.specifiedzoom is None:
         maxzoom = tm.maxzoom(self.tiletype) if self.maxzoom is None else self.maxzoom
         autozoom = osm.autozoom(widthpx/(extll.xMaximum()-extll.xMinimum()))
         return min(max((tm.minzoom(self.tiletype), autozoom)),
                    maxzoom)
     else:
         numtiles = len(osm.tiles(extll.xMinimum(), extll.xMaximum(), 
                       extll.yMinimum(), extll.yMaximum(), self.specifiedzoom))
         if numtiles > qosmsettings.get(qosmsettings.MAX_TILES):
             log("too many tiles for fixed zoom layer!: %s" % numtiles)
             self.rendererrors += 1
             return None
         else:
             return self.specifiedzoom
Exemple #4
0
 def set_summarystats(self):   
     numtiles = len(self.layer.loadedlayers)
     zoom = self.layer.actualzoom if self.layer.specifiedzoom is None else \
             self.layer.specifiedzoom
     
     extent = self.iface.mapCanvas().extent() 
     crs = self.iface.mapCanvas().mapRenderer().destinationCrs()
     widthpx = self.iface.mapCanvas().width()
     extll = osm.unproject(extent, crs)
     
     calczoom = osm.autozoom(widthpx/(extll.xMaximum()-extll.xMinimum()))
     layerzoom = calczoom if zoom is None else zoom
     numtilestot = len(osm.tiles(extll.xMinimum(), extll.xMaximum(), 
                   extll.yMinimum(), extll.yMaximum(), layerzoom))
     
     self.statusText.setText("Loaded %s of %s tiles at zoom level %s (automatic zoom would be %s). \
                             %s rendering errors (see QOSM Settings/Logs for more details)." %
                             (numtiles, numtilestot, zoom, calczoom, self.layer.rendererrors))