load a lower resolution tile from cache to fill in a
		map while waiting for a higher resolution tile
162155
def load_tile_lowres(self, tile):
		''''''
		if tile.zoom == self.min_zoom:
			return None

		# find the equivalent lower res tile
		(lat,lon) = tile.coord()

		width2 = TILES_WIDTH
		height2 = TILES_HEIGHT

		for zoom2 in range(tile.zoom-1, self.min_zoom-1, -1):
			width2 /= 2
			height2 /= 2

			if width2 == 0 or height2 == 0:
				break

			tile_info = self.coord_to_tile(lat, lon, zoom2)

			# see if its in the tile cache
			key = tile_info.key()
			if key in self._tile_cache:
				img = self._tile_cache[key]
				if img == self._unavailable:
					continue
			else:
				path = self.tile_to_path(tile_info)
				try:
					img = cv.LoadImage(path)
					# add it to the tile cache
					self._tile_cache[key] = img
					while len(self._tile_cache) > self.cache_size:
						self._tile_cache.popitem(0)
				except IOError as e:
					continue

			# copy out the quadrant we want
			availx = min(TILES_WIDTH - tile_info.offsetx, width2)
			availy = min(TILES_HEIGHT - tile_info.offsety, height2)
			if availx != width2 or availy != height2:
				continue
			cv.SetImageROI(img, (tile_info.offsetx, tile_info.offsety, width2, height2))
			img2 = cv.CreateImage((width2,height2), 8, 3)
			try:
				cv.Copy(img, img2)
			except Exception:
				continue
			cv.ResetImageROI(img)

			# and scale it
			scaled = cv.CreateImage((TILES_WIDTH, TILES_HEIGHT), 8, 3)
			cv.Resize(img2, scaled)
			#cv.Rectangle(scaled, (0,0), (255,255), (0,255,0), 1)
			return scaled
		return None
759392
private void loadAllAndKeepExisting(Set<? extends K> keys) {
    List<K> keysToLoad = keys.stream()
        .filter(key -> !cache.asMap().containsKey(key))
        .collect(toList());
    Map<K, V> result = cacheLoader.get().loadAll(keysToLoad);
    for (Map.Entry<K, V> entry : result.entrySet()) {
      if ((entry.getKey() != null) && (entry.getValue() != null)) {
        putIfAbsentNoAwait(entry.getKey(), entry.getValue(), /* publishToWriter */ false);
      }
    }
  }
1009154
function mapCacheSet$1(key, value) {
  var data = getMapData$4(this, key),
      size = data.size;

  data.set(key, value);
  this.size += data.size == size ? 0 : 1;
  return this;
}
402835
public static void getTile (int width, int height, int tileWidth, int tileHeight, int tileIndex,
                                Rectangle bounds)
    {
        // figure out from whence to crop the tile
        int tilesPerRow = width / tileWidth;

        // if we got a bogus region, return bogus tile bounds
        if (tilesPerRow == 0) {
            bounds.setBounds(0, 0, width, height);

        } else {
            int row = tileIndex / tilesPerRow;
            int col = tileIndex % tilesPerRow;
            // crop the tile-sized image chunk from the full image
            bounds.setBounds(tileWidth*col, tileHeight*row, tileWidth, tileHeight);
        }
    }
140501
function(tile, tileUrl, done) {
		return function(err, data) {
			if (data) {
				return this._onCacheHit(tile, tileUrl, data, done);
			} else {
				return this._onCacheMiss(tile, tileUrl, done);
			}
		}.bind(this);
	}
295220
function() {
        var tileWidth = this.extent.getWidth() / this.map.getResolution();
        var tileHeight = this.extent.getHeight() / this.map.getResolution();
        this.tileSize = new OpenLayers.Size(tileWidth, tileHeight);
    }
