Mercurial > gemma
annotate pkg/geoserver/templates.go @ 4285:6b415dcdaf8a
Let the geoserver expose primary keys for features.
author | Raimund Renkert <raimund@renkert.org> |
---|---|
date | Fri, 30 Aug 2019 09:29:19 +0200 |
parents | 152b9eb5ca47 |
children | 124a5a7fe8d6 |
rev | line source |
---|---|
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
13 // * Markus Kottländer <markus.kottlaender@intevation.de> |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package geoserver |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
18 "context" |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
19 "database/sql" |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
20 "regexp" |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "strings" |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
22 "text/template" |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
23 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/auth" |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/models" |
3826
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 ) |
4b1184fa0326
Added templating and a failing test.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
28 const ( |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
29 selectConfigValSQL = ` |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
30 SELECT config_val FROM sys_admin.system_config |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
31 WHERE config_key = $1` |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
32 ) |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
33 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
34 func init() { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
35 RegisterStylePreprocessor( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
36 "sounding_results_contour_lines_geoserver", |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
37 templateContourLinesFunc("morphology_classbreaks")) |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
38 RegisterStylePreprocessor( |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
39 "sounding_differences", |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
40 templateContourLinesFunc("morphology_classbreaks_compare")) |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
41 RegisterStylePreprocessor( |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
42 "distance_marks_geoserver", |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
43 templateConfigValues) |
4247
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
44 RegisterStylePreprocessor( |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
45 "distance_marks_ashore_geoserver", |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
46 templateConfigValues) |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
47 RegisterStylePreprocessor( |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
48 "waterway_area", |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
49 templateConfigValues) |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
50 RegisterStylePreprocessor( |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
51 "waterway_axis", |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4232
diff
changeset
|
52 templateConfigValues) |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
53 // TODO: Add more layers. |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
54 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
55 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
56 func templateConfigValues(tmplTxt string) (string, error) { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
57 tmpl, err := template.New("template").Parse(tmplTxt) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
58 if err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
59 return "", err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
60 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
61 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
62 // Try to extract the needed keys from the template. |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
63 keys := extractKeysFromTemplate(tmplTxt) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
64 kv, err := loadConfigValues(keys) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
65 if err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
66 return "", err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
67 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
68 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
69 var buf strings.Builder |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
70 if err = tmpl.Execute(&buf, kv); err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
71 return "", err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
72 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
73 return buf.String(), nil |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
74 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
75 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
76 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
77 // TODO: Use the parse tree of the template to extract keys. |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
78 var findKeysRe = regexp.MustCompile(`{{[-]?\s*\.([^-.\s]+)\s*[-]?}}`) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
79 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
80 func extractKeysFromTemplate(tmpl string) []string { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
81 parts := findKeysRe.FindAllStringSubmatch(tmpl, -1) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
82 keys := make(map[string]struct{}) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
83 for _, part := range parts { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
84 keys[part[1]] = struct{}{} |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
85 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
86 out := make([]string, len(keys)) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
87 var i int |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
88 for key := range keys { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
89 out[i] = key |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
90 i++ |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
91 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
92 return out |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
93 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
94 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
95 func loadConfigValues(keys []string) (map[string]string, error) { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
96 kv := make(map[string]string, len(keys)) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
97 if len(keys) == 0 { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
98 return kv, nil |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
99 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
100 ctx := context.Background() |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
101 if err := auth.RunAs( |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
102 ctx, |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
103 "sys_admin", |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
104 func(conn *sql.Conn) error { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
105 stmt, err := conn.PrepareContext(ctx, selectConfigValSQL) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
106 if err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
107 return err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
108 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
109 defer stmt.Close() |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
110 for _, key := range keys { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
111 var val string |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
112 if err := stmt.QueryRowContext(ctx, key).Scan(&val); err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
113 return err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
114 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
115 kv[key] = val |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
116 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
117 return nil |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
118 }, |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
119 ); err != nil { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
120 return nil, err |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
121 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
122 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
123 return kv, nil |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
124 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
125 |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
126 func templateContourLinesFunc(configKey string) func(string) (string, error) { |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
127 return func(data string) (string, error) { |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
128 return templateContourLines(data, configKey) |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
129 } |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
130 } |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
131 |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
132 func templateContourLines(data, configKey string) (string, error) { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
133 tmpl, err := template.New("template").Parse(data) |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
134 if err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
135 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
136 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
137 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
138 var cb []models.ClassBreak |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
139 |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
140 if cb, err = countourLinesClassBreaks(configKey); err != nil { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
141 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
142 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
143 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
144 var buf strings.Builder |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
145 if err = tmpl.Execute(&buf, cb); err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
146 return "", err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
147 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
148 return buf.String(), nil |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
149 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
150 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
151 func countourLinesClassBreaks(configKey string) ([]models.ClassBreak, error) { |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
152 |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
153 var config string |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
154 ctx := context.Background() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
155 if err := auth.RunAs( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
156 ctx, |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
157 "sys_admin", |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
158 func(conn *sql.Conn) error { |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
159 return conn.QueryRowContext( |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
160 ctx, |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
161 selectConfigValSQL, |
3831
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
162 configKey, |
0ffea636d6b0
Prepared class break templating mechanism to work with differences, too. Needs an adjusted template.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3830
diff
changeset
|
163 ).Scan(&config) |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
164 }, |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
165 ); err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
166 return nil, err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
167 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
168 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
169 cc, err := models.ParseColorValues(config) |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
170 if err != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
171 return nil, err |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
172 } |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
173 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3831
diff
changeset
|
174 return cc.ClassBreaks(), nil |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3826
diff
changeset
|
175 } |