forked from MTSR/mapserver
colormapping api
This commit is contained in:
parent
eee305180f
commit
8d233df733
@ -20,6 +20,10 @@ func (m *ColorMapping) GetColor(name string) *color.RGBA {
|
|||||||
return m.colors[name]
|
return m.colors[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ColorMapping) GetColors() map[string]*color.RGBA {
|
||||||
|
return m.colors
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ColorMapping) LoadBytes(buffer []byte) (int, error) {
|
func (m *ColorMapping) LoadBytes(buffer []byte) (int, error) {
|
||||||
scanner := bufio.NewScanner(bytes.NewReader(buffer))
|
scanner := bufio.NewScanner(bytes.NewReader(buffer))
|
||||||
count := 0
|
count := 0
|
||||||
|
29
server/web/colormapping.go
Normal file
29
server/web/colormapping.go
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"mapserver/app"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ColorMappingHandler struct {
|
||||||
|
ctx *app.App
|
||||||
|
}
|
||||||
|
|
||||||
|
type Color struct {
|
||||||
|
R uint8 `json:"r"`
|
||||||
|
G uint8 `json:"g"`
|
||||||
|
B uint8 `json:"b"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ColorMappingHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
cm := make(map[string]Color)
|
||||||
|
|
||||||
|
for k, v := range h.ctx.Colormapping.GetColors() {
|
||||||
|
cm[k] = Color{R: v.R, G: v.G, B: v.B}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.Header().Add("content-type", "application/json")
|
||||||
|
json.NewEncoder(resp).Encode(cm)
|
||||||
|
}
|
@ -31,6 +31,7 @@ func Serve(ctx *app.App) {
|
|||||||
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
|
mux.Handle("/api/config", &ConfigHandler{ctx: ctx})
|
||||||
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
mux.Handle("/api/minetest", &Minetest{ctx: ctx})
|
||||||
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
mux.Handle("/api/mapobjects/", &MapObjects{ctx: ctx})
|
||||||
|
mux.Handle("/api/colormapping/", &ColorMappingHandler{ctx: ctx})
|
||||||
|
|
||||||
if ctx.Config.MapObjects.Areas {
|
if ctx.Config.MapObjects.Areas {
|
||||||
mux.Handle("/api/areas", &AreasHandler{ctx: ctx})
|
mux.Handle("/api/areas", &AreasHandler{ctx: ctx})
|
||||||
|
Loading…
Reference in New Issue
Block a user