@vidro/map-handler 1.3.1 → 1.3.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.
- package/README.md +67 -1
- package/dist/map-handler.js +1 -1
- package/map-handler.d.ts +134 -0
- package/package.json +11 -4
- package/src/types.d.ts +63 -0
- package/.babelrc +0 -6
- package/doc/animation.png +0 -0
- package/doc/confirmComponent.png +0 -0
- package/doc/giswater.png +0 -0
- package/doc/giswaterInfo.png +0 -0
- package/doc/giswaterInfoApi.png +0 -0
- package/doc/giswatergeojson.png +0 -0
- package/doc/multiTile.png +0 -0
- package/doc/multiTileNoGutter.png +0 -0
- package/doc/togglelayergiswater.png +0 -0
- package/doc/vidromaps-basic.png +0 -0
- package/examples/full/apidemo.js +0 -387
- package/examples/full/cachedToken.dat +0 -1
- package/examples/full/cachedTokenData.dat +0 -1
- package/examples/full/docker/Docker_compose.yml +0 -14
- package/examples/full/docker/Dockerfile +0 -27
- package/examples/full/index.php +0 -200
- package/examples/full/storeToken.php +0 -6
- package/examples/full/tester.css +0 -74
- package/examples/full/tester.js +0 -658
- package/examples/multipleIframes/index.js +0 -82
- package/examples/multipleIframes/index.php +0 -52
- package/examples/react-next/README.md +0 -282
- package/examples/react-next/atoms/PrintLayoutSelector.js +0 -50
- package/examples/react-next/atoms/PrintPaperSizeSelector.js +0 -48
- package/examples/react-next/atoms/ZoomToScaleButton.js +0 -57
- package/examples/react-next/components/AuthComponent.js +0 -88
- package/examples/react-next/components/MapButtons.js +0 -136
- package/examples/react-next/components/MapFilters.js +0 -120
- package/examples/react-next/components/MapIframe.js +0 -25
- package/examples/react-next/components/MapInfo.js +0 -36
- package/examples/react-next/components/MapLayers.js +0 -60
- package/examples/react-next/components/MapList.js +0 -51
- package/examples/react-next/contexts/auth.js +0 -147
- package/examples/react-next/contexts/maps.js +0 -185
- package/examples/react-next/contexts/messages.js +0 -360
- package/examples/react-next/contexts/print.js +0 -51
- package/examples/react-next/env.sample +0 -3
- package/examples/react-next/eslint.config.mjs +0 -14
- package/examples/react-next/hooks/useMapEvents.js +0 -118
- package/examples/react-next/jsconfig.json +0 -7
- package/examples/react-next/next.config.mjs +0 -6
- package/examples/react-next/package.json +0 -25
- package/examples/react-next/pages/_app.js +0 -5
- package/examples/react-next/pages/index.js +0 -90
- package/examples/react-next/postcss.config.mjs +0 -8
- package/examples/react-next/public/discord.svg +0 -8
- package/examples/react-next/public/favicon.ico +0 -0
- package/examples/react-next/public/file.svg +0 -1
- package/examples/react-next/public/logo.png +0 -0
- package/examples/react-next/public/next.svg +0 -1
- package/examples/react-next/shared/constants.js +0 -47
- package/examples/react-next/shared/cookies.js +0 -23
- package/examples/react-next/styles/globals.css +0 -24
- package/examples/react-next/tailwind.config.mjs +0 -17
- package/examples/serverLess/dist/index.23420cfa.js +0 -2973
- package/examples/serverLess/dist/index.23420cfa.js.map +0 -1
- package/examples/serverLess/dist/index.91b6cacc.js +0 -2
- package/examples/serverLess/dist/index.91b6cacc.js.map +0 -1
- package/examples/serverLess/dist/index.html +0 -1
- package/examples/serverLess/index.html +0 -39
- package/examples/serverLess/main.js +0 -113
- package/examples/serverLess/package.json +0 -18
- package/examples/serverLess/readme.md +0 -41
- package/examples/simple/index.html +0 -23
- package/examples/simple/simple.js +0 -80
- package/examples/taigua/index.html +0 -55
- package/examples/taigua/main.js +0 -490
- package/examples/tester.css +0 -74
- package/examples/vidromap/index.js +0 -20
- package/examples/vidromap/index.php +0 -111
- package/flows.md +0 -73
- package/helpers.md +0 -45
- package/src/index.js +0 -879
- package/src/shared/iframe-communicator.js +0 -18
- package/webpack.config.js +0 -22
package/src/index.js
DELETED
|
@@ -1,879 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from "events";
|
|
2
|
-
import { iframeCommunicator } from "./shared/iframe-communicator";
|
|
3
|
-
|
|
4
|
-
class Communicator extends EventEmitter {
|
|
5
|
-
constructor(data) {
|
|
6
|
-
super();
|
|
7
|
-
this.domId = "map-frame";
|
|
8
|
-
if (typeof window === "undefined") {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (typeof data.id === "string") {
|
|
12
|
-
this.domId = data.id;
|
|
13
|
-
}
|
|
14
|
-
this.com = new iframeCommunicator(data);
|
|
15
|
-
window.addEventListener("message", (e) => this.onMessageReceived(e));
|
|
16
|
-
this.sessionToken = data.sessionToken;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
removeListener(event, listener) {
|
|
20
|
-
super.removeListener(event, listener);
|
|
21
|
-
}
|
|
22
|
-
onMessageReceived = (e) => {
|
|
23
|
-
switch (e.data.type) {
|
|
24
|
-
case "onZoomChange":
|
|
25
|
-
this.emitEvent("onZoomChange", e.data, e.data.domId);
|
|
26
|
-
break;
|
|
27
|
-
case "onCenterChange":
|
|
28
|
-
this.emitEvent("onCenterChange", e.data, e.data.domId);
|
|
29
|
-
break;
|
|
30
|
-
case "geomAdded":
|
|
31
|
-
this.emitEvent("geomAdded", e.data, e.data.domId);
|
|
32
|
-
break;
|
|
33
|
-
case "layers":
|
|
34
|
-
this.emitEvent("layers", e.data, e.data.domId);
|
|
35
|
-
break;
|
|
36
|
-
case "geoJSONlayers":
|
|
37
|
-
this.emitEvent("geoJSONlayers", e.data, e.data.domId);
|
|
38
|
-
break;
|
|
39
|
-
case "info":
|
|
40
|
-
this.emitEvent("info", e.data, e.data.domId);
|
|
41
|
-
break;
|
|
42
|
-
case "error":
|
|
43
|
-
this.emitEvent("error", e.data, e.data.domId);
|
|
44
|
-
break;
|
|
45
|
-
case "coordinates":
|
|
46
|
-
this.emitEvent("coordinates", e.data, e.data.domId);
|
|
47
|
-
break;
|
|
48
|
-
case "activeLayer":
|
|
49
|
-
this.emitEvent("activeLayer", e.data, e.data.domId);
|
|
50
|
-
break;
|
|
51
|
-
case "geolocation":
|
|
52
|
-
this.emitEvent("geolocation", e.data, e.data.domId);
|
|
53
|
-
break;
|
|
54
|
-
case "WMSInfoAvailable":
|
|
55
|
-
this.emitEvent("WMSInfoAvailable", e.data, e.data.domId);
|
|
56
|
-
break;
|
|
57
|
-
case "giswaterTiledBackgroundDisplayed":
|
|
58
|
-
this.emitEvent(
|
|
59
|
-
"giswaterTiledBackgroundDisplayed",
|
|
60
|
-
e.data,
|
|
61
|
-
e.data.domId
|
|
62
|
-
);
|
|
63
|
-
break;
|
|
64
|
-
case "giswaterTiledBackgroundAvailable":
|
|
65
|
-
this.emitEvent(
|
|
66
|
-
"giswaterTiledBackgroundAvailable",
|
|
67
|
-
e.data,
|
|
68
|
-
e.data.domId
|
|
69
|
-
);
|
|
70
|
-
break;
|
|
71
|
-
case "GiswaterLayerAvailableFilters":
|
|
72
|
-
this.emitEvent("GiswaterLayerAvailableFilters", e.data, e.data.domId);
|
|
73
|
-
break;
|
|
74
|
-
case "loaded":
|
|
75
|
-
this.emitEvent("loaded", e.data, e.data.domId);
|
|
76
|
-
break;
|
|
77
|
-
case "unloaded":
|
|
78
|
-
this.emitEvent("unloaded", e.data, e.data.domId);
|
|
79
|
-
break;
|
|
80
|
-
case "availableWMSLayers":
|
|
81
|
-
this.emitEvent("availableWMSLayers", e.data.layers, e.data.domId);
|
|
82
|
-
break;
|
|
83
|
-
case "layerElements":
|
|
84
|
-
this.emitEvent("layerElements", e.data, e.data.domId);
|
|
85
|
-
break;
|
|
86
|
-
case "getToc":
|
|
87
|
-
this.emitEvent("getToc", e.data, e.data.domId);
|
|
88
|
-
break;
|
|
89
|
-
case "status":
|
|
90
|
-
this.emitEvent("status", e.data, e.data.domId);
|
|
91
|
-
break;
|
|
92
|
-
case "MeasureEnd":
|
|
93
|
-
this.emitEvent("MeasureEnd", e.data, e.data.domId);
|
|
94
|
-
break;
|
|
95
|
-
case "queue":
|
|
96
|
-
this.emitEvent("queue", e.data, e.data.domId);
|
|
97
|
-
break;
|
|
98
|
-
case "version":
|
|
99
|
-
this.emitEvent("version", e.data, e.data.domId);
|
|
100
|
-
break;
|
|
101
|
-
case "hover":
|
|
102
|
-
this.emitEvent("hover", e.data, e.data.domId);
|
|
103
|
-
break;
|
|
104
|
-
case "screenshot":
|
|
105
|
-
this.emitEvent("screenshot", e.data, e.data.domId);
|
|
106
|
-
break;
|
|
107
|
-
case "print":
|
|
108
|
-
this.emitEvent("print", e.data, e.data.domId);
|
|
109
|
-
break;
|
|
110
|
-
|
|
111
|
-
//case "getLegend": this.emitEvent("getLegend", e.data,e.data.domId); break;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
emitEvent = (type, data, domId) => {
|
|
116
|
-
if (domId === this.domId) {
|
|
117
|
-
delete data.domId;
|
|
118
|
-
this.emit(type, data);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
ZoomIn = () => {
|
|
123
|
-
this.com.sendMessageToMap({
|
|
124
|
-
type: "zoomIn",
|
|
125
|
-
sessionToken: this.sessionToken,
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
ZoomOut = () => {
|
|
130
|
-
this.com.sendMessageToMap({
|
|
131
|
-
type: "zoomOut",
|
|
132
|
-
sessionToken: this.sessionToken,
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
AddGeom = (geomtype, options) => {
|
|
137
|
-
this.com.sendMessageToMap({
|
|
138
|
-
type: "AddGeom",
|
|
139
|
-
geom: geomtype,
|
|
140
|
-
texts: options?.texts,
|
|
141
|
-
style: options?.style,
|
|
142
|
-
drawOnEnd: options?.drawOnEnd,
|
|
143
|
-
showConfirm: options?.showConfirm,
|
|
144
|
-
sessionToken: this.sessionToken,
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
CancelAddGeom = (s) => {
|
|
149
|
-
this.com.sendMessageToMap({
|
|
150
|
-
type: "CancelAddGeom",
|
|
151
|
-
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
loadMultipleLayers = (layers) => {
|
|
155
|
-
if (typeof layers !== "undefined") {
|
|
156
|
-
this.com.sendMessageToMap({
|
|
157
|
-
type: "loadMultipleLayers",
|
|
158
|
-
layers: layers,
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
this.emit("error", { error: "no layers" });
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
toggleGroup = (layers) => {
|
|
166
|
-
this.com.sendMessageToMap({
|
|
167
|
-
type: "toggleGroup",
|
|
168
|
-
layers,
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
toggleLayer = (layer, properties) => {
|
|
173
|
-
if (typeof properties === "undefined") {
|
|
174
|
-
properties = {
|
|
175
|
-
gutter: null,
|
|
176
|
-
transparent: null,
|
|
177
|
-
singletile: null,
|
|
178
|
-
zIndex: null,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (properties.singletile !== null) {
|
|
183
|
-
if (typeof properties.singletile !== "boolean") {
|
|
184
|
-
properties.singletile = null;
|
|
185
|
-
this.emit("error", {
|
|
186
|
-
error: "singletile must be a Boolean",
|
|
187
|
-
type: "error",
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (
|
|
192
|
-
properties.gutter !== "" &&
|
|
193
|
-
properties.gutter !== null &&
|
|
194
|
-
!properties.singletile
|
|
195
|
-
) {
|
|
196
|
-
if (isNaN(parseInt(properties.gutter))) {
|
|
197
|
-
properties.gutter = null;
|
|
198
|
-
this.emit("error", { type: "error", error: "Gutter must be a number" });
|
|
199
|
-
}
|
|
200
|
-
if (properties.singletile) {
|
|
201
|
-
properties.gutter = null;
|
|
202
|
-
this.emit("error", {
|
|
203
|
-
type: "error",
|
|
204
|
-
error:
|
|
205
|
-
"Gutter can only be user with multitile layers; set singletile to false",
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (properties.transparent !== null) {
|
|
211
|
-
if (typeof properties.transparent !== "boolean") {
|
|
212
|
-
properties.transparent = null;
|
|
213
|
-
this.emit("error", {
|
|
214
|
-
type: "error",
|
|
215
|
-
error: "transparent must be a Boolean",
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
this.com.sendMessageToMap({
|
|
220
|
-
type: "toggleLayer",
|
|
221
|
-
layer: layer,
|
|
222
|
-
gutter: !isNaN(parseInt(properties.gutter))
|
|
223
|
-
? parseInt(properties.gutter)
|
|
224
|
-
: null,
|
|
225
|
-
transparent: properties.transparent,
|
|
226
|
-
singletile: properties.singletile,
|
|
227
|
-
sessionToken: this.sessionToken,
|
|
228
|
-
zIndex: !isNaN(parseInt(properties.zIndex))
|
|
229
|
-
? parseInt(properties.zIndex)
|
|
230
|
-
: null,
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
removeLayer = (layer) => {
|
|
235
|
-
this.com.sendMessageToMap({
|
|
236
|
-
type: "removeLayer",
|
|
237
|
-
layer: layer,
|
|
238
|
-
sessionToken: this.sessionToken,
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
displayLayer = (layer) => {
|
|
243
|
-
this.com.sendMessageToMap({
|
|
244
|
-
type: "displayLayer",
|
|
245
|
-
layer: layer,
|
|
246
|
-
sessionToken: this.sessionToken,
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
setActiveLayer = (layer) => {
|
|
250
|
-
this.com.sendMessageToMap({
|
|
251
|
-
type: "setActiveLayer",
|
|
252
|
-
layer: layer,
|
|
253
|
-
sessionToken: this.sessionToken,
|
|
254
|
-
});
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
getActiveLayer = () => {
|
|
258
|
-
this.com.sendMessageToMap({
|
|
259
|
-
type: "getActiveLayer",
|
|
260
|
-
sessionToken: this.sessionToken,
|
|
261
|
-
});
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
bringLayerToTop = (layer) => {
|
|
265
|
-
this.com.sendMessageToMap({
|
|
266
|
-
type: "bringLayerToTop",
|
|
267
|
-
layer: layer,
|
|
268
|
-
sessionToken: this.sessionToken,
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
bringLayerToBottom = (layer) => {
|
|
273
|
-
this.com.sendMessageToMap({
|
|
274
|
-
type: "bringLayerToBottom",
|
|
275
|
-
layer: layer,
|
|
276
|
-
sessionToken: this.sessionToken,
|
|
277
|
-
});
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
loadWMSAvailableLayers = () => {
|
|
281
|
-
this.com.sendMessageToMap({
|
|
282
|
-
type: "loadWMSAvailableLayers",
|
|
283
|
-
sessionToken: this.sessionToken,
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
clear = () => {
|
|
288
|
-
this.com.sendMessageToMap({
|
|
289
|
-
type: "clear",
|
|
290
|
-
sessionToken: this.sessionToken,
|
|
291
|
-
});
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
Highlight = (options) => {
|
|
295
|
-
this.com.sendMessageToMap({
|
|
296
|
-
type: "highlight",
|
|
297
|
-
geom: options.geom,
|
|
298
|
-
zoom: options.zoom,
|
|
299
|
-
metadata: options?.data,
|
|
300
|
-
center: options?.center !== undefined ? options.center : false,
|
|
301
|
-
animate: options?.animate,
|
|
302
|
-
style: options?.style,
|
|
303
|
-
sessionToken: this.sessionToken,
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
DrawGeometries = (geoms) => {
|
|
308
|
-
if (typeof geoms !== "undefined") {
|
|
309
|
-
this.com.sendMessageToMap({
|
|
310
|
-
type: "DrawGeometries",
|
|
311
|
-
geoms: geoms,
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
this.emit("error", { type: "error", error: "no geoms" });
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
RemoveGeometriesByProperty = (layer, property, value) => {
|
|
319
|
-
if (
|
|
320
|
-
typeof layer !== "undefined" &&
|
|
321
|
-
typeof property !== "undefined" &&
|
|
322
|
-
typeof value !== "undefined"
|
|
323
|
-
) {
|
|
324
|
-
this.com.sendMessageToMap({
|
|
325
|
-
type: "RemoveGeometriesByProperty",
|
|
326
|
-
layer,
|
|
327
|
-
property,
|
|
328
|
-
value,
|
|
329
|
-
});
|
|
330
|
-
} else {
|
|
331
|
-
this.emit("error", {
|
|
332
|
-
type: "error",
|
|
333
|
-
error: "no layer, property or value",
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
UpdateGeometriesByProperty = (layer, property, value, style) => {
|
|
339
|
-
if (
|
|
340
|
-
typeof layer !== "undefined" &&
|
|
341
|
-
typeof property !== "undefined" &&
|
|
342
|
-
typeof style !== "undefined" &&
|
|
343
|
-
typeof value !== "undefined"
|
|
344
|
-
) {
|
|
345
|
-
this.com.sendMessageToMap({
|
|
346
|
-
type: "UpdateGeometriesByProperty",
|
|
347
|
-
layer,
|
|
348
|
-
property,
|
|
349
|
-
value,
|
|
350
|
-
style,
|
|
351
|
-
});
|
|
352
|
-
} else {
|
|
353
|
-
this.emit("error", {
|
|
354
|
-
type: "error",
|
|
355
|
-
error: "no layer, property or value",
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
DrawGeometry = (geom, styles, name, id) => {
|
|
361
|
-
console.warn("DrawGeometry is deprecated. Use DrawGeometries");
|
|
362
|
-
const sty = {
|
|
363
|
-
stroke_color: styles.stroke_color ? styles.stroke_color : null,
|
|
364
|
-
fill_color: styles.fill_color ? styles.fill_color : null,
|
|
365
|
-
point_fill_color: styles.point_fill_color
|
|
366
|
-
? styles.point_fill_color
|
|
367
|
-
: null,
|
|
368
|
-
geom_radius: styles.geom_radius ? styles.geom_radius : null,
|
|
369
|
-
stroke_width: styles.stroke_width ? styles.stroke_width : null,
|
|
370
|
-
//text
|
|
371
|
-
font_color: styles.font_color ? styles.font_color : null,
|
|
372
|
-
font: styles.font ? styles.font : null,
|
|
373
|
-
font_size: styles.font_size ? styles.font_size : null,
|
|
374
|
-
placement: styles.placement ? styles.placement : null,
|
|
375
|
-
fontFillColor: styles.fontFillColor ? styles.fontFillColor : null,
|
|
376
|
-
fontStrokeColor: styles.fontStrokeColor ? styles.fontStrokeColor : null,
|
|
377
|
-
fontStrokeWidth: styles.fontStrokeWidth ? styles.fontStrokeWidth : null,
|
|
378
|
-
baseline: styles.baseline ? styles.baseline : null,
|
|
379
|
-
align: styles.align ? styles.align : null,
|
|
380
|
-
display: styles.display ? styles.display : null,
|
|
381
|
-
offsetY: styles.offsetY ? styles.offsetY : null,
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
this.com.sendMessageToMap({
|
|
385
|
-
type: "drawGeometry",
|
|
386
|
-
geom: geom,
|
|
387
|
-
style: sty,
|
|
388
|
-
name: name ? name : "highlight",
|
|
389
|
-
id: id ? id : Math.floor(Math.random() * 1000) + 1,
|
|
390
|
-
sessionToken: this.sessionToken,
|
|
391
|
-
});
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
RemoveGeometry = (id, layer = null) => {
|
|
395
|
-
const _id = typeof id == "undefined" ? null : id;
|
|
396
|
-
if (!_id) {
|
|
397
|
-
console.error("No element id");
|
|
398
|
-
this.emit("error", { type: "error", error: "No element id" });
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
this.com.sendMessageToMap({
|
|
402
|
-
type: "removeGeometry",
|
|
403
|
-
layer,
|
|
404
|
-
id: _id,
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
zoomToExtent = () => {
|
|
409
|
-
this.com.sendMessageToMap({
|
|
410
|
-
type: "zoomToExtent",
|
|
411
|
-
sessionToken: this.sessionToken,
|
|
412
|
-
});
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
zoomToScale = (scale) => {
|
|
416
|
-
const allowedScales = [
|
|
417
|
-
"1:100",
|
|
418
|
-
"1:200",
|
|
419
|
-
"1:400",
|
|
420
|
-
"1:500",
|
|
421
|
-
"1:1000",
|
|
422
|
-
"1:2000",
|
|
423
|
-
"1:5000",
|
|
424
|
-
"1:10000",
|
|
425
|
-
"1:50000",
|
|
426
|
-
];
|
|
427
|
-
|
|
428
|
-
if (!allowedScales.includes(scale)) {
|
|
429
|
-
console.error(
|
|
430
|
-
`Invalid scale: ${scale}. Allowed values are: ${allowedScales.join(
|
|
431
|
-
", "
|
|
432
|
-
)}`
|
|
433
|
-
);
|
|
434
|
-
this.emit("error", {
|
|
435
|
-
type: "error",
|
|
436
|
-
error: `Invalid scale: ${scale}`,
|
|
437
|
-
});
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
this.com.sendMessageToMap({
|
|
441
|
-
type: "zoomToScale",
|
|
442
|
-
sessionToken: this.sessionToken,
|
|
443
|
-
scale: scale,
|
|
444
|
-
});
|
|
445
|
-
};
|
|
446
|
-
zoomToCoordinates = (lat, lon, zoomLevel) => {
|
|
447
|
-
if (!isNaN(parseInt(zoomLevel))) {
|
|
448
|
-
this.com.sendMessageToMap({
|
|
449
|
-
type: "zoomToCoordinates",
|
|
450
|
-
sessionToken: this.sessionToken,
|
|
451
|
-
coordinates: [lat, lon],
|
|
452
|
-
zoomLevel: zoomLevel,
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
zoomToGeometry = (geom, limits) => {
|
|
458
|
-
this.com.sendMessageToMap({
|
|
459
|
-
type: "zoomToGeometry",
|
|
460
|
-
sessionToken: this.sessionToken,
|
|
461
|
-
geom,
|
|
462
|
-
limits,
|
|
463
|
-
});
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
infoFromCoordinates = (type, layer, hitTolerance, format) => {
|
|
467
|
-
const _layer = typeof layer == "undefined" ? null : layer;
|
|
468
|
-
const _hitTolerance =
|
|
469
|
-
typeof hitTolerance == "undefined" || !hitTolerance
|
|
470
|
-
? 5
|
|
471
|
-
: parseInt(hitTolerance);
|
|
472
|
-
const _format = typeof format == "undefined" ? "xml" : format.toLowerCase();
|
|
473
|
-
if (_format !== "xml" && _format !== "json") {
|
|
474
|
-
console.error("Format must be 'xml' or 'json");
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
if (isNaN(_hitTolerance)) {
|
|
478
|
-
console.error("hitTolerance must be a number");
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
this.com.sendMessageToMap({
|
|
482
|
-
type: "infoFromCoordinates",
|
|
483
|
-
info: type,
|
|
484
|
-
layer: _layer,
|
|
485
|
-
format: _format,
|
|
486
|
-
hitTolerance: _hitTolerance,
|
|
487
|
-
sessionToken: this.sessionToken,
|
|
488
|
-
});
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
getElementsFromLayer = (layer, limit, format) => {
|
|
492
|
-
const _format = typeof format == "undefined" ? "xml" : format.toLowerCase();
|
|
493
|
-
if (_format !== "xml" && _format !== "json") {
|
|
494
|
-
console.error("Format must be 'xml' or 'json");
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
if (isNaN(limit)) {
|
|
498
|
-
console.error("Limit must be a number");
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const _layer = typeof layer == "undefined" ? null : layer;
|
|
502
|
-
this.com.sendMessageToMap({
|
|
503
|
-
type: "getElementsFromLayer",
|
|
504
|
-
layer: _layer,
|
|
505
|
-
limit: typeof limit != "undefined" ? parseInt(limit) : 100,
|
|
506
|
-
format: format,
|
|
507
|
-
sessionToken: this.sessionToken,
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
Geolocalize = (toggle, options) => {
|
|
512
|
-
this.com.sendMessageToMap({
|
|
513
|
-
type: "Geolocalize",
|
|
514
|
-
toggle: toggle,
|
|
515
|
-
options: options,
|
|
516
|
-
sessionToken: this.sessionToken,
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
/* deprecated since v1.1.19 */
|
|
521
|
-
toggleGiswaterTiled = (toggle, tiled) => {
|
|
522
|
-
this.com.sendMessageToMap({
|
|
523
|
-
type: "toggleTiled",
|
|
524
|
-
toggle: toggle,
|
|
525
|
-
tiled: tiled,
|
|
526
|
-
sessionToken: this.sessionToken,
|
|
527
|
-
});
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
toggleTiled = (toggle, tiled) => {
|
|
531
|
-
this.com.sendMessageToMap({
|
|
532
|
-
type: "toggleTiled",
|
|
533
|
-
toggle: toggle,
|
|
534
|
-
tiled: tiled,
|
|
535
|
-
sessionToken: this.sessionToken,
|
|
536
|
-
});
|
|
537
|
-
};
|
|
538
|
-
|
|
539
|
-
getTiled = () => {
|
|
540
|
-
this.com.sendMessageToMap({
|
|
541
|
-
type: "getTiled",
|
|
542
|
-
sessionToken: this.sessionToken,
|
|
543
|
-
});
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
toggleSecondaryBackground = (toggle) => {
|
|
547
|
-
this.com.sendMessageToMap({
|
|
548
|
-
type: "toggleSecondaryBackground",
|
|
549
|
-
toggle: toggle,
|
|
550
|
-
});
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
getSecondaryBackground = () => {
|
|
554
|
-
this.com.sendMessageToMap({
|
|
555
|
-
type: "getSecondaryBackground",
|
|
556
|
-
sessionToken: this.sessionToken,
|
|
557
|
-
});
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
reloadDisplayedLayers = () => {
|
|
561
|
-
return this.com.sendMessageToMap({
|
|
562
|
-
type: "reloadDisplayedLayers",
|
|
563
|
-
sessionToken: this.sessionToken,
|
|
564
|
-
});
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
addGeoJSON = (geoJSON, options, name) => {
|
|
568
|
-
if (geoJSON) {
|
|
569
|
-
return this.com.sendMessageToMap({
|
|
570
|
-
type: "addGeoJSON",
|
|
571
|
-
geoJSON: geoJSON,
|
|
572
|
-
options:
|
|
573
|
-
typeof options != "undefined"
|
|
574
|
-
? options
|
|
575
|
-
: { fillcolor: null, strokecolor: null },
|
|
576
|
-
name: name ? name : Math.random().toString(36).substring(7),
|
|
577
|
-
sessionToken: this.sessionToken,
|
|
578
|
-
});
|
|
579
|
-
} else {
|
|
580
|
-
this.emit("error", { type: "error", error: "No geoJSON data" });
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
|
|
585
|
-
clearGeoJSON = (name) => {
|
|
586
|
-
if (!name) {
|
|
587
|
-
this.emit("error", { type: "error", error: "No geoJSON layer name" });
|
|
588
|
-
}
|
|
589
|
-
return this.com.sendMessageToMap({
|
|
590
|
-
type: "clearGeoJSON",
|
|
591
|
-
name: name,
|
|
592
|
-
sessionToken: this.sessionToken,
|
|
593
|
-
});
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
removeGeoJSONLayer = (name) => {
|
|
597
|
-
if (name) {
|
|
598
|
-
return this.com.sendMessageToMap({
|
|
599
|
-
type: "removeGeoJSONLayer",
|
|
600
|
-
name: name,
|
|
601
|
-
sessionToken: this.sessionToken,
|
|
602
|
-
});
|
|
603
|
-
} else {
|
|
604
|
-
this.emit("error", { type: "error", error: "No geoJSON data" });
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
setGiswaterFilters = (filters) => {
|
|
610
|
-
var filtersJson = filters;
|
|
611
|
-
if (filters) {
|
|
612
|
-
if (typeof filters != "object") {
|
|
613
|
-
filters = filters.trim();
|
|
614
|
-
filters = filters.replace(/^\s+|\s+$/g, "");
|
|
615
|
-
filters = filters.replace(/\\/g, "");
|
|
616
|
-
try {
|
|
617
|
-
filtersJson = JSON.parse(filters);
|
|
618
|
-
} catch (e) {
|
|
619
|
-
this.emit("error", {
|
|
620
|
-
type: "error",
|
|
621
|
-
error: "Filters is not a valid JSON",
|
|
622
|
-
});
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
return this.com.sendMessageToMap({
|
|
628
|
-
type: "setGiswaterFilters",
|
|
629
|
-
filters: filtersJson,
|
|
630
|
-
sessionToken: this.sessionToken,
|
|
631
|
-
});
|
|
632
|
-
} else {
|
|
633
|
-
this.emit("error", { type: "error", error: "No filters" });
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
setFilters = (filters) => {
|
|
639
|
-
var filtersJson = filters;
|
|
640
|
-
if (filters) {
|
|
641
|
-
if (typeof filters != "object") {
|
|
642
|
-
filters = filters.trim();
|
|
643
|
-
filters = filters.replace(/^\s+|\s+$/g, "");
|
|
644
|
-
filters = filters.replace(/\\/g, "");
|
|
645
|
-
try {
|
|
646
|
-
filtersJson = JSON.parse(filters);
|
|
647
|
-
} catch (e) {
|
|
648
|
-
this.emit("error", {
|
|
649
|
-
type: "error",
|
|
650
|
-
error: "Filters is not a valid JSON",
|
|
651
|
-
});
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
const isValid = filtersJson.every((item) => Array.isArray(item.filters));
|
|
656
|
-
|
|
657
|
-
// isValid will be true if all elements have "filters" property that is an array
|
|
658
|
-
if (!isValid) {
|
|
659
|
-
this.emit("error", {
|
|
660
|
-
type: "error",
|
|
661
|
-
error: "Filters is not a valid JSON - missing filters array",
|
|
662
|
-
});
|
|
663
|
-
return;
|
|
664
|
-
}
|
|
665
|
-
return this.com.sendMessageToMap({
|
|
666
|
-
type: "setFilters",
|
|
667
|
-
filters: filtersJson,
|
|
668
|
-
sessionToken: this.sessionToken,
|
|
669
|
-
});
|
|
670
|
-
} else {
|
|
671
|
-
this.emit("error", { type: "error", error: "No filters" });
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
getGiswaterLayerAvailableFilters = (layer_name) => {
|
|
677
|
-
if (layer_name) {
|
|
678
|
-
return this.com.sendMessageToMap({
|
|
679
|
-
type: "getGiswaterLayerAvailableFilters",
|
|
680
|
-
name: layer_name,
|
|
681
|
-
sessionToken: this.sessionToken,
|
|
682
|
-
});
|
|
683
|
-
} else {
|
|
684
|
-
this.emit("error", { type: "error", error: "No layer_name" });
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
CenterMap = (lat, lon) => {
|
|
690
|
-
this.com.sendMessageToMap({
|
|
691
|
-
type: "centerMap",
|
|
692
|
-
coordinates: [lat, lon],
|
|
693
|
-
});
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
getToc = () => {
|
|
697
|
-
return this.com.sendMessageToMap({
|
|
698
|
-
type: "getToc",
|
|
699
|
-
sessionToken: this.sessionToken,
|
|
700
|
-
});
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
setDebug = (what) => {
|
|
704
|
-
if (!isNaN(parseInt(what))) {
|
|
705
|
-
this.com.sendMessageToMap({
|
|
706
|
-
type: "setDebug",
|
|
707
|
-
what: what,
|
|
708
|
-
sessionToken: this.sessionToken,
|
|
709
|
-
});
|
|
710
|
-
} else {
|
|
711
|
-
console.error("Debug is not a integer");
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
|
|
715
|
-
setCustomColors = (properties) => {
|
|
716
|
-
//validate data
|
|
717
|
-
if (typeof properties !== "object") {
|
|
718
|
-
console.error("properties is not an object");
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
if (properties.hasOwnProperty("geom_stroke_width")) {
|
|
722
|
-
if (isNaN(parseInt(properties.geom_stroke_width))) {
|
|
723
|
-
console.error("geom_stroke_width is not an number");
|
|
724
|
-
return;
|
|
725
|
-
} else {
|
|
726
|
-
properties.geom_stroke_width = parseInt(properties.geom_stroke_width);
|
|
727
|
-
}
|
|
728
|
-
} else {
|
|
729
|
-
properties.geom_stroke_width = 1;
|
|
730
|
-
}
|
|
731
|
-
if (properties.hasOwnProperty("geom_radius")) {
|
|
732
|
-
if (isNaN(parseInt(properties.geom_radius))) {
|
|
733
|
-
console.error("geom_stroke_width is not an number");
|
|
734
|
-
return;
|
|
735
|
-
} else {
|
|
736
|
-
properties.geom_radius = parseInt(properties.geom_radius);
|
|
737
|
-
}
|
|
738
|
-
} else {
|
|
739
|
-
properties.geom_radius = 4;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
if (properties.hasOwnProperty("geom_shape")) {
|
|
743
|
-
if (
|
|
744
|
-
properties.geom_shape !== "circle" &&
|
|
745
|
-
properties.geom_shape !== "square"
|
|
746
|
-
) {
|
|
747
|
-
properties.geom_shape = "circle";
|
|
748
|
-
console.error("geom_shape must be either 'circle' or 'square'");
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
this.com.sendMessageToMap({
|
|
752
|
-
type: "setCustomColors",
|
|
753
|
-
properties: properties,
|
|
754
|
-
sessionToken: this.sessionToken,
|
|
755
|
-
});
|
|
756
|
-
};
|
|
757
|
-
|
|
758
|
-
changeBackground = (newBackground) => {
|
|
759
|
-
return this.com.sendMessageToMap({
|
|
760
|
-
type: "changeBackground",
|
|
761
|
-
sessionToken: this.sessionToken,
|
|
762
|
-
newBackground: newBackground,
|
|
763
|
-
});
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
getBackground = () => {
|
|
767
|
-
this.com.sendMessageToMap({
|
|
768
|
-
type: "getBackground",
|
|
769
|
-
sessionToken: this.sessionToken,
|
|
770
|
-
});
|
|
771
|
-
};
|
|
772
|
-
|
|
773
|
-
initMeasure = (measure, textStart, textContinue) => {
|
|
774
|
-
return this.com.sendMessageToMap({
|
|
775
|
-
type: "initMeasure",
|
|
776
|
-
sessionToken: this.sessionToken,
|
|
777
|
-
measure,
|
|
778
|
-
textStart,
|
|
779
|
-
textContinue,
|
|
780
|
-
});
|
|
781
|
-
};
|
|
782
|
-
cancelMeasure = () => {
|
|
783
|
-
return this.com.sendMessageToMap({
|
|
784
|
-
type: "cancelMeasure",
|
|
785
|
-
sessionToken: this.sessionToken,
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
setBboxSize = (bbox) => {
|
|
790
|
-
if (!isNaN(parseInt(bbox))) {
|
|
791
|
-
this.com.sendMessageToMap({
|
|
792
|
-
type: "setBoundingBoxSize",
|
|
793
|
-
bbox: bbox,
|
|
794
|
-
sessionToken: this.sessionToken,
|
|
795
|
-
});
|
|
796
|
-
} else {
|
|
797
|
-
console.error("bbox is not a integer");
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
addIcon = ({ icon, coordinates }) => {
|
|
801
|
-
// Validate icon
|
|
802
|
-
if (!(icon instanceof ArrayBuffer)) {
|
|
803
|
-
this.emit("error", {
|
|
804
|
-
type: "error",
|
|
805
|
-
error: "Invalid icon: Expected an ArrayBuffer.",
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
// Validate coordinates
|
|
810
|
-
if (!Array.isArray(coordinates)) {
|
|
811
|
-
this.emit("error", {
|
|
812
|
-
type: "error",
|
|
813
|
-
error: "Invalid coordinates: Expected an array [longitude, latitude].",
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
// Ensure coordinates contain exactly two numeric values
|
|
818
|
-
if (
|
|
819
|
-
coordinates.length !== 2 ||
|
|
820
|
-
typeof coordinates[0] !== "number" ||
|
|
821
|
-
typeof coordinates[1] !== "number"
|
|
822
|
-
) {
|
|
823
|
-
this.emit("error", {
|
|
824
|
-
type: "error",
|
|
825
|
-
error:
|
|
826
|
-
"Invalid coordinates: Expected an array with two numeric values [longitude, latitude].",
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// Send the message to the map
|
|
831
|
-
this.com.sendMessageToMap({
|
|
832
|
-
type: "AddIcon",
|
|
833
|
-
icon,
|
|
834
|
-
coordinates,
|
|
835
|
-
sessionToken: this.sessionToken,
|
|
836
|
-
});
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
screenshot = (options) => {
|
|
840
|
-
this.com.sendMessageToMap({
|
|
841
|
-
type: "screenshot",
|
|
842
|
-
options,
|
|
843
|
-
sessionToken: this.sessionToken,
|
|
844
|
-
});
|
|
845
|
-
};
|
|
846
|
-
|
|
847
|
-
//***** PRINT ******/
|
|
848
|
-
printPaperSize = (paperSize) => {
|
|
849
|
-
this.com.sendMessageToMap({
|
|
850
|
-
type: "printSetPaperSize",
|
|
851
|
-
paperSize: paperSize,
|
|
852
|
-
sessionToken: this.sessionToken,
|
|
853
|
-
});
|
|
854
|
-
};
|
|
855
|
-
printPaperLayout = (paperLayout) => {
|
|
856
|
-
this.com.sendMessageToMap({
|
|
857
|
-
type: "printSetOrientation",
|
|
858
|
-
paperLayout: paperLayout,
|
|
859
|
-
sessionToken: this.sessionToken,
|
|
860
|
-
});
|
|
861
|
-
};
|
|
862
|
-
|
|
863
|
-
startPrint = (options) => {
|
|
864
|
-
this.com.sendMessageToMap({
|
|
865
|
-
type: "printStart",
|
|
866
|
-
options,
|
|
867
|
-
sessionToken: this.sessionToken,
|
|
868
|
-
});
|
|
869
|
-
};
|
|
870
|
-
cancelPrint = (options) => {
|
|
871
|
-
this.com.sendMessageToMap({
|
|
872
|
-
type: "printCancel",
|
|
873
|
-
options,
|
|
874
|
-
sessionToken: this.sessionToken,
|
|
875
|
-
});
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
export { Communicator };
|