在LeafletJS中使用自定义地图图像图块? [英] Using custom map image tiles in LeafletJS?

查看:755
本文介绍了在LeafletJS中使用自定义地图图像图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的瓷砖需要遵守任何特定规格吗?

Do my tiles need to adhere to any particular specs?

我有一个很大的图像文件,我想用LeafletJS变成一张地图.我将使用Python Imaging Library将其切成我需要的所有各种图块.

I have a large image file which I'd like to turn into a map with LeafletJS. I am going to be using the Python Imaging Library to cut it up into all the various tiles I need.

但是,我在Leaflet中找不到有关使用自定义地图的任何信息.是否以某种方式向Leaflet提供X,Y,Z信息范围?我要给它每个瓦片的像素大小吗?它会自己解决吗?

However, I can't find any information about using custom maps in Leaflet. Do I provide Leaflet with the range of X,Y,Z info somehow? Do I give it the pixel size of each tile? Does it figure this out on its own?

将我的问题简化为一个简单的问题:要使图像文件可以与LeafletJS一起用作地图图块,我需要做什么?在前端脚本中需要做些什么(如果有的话) ? (除了明显指定我的自定义网址外)

To put my question into one concise question: What do I need to do in order to have image files that can double as map tiles with LeafletJS, and what, if anything, do I need to do in my front-end script? (beyond the obvious specifying of my custom URL)

推荐答案

您正在寻找 TileLayer .在此TileLayer中,使用以下模板将要获取的图像的URL分配给传单:

You are looking for a TileLayer. In this TileLayer, you give the URL for the to-be-fetched images to leaflet with a template like this:

http://{s}.somedomain.com/blabla/{z}/{x}/{y}.png

当您处于指定的缩放级别(x和y)时,Leaflet将自动获取您提供的URL上的图块.

When you are at the specified zoom, x and y level, Leaflet will automatically fetch the tiles on the URL you gave.

但是,根据要显示的图像,大部分工作将在图块生成中.默认情况下,图块的大小为256x256px(可以在TileLayer选项中更改),如果使用的是地理数据,则使用的投影是Mercator投影.可能需要一些时间来获得正确的图块ID. 这里是一个示例,说明磁贴ID的工作方式.

Depending on the image you want to show, the bigger part of the work will however be in the tile generation. Tiles by default have a 256x256px size (can be changed in the TileLayer options), and if you are using geodata the used projection is Mercator projection. It may take some time to get the tile ids right. Here is an example on how the tile ids work.

这篇关于在LeafletJS中使用自定义地图图像图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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