@lbdudc/gp-gis-dsl 0.2.0

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.
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ test/files/**/*
2
+ src/lib/**/*
package/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ package-lock.json diff
2
+ *.g4 diff
3
+ *.interp diff
4
+ *.tokens diff
@@ -0,0 +1,2 @@
1
+ test/files/**/*
2
+ src/lib/**/*
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Víctor Lamas
4
+ Copyright (c) 2023 Databases Laboratory - University of A Coruña
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # GIS DSL
2
+
3
+ ![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)
4
+ ![Node.js Version](https://img.shields.io/badge/node-%3E%3D%2019.0.0-brightgreen.svg)
5
+ ![npm version](https://badge.fury.io/js/gis-dsl.svg)
6
+
7
+ It parses a DSL instance and generates the spec for the web-based GIS SPL.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import gisdslParser from "gisdsl";
19
+
20
+ const spec = gisdslParser(inputString);
21
+ ```
22
+
23
+ The DSL instance must finish with a `GENERATE GIS` sentence in order to work. See examples within the tests files.
24
+
25
+ ## Pre-requisites
26
+
27
+ - Have installed in your machine:
28
+ - [Node.js](https://nodejs.org/en/download/)
29
+
30
+ ## Author
31
+
32
+ Alejandro Cortiñas
33
+ Email: <alejandro.cortinas@udc.es>
34
+
35
+ ## License
36
+
37
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
@@ -0,0 +1,230 @@
1
+ grammar GISGrammar;
2
+
3
+ parse
4
+ : sentence+
5
+ ;
6
+
7
+ sentence
8
+ : createStatement
9
+ | useGIS
10
+ | generateGIS
11
+ | setDeployment
12
+ ;
13
+
14
+ createStatement:
15
+ CREATE_SYMBOL (
16
+ createGIS
17
+ | createEntity
18
+ | createLayer
19
+ )
20
+ ;
21
+
22
+ createGIS:
23
+ GIS_SYMBOL identifier USING_SYMBOL srid SCOL_SYMBOL
24
+ ;
25
+
26
+ createEntity:
27
+ ENTITY_SYMBOL identifier OPAR_SYMBOL
28
+ property (COMMA_SYMBOL property)*
29
+ CPAR_SYMBOL SCOL_SYMBOL
30
+ ;
31
+
32
+ createLayer: createTileLayer | createGeoJSONLayer | createWmsStyle | createWmsLayer | createMap | createSortableMap;
33
+
34
+ createTileLayer: TILE_SYMBOL LAYER_SYMBOL identifier (AS_SYMBOL text)? OPAR_SYMBOL
35
+ URL_SYMBOL text
36
+ CPAR_SYMBOL SCOL_SYMBOL;
37
+
38
+ createGeoJSONLayer: GEOJSON_SYMBOL LAYER_SYMBOL identifier (AS_SYMBOL text)? OPAR_SYMBOL
39
+ identifier (EDITABLE_SYMBOL)? COMMA_SYMBOL
40
+ FILL_COLOR_SYMBOL hexColor COMMA_SYMBOL
41
+ STROKE_COLOR_SYMBOL hexColor COMMA_SYMBOL
42
+ FILL_OPACITY_SYMBOL floatNumber COMMA_SYMBOL
43
+ STROKE_OPACITY_SYMBOL floatNumber
44
+ CPAR_SYMBOL SCOL_SYMBOL;
45
+
46
+ createWmsStyle: WMS_SYMBOL STYLE_SYMBOL identifier OPAR_SYMBOL
47
+ SLD_SYMBOL text
48
+ CPAR_SYMBOL SCOL_SYMBOL;
49
+
50
+ createWmsLayer: WMS_SYMBOL LAYER_SYMBOL identifier (AS_SYMBOL text)? OPAR_SYMBOL
51
+ wmsSubLayer (COMMA_SYMBOL wmsSubLayer)*
52
+ CPAR_SYMBOL SCOL_SYMBOL;
53
+
54
+ wmsSubLayer: identifier identifier;
55
+
56
+ createSortableMap: SORTABLE_SYMBOL createMap;
57
+
58
+ createMap: MAP_SYMBOL identifier (AS_SYMBOL text)? OPAR_SYMBOL
59
+ mapLayer (COMMA_SYMBOL mapLayer)*
60
+ CPAR_SYMBOL SCOL_SYMBOL;
61
+
62
+ mapLayer: identifier (IS_BASE_LAYER_SYMBOL)? (HIDDEN_SYMBOL)?;
63
+
64
+ useGIS: USE_SYMBOL GIS_SYMBOL identifier SCOL_SYMBOL;
65
+
66
+ generateGIS: GENERATE_SYMBOL GIS_SYMBOL identifier SCOL_SYMBOL;
67
+
68
+ setDeployment:
69
+ SET_SYMBOL DEPLOYMENT_SYMBOL OPAR_SYMBOL
70
+ deploymentProperty (COMMA_SYMBOL deploymentProperty)*
71
+ CPAR_SYMBOL SCOL_SYMBOL
72
+ ;
73
+
74
+ deploymentProperty: text text;
75
+
76
+ property: propertyDefinition | relationshipDefinition;
77
+
78
+ propertyDefinition:
79
+ identifier TYPE (
80
+ IDENTIFIER_SYMBOL
81
+ | DISPLAYSTRING_SYMBOL
82
+ | REQUIRED_SYMBOL
83
+ | UNIQUE_SYMBOL
84
+ )*
85
+ ;
86
+
87
+ relationshipDefinition:
88
+ ownedRelationshipDefinition | mappedRelationshipDefinition;
89
+
90
+ mappedRelationshipDefinition:
91
+ identifier identifier RELATIONSHIP_SYMBOL MAPPEDBY_SYMBOL identifier;
92
+
93
+ ownedRelationshipDefinition:
94
+ identifier identifier RELATIONSHIP_SYMBOL OPAR_SYMBOL cardinality COMMA_SYMBOL cardinality
95
+ CPAR_SYMBOL BIDIRECTIONAL_SYMBOL?;
96
+
97
+ cardinality:
98
+ ZERO_ONE_SYMBOL
99
+ | ONE_ONE_SYMBOL
100
+ | ZERO_MANY_SYMBOL
101
+ | ONE_MANY_SYMBOL
102
+ ;
103
+ srid: INT_NUMBER;
104
+ identifier: IDENTIFIER;
105
+ text: QUOTED_TEXT;
106
+
107
+ hexColor: HEX_COLOR;
108
+ floatNumber: FLOAT_NUMBER;
109
+
110
+
111
+ //-----------------------------------------------------------------------
112
+
113
+
114
+ fragment A: [aA];
115
+ fragment B: [bB];
116
+ fragment C: [cC];
117
+ fragment D: [dD];
118
+ fragment E: [eE];
119
+ fragment F: [fF];
120
+ fragment G: [gG];
121
+ fragment H: [hH];
122
+ fragment I: [iI];
123
+ fragment J: [jJ];
124
+ fragment K: [kK];
125
+ fragment L: [lL];
126
+ fragment M: [mM];
127
+ fragment N: [nN];
128
+ fragment O: [oO];
129
+ fragment P: [pP];
130
+ fragment Q: [qQ];
131
+ fragment R: [rR];
132
+ fragment S: [sS];
133
+ fragment T: [tT];
134
+ fragment U: [uU];
135
+ fragment V: [vV];
136
+ fragment W: [wW];
137
+ fragment X: [xX];
138
+ fragment Y: [yY];
139
+ fragment Z: [zZ];
140
+
141
+ fragment DIGIT: [0-9];
142
+ fragment DIGITS: DIGIT+;
143
+ fragment HEXDIGIT: [0-9a-fA-F];
144
+
145
+
146
+
147
+ fragment LETTER_WHEN_UNQUOTED_NO_DIGIT: [a-zA-Z_$\u0080-\uffff];
148
+ fragment LETTER_WHEN_UNQUOTED: DIGIT | LETTER_WHEN_UNQUOTED_NO_DIGIT;
149
+ // Any letter but without e/E and digits (which are used to match a decimal number).
150
+ fragment LETTER_WITHOUT_FLOAT_PART: [a-df-zA-DF-Z_$\u0080-\uffff];
151
+
152
+ fragment UNDERLINE_SYMBOL: '_';
153
+ fragment QUOTE_SYMBOL: '"';
154
+
155
+ CREATE_SYMBOL: C R E A T E;
156
+ GIS_SYMBOL: G I S;
157
+ ENTITY_SYMBOL: E N T I T Y;
158
+ USING_SYMBOL: U S I N G;
159
+ USE_SYMBOL: U S E;
160
+ GENERATE_SYMBOL: G E N E R A T E;
161
+ IDENTIFIER_SYMBOL: I D E N T I F I E R;
162
+ RELATIONSHIP_SYMBOL: R E L A T I O N S H I P;
163
+ DISPLAYSTRING_SYMBOL: D I S P L A Y UNDERLINE_SYMBOL S T R I N G;
164
+ REQUIRED_SYMBOL: R E Q U I R E D;
165
+ UNIQUE_SYMBOL: U N I Q U E;
166
+ BIDIRECTIONAL_SYMBOL: B I D I R E C T I O N A L;
167
+ MAPPEDBY_SYMBOL: M A P P E D UNDERLINE_SYMBOL B Y;
168
+ LAYER_SYMBOL: L A Y E R;
169
+ TILE_SYMBOL: T I L E;
170
+ GEOJSON_SYMBOL: G E O J S O N;
171
+ AS_SYMBOL: A S;
172
+ URL_SYMBOL: U R L;
173
+ SLD_SYMBOL: S T Y L E L A Y E R D E S C R I P T O R;
174
+ EDITABLE_SYMBOL: E D I T A B L E;
175
+ FILL_COLOR_SYMBOL: F I L L C O L O R;
176
+ STROKE_COLOR_SYMBOL: S T R O K E C O L O R;
177
+ FILL_OPACITY_SYMBOL: F I L L O P A C I T Y;
178
+ STROKE_OPACITY_SYMBOL: S T R O K E O P A C I T Y;
179
+ WMS_SYMBOL: W M S;
180
+ STYLE_SYMBOL: S T Y L E;
181
+ IS_BASE_LAYER_SYMBOL: I S UNDERLINE_SYMBOL B A S E UNDERLINE_SYMBOL L A Y E R;
182
+ HIDDEN_SYMBOL: H I D D E N;
183
+ SORTABLE_SYMBOL: S O R T A B L E;
184
+ MAP_SYMBOL: M A P;
185
+ SET_SYMBOL: S E T;
186
+ DEPLOYMENT_SYMBOL: D E P L O Y M E N T;
187
+
188
+ ZERO_ONE_SYMBOL: '0..1';
189
+ ONE_ONE_SYMBOL: '1..1';
190
+ ZERO_MANY_SYMBOL: '0..*';
191
+ ONE_MANY_SYMBOL: '1..*';
192
+
193
+ TYPE
194
+ : L O N G
195
+ | B O O L E A N
196
+ | I N T E G E R
197
+ | D O U B L E
198
+ | L O C A L D A T E
199
+ | S T R I N G
200
+ | L I N E S T R I N G
201
+ | M U L T I L I N E S T R I N G
202
+ | P O L Y G O N
203
+ | M U L T I P O L Y G O N
204
+ | P O I N T
205
+ | M U L T I P O I N T
206
+ ;
207
+
208
+ POUND_SYMBOL : '#';
209
+ DOT_SYMBOL : '.';
210
+ OPAR_SYMBOL : '(';
211
+ CPAR_SYMBOL : ')';
212
+ COMMA_SYMBOL : ',';
213
+ SCOL_SYMBOL : ';';
214
+
215
+ HEX_COLOR: POUND_SYMBOL HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT;
216
+ INT_NUMBER: DIGITS;
217
+ FLOAT_NUMBER: (DIGITS? DOT_SYMBOL)? DIGITS;
218
+
219
+ COMMENT: '//' ~[\r\n]* -> skip;
220
+ //SPACE: [ \t]+ -> skip;
221
+ //EOFS: [\r\n] -> skip;
222
+ WHITESPACE: [ \t\f\r\n] -> channel(HIDDEN); // Ignore whitespaces.
223
+
224
+ IDENTIFIER:
225
+ DIGITS+ [eE] (LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED*)? // Have to exclude float pattern, as this rule matches more.
226
+ | DIGITS+ LETTER_WITHOUT_FLOAT_PART LETTER_WHEN_UNQUOTED*
227
+ | LETTER_WHEN_UNQUOTED_NO_DIGIT LETTER_WHEN_UNQUOTED* // INT_NUMBER matches first if there are only digits.
228
+ ;
229
+
230
+ QUOTED_TEXT: QUOTE_SYMBOL (~[\r\n"])* QUOTE_SYMBOL;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@lbdudc/gp-gis-dsl",
3
+ "version": "0.2.0",
4
+ "homepage": "https://gitlab.lbd.org.es/publico/gis-publisher/gis-dsl",
5
+ "description": "A library that parses a DSL instance and generates the spec for the web-based GIS SPL.",
6
+ "bin": {
7
+ "gis-dsl": "src/cli.js"
8
+ },
9
+ "main": "src/index.js",
10
+ "type": "module",
11
+ "author": "Álex Cortiñas",
12
+ "dependencies": {
13
+ "antlr4": "^4.13.0",
14
+ "meow": "^12.0.1",
15
+ "mocha": "^10.2.0"
16
+ },
17
+ "devDependencies": {
18
+ "eslint": "^8.54.0",
19
+ "eslint-config-prettier": "^9.0.0",
20
+ "eslint-plugin-prettier": "^5.0.1",
21
+ "husky": "^8.0.3",
22
+ "lint-staged": "^15.1.0",
23
+ "npm-run-all": "^4.1.5",
24
+ "prettier": "^3.1.0",
25
+ "strip-bom": "^5.0.0"
26
+ },
27
+ "keywords": [
28
+ "gis",
29
+ "dsl"
30
+ ],
31
+ "license": "MIT",
32
+ "lint-staged": {
33
+ "*.{json,md,yml}": "prettier --write",
34
+ "*.{js}": [
35
+ "eslint --fix",
36
+ "prettier --write"
37
+ ]
38
+ },
39
+ "scripts": {
40
+ "build-grammar": "antlr -Dlanguage=JavaScript -lib grammar -o src/lib -visitor -Xexact-output-dir grammar/GISGrammar.g4",
41
+ "eslint": "eslint --ext js src",
42
+ "eslint:fix": "eslint --ext js --fix src",
43
+ "lint": "npm-run-all eslint prettier",
44
+ "lint:fix": "npm-run-all eslint:fix prettier:fix",
45
+ "prettier": "prettier --check --ignore-unknown src",
46
+ "prettier:fix": "prettier --write --ignore-unknown src",
47
+ "prepare": "husky install",
48
+ "test": "mocha --ui qunit"
49
+ }
50
+ }
@@ -0,0 +1,318 @@
1
+ import GISGrammarVisitor from "./lib/GISGrammarVisitor.js";
2
+ import GIS from "./spl/GIS.js";
3
+ import {
4
+ TileLayer,
5
+ GeoJSONLayer,
6
+ WMSStyle,
7
+ WMSLayer,
8
+ Map,
9
+ GeoJSONLayerStyle,
10
+ } from "./spl/Map.js";
11
+ import { transformation, getPropertyParams } from "./GISVisitorHelper.js";
12
+ // import { generateProduct } from "./project-generator.js";
13
+
14
+ class Visitor extends GISGrammarVisitor {
15
+ constructor(store, debug) {
16
+ super();
17
+ this.store = store;
18
+ this.debug = debug || false;
19
+ }
20
+
21
+ log(msg) {
22
+ if (this.debug) {
23
+ console.log(msg);
24
+ }
25
+ }
26
+
27
+ start(ctx) {
28
+ return this.visitParse(ctx);
29
+ }
30
+
31
+ visitParse(ctx) {
32
+ this.log(`visitParse: ${ctx.getText()}`);
33
+ return super.visitParse(ctx);
34
+ }
35
+
36
+ visitCreateGIS(ctx) {
37
+ const gisName = ctx.getChild(1).getText();
38
+ const srid = ctx.getChild(3).getText();
39
+ this.log(`visitCreateGIS: ${gisName}`);
40
+ if (this.store.getProduct(gisName)) {
41
+ throw `GIS ${gisName} already exists!`;
42
+ }
43
+
44
+ this.store.addProduct(gisName, new GIS(gisName, srid));
45
+ }
46
+
47
+ visitUseGIS(ctx) {
48
+ const gisName = ctx.getChild(2).getText();
49
+ this.log(`visitUseGIS: ${gisName}`);
50
+ this.store.setCurrentProduct(gisName);
51
+ }
52
+
53
+ visitGenerateGIS(ctx) {
54
+ const gisName = ctx.getChild(2).getText();
55
+ this.log(`visitGenerateGIS: ${gisName}`);
56
+ this.store.setCurrentProduct(gisName);
57
+ this.store.getCurrentProduct().validate();
58
+ this.store.setLastGeneratedProduct(
59
+ transformation(this.store.getCurrentProduct()),
60
+ );
61
+ }
62
+
63
+ visitCreateEntity(ctx) {
64
+ const entityName = ctx.getChild(1).getText();
65
+ this.log(`visitCreateEntity: ${entityName}`);
66
+
67
+ this.store.getCurrentProduct().addEntity(entityName);
68
+ this.store.setCurrentEntity(entityName);
69
+
70
+ super.visitCreateEntity(ctx);
71
+
72
+ this.store.getCurrentEntity().validate();
73
+ this.store.setCurrentEntity(null);
74
+ }
75
+
76
+ visitPropertyDefinition(ctx) {
77
+ const pName = ctx.getChild(0).getText();
78
+ this.log(`visitPropertyDefinition: ${pName}`);
79
+ const pType = ctx.getChild(1).getText();
80
+
81
+ this.store.getCurrentEntity().addProperty(
82
+ pName,
83
+ pType,
84
+ getPropertyParams(
85
+ ctx.children
86
+ .slice(2)
87
+ .filter((s) => s.getSymbol)
88
+ .map((s) => s.getSymbol().text.toLowerCase()),
89
+ ),
90
+ );
91
+ }
92
+
93
+ visitOwnedRelationshipDefinition(ctx) {
94
+ const sourceOpts = {
95
+ label: ctx.getChild(0).getText(),
96
+ multiplicity: ctx.getChild(6).getText(),
97
+ };
98
+ const targetOpts = {
99
+ label: null,
100
+ multiplicity: ctx.getChild(4).getText(),
101
+ };
102
+ const rSource = this.store.getCurrentEntity().name;
103
+ const rTarget = ctx.getChild(1).getText();
104
+
105
+ this.store
106
+ .getCurrentProduct()
107
+ .addRelationship(rSource, rTarget, sourceOpts, targetOpts);
108
+ }
109
+
110
+ visitMappedRelationshipDefinition(ctx) {
111
+ const sourceOpts = {
112
+ label: ctx.getChild(4).getText(),
113
+ multiplicity: null,
114
+ };
115
+ const targetOpts = {
116
+ label: ctx.getChild(0).getText(),
117
+ multiplicity: null,
118
+ };
119
+ const rTarget = this.store.getCurrentEntity().name;
120
+ const rSource = ctx.getChild(1).getText();
121
+
122
+ this.store
123
+ .getCurrentProduct()
124
+ .addRelationship(rSource, rTarget, sourceOpts, targetOpts);
125
+ }
126
+
127
+ /* ****************** Map & layers stuff ************************ */
128
+
129
+ visitCreateTileLayer(ctx) {
130
+ const id = ctx.getChild(2).getText();
131
+ let label, url;
132
+ if (ctx.getChildCount() != 10) {
133
+ label = id;
134
+ url = ctx.getChild(5).getText().slice(1, -1);
135
+ } else {
136
+ // tiene AS label
137
+ label = ctx.getChild(4).getText().slice(1, -1);
138
+ url = ctx.getChild(7).getText().slice(1, -1);
139
+ }
140
+ this.log(`visitCreateTileLayer ${id} - ${label} (url: ${url})`);
141
+ this.store.getCurrentProduct().addLayer(new TileLayer(id, label, url));
142
+ }
143
+
144
+ visitCreateGeoJSONLayer(ctx) {
145
+ const id = ctx.getChild(2).getText();
146
+ let label,
147
+ entityId,
148
+ editable,
149
+ offset = 0,
150
+ style = {
151
+ fillColor: null,
152
+ strokeColor: null,
153
+ fillOpacity: null,
154
+ strokeOpacity: null,
155
+ };
156
+ const childCound = ctx.getChildCount();
157
+ if (childCound == 21 || childCound == 19) {
158
+ // no editable
159
+ editable = false;
160
+ offset += 1;
161
+ } else {
162
+ editable = true;
163
+ }
164
+ if (childCound == 20 || childCound == 19) {
165
+ // no label
166
+ label = id;
167
+ entityId = ctx.getChild(4).getText();
168
+ offset += 2;
169
+ } else {
170
+ label = ctx.getChild(4).getText().slice(1, -1);
171
+ entityId = ctx.getChild(6).getText();
172
+ }
173
+
174
+ // to check if the entity exists
175
+ this.store.getCurrentProduct().getEntity(entityId);
176
+
177
+ style.fillColor = ctx.getChild(10 - offset).getText();
178
+ style.strokeColor = ctx.getChild(13 - offset).getText();
179
+ style.fillOpacity = ctx.getChild(16 - offset).getText();
180
+ style.strokeOpacity = ctx.getChild(19 - offset).getText();
181
+ this.log(
182
+ `visitCreateGeoJSONLayer ${id} - ${label} (entityId: ${entityId} - ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity})`,
183
+ );
184
+ this.store
185
+ .getCurrentProduct()
186
+ .addStyle(
187
+ new GeoJSONLayerStyle(
188
+ id + "Style",
189
+ style.fillColor,
190
+ style.strokeColor,
191
+ style.fillOpacity,
192
+ style.strokeOpacity,
193
+ ),
194
+ );
195
+ this.store
196
+ .getCurrentProduct()
197
+ .addLayer(new GeoJSONLayer(id, label, entityId, editable, id + "Style"));
198
+ }
199
+
200
+ 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));
205
+ }
206
+
207
+ visitCreateWmsLayer(ctx) {
208
+ const id = ctx.getChild(2).getText();
209
+ let label = id,
210
+ from = 4,
211
+ i,
212
+ aux,
213
+ entity,
214
+ auxEntityName,
215
+ style,
216
+ styleName;
217
+ if (ctx.getChild(3).getText() != ")") {
218
+ // tiene label
219
+ label = ctx.getChild(4).getText().slice(1, -1);
220
+ from = 6;
221
+ }
222
+
223
+ const layer = new WMSLayer(id, label);
224
+
225
+ for (i = from; i < ctx.getChildCount() - 2; i = i + 2) {
226
+ aux = ctx.getChild(i);
227
+ auxEntityName = aux.getChild(0).getText();
228
+ entity = this.store.getCurrentProduct().getEntity(auxEntityName);
229
+
230
+ if (!entity) {
231
+ throw `ERROR: entity ${auxEntityName} required by layer ${id} does not exists!!`;
232
+ }
233
+
234
+ styleName = aux.getChild(1).getText();
235
+ style = this.store.getCurrentProduct().getStyle(styleName);
236
+ if (!style) {
237
+ throw `Style ${aux.getChild(1).getText()} does not exist!!!`;
238
+ }
239
+ layer.addSubLayer(entity.name, styleName);
240
+ }
241
+ this.log(`visitCreateWmsLayer ${id} - ${label}`);
242
+
243
+ this.store.getCurrentProduct().addLayer(layer);
244
+ }
245
+
246
+ visitCreateMap(ctx, sortable) {
247
+ const id = ctx.getChild(1).getText();
248
+ let label,
249
+ from,
250
+ i,
251
+ auxLayer,
252
+ layers = [];
253
+ if (ctx.getChild(4).getText() == "(") {
254
+ // tiene label
255
+ label = ctx.getChild(3).getText().slice(1, -1);
256
+ from = 5;
257
+ } else {
258
+ // no tiene label
259
+ label = id;
260
+ from = 3;
261
+ }
262
+ for (i = from; i < ctx.getChildCount() - 2; i = i + 2) {
263
+ layers.push(this.visitMapLayer(ctx.getChild(i)));
264
+ }
265
+ this.log(
266
+ `visitCreateMap ${id} - ${label} with ${layers.length} layers: ${layers
267
+ .map((e) => e.id)
268
+ .join(", ")}`,
269
+ );
270
+ const map = new Map(id, label, sortable);
271
+ layers.forEach((l) => {
272
+ auxLayer = this.store.getCurrentProduct().getLayer(l.id);
273
+ if (!auxLayer) {
274
+ throw `Layer ${l.id} does not exists!!!`;
275
+ }
276
+ map.addLayer(l.id, l.baseLayer, l.hidden);
277
+ });
278
+ this.store.getCurrentProduct().addMap(id, map);
279
+ }
280
+
281
+ visitMapLayer(ctx) {
282
+ const ret = {
283
+ id: ctx.getChild(0).getText(),
284
+ };
285
+ if (ctx.getChildCount() == 3) {
286
+ // las dos opciones
287
+ ret.hidden = ret.baseLayer = true;
288
+ } else if (ctx.getChildCount() == 2) {
289
+ if (ctx.getChild(1).getSymbol().text.toLowerCase() == "is_base_layer") {
290
+ // base layer
291
+ ret.baseLayer = true;
292
+ } else {
293
+ // capa oculta
294
+ ret.hidden = true;
295
+ }
296
+ }
297
+ return ret;
298
+ }
299
+
300
+ visitCreateSortableMap(ctx) {
301
+ this.log(`visitCreateSortableMap`);
302
+ this.visitCreateMap(ctx.getChild(1), true);
303
+ }
304
+
305
+ /* ****************** Deployment ************************ */
306
+
307
+ visitDeploymentProperty(ctx) {
308
+ this.log(`visitDeploymentProperty`);
309
+ this.store
310
+ .getCurrentProduct()
311
+ .addDeploymentProperty(
312
+ ctx.getChild(0).getText().slice(1, -1),
313
+ ctx.getChild(1).getText().slice(1, -1),
314
+ );
315
+ }
316
+ }
317
+
318
+ export default Visitor;