Upper left tile for an area.

@param boundingBox the area boundingBox
@param zoomLevel   the zoom level.
@param tileSize    the tile size.
@return the tile at the upper left of the bbox.
976765
public static Tile getUpperLeft(BoundingBox boundingBox, byte zoomLevel, int tileSize) {
        int tileLeft = MercatorProjection.longitudeToTileX(boundingBox.minLongitude, zoomLevel);
        int tileTop = MercatorProjection.latitudeToTileY(boundingBox.maxLatitude, zoomLevel);
        return new Tile(tileLeft, tileTop, zoomLevel, tileSize);
    }
1294784
@Override
    public Tile getTile(int x, int y, int zoom)
    {
        return new Tile(x, y, zoom)
        {
            @Override
            public synchronized boolean isLoaded()
            {
                return true;
            }

            @Override
            public BufferedImage getImage()
            {
                return emptyTile;
            }

        };
    }
951267
public Coordinate metersToTile(Coordinate coord, int zoomLevel) {
        Coordinate pixels = metersToPixels(coord.x, coord.y, zoomLevel);
        int tx = (int) pixels.x / 256;
        int ty = (int) pixels.y / 256;
        return new Coordinate(tx, ty, zoomLevel);
    }
489432
public Envelope TileLatLonBounds( int tx, int ty, int zoom ) {
        double[] wsenBounds = TileBounds(tx, ty, zoom);
        double[] sw = MetersToLatLon(wsenBounds[0], wsenBounds[1]);
        double[] ne = MetersToLatLon(wsenBounds[2], wsenBounds[3]);
        return new Envelope(sw[1], ne[1], sw[0], ne[0]);
    }
1214483
function (bounds) {
        bounds = this.adjustBounds(bounds);
        var mapRes = this.map.getResolution();
        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
        var pX = Math.round(bounds.left / mapRes);
        var pY = -Math.round(bounds.top / mapRes);

        var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w;
        var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h;
    
        var components = [
            "/",
            this.params.map,
            "/",
            scale,
            "/",
            this.params.g.replace(/\s/g, '_'),
            "/def/t", 
            metaY,
            "/l",
            metaX,
            "/t",
            pY,
            "l",
            pX,
            ".",
            this.extension
          ];

        var url = this.url;

        if (OpenLayers.Util.isArray(url)) {
            url = this.selectUrl(components.join(''), url);
        }
        return url + components.join("");
    }
51948
public double[] TileBounds( int tx, int ty, int zoom ) {
        double[] min = PixelsToMeters(tx * tileSize, ty * tileSize, zoom);
        double minx = min[0], miny = min[1];
        double[] max = PixelsToMeters((tx + 1) * tileSize, (ty + 1) * tileSize, zoom);
        double maxx = max[0], maxy = max[1];
        return new double[]{minx, miny, maxx, maxy};
    }
831571
public static double[] tileBounds3857( int tx, int ty, int zoom, int tileSize ) {
        double[] min = pixelsToMeters(tx * tileSize, ty * tileSize, zoom, tileSize);
        double minx = min[0], miny = min[1];
        double[] max = pixelsToMeters((tx + 1) * tileSize, (ty + 1) * tileSize, zoom, tileSize);
        double maxx = max[0], maxy = max[1];
        return new double[]{minx, miny, maxx, maxy};
    }
107942
function (bounds) {
        bounds = this.adjustBounds(bounds);
        var res = this.getServerResolution();
        var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
        var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
        var z = this.getServerZoom();
        var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; 
        var url = this.url;
        if (OpenLayers.Util.isArray(url)) {
            url = this.selectUrl(path, url);
        }
        return url + path;
    }
370195
public TileResultSet queryForTilesInColumn(long column, long zoomLevel) {

		Map<String, Object> fieldValues = new HashMap<String, Object>();
		fieldValues.put(TileTable.COLUMN_TILE_COLUMN, column);
		fieldValues.put(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel);

		return queryForFieldValues(fieldValues);
	}
498712
public static Bbox getWorldBoundsForTile(TileConfiguration tileConfiguration, TileCode tileCode) {
		double resolution = tileConfiguration.getResolution(tileCode.getTileLevel());
		double worldTileWidth = tileConfiguration.getTileWidth() * resolution;
		double worldTileHeight = tileConfiguration.getTileHeight() * resolution;

		double x = tileConfiguration.getTileOrigin().getX() + tileCode.getX() * worldTileWidth;
		double y = tileConfiguration.getTileOrigin().getY() + tileCode.getY() * worldTileHeight;
		return new Bbox(x, y, worldTileWidth, worldTileHeight);
	}
