@lbdudc/gp-gis-dsl 0.2.0 → 0.2.2

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.
@@ -1,4 +1,4 @@
1
- // Generated from grammar/GISGrammar.g4 by ANTLR 4.13.0
1
+ // Generated from grammar/GISGrammar.g4 by ANTLR 4.13.1
2
2
  // jshint ignore: start
3
3
  import antlr4 from 'antlr4';
4
4
 
@@ -54,6 +54,12 @@ export default class GISGrammarVisitor extends antlr4.tree.ParseTreeVisitor {
54
54
  }
55
55
 
56
56
 
57
+ // Visit a parse tree produced by GISGrammarParser#sldCustomBody.
58
+ visitSldCustomBody(ctx) {
59
+ return this.visitChildren(ctx);
60
+ }
61
+
62
+
57
63
  // Visit a parse tree produced by GISGrammarParser#createWmsStyle.
58
64
  visitCreateWmsStyle(ctx) {
59
65
  return this.visitChildren(ctx);
@@ -180,5 +186,11 @@ export default class GISGrammarVisitor extends antlr4.tree.ParseTreeVisitor {
180
186
  }
181
187
 
182
188
 
189
+ // Visit a parse tree produced by GISGrammarParser#intNumber.
190
+ visitIntNumber(ctx) {
191
+ return this.visitChildren(ctx);
192
+ }
193
+
194
+
183
195
 
184
196
  }