1029620
public boolean forceLoadTile(final OnlineTileSourceBase tileSource, final long pMapTileIndex) {
        try {
            final Drawable drawable = mTileDownloader.downloadTile(pMapTileIndex, mTileWriter, tileSource);
            return drawable != null;
        } catch (CantContinueException e) {
            return false;
        }
    }
237727
function(tile) {
        
        var replacingCls = 'olTileReplacing';

        tile.onLoadStart = function() {
            //if that was first tile then trigger a 'loadstart' on the layer
            if (this.loading === false) {
                this.loading = true;
                this.events.triggerEvent("loadstart");
            }
            this.events.triggerEvent("tileloadstart", {tile: tile});
            this.numLoadingTiles++;
            if (!this.singleTile && this.backBuffer && this.gridResolution === this.backBufferResolution) {
                OpenLayers.Element.addClass(tile.getTile(), replacingCls);
            }
        };
      
        tile.onLoadEnd = function(evt) {
            this.numLoadingTiles--;
            var aborted = evt.type === 'unload';
            this.events.triggerEvent("tileloaded", {
                tile: tile,
                aborted: aborted
            });
            if (!this.singleTile && !aborted && this.backBuffer && this.gridResolution === this.backBufferResolution) {
                var tileDiv = tile.getTile();
                if (OpenLayers.Element.getStyle(tileDiv, 'display') === 'none') {
                    var bufferTile = document.getElementById(tile.id + '_bb');
                    if (bufferTile) {
                        bufferTile.parentNode.removeChild(bufferTile);
                    }
                }
                OpenLayers.Element.removeClass(tileDiv, replacingCls);
            }
            //if that was the last tile, then trigger a 'loadend' on the layer
            if (this.numLoadingTiles === 0) {
                if (this.backBuffer) {
                    if (this.backBuffer.childNodes.length === 0) {
                        // no tiles transitioning, remove immediately
                        this.removeBackBuffer();
                    } else {
                        // wait until transition has ended or delay has passed
                        this._transitionElement = aborted ?
                            this.div.lastChild : tile.imgDiv;
                        var transitionendEvents = this.transitionendEvents;
                        for (var i=transitionendEvents.length-1; i>=0; --i) {
                            OpenLayers.Event.observe(this._transitionElement,
                                transitionendEvents[i],
                                this._removeBackBuffer);
                        }
                        // the removal of the back buffer is delayed to prevent
                        // flash effects due to the animation of tile displaying
                        this.backBufferTimerId = window.setTimeout(
                            this._removeBackBuffer, this.removeBackBufferDelay
                        );
                    }
                }
                this.loading = false;
                this.events.triggerEvent("loadend");
            }
        };
        
        tile.onLoadError = function() {
            this.events.triggerEvent("tileerror", {tile: tile});
        };
        
        tile.events.on({
            "loadstart": tile.onLoadStart,
            "loadend": tile.onLoadEnd,
            "unload": tile.onLoadEnd,
            "loaderror": tile.onLoadError,
            scope: this
        });
    }
813020
function ready() {
  for (var i = 0; i < preloadTiles.length; i++) {
    var state = layerAbove.textureStore().query(preloadTiles[i]);
    if (!state.hasTexture) {
      return false;
    }
  }
  return true;
}
1159388
private void populateLocalCache() {
      CloseableIterator iterator = cache.keySet().iterator();
      try {
         while (iterator.hasNext()) {
            get(null, iterator.next());
         }
      } finally {
         iterator.close();
      }
   }
444954
def _flush_tile_queue(self, surface):
        
        tw, th = self.data.tile_size
        ltw = self._tile_view.left * tw
        tth = self._tile_view.top * th
        surface_blit = surface.blit

        self.data.prepare_tiles(self._tile_view)

        for x, y, l, image in self._tile_queue:
            surface_blit(image, (x * tw - ltw, y * th - tth))
