1
0
forked from MTSR/mapserver

custom colors

This commit is contained in:
NatureFreshMilk 2019-02-08 07:40:40 +01:00
parent df67703e10
commit 986b9dbdb9
4 changed files with 66 additions and 24 deletions

View File

@ -1,12 +1,29 @@
# Configuration # Configuration
## Colors
There are builtin default colors, if you want new ones or override them
just put your `colors.txt` in the same directory the mapserver runs.
Example `colors.txt`:
```
# scifi nodes
scifi_nodes:slope_white 240 240 240
scifi_nodes:slope_vent 120 120 120
scifi_nodes:white2 240 240 240
```
Default colors, see: [colors.txt](../server/static/colors.txt)
## Configuration json
All config options reside in the `mapserver.json` file with the default values All config options reside in the `mapserver.json` file with the default values
Please stop the server if you make any changes there. Please stop the server if you make any changes there.
The mapserver will generate a fresh `mapserver.json` if there is none at startup. The mapserver will generate a fresh `mapserver.json` if there is none at startup.
## Example json ### Example json
```json ```json
{ {
"port": 8080, "port": 8080,
@ -16,14 +33,6 @@ The mapserver will generate a fresh `mapserver.json` if there is none at startup
"enablemapblock": false, "enablemapblock": false,
"secretkey": "ZJoSpysiKGlYexof" "secretkey": "ZJoSpysiKGlYexof"
}, },
"renderstate": {
"initialrun": false,
"legacyprocessed": 16111,
"lastx": 3,
"lasty": 3,
"lastz": 8,
"lastmtime": 0
},
"layers": [ "layers": [
{ {
"id": 0, "id": 0,
@ -38,15 +47,15 @@ The mapserver will generate a fresh `mapserver.json` if there is none at startup
} }
``` ```
## Settings ### Settings
### port #### port
The port on which the server listens to The port on which the server listens to
### webapi.secretkey #### webapi.secretkey
The generated secret for the [mod bridge](./install) The generated secret for the [mod bridge](./install)
### layers #### layers
The layers as a list The layers as a list
More layers can be added here: More layers can be added here:
```json ```json
@ -70,5 +79,5 @@ Don't reuse the `id` after the tiles are generated.
If you make more substantial changes here you may have to remove all If you make more substantial changes here you may have to remove all
existing tiles and start rendering from scratch. existing tiles and start rendering from scratch.
### renderingjobs #### renderingjobs
Number of cores to use for rendering, defaults to all available cores Number of cores to use for rendering, defaults to all available cores

View File

@ -14,6 +14,9 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"os"
"io/ioutil"
"errors" "errors"
) )
@ -50,10 +53,33 @@ func Setup(p params.ParamsType, cfg *Config) *App {
//color mapping //color mapping
a.Colormapping = colormapping.NewColorMapping() a.Colormapping = colormapping.NewColorMapping()
err = a.Colormapping.LoadVFSColors(false, "/colors.txt")
//load default colors
count, err := a.Colormapping.LoadVFSColors(false, "/colors.txt")
if err != nil { if err != nil {
panic(err) panic(err)
} }
logrus.WithFields(logrus.Fields{"count": count}).Info("Loaded default colors")
//load provided colors, if available
info, err := os.Stat("colors.txt")
if info != nil && err == nil {
logrus.WithFields(logrus.Fields{"filename": "colors.txt"}).Info("Loading colors from filesystem")
data, err := ioutil.ReadFile("colors.txt")
if err != nil {
panic(err)
}
count, err = a.Colormapping.LoadBytes(data)
if err != nil {
panic(err)
}
logrus.WithFields(logrus.Fields{"count": count}).Info("Loaded custom colors")
}
//mapblock renderer //mapblock renderer
a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping) a.Mapblockrenderer = mapblockrenderer.NewMapBlockRenderer(a.BlockAccessor, a.Colormapping)

View File

@ -19,9 +19,14 @@ func (m *ColorMapping) GetColor(name string) *color.RGBA {
return m.colors[name] return m.colors[name]
} }
func (m *ColorMapping) LoadBytes(buffer []byte) error { func (m *ColorMapping) LoadBytes(buffer []byte) (int, error) {
scanner := bufio.NewScanner(bytes.NewReader(buffer)) scanner := bufio.NewScanner(bytes.NewReader(buffer))
count := 0
line := 0
for scanner.Scan() { for scanner.Scan() {
line++
txt := strings.Trim(scanner.Text(), " ") txt := strings.Trim(scanner.Text(), " ")
if len(txt) == 0 { if len(txt) == 0 {
@ -37,27 +42,28 @@ func (m *ColorMapping) LoadBytes(buffer []byte) error {
parts := strings.Fields(txt) parts := strings.Fields(txt)
if len(parts) < 4 { if len(parts) < 4 {
return errors.New("invalid line") return 0, errors.New("invalid line: #" + strconv.Itoa(line))
} }
if len(parts) >= 4 { if len(parts) >= 4 {
r, err := strconv.ParseInt(parts[1], 10, 32) r, err := strconv.ParseInt(parts[1], 10, 32)
if err != nil { if err != nil {
return err return 0, err
} }
g, err := strconv.ParseInt(parts[2], 10, 32) g, err := strconv.ParseInt(parts[2], 10, 32)
if err != nil { if err != nil {
return err return 0, err
} }
b, err := strconv.ParseInt(parts[3], 10, 32) b, err := strconv.ParseInt(parts[3], 10, 32)
if err != nil { if err != nil {
return err return 0, err
} }
c := color.RGBA{uint8(r), uint8(g), uint8(b), 0xFF} c := color.RGBA{uint8(r), uint8(g), uint8(b), 0xFF}
m.colors[parts[0]] = &c m.colors[parts[0]] = &c
count++
} }
if len(parts) >= 5 { if len(parts) >= 5 {
@ -66,20 +72,20 @@ func (m *ColorMapping) LoadBytes(buffer []byte) error {
} }
return nil return count, nil
} }
//TODO: colors from fs //TODO: colors from fs
func (m *ColorMapping) LoadVFSColors(useLocal bool, filename string) error { func (m *ColorMapping) LoadVFSColors(useLocal bool, filename string) (int, error) {
buffer, err := vfs.FSByte(useLocal, "/colors.txt") buffer, err := vfs.FSByte(useLocal, "/colors.txt")
if err != nil { if err != nil {
return err return 0, err
} }
log.WithFields(logrus.Fields{"size": len(buffer), log.WithFields(logrus.Fields{"size": len(buffer),
"filename": filename, "filename": filename,
"useLocal": useLocal}).Info("Loading local colors file") "useLocal": useLocal}).Info("Loading default colors")
return m.LoadBytes(buffer) return m.LoadBytes(buffer)
} }

1
server/colors.txt Normal file
View File

@ -0,0 +1 @@
test:example 147 94 25 1 2