diff --git a/API/Line.go b/API/Line.go index ed354ca..068b61f 100644 --- a/API/Line.go +++ b/API/Line.go @@ -13,7 +13,7 @@ import ( // @Accept json // @Produce json // @Param id 5dfb03070a9ac17ac7a82054 string true "id" -// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /LineInfo? [get] func LineInfo(c *gin.Context) { @@ -51,7 +51,7 @@ func LineInfo(c *gin.Context) { // @Description 查询所有线路 // @Accept json // @Produce json -// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /AllLine? [get] func AllLine(c *gin.Context) { @@ -97,6 +97,7 @@ func UpdateLine(c *gin.Context) { "PlayDuration": c.PostForm("PlayDuration"), "Suitable": c.PostForm("Suitable"), "Content": c.PostForm("Content"), + "Distance": c.PostForm("Distance"), "Annotations": Annotations, "Location": Location, }}, diff --git a/API/Tiles.go b/API/Tiles.go new file mode 100644 index 0000000..aaeb446 --- /dev/null +++ b/API/Tiles.go @@ -0,0 +1,42 @@ +package Api + +import ( + "fmt" + "github.com/gin-gonic/gin" + "io/ioutil" + "os" +) + +func Tiles(c *gin.Context) { + + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + dir, _ := os.Getwd() + + //path := dir + "/tiles/" + c.Query("z") + "/" + c.Query("x") + "/" + c.Query("y") + ".jpg" + path := fmt.Sprintf("%s/tiles/%s/%s/%s.jpg",dir,c.Query("z"),c.Query("x"),c.Query("y")) + + if !PathExists(path) { + path = dir + "/tiles/blank.png" + } + + b, err := ioutil.ReadFile(path) + if err != nil { + fmt.Print(err) + } + + + c.Data(200, "Content-type: image/jpeg", b) +} + +func PathExists(path string) (bool) { + _, err := os.Stat(path) + if err == nil { + return true + } + if os.IsNotExist(err) { + return false + } + return false +} diff --git a/DB/db.go b/DB/db.go index 1792fcb..4e7b6bf 100644 --- a/DB/db.go +++ b/DB/db.go @@ -65,6 +65,7 @@ type SLine struct { PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` Suitable string `bson:"Suitable" json:"Suitable"` //适合人群 Content string `bson:"Content" json:"Content"` + Distance string `bson:"Distance" json:"Distance"` // 距离 Annotations []string `bson:"Annotations" json:"Annotations"` //需要点亮的设施id } diff --git a/README.md b/README.md index 8cb3592..f8df8ca 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ | Code | Type | Model | Message | |-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | @@ -210,7 +210,7 @@ | Code | Type | Model | Message | |-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | diff --git a/main.go b/main.go index 25f4519..301f28d 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,8 @@ func main() { r := gin.Default() //r.Static("/.well-known", "./.well-known/") - r.Static("/tiles", dir+"/tiles") + //r.Static("/tiles", dir+"/tiles") + r.GET("/Tiles", Api.Tiles) r.GET("/AllItems", Api.AllItems) r.GET("/AllCommodity", Api.AllCommodity) r.GET("/AllLine", Api.AllLine) -- libgit2 0.21.0