918113
public TileResultSet queryForTilesInRow(long row, long zoomLevel) {

		Map<String, Object> fieldValues = new HashMap<String, Object>();
		fieldValues.put(TileTable.COLUMN_TILE_ROW, row);
		fieldValues.put(TileTable.COLUMN_ZOOM_LEVEL, zoomLevel);

		return queryForFieldValues(fieldValues);
	}
1281187
public static int getZoomLevel(BoundingBox webMercatorBoundingBox) {

		double worldLength = ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH * 2;

		double longitudeDistance = webMercatorBoundingBox.getMaxLongitude()
				- webMercatorBoundingBox.getMinLongitude();
		double latitudeDistance = webMercatorBoundingBox.getMaxLatitude()
				- webMercatorBoundingBox.getMinLatitude();

		if (longitudeDistance <= 0) {
			longitudeDistance = Double.MIN_VALUE;
		}
		if (latitudeDistance <= 0) {
			latitudeDistance = Double.MIN_VALUE;
		}

		int widthTiles = (int) (worldLength / longitudeDistance);
		int heightTiles = (int) (worldLength / latitudeDistance);

		int tilesPerSide = Math.min(widthTiles, heightTiles);
		tilesPerSide = Math.max(tilesPerSide, 1);

		int zoom = zoomFromTilesPerSide(tilesPerSide);

		return zoom;
	}
1185758
public static Rectangle getTile (
        int width, int height, int tileWidth, int tileHeight, int tileIndex)
    {
        Rectangle bounds = new Rectangle();
        getTile(width, height, tileWidth, tileHeight, tileIndex, bounds);
        return bounds;
    }
1228783
public BufferedImage drawTileQueryAll(int x, int y, int zoom) {

		BoundingBox boundingBox = TileBoundingBoxUtils
				.getWebMercatorBoundingBox(x, y, zoom);

		BufferedImage image = null;

		// Query for all features
		FeatureResultSet resultSet = featureDao.queryForAll();

		try {

			int totalCount = resultSet.getCount();

			// Draw if at least one geometry exists
			if (totalCount > 0) {

				if (maxFeaturesPerTile == null
						|| totalCount <= maxFeaturesPerTile) {

					// Draw the tile image
					image = drawTile(zoom, boundingBox, resultSet);

				} else if (maxFeaturesTileDraw != null) {

					// Draw the unindexed max features tile
					image = maxFeaturesTileDraw.drawUnindexedTile(tileWidth,
							tileHeight, totalCount, resultSet);
				}

			}
		} finally {
			resultSet.close();
		}

		return image;
	}
1176986
public static double zoomLevelOfTileSize(double tileSize) {
		double tilesPerSide = (2 * ProjectionConstants.WEB_MERCATOR_HALF_WORLD_WIDTH)
				/ tileSize;
		double zoom = Math.log(tilesPerSide) / Math.log(2);
		return zoom;
	}
494679
@Override
    public Tile getTile(int x, int y, int zoom)
    {
        return getTile(x, y, zoom, true);
    }
477969
public List<TileCoordinate> translateToZoomLevel(byte zoomlevelNew) {
        List<TileCoordinate> tiles = null;
        int zoomlevelDistance = zoomlevelNew - this.zoomlevel;

        int factor = (int) Math.pow(2, Math.abs(zoomlevelDistance));
        if (zoomlevelDistance > 0) {
            tiles = new ArrayList<>((int) Math.pow(4, Math.abs(zoomlevelDistance)));
            int tileUpperLeftX = this.x * factor;
            int tileUpperLeftY = this.y * factor;
            for (int i = 0; i < factor; i++) {
                for (int j = 0; j < factor; j++) {
                    tiles.add(new TileCoordinate(tileUpperLeftX + j, tileUpperLeftY + i, zoomlevelNew));
                }
            }
        } else {
            tiles = new ArrayList<>(1);
            tiles.add(new TileCoordinate(this.x / factor, this.y / factor, zoomlevelNew));
        }
        return tiles;
    }