I have a RasterTileLayer for showing wms layer and i need getting features of touched area from geoServer; but geoServer needs x and y coordinate of touched mapTile in range of 0 to 256 (cause tile size set to 256); but i don`t know how to get it or calculate it,Do you have any solution?
Asked
Active
Viewed 106 times
0
-
Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour) and read through the [help center](http://stackoverflow.com/help), in particular how to ask. Your best bet here is to do your research, search for related topics on SO, and give it a go. After doing more research and searching, post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) of your attempt and say specifically where you're stuck, which can help you get better answers. – help-info.de Sep 09 '18 at 09:18
1 Answers
0
in general you will receive click events by registering your RasterTileEventListener. But the argument you receive (RasterTileClickInfo) does not currently provide you exact click coordinates. In SDK versions prior to 4.1.4 you have to do some calculations manually. The following snippet should help you:
rasterLayer.setRasterTileEventListener(new RasterTileEventListener() {
@Override
public boolean onRasterTileClicked(RasterTileClickInfo clickInfo) {
MapTile mapTile = clickInfo.getMapTile();
Projection proj = rasterLayer.getDataSource().getProjection();
double projTileWidth = proj.getBounds().getDelta().getX() / (1 << mapTile.getZoom());
double projTileHeight = proj.getBounds().getDelta().getY() / (1 << mapTile.getZoom());
double projTileX0 = proj.getBounds().getMin().getX() + mapTile.getX() * projTileWidth;
double projTileY0 = proj.getBounds().getMin().getY() + ((1 << mapTile.getZoom()) - 1 - mapTile.getY()) * projTileHeight;
double normTileX = (clickInfo.getClickPos().getX() - projTileX0) / projTileWidth;
double normTileY = (clickInfo.getClickPos().getY() - projTileY0) / projTileHeight;
Log.d("", "Clicked at: " + (int) (normTileX * 256) + ", " + (int) (normTileY * 256));
return true;
}
});
Note that you may need to flip the y-coordinate as it starts from the bottom.
As a side note, SDK 4.1.4 exposes TileUtils class with some static methods that perform the same calculations used above.

MarkT
- 301
- 2
- 2