Commit ec7ef34e172ab7520bc8be90746994ad3ed1f702
1 parent
8bd8be34
Exists in
v1.2
and in
2 other branches
...
Showing
5 changed files
with
50 additions
and
5 deletions
Show diff stats
API/Line.go
| @@ -13,7 +13,7 @@ import ( | @@ -13,7 +13,7 @@ import ( | ||
| 13 | // @Accept json | 13 | // @Accept json |
| 14 | // @Produce json | 14 | // @Produce json |
| 15 | // @Param id 5dfb03070a9ac17ac7a82054 string true "id" | 15 | // @Param id 5dfb03070a9ac17ac7a82054 string true "id" |
| 16 | -// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" | 16 | +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离" |
| 17 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | 17 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" |
| 18 | // @Router /LineInfo? [get] | 18 | // @Router /LineInfo? [get] |
| 19 | func LineInfo(c *gin.Context) { | 19 | func LineInfo(c *gin.Context) { |
| @@ -51,7 +51,7 @@ func LineInfo(c *gin.Context) { | @@ -51,7 +51,7 @@ func LineInfo(c *gin.Context) { | ||
| 51 | // @Description 查询所有线路 | 51 | // @Description 查询所有线路 |
| 52 | // @Accept json | 52 | // @Accept json |
| 53 | // @Produce json | 53 | // @Produce json |
| 54 | -// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id" | 54 | +// @Success 200 {object} tools.ResponseSeccess "Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离" |
| 55 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | 55 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" |
| 56 | // @Router /AllLine? [get] | 56 | // @Router /AllLine? [get] |
| 57 | func AllLine(c *gin.Context) { | 57 | func AllLine(c *gin.Context) { |
| @@ -97,6 +97,7 @@ func UpdateLine(c *gin.Context) { | @@ -97,6 +97,7 @@ func UpdateLine(c *gin.Context) { | ||
| 97 | "PlayDuration": c.PostForm("PlayDuration"), | 97 | "PlayDuration": c.PostForm("PlayDuration"), |
| 98 | "Suitable": c.PostForm("Suitable"), | 98 | "Suitable": c.PostForm("Suitable"), |
| 99 | "Content": c.PostForm("Content"), | 99 | "Content": c.PostForm("Content"), |
| 100 | + "Distance": c.PostForm("Distance"), | ||
| 100 | "Annotations": Annotations, | 101 | "Annotations": Annotations, |
| 101 | "Location": Location, | 102 | "Location": Location, |
| 102 | }}, | 103 | }}, |
| @@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
| 1 | +package Api | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/gin-gonic/gin" | ||
| 6 | + "io/ioutil" | ||
| 7 | + "os" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +func Tiles(c *gin.Context) { | ||
| 11 | + | ||
| 12 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | ||
| 13 | + c.Header("Access-Control-Allow-Credentials", "true") | ||
| 14 | + | ||
| 15 | + dir, _ := os.Getwd() | ||
| 16 | + | ||
| 17 | + //path := dir + "/tiles/" + c.Query("z") + "/" + c.Query("x") + "/" + c.Query("y") + ".jpg" | ||
| 18 | + path := fmt.Sprintf("%s/tiles/%s/%s/%s.jpg",dir,c.Query("z"),c.Query("x"),c.Query("y")) | ||
| 19 | + | ||
| 20 | + if !PathExists(path) { | ||
| 21 | + path = dir + "/tiles/blank.png" | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + b, err := ioutil.ReadFile(path) | ||
| 25 | + if err != nil { | ||
| 26 | + fmt.Print(err) | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + c.Data(200, "Content-type: image/jpeg", b) | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func PathExists(path string) (bool) { | ||
| 34 | + _, err := os.Stat(path) | ||
| 35 | + if err == nil { | ||
| 36 | + return true | ||
| 37 | + } | ||
| 38 | + if os.IsNotExist(err) { | ||
| 39 | + return false | ||
| 40 | + } | ||
| 41 | + return false | ||
| 42 | +} |
DB/db.go
| @@ -65,6 +65,7 @@ type SLine struct { | @@ -65,6 +65,7 @@ type SLine struct { | ||
| 65 | PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` | 65 | PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` |
| 66 | Suitable string `bson:"Suitable" json:"Suitable"` //适合人群 | 66 | Suitable string `bson:"Suitable" json:"Suitable"` //适合人群 |
| 67 | Content string `bson:"Content" json:"Content"` | 67 | Content string `bson:"Content" json:"Content"` |
| 68 | + Distance string `bson:"Distance" json:"Distance"` // 距离 | ||
| 68 | Annotations []string `bson:"Annotations" json:"Annotations"` //需要点亮的设施id | 69 | Annotations []string `bson:"Annotations" json:"Annotations"` //需要点亮的设施id |
| 69 | } | 70 | } |
| 70 | 71 |
README.md
| @@ -93,7 +93,7 @@ | @@ -93,7 +93,7 @@ | ||
| 93 | 93 | ||
| 94 | | Code | Type | Model | Message | | 94 | | Code | Type | Model | Message | |
| 95 | |-----|-----|-----|-----| | 95 | |-----|-----|-----|-----| |
| 96 | -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id | | 96 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离 | |
| 97 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | 97 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | |
| 98 | 98 | ||
| 99 | 99 | ||
| @@ -210,7 +210,7 @@ | @@ -210,7 +210,7 @@ | ||
| 210 | 210 | ||
| 211 | | Code | Type | Model | Message | | 211 | | Code | Type | Model | Message | |
| 212 | |-----|-----|-----|-----| | 212 | |-----|-----|-----|-----| |
| 213 | -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id | | 213 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Name名称;SubName副标题;PlayDuration游玩时长;Suitable适合人群;Location线路点坐标;Annotations需要点亮的设施id;Distance距离 | |
| 214 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | 214 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | |
| 215 | 215 | ||
| 216 | 216 |
main.go
| @@ -46,7 +46,8 @@ func main() { | @@ -46,7 +46,8 @@ func main() { | ||
| 46 | 46 | ||
| 47 | r := gin.Default() | 47 | r := gin.Default() |
| 48 | //r.Static("/.well-known", "./.well-known/") | 48 | //r.Static("/.well-known", "./.well-known/") |
| 49 | - r.Static("/tiles", dir+"/tiles") | 49 | + //r.Static("/tiles", dir+"/tiles") |
| 50 | + r.GET("/Tiles", Api.Tiles) | ||
| 50 | r.GET("/AllItems", Api.AllItems) | 51 | r.GET("/AllItems", Api.AllItems) |
| 51 | r.GET("/AllCommodity", Api.AllCommodity) | 52 | r.GET("/AllCommodity", Api.AllCommodity) |
| 52 | r.GET("/AllLine", Api.AllLine) | 53 | r.GET("/AllLine", Api.AllLine) |