package/src/spl/GIS.js CHANGED
@@ -1,234 +1,234 @@
1
- class GIS {
2
- constructor(name, srid) {
3
- this.name = name;
4
- this.srid = parseInt(srid);
5
- if (srid != 4326) {
6
- console.warn("Only SRID 4326 supported!");
7
- }
8
- this.entities = [];
9
- this.relationships = [];
10
- this.enums = [];
11
- this.layers = [];
12
- this.styles = [];
13
- this.maps = [];
14
- }
15
-
16
- addEntity(name) {
17
- if (this.getEntity(name)) {
18
- throw `Entity ${name} already exists!!!`;
19
- }
20
- this.entities.push(new Entity(name));
21
- }
22
-
23
- getEntity(name) {
24
- return this.entities.find((e) => e.name == name);
25
- }
26
-
27
- addRelationship(source, target, sourceOpts, targetOpts) {
28
- const existingRelationship = this.getRelationship(
29
- source,
30
- target,
31
- sourceOpts.label,
32
- );
33
- if (existingRelationship) {
34
- existingRelationship.update(sourceOpts, targetOpts);
35
- } else {
36
- this.relationships.push(
37
- new Relationship(source, target, sourceOpts, targetOpts),
38
- );
39
- }
40
- }
41
-
42
- getRelationship(source, target, sourceLabel) {
43
- return this.relationships.find(
44
- (e) =>
45
- e.source == source &&
46
- e.target == target &&
47
- e.sourceOpts.label == sourceLabel,
48
- );
49
- }
50
-
51
- _entityExists(name) {
52
- return this.getEntity(name) != null;
53
- }
54
-
55
- /**
56
- * Only for things that cannot be validated earlier
57
- */
58
- validate() {
59
- this.relationships.forEach((r) => {
60
- if (!this._entityExists(r.source)) {
61
- throw `ERROR: entity ${r.source} required by relationship does not exists!!`;
62
- }
63
- if (!this._entityExists(r.target)) {
64
- throw `ERROR: entity ${r.target} required by relationship does not exists!!`;
65
- }
66
- });
67
-
68
- this.layers.forEach((layer) => {
69
- if (layer.type == "GeoJSONLayer") {
70
- if (!this._entityExists(layer.entityId)) {
71
- throw `ERROR: entity ${layer.entityId} required by layer ${layer.id} does not exists!!`;
72
- }
73
- }
74
- });
75
- }
76
-
77
- getMaps() {
78
- return this.maps;
79
- }
80
-
81
- getLayer(id) {
82
- return this.layers.find((l) => l.getId() == id);
83
- }
84
-
85
- addLayer(layer) {
86
- this.layers.push(layer);
87
- }
88
-
89
- getStyle(id) {
90
- return this.styles.find((s) => s.getId() == id);
91
- }
92
-
93
- addStyle(style) {
94
- this.styles.push(style);
95
- }
96
-
97
- getMap(id) {
98
- return this.maps.find((m) => m.id == id);
99
- }
100
-
101
- addMap(id, map) {
102
- this.maps.push(map);
103
- }
104
-
105
- addDeploymentProperty(key, value) {
106
- if (!this.extra) {
107
- this.extra = {};
108
- }
109
- this.extra[key] = value;
110
- }
111
-
112
- toString() {
113
- return (
114
- `\nGIS(${this.name} in ${this.srid}) - ${this.entities.length} entities, ${this.relationships.length} relationships:\n\t` +
115
- `${this.entities.map((e) => e.toString()).join("\n\t")}\n\n\t` +
116
- `${this.relationships.map((r) => r.toString()).join("\n\t")}` +
117
- `${this.getMaps()
118
- .map((m) => m.toString())
119
- .join("\n\t")}`
120
- );
121
- }
122
- }
123
-
124
- class Entity {
125
- constructor(name) {
126
- this.name = name;
127
- this.properties = [];
128
- }
129
-
130
- addProperty(name, type, params) {
131
- if (this.getProperty(name)) {
132
- throw `Property ${name} already exists in entity ${this.name}!!!`;
133
- }
134
- this.properties.push(new Property(name, type, params));
135
- }
136
-
137
- getProperty(name) {
138
- return this.properties.find((p) => p.name == name);
139
- }
140
-
141
- validate() {
142
- let pk = false;
143
- let displayString = false;
144
- this.properties.forEach((prop) => {
145
- if (prop.pk) {
146
- if (pk) throw "ERROR: already has a primary key";
147
- pk = true;
148
- }
149
- if (prop.displayString) {
150
- if (displayString) throw "ERROR: already has a displayString";
151
- this.displayString = "$" + prop.name;
152
- delete prop.displayString;
153
- displayString = true;
154
- }
155
- });
156
- }
157
-
158
- toString() {
159
- return `Entity ${this.name}: ${this.properties
160
- .map((e) => e.toString())
161
- .join(", ")}`;
162
- }
163
- }
164
-
165
- class Property {
166
- constructor(name, type, params) {
167
- this.name = name;
168
- this.class = type;
169
- if (params) {
170
- if (params.pk) {
171
- this.pk = true;
172
- this.required = true;
173
- this.unique = true;
174
- if (this.class == "Long") {
175
- this.class = "Long (autoinc)";
176
- }
177
- }
178
- if (params.required) {
179
- this.required = true;
180
- }
181
- if (params.unique) {
182
- this.unique = true;
183
- }
184
- if (params.displayString) {
185
- this.displayString = true;
186
- }
187
- }
188
- }
189
-
190
- toString() {
191
- return (
192
- this.name +
193
- ":" +
194
- this.class +
195
- (this.params ? "(" + Object.keys(this.params).join(", ") + ")" : "")
196
- );
197
- }
198
- }
199
-
200
- class Relationship {
201
- constructor(source, target, sourceOpts, targetOpts) {
202
- this.source = source;
203
- this.target = target;
204
- this.sourceOpts = sourceOpts;
205
- this.targetOpts = targetOpts;
206
- if (!this.targetOpts.label) {
207
- this.targetOpts.label = this.source.toLowerCase();
208
- if (this.targetOpts.multiplicity.indexOf("*") != -1) {
209
- this.targetOpts.label += "s";
210
- }
211
- }
212
- }
213
-
214
- update(sourceOpts, targetOpts) {
215
- if (targetOpts.label) {
216
- this.targetOpts.label = targetOpts.label;
217
- }
218
- if (targetOpts.multiplicity) {
219
- this.targetOpts.multiplicity = targetOpts.multiplicity;
220
- }
221
- if (sourceOpts.multiplicity) {
222
- this.sourceOpts.multiplicity = sourceOpts.multiplicity;
223
- }
224
- }
225
-
226
- toString() {
227
- return (
228
- `${this.source}.${this.sourceOpts.label}(${this.sourceOpts.multiplicity})` +
229
- ` -> ${this.target}.${this.targetOpts.label}(${this.targetOpts.multiplicity})`
230
- );
231
- }
232
- }
233
-
234
- export default GIS;
1
+ class GIS {
2
+ constructor(name, srid) {
3
+ this.name = name;
4
+ this.srid = parseInt(srid);
5
+ if (srid != 4326) {
6
+ console.warn("Only SRID 4326 supported!");
7
+ }
8
+ this.entities = [];
9
+ this.relationships = [];
10
+ this.enums = [];
11
+ this.layers = [];
12
+ this.styles = [];
13
+ this.maps = [];
14
+ }
15
+
16
+ addEntity(name) {
17
+ if (this.getEntity(name)) {
18
+ throw `Entity ${name} already exists!!!`;
19
+ }
20
+ this.entities.push(new Entity(name));
21
+ }
22
+
23
+ getEntity(name) {
24
+ return this.entities.find((e) => e.name == name);
25
+ }
26
+
27
+ addRelationship(source, target, sourceOpts, targetOpts) {
28
+ const existingRelationship = this.getRelationship(
29
+ source,
30
+ target,
31
+ sourceOpts.label,
32
+ );
33
+ if (existingRelationship) {
34
+ existingRelationship.update(sourceOpts, targetOpts);
35
+ } else {
36
+ this.relationships.push(
37
+ new Relationship(source, target, sourceOpts, targetOpts),
38
+ );
39
+ }
40
+ }
41
+
42
+ getRelationship(source, target, sourceLabel) {
43
+ return this.relationships.find(
44
+ (e) =>
45
+ e.source == source &&
46
+ e.target == target &&
47
+ e.sourceOpts.label == sourceLabel,
48
+ );
49
+ }
50
+
51
+ _entityExists(name) {
52
+ return this.getEntity(name) != null;
53
+ }
54
+
55
+ /**
56
+ * Only for things that cannot be validated earlier
57
+ */
58
+ validate() {
59
+ this.relationships.forEach((r) => {
60
+ if (!this._entityExists(r.source)) {
61
+ throw `ERROR: entity ${r.source} required by relationship does not exists!!`;
62
+ }
63
+ if (!this._entityExists(r.target)) {
64
+ throw `ERROR: entity ${r.target} required by relationship does not exists!!`;
65
+ }
66
+ });
67
+
68
+ this.layers.forEach((layer) => {
69
+ if (layer.type == "GeoJSONLayer") {
70
+ if (!this._entityExists(layer.entityId)) {
71
+ throw `ERROR: entity ${layer.entityId} required by layer ${layer.id} does not exists!!`;
72
+ }
73
+ }
74
+ });
75
+ }
76
+
77
+ getMaps() {
78
+ return this.maps;
79
+ }
80
+
81
+ getLayer(id) {
82
+ return this.layers.find((l) => l.getId() == id);
83
+ }
84
+
85
+ addLayer(layer) {
86
+ this.layers.push(layer);
87
+ }
88
+
89
+ getStyle(id) {
90
+ return this.styles.find((s) => s.getId() == id);
91
+ }
92
+
93
+ addStyle(style) {
94
+ this.styles.push(style);
95
+ }
96
+
97
+ getMap(id) {
98
+ return this.maps.find((m) => m.id == id);
99
+ }
100
+
101
+ addMap(id, map) {
102
+ this.maps.push(map);
103
+ }
104
+
105
+ addDeploymentProperty(key, value) {
106
+ if (!this.extra) {
107
+ this.extra = {};
108
+ }
109
+ this.extra[key] = value;
110
+ }
111
+
112
+ toString() {
113
+ return (
114
+ `\nGIS(${this.name} in ${this.srid}) - ${this.entities.length} entities, ${this.relationships.length} relationships:\n\t` +
115
+ `${this.entities.map((e) => e.toString()).join("\n\t")}\n\n\t` +
116
+ `${this.relationships.map((r) => r.toString()).join("\n\t")}` +
117
+ `${this.getMaps()
118
+ .map((m) => m.toString())
119
+ .join("\n\t")}`
120
+ );
121
+ }
122
+ }
123
+
124
+ class Entity {
125
+ constructor(name) {
126
+ this.name = name;
127
+ this.properties = [];
128
+ }
129
+
130
+ addProperty(name, type, params) {
131
+ if (this.getProperty(name)) {
132
+ throw `Property ${name} already exists in entity ${this.name}!!!`;
133
+ }
134
+ this.properties.push(new Property(name, type, params));
135
+ }
136
+
137
+ getProperty(name) {
138
+ return this.properties.find((p) => p.name == name);
139
+ }
140
+
141
+ validate() {
142
+ let pk = false;
143
+ let displayString = false;
144
+ this.properties.forEach((prop) => {
145
+ if (prop.pk) {
146
+ if (pk) throw "ERROR: already has a primary key";
147
+ pk = true;
148
+ }
149
+ if (prop.displayString) {
150
+ if (displayString) throw "ERROR: already has a displayString";
151
+ this.displayString = "$" + prop.name;
152
+ delete prop.displayString;
153
+ displayString = true;
154
+ }
155
+ });
156
+ }
157
+
158
+ toString() {
159
+ return `Entity ${this.name}: ${this.properties
160
+ .map((e) => e.toString())
161
+ .join(", ")}`;
162
+ }
163
+ }
164
+
165
+ class Property {
166
+ constructor(name, type, params) {
167
+ this.name = name;
168
+ this.class = type;
169
+ if (params) {
170
+ if (params.pk) {
171
+ this.pk = true;
172
+ this.required = true;
173
+ this.unique = true;
174
+ if (this.class == "Long") {
175
+ this.class = "Long (autoinc)";
176
+ }
177
+ }
178
+ if (params.required) {
179
+ this.required = true;
180
+ }
181
+ if (params.unique) {
182
+ this.unique = true;
183
+ }
184
+ if (params.displayString) {
185
+ this.displayString = true;
186
+ }
187
+ }
188
+ }
189
+
190
+ toString() {
191
+ return (
192
+ this.name +
193
+ ":" +
194
+ this.class +
195
+ (this.params ? "(" + Object.keys(this.params).join(", ") + ")" : "")
196
+ );
197
+ }
198
+ }
199
+
200
+ class Relationship {
201
+ constructor(source, target, sourceOpts, targetOpts) {
202
+ this.source = source;
203
+ this.target = target;
204
+ this.sourceOpts = sourceOpts;
205
+ this.targetOpts = targetOpts;
206
+ if (!this.targetOpts.label) {
207
+ this.targetOpts.label = this.source.toLowerCase();
208
+ if (this.targetOpts.multiplicity.indexOf("*") != -1) {
209
+ this.targetOpts.label += "s";
210
+ }
211
+ }
212
+ }
213
+
214
+ update(sourceOpts, targetOpts) {
215
+ if (targetOpts.label) {
216
+ this.targetOpts.label = targetOpts.label;
217
+ }
218
+ if (targetOpts.multiplicity) {
219
+ this.targetOpts.multiplicity = targetOpts.multiplicity;
220
+ }
221
+ if (sourceOpts.multiplicity) {
222
+ this.sourceOpts.multiplicity = sourceOpts.multiplicity;
223
+ }
224
+ }
225
+
226
+ toString() {
227
+ return (
228
+ `${this.source}.${this.sourceOpts.label}(${this.sourceOpts.multiplicity})` +
229
+ ` -> ${this.target}.${this.targetOpts.label}(${this.targetOpts.multiplicity})`
230
+ );
231
+ }
232
+ }
233
+
234
+ export default GIS;
package/src/spl/Map.js CHANGED
@@ -1,44 +1,53 @@
1
- import TileLayer from "./TileLayer.js";
2
- import WMSLayer from "./WMSLayer.js";
3
- import WMSStyle from "./WMSStyle.js";
4
- import GeoJSONLayer from "./GeoJSONLayer.js";
5
- import GeoJSONLayerStyle from "./GeoJSONLayerStyle.js";
6
-
7
- class Map {
8
- constructor(id, label, sortable = false) {
9
- this.name = id;
10
- this.label = label;
11
- this.sortable = sortable;
12
- this.layers = [];
13
- }
14
-
15
- getId() {
16
- return this.name;
17
- }
18
-
19
- addLayer(layer, isBaseLayer = false, hidden = false) {
20
- this.layers.push({
21
- name: layer,
22
- baseLayer: isBaseLayer,
23
- selected: !hidden,
24
- });
25
- }
26
-
27
- toString() {
28
- return (
29
- `\n${this.sortable ? "Sortable" : ""}Map(${this.name} as ${
30
- this.label
31
- }) - ${this.layers.length} layers:\n\t` +
32
- `${this.layers
33
- .map(
34
- (l) =>
35
- (l.isBaseLayer ? "BL-" : "") +
36
- (l.hidden ? "H-" : "") +
37
- l.layer.toString(),
38
- )
39
- .join("\n\t")}`
40
- );
41
- }
42
- }
43
-
44
- export { GeoJSONLayer, TileLayer, WMSStyle, WMSLayer, Map, GeoJSONLayerStyle };
1
+ import TileLayer from "./TileLayer.js";
2
+ import WMSLayer from "./WMSLayer.js";
3
+ import WMSStyle from "./WMSStyle.js";
4
+ import GeoJSONLayer from "./GeoJSONLayer.js";
5
+ import GeoJSONLayerStyle from "./GeoJSONLayerStyle.js";
6
+ import WMSStyleCustom from "./WMSStyleCustom.js";
7
+
8
+ class Map {
9
+ constructor(id, label, sortable = false) {
10
+ this.name = id;
11
+ this.label = label;
12
+ this.sortable = sortable;
13
+ this.layers = [];
14
+ }
15
+
16
+ getId() {
17
+ return this.name;
18
+ }
19
+
20
+ addLayer(layer, isBaseLayer = false, hidden = false) {
21
+ this.layers.push({
22
+ name: layer,
23
+ baseLayer: isBaseLayer,
24
+ selected: !hidden,
25
+ });
26
+ }
27
+
28
+ toString() {
29
+ return (
30
+ `\n${this.sortable ? "Sortable" : ""}Map(${this.name} as ${
31
+ this.label
32
+ }) - ${this.layers.length} layers:\n\t` +
33
+ `${this.layers
34
+ .map(
35
+ (l) =>
36
+ (l.isBaseLayer ? "BL-" : "") +
37
+ (l.hidden ? "H-" : "") +
38
+ l.layer.toString(),
39
+ )
40
+ .join("\n\t")}`
41
+ );
42
+ }
43
+ }
44
+
45
+ export {
46
+ GeoJSONLayer,
47
+ TileLayer,
48
+ WMSStyle,
49
+ WMSStyleCustom,
50
+ WMSLayer,
51
+ Map,
52
+ GeoJSONLayerStyle,
53
+ };
@@ -0,0 +1,22 @@
1
+ export default class WMSStyleCustom {
2
+ constructor(
3
+ id,
4
+ geometryType,
5
+ fillColor,
6
+ strokeColor,
7
+ fillOpacity,
8
+ strokeOpacity,
9
+ ) {
10
+ this.name = id;
11
+ this.type = "WMSLayerStyle";
12
+ this.geometryType = geometryType;
13
+ this.fillColor = fillColor;
14
+ this.strokeColor = strokeColor;
15
+ this.fillOpacity = fillOpacity;
16
+ this.strokeOpacity = strokeOpacity;
17
+ }
18
+
19
+ getId() {
20
+ return this.name;
21
+ }
22
+ }