Search current tile of image map by checking all surfaces.

@param map The destination map reference.
@param tileSprite The tiled sprite
@param x The location x.
@param y The location y.
@return The tile found.
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;
    }
747551
function (tileset) {
            var i = 0;
            // first gid

            // tile properties (collidable, etc..)
            this.TileProperties = [];

            // hold reference to each tile image
            this.imageCollection = [];

            this.firstgid = this.lastgid = +tileset.firstgid;

            // check if an external tileset is defined
            if (typeof(tileset.source) !== "undefined") {
                var src = tileset.source;
                var ext = me.utils.file.getExtension(src);
                if (ext === "tsx" || ext === "json") {
                    // load the external tileset (TSX/JSON)
                    tileset = me.loader.getTMX(me.utils.file.getBasename(src));
                    if (!tileset) {
                        throw new Error(src + " external TSX/JSON tileset not found");
                    }
                }
            }

            this.name = tileset.name;
            this.tilewidth = +tileset.tilewidth;
            this.tileheight = +tileset.tileheight;
            this.spacing = +tileset.spacing || 0;
            this.margin = +tileset.margin || 0;

            // set tile offset properties (if any)
            this.tileoffset = new me.Vector2d();

            /**
             * Tileset contains animated tiles
             * @public
             * @type Boolean
             * @name me.TMXTileset#isAnimated
             */
            this.isAnimated = false;

            /**
             * true if the tileset is a "Collection of Image" Tileset
             * @public
             * @type Boolean
             * @name me.TMXTileset#isCollection
             */
            this.isCollection = false;

            /**
             * Tileset animations
             * @private
             * @type Map
             * @name me.TMXTileset#animations
             */
            this.animations = new Map();

            /**
             * Remember the last update timestamp to prevent too many animation updates
             * @private
             * @type Map
             * @name me.TMXTileset#_lastUpdate
             */
            this._lastUpdate = 0;

            var tiles = tileset.tiles;
            for (i in tiles) {
                if (tiles.hasOwnProperty(i)) {
                    if ("animation" in tiles[i]) {
                        this.isAnimated = true;
                        this.animations.set(+i + this.firstgid, {
                            dt      : 0,
                            idx     : 0,
                            frames  : tiles[i].animation,
                            cur     : tiles[i].animation[0]
                        });
                    }
                    // set tile properties, if any (XML format)
                    if ("properties" in tiles[i]) {
                        this.setTileProperty(+i + this.firstgid, tiles[i].properties);
                    }
                    if ("image" in tiles[i]) {
                        var image = me.loader.getImage(tiles[i].image);
                        if (!image) {
                            throw new Error("melonJS: '" + tiles[i].image + "' file for tile '" + (+i + this.firstgid) + "' not found!");
                        }
                        this.imageCollection[+i + this.firstgid] = image;
                    }
                }
            }

            this.isCollection = this.imageCollection.length > 0;

            var offset = tileset.tileoffset;
            if (offset) {
                this.tileoffset.x = +offset.x;
                this.tileoffset.y = +offset.y;
            }

            // set tile properties, if any (JSON format)
            var tileInfo = tileset.tileproperties;
            if (tileInfo) {
                for (i in tileInfo) {
                    if (tileInfo.hasOwnProperty(i)) {
                        this.setTileProperty(+i + this.firstgid, tileInfo[i]);
                    }
                }
            }

            // if not a tile image collection
            if (this.isCollection === false) {

                // get the global tileset texture
                this.image = me.loader.getImage(tileset.image);

                if (!this.image) {
                    throw new Error("melonJS: '" + tileset.image + "' file for tileset '" + this.name + "' not found!");
                }

                // create a texture atlas for the given tileset
                this.texture = me.video.renderer.cache.get(this.image, {
                    framewidth : this.tilewidth,
                    frameheight : this.tileheight,
                    margin : this.margin,
                    spacing : this.spacing
                });
                this.atlas = this.texture.getAtlas();

                // calculate the number of tiles per horizontal line
                var hTileCount = +tileset.columns || ~~(this.image.width / (this.tilewidth + this.spacing));
                var vTileCount = ~~(this.image.height / (this.tileheight + this.spacing));
                // compute the last gid value in the tileset
                this.lastgid = this.firstgid + (((hTileCount * vTileCount) - 1) || 0);
                if (tileset.tilecount && this.lastgid - this.firstgid + 1 !== +tileset.tilecount) {
                    console.warn(
                        "Computed tilecount (" + (this.lastgid - this.firstgid + 1) +
                        ") does not match expected tilecount (" + tileset.tilecount + ")"
                    );
                }
            }
        }
