How TO serve Map tiles from a database using Leafletjs

一世执手 提交于 2019-11-28 07:05:50

问题


Leaflet js requires the following tile source format:

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

How can I serve tile images from a database instead of file system using Leafletjs (and ASP.net)


回答1:


You'll need to write a server application that reads a request URL, pulls tiles out of a database, and delivers them over the web. JavaScript does not read directly from databases.




回答2:


This works very fast and seamlessly with Leaflet:

Apparently Leaflet just uses the z,x,y place holders to request specific tiles.

How you generate and return the tiles is very flexible indeed

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

where 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


来源:https://stackoverflow.com/questions/29732790/how-to-serve-map-tiles-from-a-database-using-leafletjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!