@lbdudc/gp-gis-dsl 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,8 +43,15 @@ createGeoJSONLayer: GEOJSON_SYMBOL LAYER_SYMBOL identifier (AS_SYMBOL text)? OPA
43
43
  STROKE_OPACITY_SYMBOL floatNumber
44
44
  CPAR_SYMBOL SCOL_SYMBOL;
45
45
 
46
+ sldCustomBody: GEOMETRY_TYPE_SYMBOL TYPE COMMA_SYMBOL
47
+ FILL_COLOR_SYMBOL? hexColor? COMMA_SYMBOL?
48
+ STROKE_COLOR_SYMBOL? hexColor? COMMA_SYMBOL?
49
+ FILL_OPACITY_SYMBOL? (floatNumber | intNumber)? COMMA_SYMBOL?
50
+ STROKE_OPACITY_SYMBOL? (floatNumber | intNumber)?;
51
+
46
52
  createWmsStyle: WMS_SYMBOL STYLE_SYMBOL identifier OPAR_SYMBOL
47
- SLD_SYMBOL text
53
+ (SLD_SYMBOL text)? COMMA_SYMBOL?
54
+ sldCustomBody?
48
55
  CPAR_SYMBOL SCOL_SYMBOL;
49
56
 
50
57
  createWmsLayer: WMS_SYMBOL LAYER_SYMBOL identifier (AS_SYMBOL text)? OPAR_SYMBOL
@@ -106,6 +113,7 @@ text: QUOTED_TEXT;
106
113
 
107
114
  hexColor: HEX_COLOR;
108
115
  floatNumber: FLOAT_NUMBER;
116
+ intNumber: INT_NUMBER;
109
117
 
110
118
 
111
119
  //-----------------------------------------------------------------------
@@ -168,6 +176,7 @@ MAPPEDBY_SYMBOL: M A P P E D UNDERLINE_SYMBOL B Y;
168
176
  LAYER_SYMBOL: L A Y E R;
169
177
  TILE_SYMBOL: T I L E;
170
178
  GEOJSON_SYMBOL: G E O J S O N;
179
+ GEOMETRY_TYPE_SYMBOL: G E O M E T R Y T Y P E;
171
180
  AS_SYMBOL: A S;
172
181
  URL_SYMBOL: U R L;
173
182
  SLD_SYMBOL: S T Y L E L A Y E R D E S C R I P T O R;
@@ -198,6 +207,7 @@ TYPE
198
207
  | L O C A L D A T E
199
208
  | S T R I N G
200
209
  | L I N E S T R I N G
210
+ | L I N E
201
211
  | M U L T I L I N E S T R I N G
202
212
  | P O L Y G O N
203
213
  | M U L T I P O L Y G O N
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lbdudc/gp-gis-dsl",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "homepage": "https://github.com/lbdudc/gis-dsl#readme",
5
5
  "repository": {
6
6
  "type": "git",
package/src/GISVisitor.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  WMSLayer,
8
8
  Map,
9
9
  GeoJSONLayerStyle,
10
+ WMSStyleCustom,
10
11
  } from "./spl/Map.js";
11
12
  import { transformation, getPropertyParams } from "./GISVisitorHelper.js";
12
13
  // import { generateProduct } from "./project-generator.js";
@@ -198,10 +199,59 @@ class Visitor extends GISGrammarVisitor {
198
199
  }
199
200
 
