如何通过点击传单图来获取瓷砖的X Y坐标 [英] How to get X Y Z coordinates of tile by click on Leaflet map

查看:212
本文介绍了如何通过点击传单图来获取瓷砖的X Y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想请求帮助处理地图上的非标准坐标可能的使用单张。

I want to ask for help to deal with the possible use of non-standard coordinates on the map Leaflet.

我想使用单张显示使用自己的瓦片生成器的自定义地图。按照脚本生成的瓦片,取决于计划显示的位置(脚本的URL请求中的参数{x},{y},{z})
Map将是可缩放的(从0到10),最大缩放约16000 * 16000个图块的大小,最小16×16个图块的大小),它将显示各种对象,每个对象在一个单独的图块中。
64 * 64像素的每个图块是地图上的对象。
对于每个对象(方块),我想通过AJAX请求发送到服务器来显示它的鼠标点击信息。我不想预先加载有关所有对象的所有信息,以实现优化。
我的主要问题 - 我无法理解如何正确获取鼠标点击的瓦片的X YЯ坐标。
基本上是因为从服务器加载的每个磁贴绑定到网格{x},{y},{z},所以我想得到这些{x},{y},{z}从地图上的点击,并发送他们进一步的AJAX请求获取关于对象的信息。
现在可以将点击点作为Latlng坐标或坐标,以相对于地图左上角的像素为单位,我无法引用到瓷砖网格。

I want to use Leaflet to display custom maps with my own tile generator. Tiles are generated on the fly by script, depending on where it is planned to display (parameters {x}, {y}, {z} in the URL request to the script) Map will be zoomable (from 0 to 10), size of ~16000 * 16000 tiles in maximum zoom, and 16 * 16 tiles in a minimum) and it will display a variety of objects, each object in a separate tile. Each tile of 64 * 64 pixels is the object on map. For each object (a square-tile) I want to display it`s information on mouse click, by sending via AJAX request to the server. I did not want to pre-load all information about all objects for the goal of optimization. My main issue - I cannot understand how to correctly get the X Y Я coordinates of the tile on which mouse clicked. Essentially because each tile when it is loaded from the server is bound to the grid {x}, {y}, {z}, and so I want to get these {x}, {y}, {z} from clicks on the map and send them for further AJAX request for getting information about the object. Now it is possible to get click point as Latlng coordinates or coordinates in pixels relative to the upper-left corner of the map, which I cannot reference to tiles grid.

此外,我也想知道获取点击坐标相对于平铺图的可能性。例如,如果图块的尺寸为64 * 64,并且点击位于图块的中心,那么如何获取点击的相对坐标[32,32]?
因为如果我们知道瓦片中的瓦片的{X},{Y},{Z}坐标和点击的相对X *和Y *坐标,那么我们可以做通用替代坐标网格。

And also I wanted to know the possibility to get the coordinates of the click relative to the tile. For example, If the tile has dimensions of 64 * 64, and click was in the center of the tile, so how can I get relative coordinate of click [32, 32]? Because If we knowing {X}, {Y}, {Z} coordinates of the tile and relative X* and Y* coordinates of click inside the tile, then we can do "universal alternative coordinate grid".

可能这不是一个问题,可以很容易解决,但我从来没有使用任何Maps API,因此我想知道这个答案题。

May be this is not a problem and it can be solved easily, but I've never worked with any Maps API, and therefore I want to know the answer to this question.

提前感谢您的帮助!

推荐答案

获取点击图块的缩放,X和Y坐标的工作示例(使用openstreet地图): http://jsfiddle.net/84P9r/

Here is a working example for getting Zoom, X, and Y coordinates of clicked tile (using openstreet map): http://jsfiddle.net/84P9r/

function getTileURL(lat, lon, zoom) {
    var xtile = parseInt(Math.floor( (lon + 180) / 360 * (1<<zoom) ));
    var ytile = parseInt(Math.floor( (1 - Math.log(Math.tan(lat.toRad()) + 1 / Math.cos(lat.toRad())) / Math.PI) / 2 * (1<<zoom) ));
    return "" + zoom + "/" + xtile + "/" + ytile;
}

根据答案 http://stackoverflow.com/a/19197572

这篇关于如何通过点击传单图来获取瓷砖的X Y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