174507
public static Collection<Long> getTilesCoverage(final ArrayList<GeoPoint> pGeoPoints,
                                                    final int pZoomLevel) {
        final Set<Long> result = new HashSet<>();

        GeoPoint prevPoint = null;
        Point tile, prevTile = null;

        final int mapTileUpperBound = 1 << pZoomLevel;
        for (GeoPoint geoPoint : pGeoPoints) {

            final double d = TileSystem.GroundResolution(geoPoint.getLatitude(), pZoomLevel);

            if (result.size() != 0) {

                if (prevPoint != null) {

                    final double leadCoef = (geoPoint.getLatitude() - prevPoint.getLatitude()) / (geoPoint.getLongitude() - prevPoint.getLongitude());
                    final double brng;
                    if (geoPoint.getLongitude() > prevPoint.getLongitude()) {
                        brng = Math.PI / 2 - Math.atan(leadCoef);
                    } else {
                        brng = 3 * Math.PI / 2 - Math.atan(leadCoef);
                    }

                    final GeoPoint wayPoint = new GeoPoint(prevPoint.getLatitude(), prevPoint.getLongitude());

                    while ((((geoPoint.getLatitude() > prevPoint.getLatitude()) && (wayPoint.getLatitude() < geoPoint.getLatitude())) ||
                            (geoPoint.getLatitude() < prevPoint.getLatitude()) && (wayPoint.getLatitude() > geoPoint.getLatitude())) &&
                            (((geoPoint.getLongitude() > prevPoint.getLongitude()) && (wayPoint.getLongitude() < geoPoint.getLongitude())) ||
                                    ((geoPoint.getLongitude() < prevPoint.getLongitude()) && (wayPoint.getLongitude() > geoPoint.getLongitude())))) {

                        final double prevLatRad = wayPoint.getLatitude() * Math.PI / 180.0;
                        final double prevLonRad = wayPoint.getLongitude() * Math.PI / 180.0;

                        final double latRad = Math.asin(Math.sin(prevLatRad) * Math.cos(d / GeoConstants.RADIUS_EARTH_METERS) + Math.cos(prevLatRad) * Math.sin(d / GeoConstants.RADIUS_EARTH_METERS) * Math.cos(brng));
                        final double lonRad = prevLonRad + Math.atan2(Math.sin(brng) * Math.sin(d / GeoConstants.RADIUS_EARTH_METERS) * Math.cos(prevLatRad), Math.cos(d / GeoConstants.RADIUS_EARTH_METERS) - Math.sin(prevLatRad) * Math.sin(latRad));

                        wayPoint.setLatitude(((latRad * 180.0 / Math.PI)));
                        wayPoint.setLongitude(((lonRad * 180.0 / Math.PI)));

                        tile = new Point(
                            MapView.getTileSystem().getTileXFromLongitude(wayPoint.getLongitude(), pZoomLevel),
                            MapView.getTileSystem().getTileYFromLatitude(wayPoint.getLatitude(), pZoomLevel));

                        if (!tile.equals(prevTile)) {
//Log.d(Constants.APP_TAG, "New Tile lat " + tile.x + " lon " + tile.y);
                            int ofsx = tile.x >= 0 ? 0 : -tile.x;
                            int ofsy = tile.y >= 0 ? 0 : -tile.y;
                            for (int xAround = tile.x + ofsx; xAround <= tile.x + 1 + ofsx; xAround++) {
                                for (int yAround = tile.y + ofsy; yAround <= tile.y + 1 + ofsy; yAround++) {
                                    final int tileY = MyMath.mod(yAround, mapTileUpperBound);
                                    final int tileX = MyMath.mod(xAround, mapTileUpperBound);
                                    result.add(MapTileIndex.getTileIndex(pZoomLevel, tileX, tileY));
                                }
                            }

                            prevTile = tile;
                        }
                    }
                }

            } else {
                tile = new Point(
                    MapView.getTileSystem().getTileXFromLongitude(geoPoint.getLongitude(), pZoomLevel),
                    MapView.getTileSystem().getTileYFromLatitude(geoPoint.getLatitude(), pZoomLevel));
                prevTile = tile;

                int ofsx = tile.x >= 0 ? 0 : -tile.x;
                int ofsy = tile.y >= 0 ? 0 : -tile.y;
                for (int xAround = tile.x + ofsx; xAround <= tile.x + 1 + ofsx; xAround++) {
                    for (int yAround = tile.y + ofsy; yAround <= tile.y + 1 + ofsy; yAround++) {
                        final int tileY = MyMath.mod(yAround, mapTileUpperBound);
                        final int tileX = MyMath.mod(xAround, mapTileUpperBound);
                        result.add(MapTileIndex.getTileIndex(pZoomLevel, tileX, tileY));
                    }
                }
            }

            prevPoint = geoPoint;
        }
        return result;
    }
