Esempio n. 1
0
  def expose_ev(self, widget, event):
    if(widget.allocation.width != self.width or widget.allocation.height != self.height ):
      #debug("Rrresize!")
      self.width = widget.allocation.width
      self.height = widget.allocation.height

    cr = widget.window.cairo_create()
    if self.old_center_coord != self.center_coord or self.old_zoom != self.zoom:
      #print "Recentered!"
      xy = projections.from4326(self.center_coord,"EPSG:3857")
      xy1 = projections.to4326((xy[0]-40075016.*(0.5**(self.zoom))/self.tiles.tilewidth*self.width, xy[1]-40075016.*(0.5**(self.zoom))/self.tiles.tileheight*self.height), "EPSG:3857")
      xy2 = projections.to4326((xy[0]+40075016.*(0.5**(self.zoom))/self.tiles.tilewidth*self.width, xy[1]+40075016.*(0.5**(self.zoom))/self.tiles.tileheight*self.height), "EPSG:3857")
      self.bbox = (xy1[0],xy1[1],xy2[0],xy2[1])
      self.tilebox = projections.tile_by_bbox(self.bbox, self.zoom, "EPSG:3857")
      self.old_center_coord = self.center_coord
      self.old_zoom = self.zoom
    from_tile_x, from_tile_y, to_tile_x, to_tile_y = self.tilebox
    dx = 1.*(from_tile_x - int(from_tile_x))*self.tiles.tilewidth
    dy = 1.*(from_tile_y - int(from_tile_y))*self.tiles.tileheight
    print dx,dy
    #print self.dx, self.dy
    onscreen_tiles = set()
    for x in range (int(from_tile_x), int(to_tile_x)+1):
      for y in range (int(to_tile_y), int(from_tile_y)+1):
        onscreen_tiles.add((self.zoom,x,y))
    self.tiles.onscreen = onscreen_tiles
    for z,x,y in onscreen_tiles:
      tile = self.tiles[(self.zoom,x,y)]
      #print dx+(x-from_tile_x)*self.tiles.tilewidth-self.width
      #print dy+(y-from_tile_y)*self.tiles.tileheight-self.height
      #cr.set_source_surface(tile, int(self.dx-dx+(x-int(from_tile_x))*self.tiles.tilewidth-self.width), int(self.dy-dy-(int(from_tile_y)-y)*self.tiles.tileheight+self.height))
      cr.set_source_surface(tile, int(self.dx-dx+(x-int(from_tile_x))*self.tiles.tilewidth), int(self.dy-dy-(int(from_tile_y)-y)*self.tiles.tileheight+self.height))
      cr.paint()
