Пример #1
0
    def query_region(self, xmin, xmax, ymin, ymax, zoom, *args, **kwargs):
        """ 
        Ask the MapDownloader to get all tiles within a given region

        @author: Brendan Johan Lee
        @contact: [email protected]
        @version: 1.0

        @param xmin: lowest horizontal tile coordinate
        @type xmin: int
        @param xmax: highest horizontal tile coordinate
        @type xmax: int
        @param ymin: lowest vertical tile coordinate
        @type ymin: int
        @param ymax: highest vertical tile coordinate
        @type ymax: int
        @param zoom: zoom level of tiles to retrieve
        @type zoom: int
        
        @todo: Rewrite so takes a tupple instead of xmin,  xmax,  etc
        """

        world_tiles = mapUtils.tiles_on_level(zoom)
        if xmax-xmin >= world_tiles:
            xmin,xmax = 0,world_tiles-1
        if ymax-ymin >= world_tiles:
            ymin,ymax = 0,world_tiles-1
        
        for i in xrange((xmax-xmin+world_tiles)%world_tiles+1):
            x = (xmin+i)%world_tiles
            for j in xrange((ymax-ymin+world_tiles)%world_tiles+1):
                y = (ymin+j)%world_tiles
                self.query_tile((x,y,zoom), *args, **kwargs)
Пример #2
0
    def query_tile(self, coord, layer, callback, online=True, force_update=False, mapServ=MAP_SERVERS[GOOGLE], styleID=1):
        """ 
        Tell the MapDownloader to retrieve a map tile. Tile will be retrieved from
        cache if the tile resides there and has not expired, else from web.

        @author: Brendan Johan Lee
        @contact: [email protected]
        @version: 1.0

        @param coord: tile coordinates
        @type coord: tupple
        @param layer: map layer tile belongs to
        @type layer: int
        @param callback: function to be called when tile download completes
        @type callback: function
        @param online: indicates if the system is online, in other words has access to the net
        @type online: bool
        @param force_update: force the system to download the tile even if it exists in cache
        @type force_update: bool
        @param mapServ: map server to use
        @type mapServ: str
        @param styleID: map style to use (map, satellite, etc)
        @type styleID: int
        """
        
        world_tiles = mapUtils.tiles_on_level(coord[2])
        coord = (mapUtils.mod(coord[0], world_tiles),
                 mapUtils.mod(coord[1], world_tiles), coord[2])

        # try to get a tile offline
        fn = self.ctx_map.get_file(coord, layer, False, False, mapServ=mapServ)

        if fn!=None or (not online):
            deleted = False
            if (force_update and online):
                deleted = fileUtils.delete_old(fn)
            if not deleted:
                callback(True, coord, layer, mapServ)
                return 

        self.taskq.put(
            DownloadTask(
                coord, layer, callback, force_update, mapServ, styleID
            )
        )