662398
private void updateTile(Tile tile, Tile neighbor, Circuit circuit)
    {
        final Iterator<TileRef> iterator = getTiles(circuit).iterator();
        while (iterator.hasNext())
        {
            final TileRef newTile = iterator.next();
            if (mapGroup.getGroup(newTile).equals(mapGroup.getGroup(tile)))
            {
                map.setTile(map.createTile(newTile.getSheet(), newTile.getNumber(), neighbor.getX(), neighbor.getY()));
                break;
            }
        }
    }
999978
public boolean clear(TileBasedMap map, Space space) {
		if (tileBased) {
			return true;
		}
		
		float x = 0;
		boolean donex = false;
		
		while (x < space.getWidth()) {
			float y = 0;
			boolean doney = false;
			
			while (y < space.getHeight()) {
				sx = (int) (space.getX()+x);
				sy = (int) (space.getY()+y);
				
				if (map.blocked(this, sx, sy)) {
					return false;
				}
				
				y += 0.1f;
				if ((y > space.getHeight()) && (!doney)) {
					y = space.getHeight();
					doney = true;
				}
			}
			
			
			x += 0.1f;
			if ((x > space.getWidth()) && (!donex)) {
				x = space.getWidth();
				donex = true;
			}
		}
		
		return true;
	}
886538
function getTile(e) {
        var g = grid();
        var regExp = new RegExp(gm.tileRegexp());
        for (var i = 0; i < g.length; i++) {
            if (e) {
                var isInside = ((g[i][0] <= e.y) &&
                     ((g[i][0] + 256) > e.y) &&
                      (g[i][1] <= e.x) &&
                     ((g[i][1] + 256) > e.x));
                if(isInside && regExp.exec(g[i][2].src)) {
                    return g[i][2];
                }
            }
        }
        return false;
    }
912193
function(x, y){
            var result = [];

            var entity = this.entityManager.get(x, y);
            if(entity){
                result.push(entity);
            }

            // add items or any other objects that can be placed at a tile coord position

            return result;
        }
162312
public static void main(String[] args) throws Exception {

		boolean valid = true;
		boolean requiredArguments = false;

		TileFormatType tileType = null;
		String imageFormat = null;
		boolean rawImage = false;
		File geoPackageFile = null;
		String tileTable = null;
		File outputDirectory = null;
		Integer width = null;
		Integer height = null;

		for (int i = 0; valid && i < args.length; i++) {

			String arg = args[i];

			// Handle optional arguments
			if (arg.startsWith(ARGUMENT_PREFIX)) {

				String argument = arg.substring(ARGUMENT_PREFIX.length());

				switch (argument) {
				case ARGUMENT_TILE_TYPE:
					if (i < args.length) {
						String tiletypeString = args[++i].toUpperCase();
						try {
							tileType = TileFormatType.valueOf(tiletypeString);
						} catch (IllegalArgumentException e) {
							valid = false;
							System.out
									.println("Error: Image Tile Type argument '"
											+ arg
											+ "' must be followed by a valid tile format type. Invalid: "
											+ tiletypeString);
						}
					} else {
						valid = false;
						System.out
								.println("Error: Tile Type argument '"
										+ arg
										+ "' must be followed by a tile type (geopackage, standard, tms)");
					}
					break;

				case ARGUMENT_IMAGE_FORMAT:
					if (i < args.length) {
						imageFormat = args[++i];
					} else {
						valid = false;
						System.out.println("Error: Image Format argument '"
								+ arg + "' must be followed by a image format");
					}
					break;

				case ARGUMENT_RAW_IMAGE:
					rawImage = true;
					break;

				case ARGUMENT_IMAGE_WIDTH:
					if (i < args.length) {
						String widthString = args[++i];
						try {
							width = Integer.valueOf(widthString);
						} catch (NumberFormatException e) {
							valid = false;
							System.out
									.println("Error: Image Width argument '"
											+ arg
											+ "' must be followed by a valid width in pixels. Invalid: "
											+ widthString);
						}
					} else {
						valid = false;
						System.out
								.println("Error: Image Width argument '"
										+ arg
										+ "' must be followed by a image width in pixels");
					}
					break;

				case ARGUMENT_IMAGE_HEIGHT:
					if (i < args.length) {
						String heightString = args[++i];
						try {
							height = Integer.valueOf(heightString);
						} catch (NumberFormatException e) {
							valid = false;
							System.out
									.println("Error: Image Height argument '"
											+ arg
											+ "' must be followed by a valid height in pixels. Invalid: "
											+ heightString);
						}
					} else {
						valid = false;
						System.out
								.println("Error: Image Height argument '"
										+ arg
										+ "' must be followed by a height width in pixels");
					}
					break;

				default:
					valid = false;
					System.out.println("Error: Unsupported arg: '" + arg + "'");
				}

			} else {
				// Set required arguments in order
				if (geoPackageFile == null) {
					geoPackageFile = new File(arg);
				} else if (tileTable == null) {
					tileTable = arg;
				} else if (outputDirectory == null) {
					outputDirectory = new File(arg);
					requiredArguments = true;
				} else {
					valid = false;
					System.out.println("Error: Unsupported extra argument: "
							+ arg);
				}
			}
		}

		if (!valid || !requiredArguments) {
			printUsage();
		} else {
			// Write the tiles
			try {
				writeTiles(geoPackageFile, tileTable, outputDirectory,
						imageFormat, width, height, tileType, rawImage);
			} catch (Exception e) {
				printUsage();
				throw e;
			}
		}

	}
589258
def get_tile_image(self, x, y, layer):
        
        try:
            assert (x >= 0 and y >= 0)
        except AssertionError:
            raise ValueError

        try:
            layer = self.layers[layer]
        except IndexError:
            raise ValueError

        assert (isinstance(layer, TiledTileLayer))

        try:
            gid = layer.data[y][x]
        except (IndexError, ValueError):
            raise ValueError
        except TypeError:
            msg = "Tiles must be specified in integers."
            logger.debug(msg)
            raise TypeError

        else:
            return self.get_tile_image_by_gid(gid)
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;
        }
    }