492046
function() {
        var context;
        if (this.cacheImageRecord) {
            context = this.cacheImageRecord.getRenderedContext();
        } else if (this.context2D) {
            context = this.context2D;
        } else {
            $.console.warn(
                '[Tile.drawCanvas] attempting to get tile scale %s when tile\'s not cached',
                this.toString());
            return 1;
        }
        return context.canvas.width / (this.size.x * $.pixelDensityRatio);
    }
864886
def tile(ctx, point, zoom):
    """"""
    tile = TilePyramid(
        ctx.obj['grid'],
        tile_size=ctx.obj['tile_size'],
        metatiling=ctx.obj['metatiling']
    ).tile_from_xy(*point, zoom=zoom)
    if ctx.obj['output_format'] == 'Tile':
        click.echo('%s %s %s' % tile.id)
    elif ctx.obj['output_format'] == 'WKT':
        click.echo(tile.bbox(pixelbuffer=ctx.obj['pixelbuffer']))
    elif ctx.obj['output_format'] == 'GeoJSON':
        click.echo(
            geojson.dumps(
                geojson.FeatureCollection([
                    geojson.Feature(
                        geometry=tile.bbox(pixelbuffer=ctx.obj['pixelbuffer']),
                        properties=dict(
                            zoom=tile.zoom,
                            row=tile.row,
                            col=tile.col
                        )
                    )
                ])
            )
        )
329589
private static Tile searchForTile(MapTile map, ImageBuffer tileSprite, int x, int y)
    {
        // Check each tile on each sheet
        for (final Integer sheet : map.getSheets())
        {
            final Tile tile = checkTile(map, tileSprite, sheet, x, y);
            if (tile != null)
            {
                return tile;
            }
        }

        // No tile found
        return null;
    }
1215197
def _get_satellite_tile(self, x_tile, y_tile, z_tile):
        """"""
        cache_file = "mapscache/{}.{}.{}.jpg".format(z_tile, x_tile, y_tile)
        if cache_file not in self._tiles:
            if not os.path.isfile(cache_file):
                url = _IMAGE_URL.format(z_tile, x_tile, y_tile, _KEY)
                data = requests.get(url).content
                with open(cache_file, 'wb') as f:
                    f.write(data)
            self._tiles[cache_file] = [
                x_tile, y_tile, z_tile,
                ColourImageFile(self._screen, cache_file, height=_START_SIZE, dither=True,
                                uni=self._screen.unicode_aware),
                True]
            if len(self._tiles) > _CACHE_SIZE:
                self._tiles.popitem(False)
            self._screen.force_update()
533099
private function loadMap()
    {
        $this->map = $this->cache->getItem($this->cacheKey);

        if (is_array($this->map)) {
            return;
        }

        $realResolverInstantiator = $this->realResolverInstantiator;
        $realResolver             = $realResolverInstantiator();

        if (! $realResolver instanceof ResolverInterface) {
            throw InvalidResolverInstantiatorException::fromInvalidResolver($realResolver);
        }

        $this->map = (new TemplateMapCompiler())->compileMap($realResolver);

        $this->cache->setItem($this->cacheKey, $this->map);
    }
629818
def _queue_edge_tiles(self, dx, dy):
        
        v = self._tile_view
        tw, th = self.data.tile_size
        self._tile_queue = iter([])

        def append(rect):
            self._tile_queue = chain(self._tile_queue, self.data.get_tile_images_by_rect(rect))
            # TODO: optimize so fill is only used when map is smaller than buffer
            self._clear_surface(self._buffer, ((rect[0] - v.left) * tw, (rect[1] - v.top) * th,
                                               rect[2] * tw, rect[3] * th))

        if dx > 0:    # right side
            append((v.right - 1, v.top, dx, v.height))

        elif dx < 0:  # left side
            append((v.left, v.top, -dx, v.height))

        if dy > 0:    # bottom side
            append((v.left, v.bottom - 1, v.width, dy))

        elif dy < 0:  # top side
            append((v.left, v.top, v.width, -dy))