Esempio n. 2
0
    def expose_ev(self, widget, event):
        if (widget.allocation.width != self.width
                or widget.allocation.height != self.height):
            # debug("Rrresize!")
            self.width = widget.allocation.width
            self.height = widget.allocation.height

        cr = widget.window.cairo_create()
        if self.old_center_coord != self.center_coord or self.old_zoom != self.zoom:
            # print "Recentered!"
            xy = projections.from4326(self.center_coord, "EPSG:3857")
            xy1 = projections.to4326(
                (xy[0] - 40075016. *
                 (0.5**(self.zoom)) / self.tiles.tilewidth * self.width,
                 xy[1] - 40075016. *
                 (0.5**(self.zoom)) / self.tiles.tileheight * self.height),
                "EPSG:3857")
            xy2 = projections.to4326(
                (xy[0] + 40075016. *
                 (0.5**(self.zoom)) / self.tiles.tilewidth * self.width,
                 xy[1] + 40075016. *
                 (0.5**(self.zoom)) / self.tiles.tileheight * self.height),
                "EPSG:3857")
            self.bbox = (xy1[0], xy1[1], xy2[0], xy2[1])
            self.tilebox = projections.tile_by_bbox(self.bbox, self.zoom,
                                                    "EPSG:3857")
            self.old_center_coord = self.center_coord
            self.old_zoom = self.zoom
        from_tile_x, from_tile_y, to_tile_x, to_tile_y = self.tilebox
        dx = 1. * (from_tile_x - int(from_tile_x)) * self.tiles.tilewidth
        dy = 1. * (from_tile_y - int(from_tile_y)) * self.tiles.tileheight
        print dx, dy
        # print self.dx, self.dy
        onscreen_tiles = set()
        for x in range(int(from_tile_x), int(to_tile_x) + 1):
            for y in range(int(to_tile_y), int(from_tile_y) + 1):
                onscreen_tiles.add((self.zoom, x, y))
        self.tiles.onscreen = onscreen_tiles
        for z, x, y in onscreen_tiles:
            tile = self.tiles[(self.zoom, x, y)]
            # print dx+(x-from_tile_x)*self.tiles.tilewidth-self.width
            # print dy+(y-from_tile_y)*self.tiles.tileheight-self.height
            # cr.set_source_surface(tile, int(self.dx-dx+(x-int(from_tile_x))*self.tiles.tilewidth-self.width), int(self.dy-dy-(int(from_tile_y)-y)*self.tiles.tileheight+self.height))
            cr.set_source_surface(
                tile,
                int(self.dx - dx +
                    (x - int(from_tile_x)) * self.tiles.tilewidth),
                int(self.dy - dy -
                    (int(from_tile_y) - y) * self.tiles.tileheight +
                    self.height))
            cr.paint()
Esempio n. 3
0
    def get_vectors(self, bbox, zoom, sql_hint=None, itags=None):
        zoom = int(zoom)
        zoom = min(
            zoom, self.max_zoom
        )  ## If requested zoom is better than the best, take the best
        zoom = max(zoom, 0)  ## Negative zooms are nonsense
        a, d, c, b = [
            int(x) for x in projections.tile_by_bbox(bbox, zoom, self.proj)
        ]
        resp = {}

        hint = set()
        for j in [x[0] for x in sql_hint]:
            hint.update(j)

        for tile in set([(zoom, i, j) for i in range(a, c + 1)
                         for j in range(b, d + 1)]):
            # Loading current vector tile
            try:
                ti = self.tiles[tile]
            except KeyError:
                ti = self.load_tile(tile)
                self.tiles[tile] = ti
            try:
                self.tile_load_log.remove(tile)
            except ValueError:
                pass
            self.tile_load_log.append(tile)

            for obj in ti:
                "filling response with interesting-tagged objects"
                need = False
                for tag in ti[obj].tags:
                    #if tag in hint:
                    need = True
                    break
                if need:
                    if twms.bbox.bbox_is_in(bbox, ti[obj].bbox, fully=False):
                        resp[obj] = ti[obj]

        self.collect_garbage()
        return resp
Esempio n. 4
0
    def get_vectors (self, bbox, zoom, sql_hint = None, itags = None):
        zoom = int(zoom)
        zoom = min(zoom, self.max_zoom)     ## If requested zoom is better than the best, take the best
        zoom = max(zoom, 0)                 ## Negative zooms are nonsense
        a,d,c,b = [int(x) for x in projections.tile_by_bbox(bbox,zoom, self.proj)]
        resp = {}

        hint = set()
        for j in [x[0] for x in sql_hint]:
            hint.update(j)

        for tile in set([(zoom,i,j) for i in range(a, c+1) for j in range(b, d+1)]):
            # Loading current vector tile
            try:
                ti = self.tiles[tile]
            except KeyError:
                ti = self.load_tile(tile)
                self.tiles[tile] = ti
            try:
                self.tile_load_log.remove(tile)
            except ValueError:
                pass
            self.tile_load_log.append(tile)

            for obj in ti:
                "filling response with interesting-tagged objects"
                need = False
                for tag in ti[obj].tags:
                    #if tag in hint:
                    need = True
                    break
                if need:
                    if twms.bbox.bbox_is_in(bbox, ti[obj].bbox, fully=False):
                        resp[obj] = ti[obj]

        self.collect_garbage()
        return resp