简体   繁体   English

在Carto移动SDK中获取触摸的MapTile的x和y像素

[英]Get x and y pixel of touched MapTile in Carto mobile SDK

I have a RasterTileLayer for showing wms layer and i need getting features of touched area from geoServer; 我有一个用于显示wms图层的RasterTileLayer,我需要从geoServer获取触摸区域的功能; but geoServer needs x and y coordinate of touched mapTile in range of 0 to 256 (cause tile size set to 256); 但是geoServer需要触摸的mapTile的x和y坐标在0到256范围内(因为瓦片大小设置为256); but i don`t know how to get it or calculate it,Do you have any solution? 但是我不知道如何得到或计算它,你有什么解决方案吗?

in general you will receive click events by registering your RasterTileEventListener. 通常,您将通过注册RasterTileEventListener来接收点击事件。 But the argument you receive (RasterTileClickInfo) does not currently provide you exact click coordinates. 但是,您收到的参数(RasterTileClickInfo)当前无法为您提供确切的点击坐标。 In SDK versions prior to 4.1.4 you have to do some calculations manually. 在4.1.4之前的SDK版本中,您必须手动进行一些计算。 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. 请注意,您可能需要从底部开始翻转y坐标。

As a side note, SDK 4.1.4 exposes TileUtils class with some static methods that perform the same calculations used above. 附带说明一下,SDK 4.1.4通过一些静态方法公开了TileUtils类,这些方法执行与上面使用的相同的计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM