@lbdudc/gp-gis-dsl 0.3.0 → 0.3.1
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/package.json +1 -1
- package/src/GISVisitor.js +436 -436
- package/src/features.js +54 -53
- package/src/lib/GISGrammar.interp +181 -181
- package/src/lib/GISGrammarLexer.interp +240 -240
- package/src/spl/Map.js +55 -55
- package/src/spl/WMSServiceLayer.js +40 -40
package/src/GISVisitor.js
CHANGED
|
@@ -1,436 +1,436 @@
|
|
|
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
|
-
WMSStyleCustom,
|
|
11
|
-
WMSServiceLayer,
|
|
12
|
-
} from "./spl/Map.js";
|
|
13
|
-
import { transformation, getPropertyParams } from "./GISVisitorHelper.js";
|
|
14
|
-
// import { generateProduct } from "./project-generator.js";
|
|
15
|
-
|
|
16
|
-
class Visitor extends GISGrammarVisitor {
|
|
17
|
-
constructor(store, debug) {
|
|
18
|
-
super();
|
|
19
|
-
this.store = store;
|
|
20
|
-
this.debug = debug || false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
log(msg) {
|
|
24
|
-
if (this.debug) {
|
|
25
|
-
console.log(msg);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
start(ctx) {
|
|
30
|
-
return this.visitParse(ctx);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
visitParse(ctx) {
|
|
34
|
-
this.log(`visitParse: ${ctx.getText()}`);
|
|
35
|
-
return super.visitParse(ctx);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
visitCreateGIS(ctx) {
|
|
39
|
-
const gisName = ctx.getChild(1).getText();
|
|
40
|
-
const srid = ctx.getChild(3).getText();
|
|
41
|
-
this.log(`visitCreateGIS: ${gisName}`);
|
|
42
|
-
if (this.store.getProduct(gisName)) {
|
|
43
|
-
throw `GIS ${gisName} already exists!`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.store.addProduct(gisName, new GIS(gisName, srid));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
visitUseGIS(ctx) {
|
|
50
|
-
const gisName = ctx.getChild(2).getText();
|
|
51
|
-
this.log(`visitUseGIS: ${gisName}`);
|
|
52
|
-
this.store.setCurrentProduct(gisName);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
visitGenerateGIS(ctx) {
|
|
56
|
-
const gisName = ctx.getChild(2).getText();
|
|
57
|
-
this.log(`visitGenerateGIS: ${gisName}`);
|
|
58
|
-
this.store.setCurrentProduct(gisName);
|
|
59
|
-
this.store.getCurrentProduct().validate();
|
|
60
|
-
this.store.setLastGeneratedProduct(
|
|
61
|
-
transformation(this.store.getCurrentProduct()),
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
visitCreateEntity(ctx) {
|
|
66
|
-
const entityName = ctx.getChild(1).getText();
|
|
67
|
-
this.log(`visitCreateEntity: ${entityName}`);
|
|
68
|
-
|
|
69
|
-
this.store.getCurrentProduct().addEntity(entityName);
|
|
70
|
-
this.store.setCurrentEntity(entityName);
|
|
71
|
-
|
|
72
|
-
super.visitCreateEntity(ctx);
|
|
73
|
-
|
|
74
|
-
this.store.getCurrentEntity().validate();
|
|
75
|
-
this.store.setCurrentEntity(null);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
visitPropertyDefinition(ctx) {
|
|
79
|
-
const pName = ctx.getChild(0).getText();
|
|
80
|
-
this.log(`visitPropertyDefinition: ${pName}`);
|
|
81
|
-
const pType = ctx.getChild(1).getText();
|
|
82
|
-
|
|
83
|
-
this.store.getCurrentEntity().addProperty(
|
|
84
|
-
pName,
|
|
85
|
-
pType,
|
|
86
|
-
getPropertyParams(
|
|
87
|
-
ctx.children
|
|
88
|
-
.slice(2)
|
|
89
|
-
.filter((s) => s.getSymbol)
|
|
90
|
-
.map((s) => s.getSymbol().text.toLowerCase()),
|
|
91
|
-
),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
visitOwnedRelationshipDefinition(ctx) {
|
|
96
|
-
const sourceOpts = {
|
|
97
|
-
label: ctx.getChild(0).getText(),
|
|
98
|
-
multiplicity: ctx.getChild(6).getText(),
|
|
99
|
-
};
|
|
100
|
-
const targetOpts = {
|
|
101
|
-
label: null,
|
|
102
|
-
multiplicity: ctx.getChild(4).getText(),
|
|
103
|
-
};
|
|
104
|
-
const rSource = this.store.getCurrentEntity().name;
|
|
105
|
-
const rTarget = ctx.getChild(1).getText();
|
|
106
|
-
|
|
107
|
-
this.store
|
|
108
|
-
.getCurrentProduct()
|
|
109
|
-
.addRelationship(rSource, rTarget, sourceOpts, targetOpts);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
visitMappedRelationshipDefinition(ctx) {
|
|
113
|
-
const sourceOpts = {
|
|
114
|
-
label: ctx.getChild(4).getText(),
|
|
115
|
-
multiplicity: null,
|
|
116
|
-
};
|
|
117
|
-
const targetOpts = {
|
|
118
|
-
label: ctx.getChild(0).getText(),
|
|
119
|
-
multiplicity: null,
|
|
120
|
-
};
|
|
121
|
-
const rTarget = this.store.getCurrentEntity().name;
|
|
122
|
-
const rSource = ctx.getChild(1).getText();
|
|
123
|
-
|
|
124
|
-
this.store
|
|
125
|
-
.getCurrentProduct()
|
|
126
|
-
.addRelationship(rSource, rTarget, sourceOpts, targetOpts);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/* ****************** Map & layers stuff ************************ */
|
|
130
|
-
|
|
131
|
-
visitCreateTileLayer(ctx) {
|
|
132
|
-
const id = ctx.getChild(2).getText();
|
|
133
|
-
let label, url;
|
|
134
|
-
if (ctx.getChildCount() != 10) {
|
|
135
|
-
label = id;
|
|
136
|
-
url = ctx.getChild(5).getText().slice(1, -1);
|
|
137
|
-
} else {
|
|
138
|
-
// tiene AS label
|
|
139
|
-
label = ctx.getChild(4).getText().slice(1, -1);
|
|
140
|
-
url = ctx.getChild(7).getText().slice(1, -1);
|
|
141
|
-
}
|
|
142
|
-
this.log(`visitCreateTileLayer ${id} - ${label} (url: ${url})`);
|
|
143
|
-
this.store.getCurrentProduct().addLayer(new TileLayer(id, label, url));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
visitCreateGeoJSONLayer(ctx) {
|
|
147
|
-
const id = ctx.getChild(2).getText();
|
|
148
|
-
let label,
|
|
149
|
-
entityId,
|
|
150
|
-
editable,
|
|
151
|
-
offset = 0,
|
|
152
|
-
style = {
|
|
153
|
-
fillColor: null,
|
|
154
|
-
strokeColor: null,
|
|
155
|
-
fillOpacity: null,
|
|
156
|
-
strokeOpacity: null,
|
|
157
|
-
};
|
|
158
|
-
const childCound = ctx.getChildCount();
|
|
159
|
-
if (childCound == 21 || childCound == 19) {
|
|
160
|
-
// no editable
|
|
161
|
-
editable = false;
|
|
162
|
-
offset += 1;
|
|
163
|
-
} else {
|
|
164
|
-
editable = true;
|
|
165
|
-
}
|
|
166
|
-
if (childCound == 20 || childCound == 19) {
|
|
167
|
-
// no label
|
|
168
|
-
label = id;
|
|
169
|
-
entityId = ctx.getChild(4).getText();
|
|
170
|
-
offset += 2;
|
|
171
|
-
} else {
|
|
172
|
-
label = ctx.getChild(4).getText().slice(1, -1);
|
|
173
|
-
entityId = ctx.getChild(6).getText();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// to check if the entity exists
|
|
177
|
-
this.store.getCurrentProduct().getEntity(entityId);
|
|
178
|
-
|
|
179
|
-
style.fillColor = ctx.getChild(10 - offset).getText();
|
|
180
|
-
style.strokeColor = ctx.getChild(13 - offset).getText();
|
|
181
|
-
style.fillOpacity = ctx.getChild(16 - offset).getText();
|
|
182
|
-
style.strokeOpacity = ctx.getChild(19 - offset).getText();
|
|
183
|
-
this.log(
|
|
184
|
-
`visitCreateGeoJSONLayer ${id} - ${label} (entityId: ${entityId} - ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity})`,
|
|
185
|
-
);
|
|
186
|
-
this.store
|
|
187
|
-
.getCurrentProduct()
|
|
188
|
-
.addStyle(
|
|
189
|
-
new GeoJSONLayerStyle(
|
|
190
|
-
id + "Style",
|
|
191
|
-
style.fillColor,
|
|
192
|
-
style.strokeColor,
|
|
193
|
-
style.fillOpacity,
|
|
194
|
-
style.strokeOpacity,
|
|
195
|
-
),
|
|
196
|
-
);
|
|
197
|
-
this.store
|
|
198
|
-
.getCurrentProduct()
|
|
199
|
-
.addLayer(new GeoJSONLayer(id, label, entityId, editable, id + "Style"));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
visitCreateWmsStyle(ctx) {
|
|
203
|
-
const descriptor = ctx
|
|
204
|
-
.getChild(4)
|
|
205
|
-
.getText()
|
|
206
|
-
.startsWith("styleLayerDescriptor");
|
|
207
|
-
if (descriptor) {
|
|
208
|
-
const id = ctx.getChild(2).getText();
|
|
209
|
-
const sld = ctx.getChild(5).getText().slice(1, -1);
|
|
210
|
-
this.log(`visitCreateWmsStyle ${id} with ${sld}`);
|
|
211
|
-
this.store.getCurrentProduct().addStyle(new WMSStyle(id, sld));
|
|
212
|
-
} else {
|
|
213
|
-
let style = {
|
|
214
|
-
geometryType: null,
|
|
215
|
-
fillColor: null,
|
|
216
|
-
strokeColor: null,
|
|
217
|
-
fillOpacity: null,
|
|
218
|
-
strokeOpacity: null,
|
|
219
|
-
};
|
|
220
|
-
const id = ctx.getChild(2).getText();
|
|
221
|
-
const props = ctx.getChild(4).getText();
|
|
222
|
-
|
|
223
|
-
props.split(",").forEach((field) => {
|
|
224
|
-
if (field.startsWith("geometryType")) {
|
|
225
|
-
style.geometryType = field.split("geometryType")[1];
|
|
226
|
-
} else if (field.startsWith("fillColor")) {
|
|
227
|
-
if (field.split("fillColor")[1] == "null") style.fillColor = null;
|
|
228
|
-
else style.fillColor = field.split("fillColor")[1]; // Remove the '#' symbol
|
|
229
|
-
} else if (field.startsWith("strokeColor")) {
|
|
230
|
-
if (field.split("strokeColor")[1] == "null") style.strokeColor = null;
|
|
231
|
-
else style.strokeColor = field.split("strokeColor")[1]; // Remove the '#' symbol
|
|
232
|
-
} else if (field.startsWith("fillOpacity")) {
|
|
233
|
-
style.fillOpacity = parseFloat(field.split("fillOpacity")[1]);
|
|
234
|
-
} else if (field.startsWith("strokeOpacity")) {
|
|
235
|
-
style.strokeOpacity = parseFloat(field.split("strokeOpacity")[1]);
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
this.log(
|
|
240
|
-
`visitCreateWmsStyle ${id} - ${style.geometryType}, ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity}`,
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
this.store
|
|
244
|
-
.getCurrentProduct()
|
|
245
|
-
.addStyle(
|
|
246
|
-
new WMSStyleCustom(
|
|
247
|
-
id,
|
|
248
|
-
style.geometryType,
|
|
249
|
-
style.fillColor,
|
|
250
|
-
style.strokeColor,
|
|
251
|
-
style.fillOpacity,
|
|
252
|
-
style.strokeOpacity,
|
|
253
|
-
),
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
visitCreateWmsLayer(ctx) {
|
|
259
|
-
const id = ctx.getChild(2).getText();
|
|
260
|
-
let label = id;
|
|
261
|
-
|
|
262
|
-
const isWmsService = ctx
|
|
263
|
-
.getChild(6)
|
|
264
|
-
.getText()
|
|
265
|
-
.toLowerCase()
|
|
266
|
-
.startsWith("urlwms");
|
|
267
|
-
|
|
268
|
-
const layer = isWmsService
|
|
269
|
-
? this._createWmsServiceLayer(ctx, id, label)
|
|
270
|
-
: this._createStandardLayer(ctx, id, label);
|
|
271
|
-
|
|
272
|
-
this.log(`visitCreateWmsLayer ${id} - ${label}`);
|
|
273
|
-
|
|
274
|
-
this.store.getCurrentProduct().addLayer(layer);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
_getCleanText = (node) => node?.text()?.getText().replace(/"/g, "") || null;
|
|
278
|
-
|
|
279
|
-
_createWmsServiceLayer(ctx, id, label) {
|
|
280
|
-
const sub = ctx.wmsSubLayer(0);
|
|
281
|
-
const clean = this._getCleanText;
|
|
282
|
-
|
|
283
|
-
const url = clean(sub.wmsUrl());
|
|
284
|
-
const layerName = clean(sub.wmsLayerName());
|
|
285
|
-
const format = clean(sub.wmsFormatName());
|
|
286
|
-
const crs = clean(sub.wmsCrs());
|
|
287
|
-
const version = clean(sub.wmsVersion());
|
|
288
|
-
const attribution = clean(sub.wmsAttribution());
|
|
289
|
-
|
|
290
|
-
const styles = sub.wmsStyles()
|
|
291
|
-
? clean(sub.wmsStyles())
|
|
292
|
-
.split(",")
|
|
293
|
-
.map((s) => s.trim())
|
|
294
|
-
: [];
|
|
295
|
-
|
|
296
|
-
const queryable = sub.wmsQueryable()
|
|
297
|
-
? clean(sub.wmsQueryable()).toLowerCase() === "true"
|
|
298
|
-
: false;
|
|
299
|
-
|
|
300
|
-
let bbox = null;
|
|
301
|
-
const bboxNode = sub.wmsBboxGroup();
|
|
302
|
-
if (bboxNode) {
|
|
303
|
-
bbox = {
|
|
304
|
-
crs: clean(bboxNode.wmsBboxCrs()),
|
|
305
|
-
minx: parseFloat(bboxNode.wmsMinX().floatNumber().getText()),
|
|
306
|
-
miny: parseFloat(bboxNode.wmsMinY().floatNumber().getText()),
|
|
307
|
-
maxx: parseFloat(bboxNode.wmsMaxX().floatNumber().getText()),
|
|
308
|
-
maxy: parseFloat(bboxNode.wmsMaxY().floatNumber().getText()),
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return new WMSServiceLayer({
|
|
313
|
-
id,
|
|
314
|
-
label,
|
|
315
|
-
url,
|
|
316
|
-
layerName,
|
|
317
|
-
format,
|
|
318
|
-
crs,
|
|
319
|
-
bbox,
|
|
320
|
-
styles,
|
|
321
|
-
queryable,
|
|
322
|
-
attribution,
|
|
323
|
-
version,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
_createStandardLayer(ctx, id, label) {
|
|
328
|
-
let from = 4,
|
|
329
|
-
i,
|
|
330
|
-
aux,
|
|
331
|
-
entity,
|
|
332
|
-
auxEntityName,
|
|
333
|
-
style,
|
|
334
|
-
styleName;
|
|
335
|
-
if (ctx.getChild(3).getText() != ")") {
|
|
336
|
-
// tiene label
|
|
337
|
-
label = ctx.getChild(4).getText().slice(1, -1);
|
|
338
|
-
from = 6;
|
|
339
|
-
}
|
|
340
|
-
const layer = new WMSLayer(id, label);
|
|
341
|
-
|
|
342
|
-
for (i = from; i < ctx.getChildCount() - 2; i += 2) {
|
|
343
|
-
aux = ctx.getChild(i);
|
|
344
|
-
auxEntityName = aux.getChild(0).getText();
|
|
345
|
-
entity = this.store.getCurrentProduct().getEntity(auxEntityName);
|
|
346
|
-
styleName = aux.getChild(1).getText();
|
|
347
|
-
style = this.store.getCurrentProduct().getStyle(styleName);
|
|
348
|
-
|
|
349
|
-
if (entity) {
|
|
350
|
-
layer.addSubLayer(entity.name, styleName);
|
|
351
|
-
} else {
|
|
352
|
-
// GeoTIFF: no entity
|
|
353
|
-
const normalizedId = id
|
|
354
|
-
.replace(/Layer$/, "")
|
|
355
|
-
.replace(/^(\d+)([A-Z][a-z]+)/, "$1_$2")
|
|
356
|
-
.toLowerCase();
|
|
357
|
-
layer.addSubLayer(normalizedId, null);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return layer;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
visitCreateMap(ctx, sortable) {
|
|
365
|
-
const id = ctx.getChild(1).getText();
|
|
366
|
-
let label,
|
|
367
|
-
from,
|
|
368
|
-
i,
|
|
369
|
-
auxLayer,
|
|
370
|
-
layers = [];
|
|
371
|
-
if (ctx.getChild(4).getText() == "(") {
|
|
372
|
-
// tiene label
|
|
373
|
-
label = ctx.getChild(3).getText().slice(1, -1);
|
|
374
|
-
from = 5;
|
|
375
|
-
} else {
|
|
376
|
-
// no tiene label
|
|
377
|
-
label = id;
|
|
378
|
-
from = 3;
|
|
379
|
-
}
|
|
380
|
-
for (i = from; i < ctx.getChildCount() - 2; i = i + 2) {
|
|
381
|
-
layers.push(this.visitMapLayer(ctx.getChild(i)));
|
|
382
|
-
}
|
|
383
|
-
this.log(
|
|
384
|
-
`visitCreateMap ${id} - ${label} with ${layers.length} layers: ${layers
|
|
385
|
-
.map((e) => e.id)
|
|
386
|
-
.join(", ")}`,
|
|
387
|
-
);
|
|
388
|
-
const map = new Map(id, label, sortable);
|
|
389
|
-
layers.forEach((l) => {
|
|
390
|
-
auxLayer = this.store.getCurrentProduct().getLayer(l.id);
|
|
391
|
-
if (!auxLayer) {
|
|
392
|
-
throw `Layer ${l.id} does not exists!!!`;
|
|
393
|
-
}
|
|
394
|
-
map.addLayer(l.id, l.baseLayer, l.hidden);
|
|
395
|
-
});
|
|
396
|
-
this.store.getCurrentProduct().addMap(id, map);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
visitMapLayer(ctx) {
|
|
400
|
-
const ret = {
|
|
401
|
-
id: ctx.getChild(0).getText(),
|
|
402
|
-
};
|
|
403
|
-
if (ctx.getChildCount() == 3) {
|
|
404
|
-
// las dos opciones
|
|
405
|
-
ret.hidden = ret.baseLayer = true;
|
|
406
|
-
} else if (ctx.getChildCount() == 2) {
|
|
407
|
-
if (ctx.getChild(1).getSymbol().text.toLowerCase() == "is_base_layer") {
|
|
408
|
-
// base layer
|
|
409
|
-
ret.baseLayer = true;
|
|
410
|
-
} else {
|
|
411
|
-
// capa oculta
|
|
412
|
-
ret.hidden = true;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return ret;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
visitCreateSortableMap(ctx) {
|
|
419
|
-
this.log(`visitCreateSortableMap`);
|
|
420
|
-
this.visitCreateMap(ctx.getChild(1), true);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/* ****************** Deployment ************************ */
|
|
424
|
-
|
|
425
|
-
visitDeploymentProperty(ctx) {
|
|
426
|
-
this.log(`visitDeploymentProperty`);
|
|
427
|
-
this.store
|
|
428
|
-
.getCurrentProduct()
|
|
429
|
-
.addDeploymentProperty(
|
|
430
|
-
ctx.getChild(0).getText().slice(1, -1),
|
|
431
|
-
ctx.getChild(1).getText().slice(1, -1),
|
|
432
|
-
);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
export default Visitor;
|
|
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
|
+
WMSStyleCustom,
|
|
11
|
+
WMSServiceLayer,
|
|
12
|
+
} from "./spl/Map.js";
|
|
13
|
+
import { transformation, getPropertyParams } from "./GISVisitorHelper.js";
|
|
14
|
+
// import { generateProduct } from "./project-generator.js";
|
|
15
|
+
|
|
16
|
+
class Visitor extends GISGrammarVisitor {
|
|
17
|
+
constructor(store, debug) {
|
|
18
|
+
super();
|
|
19
|
+
this.store = store;
|
|
20
|
+
this.debug = debug || false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
log(msg) {
|
|
24
|
+
if (this.debug) {
|
|
25
|
+
console.log(msg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
start(ctx) {
|
|
30
|
+
return this.visitParse(ctx);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
visitParse(ctx) {
|
|
34
|
+
this.log(`visitParse: ${ctx.getText()}`);
|
|
35
|
+
return super.visitParse(ctx);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
visitCreateGIS(ctx) {
|
|
39
|
+
const gisName = ctx.getChild(1).getText();
|
|
40
|
+
const srid = ctx.getChild(3).getText();
|
|
41
|
+
this.log(`visitCreateGIS: ${gisName}`);
|
|
42
|
+
if (this.store.getProduct(gisName)) {
|
|
43
|
+
throw `GIS ${gisName} already exists!`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.store.addProduct(gisName, new GIS(gisName, srid));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
visitUseGIS(ctx) {
|
|
50
|
+
const gisName = ctx.getChild(2).getText();
|
|
51
|
+
this.log(`visitUseGIS: ${gisName}`);
|
|
52
|
+
this.store.setCurrentProduct(gisName);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
visitGenerateGIS(ctx) {
|
|
56
|
+
const gisName = ctx.getChild(2).getText();
|
|
57
|
+
this.log(`visitGenerateGIS: ${gisName}`);
|
|
58
|
+
this.store.setCurrentProduct(gisName);
|
|
59
|
+
this.store.getCurrentProduct().validate();
|
|
60
|
+
this.store.setLastGeneratedProduct(
|
|
61
|
+
transformation(this.store.getCurrentProduct()),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
visitCreateEntity(ctx) {
|
|
66
|
+
const entityName = ctx.getChild(1).getText();
|
|
67
|
+
this.log(`visitCreateEntity: ${entityName}`);
|
|
68
|
+
|
|
69
|
+
this.store.getCurrentProduct().addEntity(entityName);
|
|
70
|
+
this.store.setCurrentEntity(entityName);
|
|
71
|
+
|
|
72
|
+
super.visitCreateEntity(ctx);
|
|
73
|
+
|
|
74
|
+
this.store.getCurrentEntity().validate();
|
|
75
|
+
this.store.setCurrentEntity(null);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
visitPropertyDefinition(ctx) {
|
|
79
|
+
const pName = ctx.getChild(0).getText();
|
|
80
|
+
this.log(`visitPropertyDefinition: ${pName}`);
|
|
81
|
+
const pType = ctx.getChild(1).getText();
|
|
82
|
+
|
|
83
|
+
this.store.getCurrentEntity().addProperty(
|
|
84
|
+
pName,
|
|
85
|
+
pType,
|
|
86
|
+
getPropertyParams(
|
|
87
|
+
ctx.children
|
|
88
|
+
.slice(2)
|
|
89
|
+
.filter((s) => s.getSymbol)
|
|
90
|
+
.map((s) => s.getSymbol().text.toLowerCase()),
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
visitOwnedRelationshipDefinition(ctx) {
|
|
96
|
+
const sourceOpts = {
|
|
97
|
+
label: ctx.getChild(0).getText(),
|
|
98
|
+
multiplicity: ctx.getChild(6).getText(),
|
|
99
|
+
};
|
|
100
|
+
const targetOpts = {
|
|
101
|
+
label: null,
|
|
102
|
+
multiplicity: ctx.getChild(4).getText(),
|
|
103
|
+
};
|
|
104
|
+
const rSource = this.store.getCurrentEntity().name;
|
|
105
|
+
const rTarget = ctx.getChild(1).getText();
|
|
106
|
+
|
|
107
|
+
this.store
|
|
108
|
+
.getCurrentProduct()
|
|
109
|
+
.addRelationship(rSource, rTarget, sourceOpts, targetOpts);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
visitMappedRelationshipDefinition(ctx) {
|
|
113
|
+
const sourceOpts = {
|
|
114
|
+
label: ctx.getChild(4).getText(),
|
|
115
|
+
multiplicity: null,
|
|
116
|
+
};
|
|
117
|
+
const targetOpts = {
|
|
118
|
+
label: ctx.getChild(0).getText(),
|
|
119
|
+
multiplicity: null,
|
|
120
|
+
};
|
|
121
|
+
const rTarget = this.store.getCurrentEntity().name;
|
|
122
|
+
const rSource = ctx.getChild(1).getText();
|
|
123
|
+
|
|
124
|
+
this.store
|
|
125
|
+
.getCurrentProduct()
|
|
126
|
+
.addRelationship(rSource, rTarget, sourceOpts, targetOpts);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* ****************** Map & layers stuff ************************ */
|
|
130
|
+
|
|
131
|
+
visitCreateTileLayer(ctx) {
|
|
132
|
+
const id = ctx.getChild(2).getText();
|
|
133
|
+
let label, url;
|
|
134
|
+
if (ctx.getChildCount() != 10) {
|
|
135
|
+
label = id;
|
|
136
|
+
url = ctx.getChild(5).getText().slice(1, -1);
|
|
137
|
+
} else {
|
|
138
|
+
// tiene AS label
|
|
139
|
+
label = ctx.getChild(4).getText().slice(1, -1);
|
|
140
|
+
url = ctx.getChild(7).getText().slice(1, -1);
|
|
141
|
+
}
|
|
142
|
+
this.log(`visitCreateTileLayer ${id} - ${label} (url: ${url})`);
|
|
143
|
+
this.store.getCurrentProduct().addLayer(new TileLayer(id, label, url));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
visitCreateGeoJSONLayer(ctx) {
|
|
147
|
+
const id = ctx.getChild(2).getText();
|
|
148
|
+
let label,
|
|
149
|
+
entityId,
|
|
150
|
+
editable,
|
|
151
|
+
offset = 0,
|
|
152
|
+
style = {
|
|
153
|
+
fillColor: null,
|
|
154
|
+
strokeColor: null,
|
|
155
|
+
fillOpacity: null,
|
|
156
|
+
strokeOpacity: null,
|
|
157
|
+
};
|
|
158
|
+
const childCound = ctx.getChildCount();
|
|
159
|
+
if (childCound == 21 || childCound == 19) {
|
|
160
|
+
// no editable
|
|
161
|
+
editable = false;
|
|
162
|
+
offset += 1;
|
|
163
|
+
} else {
|
|
164
|
+
editable = true;
|
|
165
|
+
}
|
|
166
|
+
if (childCound == 20 || childCound == 19) {
|
|
167
|
+
// no label
|
|
168
|
+
label = id;
|
|
169
|
+
entityId = ctx.getChild(4).getText();
|
|
170
|
+
offset += 2;
|
|
171
|
+
} else {
|
|
172
|
+
label = ctx.getChild(4).getText().slice(1, -1);
|
|
173
|
+
entityId = ctx.getChild(6).getText();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// to check if the entity exists
|
|
177
|
+
this.store.getCurrentProduct().getEntity(entityId);
|
|
178
|
+
|
|
179
|
+
style.fillColor = ctx.getChild(10 - offset).getText();
|
|
180
|
+
style.strokeColor = ctx.getChild(13 - offset).getText();
|
|
181
|
+
style.fillOpacity = ctx.getChild(16 - offset).getText();
|
|
182
|
+
style.strokeOpacity = ctx.getChild(19 - offset).getText();
|
|
183
|
+
this.log(
|
|
184
|
+
`visitCreateGeoJSONLayer ${id} - ${label} (entityId: ${entityId} - ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity})`,
|
|
185
|
+
);
|
|
186
|
+
this.store
|
|
187
|
+
.getCurrentProduct()
|
|
188
|
+
.addStyle(
|
|
189
|
+
new GeoJSONLayerStyle(
|
|
190
|
+
id + "Style",
|
|
191
|
+
style.fillColor,
|
|
192
|
+
style.strokeColor,
|
|
193
|
+
style.fillOpacity,
|
|
194
|
+
style.strokeOpacity,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
this.store
|
|
198
|
+
.getCurrentProduct()
|
|
199
|
+
.addLayer(new GeoJSONLayer(id, label, entityId, editable, id + "Style"));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
visitCreateWmsStyle(ctx) {
|
|
203
|
+
const descriptor = ctx
|
|
204
|
+
.getChild(4)
|
|
205
|
+
.getText()
|
|
206
|
+
.startsWith("styleLayerDescriptor");
|
|
207
|
+
if (descriptor) {
|
|
208
|
+
const id = ctx.getChild(2).getText();
|
|
209
|
+
const sld = ctx.getChild(5).getText().slice(1, -1);
|
|
210
|
+
this.log(`visitCreateWmsStyle ${id} with ${sld}`);
|
|
211
|
+
this.store.getCurrentProduct().addStyle(new WMSStyle(id, sld));
|
|
212
|
+
} else {
|
|
213
|
+
let style = {
|
|
214
|
+
geometryType: null,
|
|
215
|
+
fillColor: null,
|
|
216
|
+
strokeColor: null,
|
|
217
|
+
fillOpacity: null,
|
|
218
|
+
strokeOpacity: null,
|
|
219
|
+
};
|
|
220
|
+
const id = ctx.getChild(2).getText();
|
|
221
|
+
const props = ctx.getChild(4).getText();
|
|
222
|
+
|
|
223
|
+
props.split(",").forEach((field) => {
|
|
224
|
+
if (field.startsWith("geometryType")) {
|
|
225
|
+
style.geometryType = field.split("geometryType")[1];
|
|
226
|
+
} else if (field.startsWith("fillColor")) {
|
|
227
|
+
if (field.split("fillColor")[1] == "null") style.fillColor = null;
|
|
228
|
+
else style.fillColor = field.split("fillColor")[1]; // Remove the '#' symbol
|
|
229
|
+
} else if (field.startsWith("strokeColor")) {
|
|
230
|
+
if (field.split("strokeColor")[1] == "null") style.strokeColor = null;
|
|
231
|
+
else style.strokeColor = field.split("strokeColor")[1]; // Remove the '#' symbol
|
|
232
|
+
} else if (field.startsWith("fillOpacity")) {
|
|
233
|
+
style.fillOpacity = parseFloat(field.split("fillOpacity")[1]);
|
|
234
|
+
} else if (field.startsWith("strokeOpacity")) {
|
|
235
|
+
style.strokeOpacity = parseFloat(field.split("strokeOpacity")[1]);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
this.log(
|
|
240
|
+
`visitCreateWmsStyle ${id} - ${style.geometryType}, ${style.fillColor}, ${style.strokeColor}, ${style.fillOpacity}, ${style.strokeOpacity}`,
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
this.store
|
|
244
|
+
.getCurrentProduct()
|
|
245
|
+
.addStyle(
|
|
246
|
+
new WMSStyleCustom(
|
|
247
|
+
id,
|
|
248
|
+
style.geometryType,
|
|
249
|
+
style.fillColor,
|
|
250
|
+
style.strokeColor,
|
|
251
|
+
style.fillOpacity,
|
|
252
|
+
style.strokeOpacity,
|
|
253
|
+
),
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
visitCreateWmsLayer(ctx) {
|
|
259
|
+
const id = ctx.getChild(2).getText();
|
|
260
|
+
let label = id;
|
|
261
|
+
|
|
262
|
+
const isWmsService = ctx
|
|
263
|
+
.getChild(6)
|
|
264
|
+
.getText()
|
|
265
|
+
.toLowerCase()
|
|
266
|
+
.startsWith("urlwms");
|
|
267
|
+
|
|
268
|
+
const layer = isWmsService
|
|
269
|
+
? this._createWmsServiceLayer(ctx, id, label)
|
|
270
|
+
: this._createStandardLayer(ctx, id, label);
|
|
271
|
+
|
|
272
|
+
this.log(`visitCreateWmsLayer ${id} - ${label}`);
|
|
273
|
+
|
|
274
|
+
this.store.getCurrentProduct().addLayer(layer);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_getCleanText = (node) => node?.text()?.getText().replace(/"/g, "") || null;
|
|
278
|
+
|
|
279
|
+
_createWmsServiceLayer(ctx, id, label) {
|
|
280
|
+
const sub = ctx.wmsSubLayer(0);
|
|
281
|
+
const clean = this._getCleanText;
|
|
282
|
+
|
|
283
|
+
const url = clean(sub.wmsUrl());
|
|
284
|
+
const layerName = clean(sub.wmsLayerName());
|
|
285
|
+
const format = clean(sub.wmsFormatName());
|
|
286
|
+
const crs = clean(sub.wmsCrs());
|
|
287
|
+
const version = clean(sub.wmsVersion());
|
|
288
|
+
const attribution = clean(sub.wmsAttribution());
|
|
289
|
+
|
|
290
|
+
const styles = sub.wmsStyles()
|
|
291
|
+
? clean(sub.wmsStyles())
|
|
292
|
+
.split(",")
|
|
293
|
+
.map((s) => s.trim())
|
|
294
|
+
: [];
|
|
295
|
+
|
|
296
|
+
const queryable = sub.wmsQueryable()
|
|
297
|
+
? clean(sub.wmsQueryable()).toLowerCase() === "true"
|
|
298
|
+
: false;
|
|
299
|
+
|
|
300
|
+
let bbox = null;
|
|
301
|
+
const bboxNode = sub.wmsBboxGroup();
|
|
302
|
+
if (bboxNode) {
|
|
303
|
+
bbox = {
|
|
304
|
+
crs: clean(bboxNode.wmsBboxCrs()),
|
|
305
|
+
minx: parseFloat(bboxNode.wmsMinX().floatNumber().getText()),
|
|
306
|
+
miny: parseFloat(bboxNode.wmsMinY().floatNumber().getText()),
|
|
307
|
+
maxx: parseFloat(bboxNode.wmsMaxX().floatNumber().getText()),
|
|
308
|
+
maxy: parseFloat(bboxNode.wmsMaxY().floatNumber().getText()),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return new WMSServiceLayer({
|
|
313
|
+
id,
|
|
314
|
+
label,
|
|
315
|
+
url,
|
|
316
|
+
layerName,
|
|
317
|
+
format,
|
|
318
|
+
crs,
|
|
319
|
+
bbox,
|
|
320
|
+
styles,
|
|
321
|
+
queryable,
|
|
322
|
+
attribution,
|
|
323
|
+
version,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
_createStandardLayer(ctx, id, label) {
|
|
328
|
+
let from = 4,
|
|
329
|
+
i,
|
|
330
|
+
aux,
|
|
331
|
+
entity,
|
|
332
|
+
auxEntityName,
|
|
333
|
+
style,
|
|
334
|
+
styleName;
|
|
335
|
+
if (ctx.getChild(3).getText() != ")") {
|
|
336
|
+
// tiene label
|
|
337
|
+
label = ctx.getChild(4).getText().slice(1, -1);
|
|
338
|
+
from = 6;
|
|
339
|
+
}
|
|
340
|
+
const layer = new WMSLayer(id, label);
|
|
341
|
+
|
|
342
|
+
for (i = from; i < ctx.getChildCount() - 2; i += 2) {
|
|
343
|
+
aux = ctx.getChild(i);
|
|
344
|
+
auxEntityName = aux.getChild(0).getText();
|
|
345
|
+
entity = this.store.getCurrentProduct().getEntity(auxEntityName);
|
|
346
|
+
styleName = aux.getChild(1).getText();
|
|
347
|
+
style = this.store.getCurrentProduct().getStyle(styleName);
|
|
348
|
+
|
|
349
|
+
if (entity) {
|
|
350
|
+
layer.addSubLayer(entity.name, styleName);
|
|
351
|
+
} else {
|
|
352
|
+
// GeoTIFF: no entity
|
|
353
|
+
const normalizedId = id
|
|
354
|
+
.replace(/Layer$/, "")
|
|
355
|
+
.replace(/^(\d+)([A-Z][a-z]+)/, "$1_$2")
|
|
356
|
+
.toLowerCase();
|
|
357
|
+
layer.addSubLayer(normalizedId, null);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return layer;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
visitCreateMap(ctx, sortable) {
|
|
365
|
+
const id = ctx.getChild(1).getText();
|
|
366
|
+
let label,
|
|
367
|
+
from,
|
|
368
|
+
i,
|
|
369
|
+
auxLayer,
|
|
370
|
+
layers = [];
|
|
371
|
+
if (ctx.getChild(4).getText() == "(") {
|
|
372
|
+
// tiene label
|
|
373
|
+
label = ctx.getChild(3).getText().slice(1, -1);
|
|
374
|
+
from = 5;
|
|
375
|
+
} else {
|
|
376
|
+
// no tiene label
|
|
377
|
+
label = id;
|
|
378
|
+
from = 3;
|
|
379
|
+
}
|
|
380
|
+
for (i = from; i < ctx.getChildCount() - 2; i = i + 2) {
|
|
381
|
+
layers.push(this.visitMapLayer(ctx.getChild(i)));
|
|
382
|
+
}
|
|
383
|
+
this.log(
|
|
384
|
+
`visitCreateMap ${id} - ${label} with ${layers.length} layers: ${layers
|
|
385
|
+
.map((e) => e.id)
|
|
386
|
+
.join(", ")}`,
|
|
387
|
+
);
|
|
388
|
+
const map = new Map(id, label, sortable);
|
|
389
|
+
layers.forEach((l) => {
|
|
390
|
+
auxLayer = this.store.getCurrentProduct().getLayer(l.id);
|
|
391
|
+
if (!auxLayer) {
|
|
392
|
+
throw `Layer ${l.id} does not exists!!!`;
|
|
393
|
+
}
|
|
394
|
+
map.addLayer(l.id, l.baseLayer, l.hidden);
|
|
395
|
+
});
|
|
396
|
+
this.store.getCurrentProduct().addMap(id, map);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
visitMapLayer(ctx) {
|
|
400
|
+
const ret = {
|
|
401
|
+
id: ctx.getChild(0).getText(),
|
|
402
|
+
};
|
|
403
|
+
if (ctx.getChildCount() == 3) {
|
|
404
|
+
// las dos opciones
|
|
405
|
+
ret.hidden = ret.baseLayer = true;
|
|
406
|
+
} else if (ctx.getChildCount() == 2) {
|
|
407
|
+
if (ctx.getChild(1).getSymbol().text.toLowerCase() == "is_base_layer") {
|
|
408
|
+
// base layer
|
|
409
|
+
ret.baseLayer = true;
|
|
410
|
+
} else {
|
|
411
|
+
// capa oculta
|
|
412
|
+
ret.hidden = true;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return ret;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
visitCreateSortableMap(ctx) {
|
|
419
|
+
this.log(`visitCreateSortableMap`);
|
|
420
|
+
this.visitCreateMap(ctx.getChild(1), true);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/* ****************** Deployment ************************ */
|
|
424
|
+
|
|
425
|
+
visitDeploymentProperty(ctx) {
|
|
426
|
+
this.log(`visitDeploymentProperty`);
|
|
427
|
+
this.store
|
|
428
|
+
.getCurrentProduct()
|
|
429
|
+
.addDeploymentProperty(
|
|
430
|
+
ctx.getChild(0).getText().slice(1, -1),
|
|
431
|
+
ctx.getChild(1).getText().slice(1, -1),
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export default Visitor;
|