def get_tiles_range_for_zoom(self, zoom):
        # get tiles - copied from mapDownloader
        dlon = mapUtils.km_to_lon(mapUtils.nice_round(self.reg_width),
                                  self.center_lat)
        dlat = mapUtils.km_to_lat(mapUtils.nice_round(self.reg_height))

        if dlat > 170:
            dlat = 170
        if dlon > 358:
            dlon = 358

        top_left = mapUtils.coord_to_tile(
            (self.center_lat + dlat / 2, self.center_lon - dlon / 2, zoom))
        bottom_right = mapUtils.coord_to_tile(
            (self.center_lat - dlat / 2, self.center_lon + dlon / 2, zoom))

        # top_left[0][0], bottom_right[0][0], top_left[0][1], bottom_right[0][1]
        # xmin, xmax, ymin, ymax

        world_tiles = mapUtils.tiles_on_level(zoom)
        if bottom_right[0][0] - top_left[0][0] >= world_tiles:
            top_left[0][0], bottom_right[0][0] = 0, world_tiles - 1
        if bottom_right[0][1] - top_left[0][1] >= world_tiles:
            top_left[0][1], bottom_right[0][1] = 0, world_tiles - 1

        # xmin, xmax, ymin, ymax
        return (top_left[0][0], bottom_right[0][0], top_left[0][1],
                bottom_right[0][1])
Exemple #2
0
    def bulk_download(self,
                      coord,
                      zoomlevels,
                      kmx,
                      kmy,
                      layer,
                      tile_callback,
                      completion_callback,
                      force_update=False,
                      conf=None,
                      nodups=True):
        dlon = mapUtils.km_to_lon(mapUtils.nice_round(kmx), coord[0])
        dlat = mapUtils.km_to_lat(mapUtils.nice_round(kmy))
        if zoomlevels[0] > zoomlevels[1]:
            zoomlevels = (zoomlevels[1], zoomlevels[0])

        def downThread():
            self.bulk_all_placed = False
            for zoom in xrange(zoomlevels[1], zoomlevels[0] - 1, -1):
                self.query_region_around_location(coord[0], coord[1], dlat,
                                                  dlon, zoom, layer,
                                                  tile_callback, True,
                                                  force_update, conf)
            if self.qsize() == 0:
                completion_callback()
            self.bulk_all_placed = True

        dThread = Timer(0, downThread)
        dThread.start()
    def get_tiles_range_for_zoom(self, zoom):
        # get tiles - copied from mapDownloader
        dlon = mapUtils.km_to_lon(mapUtils.nice_round(self.reg_width), self.center_lat)
        dlat = mapUtils.km_to_lat(mapUtils.nice_round(self.reg_height))

        if dlat > 170:
            dlat = 170
        if dlon > 358:
            dlon = 358

        top_left = mapUtils.coord_to_tile(
            (self.center_lat + dlat / 2, self.center_lon - dlon / 2, zoom)
        )
        bottom_right = mapUtils.coord_to_tile(
            (self.center_lat - dlat / 2, self.center_lon + dlon / 2, zoom)
        )

        # top_left[0][0], bottom_right[0][0], top_left[0][1], bottom_right[0][1]
        # xmin, xmax, ymin, ymax

        world_tiles = mapUtils.tiles_on_level(zoom)
        if bottom_right[0][0] - top_left[0][0] >= world_tiles:
            top_left[0][0], bottom_right[0][0] = 0, world_tiles - 1
        if bottom_right[0][1] - top_left[0][1] >= world_tiles:
            top_left[0][1], bottom_right[0][1] = 0, world_tiles - 1

        # xmin, xmax, ymin, ymax
        return(top_left[0][0], bottom_right[0][0], top_left[0][1], bottom_right[0][1])
    def bulk_download(
        self, coord, zoomlevels, kmx, kmy, layer, tile_callback, completion_callback, force_update=False, conf=None
    ):
        dlon = mapUtils.km_to_lon(mapUtils.nice_round(kmx), coord[0])
        dlat = mapUtils.km_to_lat(mapUtils.nice_round(kmy))
        if zoomlevels[0] > zoomlevels[1]:
            zoomlevels = (zoomlevels[1], zoomlevels[0])

        def downThread():
            self.bulk_all_placed = False
            for zoom in xrange(zoomlevels[1], zoomlevels[0] - 1, -1):
                self.query_region_around_location(
                    coord[0], coord[1], dlat, dlon, zoom, layer, tile_callback, True, force_update, conf
                )
            if self.qsize() == 0:
                completion_callback()
            self.bulk_all_placed = True

        dThread = Timer(0, downThread)
        dThread.start()