108245
function(layer, xy) {
        var loc = this.map.getLonLatFromPixel(xy);
        var getTileUrl = layer.getURL(
            new OpenLayers.Bounds(loc.lon, loc.lat, loc.lon, loc.lat)
        );
        var params = OpenLayers.Util.getParameters(getTileUrl);
        var tileInfo = layer.getTileInfo(loc);
        OpenLayers.Util.extend(params, {
            service: "WMTS",
            version: layer.version,
            request: "GetFeatureInfo",
            infoFormat: this.infoFormat,
            i: tileInfo.i,
            j: tileInfo.j
        });
        OpenLayers.Util.applyDefaults(params, this.vendorParams);
        return {
            url: OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url,
            params: OpenLayers.Util.upperCaseObject(params),
            callback: function(request) {
                this.handleResponse(xy, request, layer);
            },
            scope: this
        };
    }
591459
public Image getSprite(int x, int y) {
		target.init();
		initImpl();

		if ((x < 0) || (x >= subImages.length)) {
			throw new RuntimeException("SubImage out of sheet bounds: "+x+","+y);
		}
		if ((y < 0) || (y >= subImages[0].length)) {
			throw new RuntimeException("SubImage out of sheet bounds: "+x+","+y);
		}

		return target.getSubImage(x*(tw+spacing) + margin, y*(th+spacing) + margin,tw,th); 
	}
686893
def tile(self, z, x, y):
        
        logger.debug(_("Download tile %s") % ((z, x, y),))
        # Render each keyword in URL ({s}, {x}, {y}, {z}, {size} ... )
        size = self.tilesize
        s = self.tiles_subdomains[(x + y) % len(self.tiles_subdomains)];
        try:
            url = self.tiles_url.format(**locals())
        except KeyError as e:
            raise DownloadError(_("Unknown keyword %s in URL") % e)

        logger.debug(_("Retrieve tile at %s") % url)
        r = DOWNLOAD_RETRIES
        sleeptime = 1
        while r > 0:
            try:
                request = requests.get(url, headers=self.headers)
                if request.status_code == 200:
                    return request.content
                raise DownloadError(_("Status code : %s, url : %s") % (request.status_code, url))
            except requests.exceptions.ConnectionError as e:
                logger.debug(_("Download error, retry (%s left). (%s)") % (r, e))
                r -= 1
                time.sleep(sleeptime)
                # progressivly sleep longer to wait for this tile
                if (sleeptime <= 10) and (r % 2 == 0):
                    sleeptime += 1  # increase wait
        raise DownloadError(_("Cannot download URL %s") % url)
180234
public void setTileFormat(TileFormatType tileFormat) {
		if (tileFormat == null) {
			tileFormat = TileFormatType.STANDARD;
		} else {
			switch (tileFormat) {
			case STANDARD:
			case TMS:
				this.tileFormat = tileFormat;
				break;
			default:
				throw new GeoPackageException(
						"Unsupported Tile Format Type for URL Tile Generation: "
								+ tileFormat);
			}
		}
	}
798730
@Override
    public void renderTile(Graphic g, MapTile map, Tile tile, int x, int y)
    {
        final SpriteTiled sprite = map.getSheet(tile.getSheet());
        sprite.setLocation(x, y);
        sprite.setTile(tile.getNumber());
        sprite.render(g);
    }
713556
private void updateTransitiveTile(Tile tile)
    {
        final Circuit circuit = extractor.getCircuit(tile);
        if (circuit == null || !circuits.containsKey(circuit))
        {
            final String group = getTransitiveGroup(circuit, tile);
            if (group != null)
            {
                final TileRef ref = mapTransition.getTiles(new Transition(TransitionType.CENTER, group, group))
                                                 .iterator()
                                                 .next();
                final Tile newTile = map.createTile(ref.getSheet(), ref.getNumber(), tile.getX(), tile.getY());
                map.setTile(newTile);
                mapTransition.resolve(newTile);
                map.setTile(tile);
            }
        }
    }
80071
private static Collection<TileRef> getTiles(Map<ColorRgba, Collection<TileRef>> colors, ColorRgba color)
    {
        if (!colors.containsKey(color))
        {
            colors.put(color, new HashSet<TileRef>());
        }
        return colors.get(color);
    }