200
201
  visitCreateWmsStyle(ctx) {
201
- const id = ctx.getChild(2).getText();
202
- const sld = ctx.getChild(5).getText().slice(1, -1);
203
- this.log(`visitCreateWmsStyle ${id} with ${sld}`);
204
- this.store.getCurrentProduct().addStyle(new WMSStyle(id, sld));
202
+ const descriptor = ctx
203
+ .getChild(4)
204
+ .getText()
205
+ .startsWith("styleLayerDescriptor");
206
+ if (descriptor) {
207
+ const id = ctx.getChild(2).getText();
208
+ const sld = ctx.getChild(5).getText().slice(1, -1);
209
+ this.log(`visitCreateWmsStyle ${id} with ${sld}`);
210
+ this.store.getCurrentProduct().addStyle(new WMSStyle(id, sld));
211
+ } else {
212
+ let style = {
213
+ geometryType: null,
214
+ fillColor: null,
215
+ strokeColor: null,
216
+ fillOpacity: null,
217
+ strokeOpacity: null,
218
+ };
219
+ const id = ctx.getChild(2).getText();
220
+ const props = ctx.getChild(4).getText();
221
+
222
+ props.split(",").forEach((field) => {
223
+ if (field.startsWith("geometryType")) {
224
+ style.geometryType = field.split("geometryType")[1];
225
+ } else if (field.startsWith("fillColor")) {
226
+ if (field.split("fillColor")[1] == "null") style.fillColor = null;
227
+ else style.fillColor = field.split("fillColor")[1]; // Remove the '#' symbol
228
+ } else if (field.startsWith("strokeColor")) {
229
+ if (field.split("strokeColor")[1] == "null") style.strokeColor = null;
230
+ else style.strokeColor = field.split("strokeColor")[1]; // Remove the '#' symbol
231
+ } else if (field.startsWith("fillOpacity")) {
232
+ style.fillOpacity = parseFloat(field.split("fillOpacity")[1]);
233
+ } else if (field.startsWith("strokeOpacity")) {
234
+ style.strokeOpacity = parseFloat(field.split("strokeOpacity")[1]);
235
+ }
236
+ });
237
+
238
+ this.log(
239
+ `visitCreateWmsStyle ${id} - ${style.geometryType}, ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity}`,
240
+ );
241
+
242
+ this.store
243
+ .getCurrentProduct()
244
+ .addStyle(
245
+ new WMSStyleCustom(
246
+ id,
247
+ style.geometryType,
248
+ style.fillColor,
249
+ style.strokeColor,
250
+ style.fillOpacity,
251
+ style.strokeOpacity,
252
+ ),
253
+ );
254
+ }
205
255
  }
206
256
 
207
257
  visitCreateWmsLayer(ctx) {
@@ -1,162 +1,93 @@
1
- function transformation(spec) {
2
- _relationships(spec);
3
- const newSpec = {
4
- features: [
5
- "GEMA_SPL",
6
- "DataManagement",
7
- "GraphicalUserInterface",
8
- "MapViewer",
9
- "Tools",
10
- "DM_SpatialDatabase",
11
- "DM_GenerationType",
12
- "DM_DataServer",
13
- "MV_MapServer",
14
- "MV_Tools",
15
- "MV_MapManagement",
16
- "DM_SD_PostGIS",
17
- "MV_T_Pan",
18
- "MV_T_Zoom",
19
- "DM_GT_Sequence",
20
- "MV_MM_MultipleMapViewer",
21
- "MV_MM_MMV_MapSelectorInMapViewer",
22
- "MV_MM_MMV_MapSelectorInMenuElement",
23
- "MV_MS_GeoServer",
24
- "GUI_Forms",
25
- "GUI_F_Editable",
26
- "GUI_F_Creatable",
27
- "GUI_F_Removable",
28
- "GUI_F_R_ConfirmationAlert",
29
- "GUI_Lists",
30
- "GUI_L_FormLink",
31
- "GUI_L_F_BasicSearch",
32
- "GUI_L_Filterable",
33
- "GUI_L_Sortable",
34
- "GUI_L_LocateInMap",
35
- "GUI_L_ViewListAsMap",
36
- "GUI_L_Export",
37
- "GUI_StaticPages",
38
- "MV_ContextInformation",
39
- "MV_CI_Scale",
40
- "MV_CI_Map",
41
- "MV_CI_CenterCoordinates",
42
- "MV_CI_Dimensions",
43
- "MV_DetailOnClick",
44
- "MV_LayerManagement",
45
- "MV_LM_CenterViewOnLayer",
46
- "MV_LM_Order",
47
- "MV_LM_Opacity",
48
- "MV_LM_HideLayer",
49
- "MV_LM_Style",
50
- "MV_LM_ExternalLayer",
51
- "MV_LM_StylePreview",
52
- "MV_T_Export",
53
- "MV_T_E_Type",
54
- "MV_T_E_F_URL",
55
- "MV_T_E_F_PDF",
56
- "MV_T_E_SetScale",
57
- "MV_T_E_ShowLegend",
58
- "MV_T_InformationMode",
59
- "MV_T_MeasureControl",
60
- "MV_T_M_Distance",
61
- "MV_T_M_Line",
62
- "MV_T_M_Polygon",
63
- "MV_T_ZoomWindow",
64
- "GUI_Menu",
65
- "GUI_M_Position",
66
- "GUI_M_Top",
67
- "DM_DataInput",
68
- "DM_DI_DataFeeding",
69
- "DM_DI_DF_Shapefile",
70
- "T_GIS",
71
- "T_EntitiesInformation",
72
- "D_C_Postgres",
73
- "D_C_Geoserver",
74
- "D_C_Nginx",
75
- ],
76
- basicData: {
77
- name: spec.name,
78
- },
79
- data: {
80
- dataModel: {
81
- entities: spec.entities,
82
- enums: [],
83
- },
84
- },
85
- mapViewer: {
86
- maps: spec.maps,
87
- layers: spec.layers,
88
- styles: spec.styles,
89
- },
90
- };
91
-
92
- if (spec.extra) {
93
- newSpec.basicData.extra = spec.extra;
94
- }
95
-
96
- return newSpec;
97
- }
98
-
99
- function _relationships(spec) {
100
- let source, target;
101
-
102
- spec.relationships.forEach((r) => {
103
- source = spec.getEntity(r.source);
104
- target = spec.getEntity(r.target);
105
- let sourceOwner = false;
106
- let targetOwner = false;
107
- let sourceMultiple = _multiple(r.sourceOpts.multiplicity);
108
- let targetMultiple = _multiple(r.targetOpts.multiplicity);
109
- if (sourceMultiple && !targetMultiple) {
110
- targetOwner = true;
111
- } else {
112
- sourceOwner = true;
113
- }
114
-
115
- source.properties.push({
116
- name: r.sourceOpts.label,
117
- class: target.name,
118
- owner: sourceOwner,
119
- bidirectional: r.targetOpts.label,
120
- multiple: sourceMultiple,
121
- required: _required(r.sourceOpts.multiplicity),
122
- });
123
-
124
- target.properties.push({
125
- name: r.targetOpts.label,
126
- class: source.name,
127
- owner: targetOwner,
128
- bidirectional: r.sourceOpts.label,
129
- multiple: targetMultiple,
130
- required: _required(r.targetOpts.multiplicity),
131
- });
132
- });
133
- }
134
-
135
- function _multiple(multiplicity) {
136
- return ["1..1", "0..1"].find((a) => a == multiplicity) == null;
137
- }
138
-
139
- function _required(multiplicity) {
140
- return ["1..1", "1..*"].find((a) => a == multiplicity) != null;
141
- }
142
-
143
- function getPropertyParams(symbols) {
144
- if (!symbols.length) return null;
145
-
146
- const ret = {};
147
- if (symbols.includes("identifier")) {
148
- ret.pk = true;
149
- }
150
- if (symbols.includes("required")) {
151
- ret.required = true;
152
- }
153
- if (symbols.includes("unique")) {
154
- ret.unique = true;
155
- }
156
- if (symbols.includes("display_string")) {
157
- ret.displayString = true;
158
- }
159
- return ret;
160
- }
161
-
162
- export { transformation, getPropertyParams };
1
+ import features from "./features.js";
2
+
3
+ function transformation(spec) {
4
+ _relationships(spec);
5
+ const newSpec = {
6
+ features: features,
7
+ basicData: {
8
+ name: spec.name,
9
+ },
10
+ data: {
11
+ dataModel: {
12
+ entities: spec.entities,
13
+ enums: [],
14
+ },
15
+ },
16
+ mapViewer: {
17
+ maps: spec.maps,
18
+ layers: spec.layers,
19
+ styles: spec.styles,
20
+ },
21
+ };
22
+
23
+ if (spec.extra) {
24
+ newSpec.basicData.extra = spec.extra;
25
+ }
26
+
27
+ return newSpec;
28
+ }
29
+
30
+ function _relationships(spec) {
31
+ let source, target;
32
+
33
+ spec.relationships.forEach((r) => {
34
+ source = spec.getEntity(r.source);
35
+ target = spec.getEntity(r.target);
36
+ let sourceOwner = false;
37
+ let targetOwner = false;
38
+ let sourceMultiple = _multiple(r.sourceOpts.multiplicity);
39
+ let targetMultiple = _multiple(r.targetOpts.multiplicity);
40
+ if (sourceMultiple && !targetMultiple) {
41
+ targetOwner = true;
42
+ } else {
43
+ sourceOwner = true;
44
+ }
45
+
46
+ source.properties.push({
47
+ name: r.sourceOpts.label,
48
+ class: target.name,
49
+ owner: sourceOwner,
50
+ bidirectional: r.targetOpts.label,
51
+ multiple: sourceMultiple,
52
+ required: _required(r.sourceOpts.multiplicity),
53
+ });
54
+
55
+ target.properties.push({
56
+ name: r.targetOpts.label,
57
+ class: source.name,
58
+ owner: targetOwner,
59
+ bidirectional: r.sourceOpts.label,
60
+ multiple: targetMultiple,
61
+ required: _required(r.targetOpts.multiplicity),
62
+ });
63
+ });
64
+ }
65
+
66
+ function _multiple(multiplicity) {
67
+ return ["1..1", "0..1"].find((a) => a == multiplicity) == null;
68
+ }
69
+
70
+ function _required(multiplicity) {
71
+ return ["1..1", "1..*"].find((a) => a == multiplicity) != null;
72
+ }
73
+
74
+ function getPropertyParams(symbols) {
75
+ if (!symbols.length) return null;
76
+
77
+ const ret = {};
78
+ if (symbols.includes("identifier")) {
79
+ ret.pk = true;
80
+ }
81
+ if (symbols.includes("required")) {
82
+ ret.required = true;
83
+ }
84
+ if (symbols.includes("unique")) {
85
+ ret.unique = true;
86
+ }
87
+ if (symbols.includes("display_string")) {
88
+ ret.displayString = true;
89
+ }
90
+ return ret;
91
+ }
92
+
93
+ export { transformation, getPropertyParams };
package/src/cli.js CHANGED
@@ -1,34 +1,34 @@
1
- #!/usr/bin/env node
2
-
3
- import meow from "meow";
4
- import fs from "fs";
5
- import gisdslParser from "./index.js";
6
- import path from "path";
7
-
8
- const usage = "Usage: gisdsl input output";
9
-
10
- const cli = meow(usage, {
11
- importMeta: import.meta,
12
- flags: {
13
- debug: {
14
- type: "boolean",
15
- default: false,
16
- },
17
- },
18
- });
19
-
20
- if (cli.input.length < 2) {
21
- cli.showHelp();
22
- }
23
-
24
- const inputPath = path.resolve(process.cwd(), cli.input.at(0));
25
- const input = fs.readFileSync(inputPath, {
26
- encoding: "utf-8",
27
- });
28
-
29
- const spec = gisdslParser(input, cli.flags.debug);
30
-
31
- const outputPath = path.resolve(process.cwd(), cli.input.at(1));
32
- fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2), "utf8");
33
-
34
- console.log(`File ${cli.input.at(1)} generated`);
1
+ #!/usr/bin/env node
2
+
3
+ import meow from "meow";
4
+ import fs from "fs";
5
+ import gisdslParser from "./index.js";
6
+ import path from "path";
7
+
8
+ const usage = "Usage: gisdsl input output";
9
+
10
+ const cli = meow(usage, {
11
+ importMeta: import.meta,
12
+ flags: {
13
+ debug: {
14
+ type: "boolean",
15
+ default: false,
16
+ },
17
+ },
18
+ });
19
+
20
+ if (cli.input.length < 2) {
21
+ cli.showHelp();
22
+ }
23
+
24
+ const inputPath = path.resolve(process.cwd(), cli.input.at(0));
25
+ const input = fs.readFileSync(inputPath, {
26
+ encoding: "utf-8",
27
+ });
28
+
29
+ const spec = gisdslParser(input, cli.flags.debug);
30
+
31
+ const outputPath = path.resolve(process.cwd(), cli.input.at(1));
32
+ fs.writeFileSync(outputPath, JSON.stringify(spec, null, 2), "utf8");
33
+
34
+ console.log(`File ${cli.input.at(1)} generated`);
@@ -1,26 +1,26 @@
1
- import antlr4 from "antlr4";
2
-
3
- import SyntaxGenericError from "./SyntaxGenericError.js";
4
-
5
- /**
6
- * Custom Error Listener
7
- *
8
- * @returns {object}
9
- */
10
- class ErrorListener extends antlr4.error.ErrorListener {
11
- /**
12
- * Checks syntax error
13
- *
14
- * @param {object} recognizer The parsing support code essentially. Most of it is error recovery stuff
15
- * @param {object} symbol Offending symbol
16
- * @param {int} line Line of offending symbol
17
- * @param {int} column Position in line of offending symbol
18
- * @param {string} message Error message
19
- * @param {string} payload Stack trace
20
- */
21
- syntaxError(recognizer, symbol, line, column, message) {
22
- throw new SyntaxGenericError({ line, column, message });
23
- }
24
- }
25
-
26
- export default ErrorListener;
1
+ import antlr4 from "antlr4";
2
+
3
+ import SyntaxGenericError from "./SyntaxGenericError.js";
4
+
5
+ /**
6
+ * Custom Error Listener
7
+ *
8
+ * @returns {object}
9
+ */
10
+ class ErrorListener extends antlr4.error.ErrorListener {
11
+ /**
12
+ * Checks syntax error
13
+ *
14
+ * @param {object} recognizer The parsing support code essentially. Most of it is error recovery stuff
15
+ * @param {object} symbol Offending symbol
16
+ * @param {int} line Line of offending symbol
17
+ * @param {int} column Position in line of offending symbol
18
+ * @param {string} message Error message
19
+ * @param {string} payload Stack trace
20
+ */
21
+ syntaxError(recognizer, symbol, line, column, message) {
22
+ throw new SyntaxGenericError({ line, column, message });
23
+ }
24
+ }
25
+
26
+ export default ErrorListener;
@@ -0,0 +1,53 @@
1
+ export default [
2
+ "MapViewer",
3
+ "Tools",
4
+ "DM_SpatialDatabase",
5
+ "DM_GenerationType",
6
+ "DM_DataServer",
7
+ "MV_MapServer",
8
+ "MV_Tools",
9
+ "MV_MapManagement",
10
+ "DM_SD_PostGIS",
11
+ "DM_GT_Sequence",
12
+ "MV_MM_MultipleMapViewer",
13
+ "MV_MM_MMV_MapSelectorInMapViewer",
14
+ "MV_MM_MMV_MapSelectorInMenuElement",
15
+ "MV_MS_GeoServer",
16
+ "GUI_Lists",
17
+ "GUI_L_FormLink",
18
+ "GUI_L_F_BasicSearch",
19
+ "GUI_L_Filterable",
20
+ "GUI_L_Sortable",
21
+ "GUI_L_LocateInMap",
22
+ "GUI_L_ViewListAsMap",
23
+ "MV_ContextInformation",
24
+ "MV_CI_Scale",
25
+ "MV_CI_Map",
26
+ "MV_CI_CenterCoordinates",
27
+ "MV_CI_Dimensions",
28
+ "MV_DetailOnClick",
29
+ "MV_LayerManagement",
30
+ "MV_LM_CenterViewOnLayer",
31
+ "MV_LM_Order",
32
+ "MV_LM_Opacity",
33
+ "MV_LM_HideLayer",
34
+ "MV_LM_Style",
35
+ "MV_LM_ExternalLayer",
36
+ "MV_LM_StylePreview",
37
+ "MV_T_E_Type",
38
+ "MV_T_E_F_URL",
39
+ "MV_T_E_F_PDF",
40
+ "MV_T_E_SetScale",
41
+ "MV_T_E_ShowLegend",
42
+ "MV_T_InformationMode",
43
+ "MV_T_MeasureControl",
44
+ "MV_T_ZoomWindow",
45
+ "DM_DataInput",
46
+ "DM_DI_DataFeeding",
47
+ "DM_DI_DF_Shapefile",
48
+ "T_GIS",
49
+ "T_EntitiesInformation",
50
+ "D_C_Postgres",
51
+ "D_C_Geoserver",
52
+ "D_C_Nginx",
53
+ ];
package/src/index.js CHANGED
@@ -1,26 +1,26 @@
1
- import antlr4 from "antlr4";
2
- import GISGrammarLexer from "./lib/GISGrammarLexer.js";
3
- import GISGrammarParser from "./lib/GISGrammarParser.js";
4
- import ErrorListener from "./error/ErrorListener.js";
5
- import GISVisitor from "./GISVisitor.js";
6
- import store from "./store.js";
7
-
8
- export default function parse(inputStr, debug = false) {
9
- const chars = new antlr4.InputStream(inputStr);
10
- const lexer = new GISGrammarLexer(chars);
11
- lexer.strictMode = false; // do not use js strictMode
12
-
13
- const tokens = new antlr4.CommonTokenStream(lexer);
14
- const parser = new GISGrammarParser(tokens);
15
-
16
- const errorListener = new ErrorListener();
17
- // Do this after creating the parser and before running it
18
- parser.removeErrorListeners(); // Remove default ConsoleErrorListener
19
- parser.addErrorListener(errorListener); // Add custom error listener
20
-
21
- const visitor = new GISVisitor(store, debug);
22
- const tree = parser.parse();
23
- visitor.start(tree);
24
-
25
- return store.getLastGeneratedProduct();
26
- }
1
+ import antlr4 from "antlr4";
2
+ import GISGrammarLexer from "./lib/GISGrammarLexer.js";
3
+ import GISGrammarParser from "./lib/GISGrammarParser.js";
4
+ import ErrorListener from "./error/ErrorListener.js";
5
+ import GISVisitor from "./GISVisitor.js";
6
+ import store from "./store.js";
7
+
8
+ export default function parse(inputStr, debug = false) {
9
+ const chars = new antlr4.InputStream(inputStr);
10
+ const lexer = new GISGrammarLexer(chars);
11
+ lexer.strictMode = false; // do not use js strictMode
12
+
13
+ const tokens = new antlr4.CommonTokenStream(lexer);
14
+ const parser = new GISGrammarParser(tokens);
15
+
16
+ const errorListener = new ErrorListener();
17
+ // Do this after creating the parser and before running it
18
+ parser.removeErrorListeners(); // Remove default ConsoleErrorListener
19
+ parser.addErrorListener(errorListener); // Add custom error listener
20
+
21
+ const visitor = new GISVisitor(store, debug);
22
+ const tree = parser.parse();
23
+ visitor.start(tree);
24
+
25
+ return store.getLastGeneratedProduct();
26
+ }