Using custom map image tiles in LeafletJS?

后端 未结 2 685
清酒与你
清酒与你 2020-12-07 08:44

Do my tiles need to adhere to any particular specs?

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 Im

2条回答
  •  一整个雨季
    2020-12-07 09:01

    You can even serve tiles directly from a database.

    The format leaflet specifies is very flexible.

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

    For example:

    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
    

提交回复
热议问题