https://github.com/JasonJe/offline-tileServer
func (c *Context) AsciiJSON(code int, obj interface{})
func (c *Context) Data(code int, contentType string, data []byte)
func (c *Context) DataFromReader(code int, contentLength int64, contentType string,
reader io.Reader, extraHeaders map[string]string)
func (c *Context) HTML(code int, name string, obj interface{})
func (c *Context) IndentedJSON(code int, obj interface{})
func (c *Context) JSON(code int, obj interface{})
func (c *Context) JSONP(code int, obj interface{})
func (c *Context) ProtoBuf(code int, obj interface{})
func (c *Context) PureJSON(code int, obj interface{})
func (c *Context) Redirect(code int, location string)
func (c *Context) Render(code int, r render.Render)
func (c *Context) SecureJSON(code int, obj interface{})
func (c *Context) String(code int, format string, values ...interface{})
func (c *Context) XML(code int, obj interface{})
func (c *Context) YAML(code int, obj interface{})
package main
import "github.com/gin-gonic/gin"
import "io/ioutil"
import "fmt"
func main() {
router := gin.Default()
router.GET("/tile", func(c *gin.Context) {
x := c.Query("x")
y := c.Query("y")
z := c.Query("z")
path := fmt.Sprintf("./tilefile/%s/%s_%s.png", z,x,y)
fmt.Println(path)
content, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err)
}
c.Writer.WriteString(string(content))
})
router.Run(":8080")
}
<!DOCTYPE html>
<html>
<head>
<title>Tile Server</title>
<meta charset="utf-8">
<link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/leaflet/1.3.1/leaflet.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/leaflet/1.3.1/leaflet.js"></script>
<style TYPE="text/css">
body {
margin: 0px;
padding: 0px;
}
html,
body,
#mapDiv {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="mapDiv">
</div>
<script>
var url = 'http://192.168.1.7:8080/tile?x={x}&y={y}&z={z}';
var latlng = new L.latLng(23.461, 111.921);
var map = new L.map('mapDiv', {
center: latlng,
zoom: 12,
detectRetina: true
});
L.tileLayer(url).addTo(map);
</script>
</body>
</html>
有疑问加站长微信联系(非本文作者)