如何使用 Leafletjs 从数据库提供地图图块

How TO serve Map tiles from a database using Leafletjs

Leaflet js 需要以下图块源格式:

http://localhost/tileserver/{z}/{x}/{y}.png

如何使用 Leafletjs 从数据库而不是文件系统提供平铺图像 (和 ASP.net)

您需要编写一个服务器应用程序来读取请求 URL,从数据库中提取图块,然后通过 Web 传送它们。 JavaScript 不直接从数据库读取。

这与 Leaflet 配合得非常快且无缝:

显然 Leaflet 只使用 z,x,y 占位符来请求特定的图块。

您如何生成并且 return 瓷砖确实非常灵活

L.tileLayer('**http://localhost/tileserver/tile.aspx?z={z}&x={x}&y={y}**', {
    minZoom: 7, maxZoom: 16,
    attribution: 'My Tile Server'
}).addTo(map);

其中 Tiles.aspx

Option Strict On

Partial Class tile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim z, x, y As Integer

        z = CInt(Request.QueryString("z"))
        x = CInt(Request.QueryString("x"))
        y = CInt(Request.QueryString("y"))

        Dim b() As Byte = DB.GetTile(z, x, y)

        Response.Buffer = True
        Response.Charset = ""
        'Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "image/png"
        Response.AddHeader("content-disposition", "attachment;filename=" & y & ".png")
        Response.BinaryWrite(b)
        Response.Flush()
        Response.End()
    End Sub