@vidro/map-handler 1.0.18 → 1.1.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/README.md +51 -5
- package/dist/map-handler.js +1 -1
- package/examples/full/cachedToken.dat +1 -1
- package/examples/full/index.php +238 -168
- package/examples/full/tester.js +161 -17
- package/package.json +1 -1
- package/src/index.js +309 -186
package/src/index.js
CHANGED
@@ -1,150 +1,217 @@
|
|
1
|
-
import { EventEmitter } from "events"
|
1
|
+
import { EventEmitter } from "events";
|
2
2
|
import { iframeCommunicator } from "./shared/iframe-communicator";
|
3
3
|
class Communicator extends EventEmitter {
|
4
|
-
|
5
|
-
constructor(data){
|
4
|
+
constructor(data) {
|
6
5
|
super();
|
7
|
-
this.domId =
|
8
|
-
if(typeof window ===
|
6
|
+
this.domId = "map-frame";
|
7
|
+
if (typeof window === "undefined") {
|
9
8
|
return;
|
10
|
-
}
|
11
|
-
if(typeof data.id==="string"){
|
9
|
+
}
|
10
|
+
if (typeof data.id === "string") {
|
12
11
|
this.domId = data.id;
|
13
|
-
}
|
14
|
-
this.com = new iframeCommunicator(data)
|
15
|
-
window.addEventListener("message", e => this.onMessageReceived(e));
|
12
|
+
}
|
13
|
+
this.com = new iframeCommunicator(data);
|
14
|
+
window.addEventListener("message", (e) => this.onMessageReceived(e));
|
16
15
|
this.sessionToken = data.sessionToken;
|
17
16
|
this.setMaxListeners(100);
|
18
17
|
}
|
19
18
|
|
20
|
-
onMessageReceived = e => {
|
21
|
-
switch(e.data.type){
|
22
|
-
case "onZoomChange":
|
23
|
-
|
24
|
-
|
25
|
-
case "
|
26
|
-
|
27
|
-
|
28
|
-
case "
|
29
|
-
|
30
|
-
|
31
|
-
case "
|
32
|
-
|
33
|
-
|
34
|
-
case "
|
35
|
-
|
36
|
-
|
37
|
-
case "
|
38
|
-
|
39
|
-
|
40
|
-
case "
|
41
|
-
|
42
|
-
|
19
|
+
onMessageReceived = (e) => {
|
20
|
+
switch (e.data.type) {
|
21
|
+
case "onZoomChange":
|
22
|
+
this.emitEvent("onZoomChange", e.data, e.data.domId);
|
23
|
+
break;
|
24
|
+
case "onCenterChange":
|
25
|
+
this.emitEvent("onCenterChange", e.data, e.data.domId);
|
26
|
+
break;
|
27
|
+
case "geomAdded":
|
28
|
+
this.emitEvent("geomAdded", e.data, e.data.domId);
|
29
|
+
break;
|
30
|
+
case "layers":
|
31
|
+
this.emitEvent("layers", e.data, e.data.domId);
|
32
|
+
break;
|
33
|
+
case "geoJSONlayers":
|
34
|
+
this.emitEvent("geoJSONlayers", e.data, e.data.domId);
|
35
|
+
break;
|
36
|
+
case "info":
|
37
|
+
this.emitEvent("info", e.data, e.data.domId);
|
38
|
+
break;
|
39
|
+
case "error":
|
40
|
+
this.emitEvent("error", e.data, e.data.domId);
|
41
|
+
break;
|
42
|
+
case "coordinates":
|
43
|
+
this.emitEvent("coordinates", e.data, e.data.domId);
|
44
|
+
break;
|
45
|
+
case "activeLayer":
|
46
|
+
this.emitEvent("activeLayer", e.data, e.data.domId);
|
47
|
+
break;
|
48
|
+
case "geolocation":
|
49
|
+
this.emitEvent("geolocation", e.data, e.data.domId);
|
50
|
+
break;
|
51
|
+
case "WMSInfoAvailable":
|
52
|
+
this.emitEvent("WMSInfoAvailable", e.data, e.data.domId);
|
53
|
+
break;
|
54
|
+
case "giswaterTiledBackgroundDisplayed":
|
55
|
+
this.emitEvent(
|
56
|
+
"giswaterTiledBackgroundDisplayed",
|
57
|
+
e.data,
|
58
|
+
e.data.domId
|
59
|
+
);
|
60
|
+
break;
|
61
|
+
case "giswaterTiledBackgroundAvailable":
|
62
|
+
this.emitEvent(
|
63
|
+
"giswaterTiledBackgroundAvailable",
|
64
|
+
e.data,
|
65
|
+
e.data.domId
|
66
|
+
);
|
67
|
+
break;
|
68
|
+
case "GiswaterLayerAvailableFilters":
|
69
|
+
this.emitEvent("GiswaterLayerAvailableFilters", e.data, e.data.domId);
|
70
|
+
break;
|
71
|
+
case "loaded":
|
72
|
+
this.emitEvent("loaded", e.data, e.data.domId);
|
73
|
+
break;
|
74
|
+
case "availableWMSLayers":
|
75
|
+
this.emitEvent("availableWMSLayers", e.data, e.data.domId);
|
76
|
+
break;
|
77
|
+
case "layerElements":
|
78
|
+
this.emitEvent("layerElements", e.data, e.data.domId);
|
79
|
+
break;
|
80
|
+
case "getToc":
|
81
|
+
this.emitEvent("getToc", e.data, e.data.domId);
|
82
|
+
break;
|
83
|
+
case "capabilities":
|
84
|
+
this.emitEvent("capabilities", e.data, e.data.domId);
|
85
|
+
break;
|
86
|
+
case "GiswaterFiltersApplied":
|
87
|
+
this.emitEvent("GiswaterFiltersApplied", e.data, e.data.domId);
|
88
|
+
break;
|
89
|
+
case "MeasureEnd":
|
90
|
+
this.emitEvent("MeasureEnd", e.data, e.data.domId);
|
91
|
+
break;
|
43
92
|
}
|
44
|
-
|
45
|
-
}
|
93
|
+
};
|
46
94
|
|
47
|
-
emitEvent = (type,data,domId)=>{
|
48
|
-
if(domId===this.domId){
|
95
|
+
emitEvent = (type, data, domId) => {
|
96
|
+
if (domId === this.domId) {
|
49
97
|
delete data.domId;
|
50
|
-
this.emit(type, data);
|
98
|
+
this.emit(type, data);
|
51
99
|
}
|
52
|
-
}
|
100
|
+
};
|
53
101
|
|
54
102
|
ZoomIn = () => {
|
55
103
|
this.com.sendMessageToMap({
|
56
104
|
type: "zoomIn",
|
57
105
|
sessionToken: this.sessionToken,
|
58
|
-
});
|
106
|
+
});
|
107
|
+
};
|
59
108
|
|
60
|
-
}
|
61
|
-
|
62
109
|
ZoomOut = () => {
|
63
110
|
this.com.sendMessageToMap({
|
64
111
|
type: "zoomOut",
|
65
112
|
sessionToken: this.sessionToken,
|
66
|
-
});
|
67
|
-
}
|
113
|
+
});
|
114
|
+
};
|
68
115
|
|
69
116
|
AddGeom = (geomtype) => {
|
70
117
|
this.com.sendMessageToMap({
|
71
118
|
type: "AddGeom",
|
72
119
|
geom: geomtype,
|
73
120
|
sessionToken: this.sessionToken,
|
74
|
-
});
|
75
|
-
}
|
121
|
+
});
|
122
|
+
};
|
76
123
|
|
77
|
-
toggleLayer = (layer,properties) => {
|
78
|
-
if(typeof properties===
|
124
|
+
toggleLayer = (layer, properties) => {
|
125
|
+
if (typeof properties === "undefined") {
|
79
126
|
properties = {
|
80
127
|
gutter: null,
|
81
128
|
transparent: null,
|
82
|
-
singletile: null
|
129
|
+
singletile: null,
|
130
|
+
layerType: null,
|
83
131
|
};
|
84
132
|
}
|
85
133
|
|
86
|
-
if(properties.
|
87
|
-
if(
|
134
|
+
if (properties.layerType !== null) {
|
135
|
+
if (
|
136
|
+
properties.layerType.toLowerCase() !== "wms" &&
|
137
|
+
properties.layerType.toLowerCase() !== "vector"
|
138
|
+
) {
|
139
|
+
this.emit("error", { error: "layerType must be 'wms' or 'vector'" });
|
140
|
+
return;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
if (
|
145
|
+
properties.singletile !== null &&
|
146
|
+
properties.layerType.toLowerCase() !== "vector"
|
147
|
+
) {
|
148
|
+
if (typeof properties.singletile !== "boolean") {
|
88
149
|
properties.singletile = null;
|
89
|
-
this.emit("error",{error:"singleTile must be a Boolean"});
|
150
|
+
this.emit("error", { error: "singleTile must be a Boolean" });
|
90
151
|
}
|
91
|
-
}
|
92
|
-
if(properties.gutter!==
|
93
|
-
if(isNaN(parseInt(properties.gutter))){
|
152
|
+
}
|
153
|
+
if (properties.gutter !== "" && properties.gutter !== null) {
|
154
|
+
if (isNaN(parseInt(properties.gutter))) {
|
94
155
|
properties.gutter = null;
|
95
|
-
this.emit("error",{error:"Gutter must be a number"});
|
156
|
+
this.emit("error", { error: "Gutter must be a number" });
|
96
157
|
}
|
97
|
-
if(properties.singletile){
|
158
|
+
if (properties.singletile) {
|
98
159
|
properties.gutter = null;
|
99
|
-
this.emit("error",{
|
160
|
+
this.emit("error", {
|
161
|
+
error:
|
162
|
+
"Gutter can only be user with multitile layers; set singletile to false",
|
163
|
+
});
|
100
164
|
}
|
101
|
-
}
|
165
|
+
}
|
102
166
|
|
103
|
-
if(properties.transparent!==null){
|
104
|
-
|
167
|
+
if (properties.transparent !== null) {
|
168
|
+
if (typeof properties.transparent !== "boolean") {
|
105
169
|
properties.transparent = null;
|
106
|
-
this.emit("error",{error:"transparent must be a Boolean"});
|
170
|
+
this.emit("error", { error: "transparent must be a Boolean" });
|
107
171
|
}
|
108
|
-
}
|
109
|
-
|
172
|
+
}
|
173
|
+
|
110
174
|
this.com.sendMessageToMap({
|
111
175
|
type: "toggleLayer",
|
112
176
|
layer: layer,
|
113
|
-
gutter: !isNaN(parseInt(properties.gutter))
|
177
|
+
gutter: !isNaN(parseInt(properties.gutter))
|
178
|
+
? parseInt(properties.gutter)
|
179
|
+
: null,
|
114
180
|
transparent: properties.transparent,
|
115
181
|
singletile: properties.singletile,
|
182
|
+
layerType: properties.layerType.toLowerCase(),
|
116
183
|
sessionToken: this.sessionToken,
|
117
|
-
});
|
118
|
-
}
|
184
|
+
});
|
185
|
+
};
|
119
186
|
|
120
187
|
setActiveLayer = (layer) => {
|
121
188
|
this.com.sendMessageToMap({
|
122
189
|
type: "setActiveLayer",
|
123
190
|
layer: layer,
|
124
191
|
sessionToken: this.sessionToken,
|
125
|
-
});
|
126
|
-
}
|
192
|
+
});
|
193
|
+
};
|
127
194
|
|
128
195
|
getActiveLayer = () => {
|
129
196
|
this.com.sendMessageToMap({
|
130
197
|
type: "getActiveLayer",
|
131
198
|
sessionToken: this.sessionToken,
|
132
|
-
});
|
133
|
-
}
|
199
|
+
});
|
200
|
+
};
|
134
201
|
|
135
202
|
loadWMSAvailableLayers = () => {
|
136
203
|
this.com.sendMessageToMap({
|
137
204
|
type: "loadWMSAvailableLayers",
|
138
205
|
sessionToken: this.sessionToken,
|
139
|
-
});
|
140
|
-
}
|
206
|
+
});
|
207
|
+
};
|
141
208
|
|
142
209
|
clear = () => {
|
143
210
|
this.com.sendMessageToMap({
|
144
211
|
type: "clear",
|
145
212
|
sessionToken: this.sessionToken,
|
146
|
-
});
|
147
|
-
}
|
213
|
+
});
|
214
|
+
};
|
148
215
|
|
149
216
|
Highlight = (options) => {
|
150
217
|
this.com.sendMessageToMap({
|
@@ -152,36 +219,39 @@ class Communicator extends EventEmitter {
|
|
152
219
|
geom: options.geom,
|
153
220
|
zoom: options.zoom,
|
154
221
|
sessionToken: this.sessionToken,
|
155
|
-
});
|
156
|
-
}
|
222
|
+
});
|
223
|
+
};
|
157
224
|
|
158
225
|
zoomToExtent = () => {
|
159
226
|
this.com.sendMessageToMap({
|
160
227
|
type: "zoomToExtent",
|
161
228
|
sessionToken: this.sessionToken,
|
162
|
-
});
|
163
|
-
}
|
229
|
+
});
|
230
|
+
};
|
164
231
|
|
165
|
-
zoomToCoordinates= (lat,lon,zoomLevel) => {
|
166
|
-
if(!isNaN(parseInt(zoomLevel))){
|
232
|
+
zoomToCoordinates = (lat, lon, zoomLevel) => {
|
233
|
+
if (!isNaN(parseInt(zoomLevel))) {
|
167
234
|
this.com.sendMessageToMap({
|
168
235
|
type: "zoomToCoordinates",
|
169
236
|
sessionToken: this.sessionToken,
|
170
|
-
coordinates:[lat,lon],
|
171
|
-
zoomLevel: zoomLevel
|
172
|
-
});
|
237
|
+
coordinates: [lat, lon],
|
238
|
+
zoomLevel: zoomLevel,
|
239
|
+
});
|
173
240
|
}
|
174
|
-
}
|
175
|
-
|
176
|
-
infoFromCoordinates = (type,layer,hitTolerance,format) => {
|
177
|
-
const _layer =
|
178
|
-
const _hitTolerance =
|
179
|
-
|
180
|
-
|
241
|
+
};
|
242
|
+
|
243
|
+
infoFromCoordinates = (type, layer, hitTolerance, format) => {
|
244
|
+
const _layer = typeof layer == "undefined" ? null : layer;
|
245
|
+
const _hitTolerance =
|
246
|
+
typeof hitTolerance == "undefined" || !hitTolerance
|
247
|
+
? 5
|
248
|
+
: parseInt(hitTolerance);
|
249
|
+
const _format = typeof format == "undefined" ? "xml" : format.toLowerCase();
|
250
|
+
if (_format !== "xml" && _format !== "json") {
|
181
251
|
console.error("Format must be 'xml' or 'json");
|
182
252
|
return;
|
183
253
|
}
|
184
|
-
if(isNaN(_hitTolerance)){
|
254
|
+
if (isNaN(_hitTolerance)) {
|
185
255
|
console.error("hitTolerance must be a number");
|
186
256
|
return;
|
187
257
|
}
|
@@ -192,209 +262,262 @@ class Communicator extends EventEmitter {
|
|
192
262
|
format: _format,
|
193
263
|
hitTolerance: _hitTolerance,
|
194
264
|
sessionToken: this.sessionToken,
|
195
|
-
});
|
196
|
-
}
|
265
|
+
});
|
266
|
+
};
|
197
267
|
|
198
|
-
getElementsFromLayer= (layer,limit,format) => {
|
199
|
-
const _format =
|
200
|
-
if(_format!=="xml" && _format!==
|
268
|
+
getElementsFromLayer = (layer, limit, format) => {
|
269
|
+
const _format = typeof format == "undefined" ? "xml" : format.toLowerCase();
|
270
|
+
if (_format !== "xml" && _format !== "json") {
|
201
271
|
console.error("Format must be 'xml' or 'json");
|
202
272
|
return;
|
203
273
|
}
|
204
|
-
if(isNaN(limit)){
|
205
|
-
|
274
|
+
if (isNaN(limit)) {
|
275
|
+
console.error("Limit must be a number");
|
206
276
|
return;
|
207
277
|
}
|
208
|
-
const _layer =
|
278
|
+
const _layer = typeof layer == "undefined" ? null : layer;
|
209
279
|
this.com.sendMessageToMap({
|
210
280
|
type: "getElementsFromLayer",
|
211
281
|
layer: _layer,
|
212
|
-
limit:
|
282
|
+
limit: typeof limit != "undefined" ? parseInt(limit) : 100,
|
213
283
|
format: format,
|
214
284
|
sessionToken: this.sessionToken,
|
215
|
-
});
|
216
|
-
}
|
285
|
+
});
|
286
|
+
};
|
217
287
|
|
218
288
|
Geolocalize = (toggle) => {
|
219
289
|
this.com.sendMessageToMap({
|
220
290
|
type: "Geolocalize",
|
221
291
|
toggle: toggle,
|
222
292
|
sessionToken: this.sessionToken,
|
223
|
-
});
|
224
|
-
}
|
293
|
+
});
|
294
|
+
};
|
225
295
|
|
226
|
-
toggleGiswaterTiled = (toggle,tiled) => {
|
296
|
+
toggleGiswaterTiled = (toggle, tiled) => {
|
227
297
|
this.com.sendMessageToMap({
|
228
298
|
type: "toggleGiswaterTiled",
|
229
299
|
toggle: toggle,
|
230
300
|
tiled: tiled,
|
231
301
|
sessionToken: this.sessionToken,
|
232
|
-
});
|
233
|
-
}
|
302
|
+
});
|
303
|
+
};
|
234
304
|
|
235
|
-
reloadDisplayedLayers = ()=>{
|
305
|
+
reloadDisplayedLayers = () => {
|
236
306
|
return this.com.sendMessageToMap({
|
237
307
|
type: "reloadDisplayedLayers",
|
238
308
|
sessionToken: this.sessionToken,
|
239
|
-
});
|
240
|
-
}
|
309
|
+
});
|
310
|
+
};
|
241
311
|
|
242
|
-
addGeoJSON = (geoJSON,options, name)=>{
|
243
|
-
if(geoJSON){
|
312
|
+
addGeoJSON = (geoJSON, options, name) => {
|
313
|
+
if (geoJSON) {
|
244
314
|
return this.com.sendMessageToMap({
|
245
315
|
type: "addGeoJSON",
|
246
316
|
geoJSON: geoJSON,
|
247
|
-
options:
|
248
|
-
|
317
|
+
options:
|
318
|
+
typeof options != "undefined"
|
319
|
+
? options
|
320
|
+
: { fillcolor: null, strokecolor: null },
|
321
|
+
name: name ? name : Math.random().toString(36).substring(7),
|
249
322
|
sessionToken: this.sessionToken,
|
250
|
-
});
|
251
|
-
}else{
|
252
|
-
this.emit("error",{error:"No geoJSON data"});
|
323
|
+
});
|
324
|
+
} else {
|
325
|
+
this.emit("error", { error: "No geoJSON data" });
|
253
326
|
return;
|
254
327
|
}
|
255
|
-
}
|
328
|
+
};
|
256
329
|
|
257
|
-
|
330
|
+
clearGeoJSON = () => {
|
258
331
|
return this.com.sendMessageToMap({
|
259
332
|
type: "clearGeoJSON",
|
260
333
|
sessionToken: this.sessionToken,
|
261
|
-
});
|
262
|
-
}
|
334
|
+
});
|
335
|
+
};
|
263
336
|
|
264
|
-
|
265
|
-
if(name){
|
337
|
+
removeGeoJSONLayer = (name) => {
|
338
|
+
if (name) {
|
266
339
|
return this.com.sendMessageToMap({
|
267
340
|
type: "removeGeoJSONLayer",
|
268
341
|
name: name,
|
269
342
|
sessionToken: this.sessionToken,
|
270
|
-
});
|
271
|
-
}else{
|
272
|
-
this.emit("error",{error:"No geoJSON data"});
|
343
|
+
});
|
344
|
+
} else {
|
345
|
+
this.emit("error", { error: "No geoJSON data" });
|
273
346
|
return;
|
274
347
|
}
|
275
|
-
}
|
276
|
-
|
277
|
-
setGiswaterFilters = (filters)=>{
|
348
|
+
};
|
349
|
+
|
350
|
+
setGiswaterFilters = (filters) => {
|
278
351
|
var filtersJson = filters;
|
279
|
-
if(filters){
|
280
|
-
if(typeof filters!="object"){
|
281
|
-
filters = filters.trim()
|
282
|
-
filters = filters.replace(/^\s+|\s+$/g,
|
283
|
-
filters = filters.replace(/\\/g,
|
284
|
-
try{
|
285
|
-
filtersJson = JSON.parse(filters);
|
286
|
-
}catch(e){
|
287
|
-
this.emit("error",{error:"Filters is not a valid JSON"});
|
352
|
+
if (filters) {
|
353
|
+
if (typeof filters != "object") {
|
354
|
+
filters = filters.trim();
|
355
|
+
filters = filters.replace(/^\s+|\s+$/g, "");
|
356
|
+
filters = filters.replace(/\\/g, "");
|
357
|
+
try {
|
358
|
+
filtersJson = JSON.parse(filters);
|
359
|
+
} catch (e) {
|
360
|
+
this.emit("error", { error: "Filters is not a valid JSON" });
|
288
361
|
return;
|
289
362
|
}
|
290
363
|
}
|
291
|
-
|
364
|
+
|
292
365
|
return this.com.sendMessageToMap({
|
293
366
|
type: "setGiswaterFilters",
|
294
367
|
filters: filtersJson,
|
295
368
|
sessionToken: this.sessionToken,
|
296
|
-
});
|
297
|
-
}else{
|
298
|
-
this.emit("error",{error:"No filters"});
|
369
|
+
});
|
370
|
+
} else {
|
371
|
+
this.emit("error", { error: "No filters" });
|
299
372
|
return;
|
300
373
|
}
|
301
|
-
}
|
374
|
+
};
|
302
375
|
|
303
|
-
getGiswaterLayerAvailableFilters = (layer_name)=>{
|
304
|
-
if(layer_name){
|
305
|
-
|
376
|
+
getGiswaterLayerAvailableFilters = (layer_name) => {
|
377
|
+
if (layer_name) {
|
378
|
+
return this.com.sendMessageToMap({
|
306
379
|
type: "getGiswaterLayerAvailableFilters",
|
307
380
|
name: layer_name,
|
308
381
|
sessionToken: this.sessionToken,
|
309
|
-
});
|
310
|
-
}else{
|
311
|
-
this.emit("error",{error:"No layer_name"});
|
382
|
+
});
|
383
|
+
} else {
|
384
|
+
this.emit("error", { error: "No layer_name" });
|
312
385
|
return;
|
313
386
|
}
|
314
|
-
}
|
387
|
+
};
|
315
388
|
|
316
|
-
getToc = ()=>{
|
389
|
+
getToc = () => {
|
317
390
|
return this.com.sendMessageToMap({
|
318
391
|
type: "getToc",
|
319
392
|
sessionToken: this.sessionToken,
|
320
|
-
});
|
321
|
-
}
|
393
|
+
});
|
394
|
+
};
|
322
395
|
|
323
|
-
setDebug = (what) =>{
|
324
|
-
if(!isNaN(parseInt(what))){
|
396
|
+
setDebug = (what) => {
|
397
|
+
if (!isNaN(parseInt(what))) {
|
325
398
|
this.com.sendMessageToMap({
|
326
399
|
type: "setDebug",
|
327
400
|
what: what,
|
328
401
|
sessionToken: this.sessionToken,
|
329
402
|
});
|
330
|
-
}else{
|
403
|
+
} else {
|
331
404
|
console.error("Debug is not a integer");
|
332
405
|
}
|
333
|
-
}
|
406
|
+
};
|
334
407
|
|
335
|
-
setCustomColors = (properties)=>{
|
408
|
+
setCustomColors = (properties) => {
|
336
409
|
//validate data
|
337
|
-
if(typeof properties!==
|
410
|
+
if (typeof properties !== "object") {
|
338
411
|
console.error("properties is not an object");
|
339
412
|
return;
|
340
413
|
}
|
341
|
-
if(properties.hasOwnProperty(
|
342
|
-
if(isNaN(parseInt(properties.geom_stroke_width))){
|
414
|
+
if (properties.hasOwnProperty("geom_stroke_width")) {
|
415
|
+
if (isNaN(parseInt(properties.geom_stroke_width))) {
|
343
416
|
console.error("geom_stroke_width is not an number");
|
344
417
|
return;
|
345
|
-
}else{
|
418
|
+
} else {
|
346
419
|
properties.geom_stroke_width = parseInt(properties.geom_stroke_width);
|
347
420
|
}
|
348
|
-
}else{
|
421
|
+
} else {
|
349
422
|
properties.geom_stroke_width = 1;
|
350
423
|
}
|
351
|
-
if(properties.hasOwnProperty(
|
352
|
-
if(isNaN(parseInt(properties.geom_radius))){
|
424
|
+
if (properties.hasOwnProperty("geom_radius")) {
|
425
|
+
if (isNaN(parseInt(properties.geom_radius))) {
|
353
426
|
console.error("geom_stroke_width is not an number");
|
354
427
|
return;
|
355
|
-
}else{
|
428
|
+
} else {
|
356
429
|
properties.geom_radius = parseInt(properties.geom_radius);
|
357
430
|
}
|
358
|
-
}else{
|
431
|
+
} else {
|
359
432
|
properties.geom_radius = 4;
|
360
433
|
}
|
361
434
|
|
362
|
-
if(properties.hasOwnProperty(
|
363
|
-
if(
|
364
|
-
properties.geom_shape
|
435
|
+
if (properties.hasOwnProperty("geom_shape")) {
|
436
|
+
if (
|
437
|
+
properties.geom_shape !== "circle" &&
|
438
|
+
properties.geom_shape !== "square"
|
439
|
+
) {
|
440
|
+
properties.geom_shape = "circle";
|
365
441
|
console.error("geom_shape must be either 'circle' or 'square'");
|
366
442
|
}
|
367
443
|
}
|
368
444
|
this.com.sendMessageToMap({
|
369
|
-
|
370
|
-
|
371
|
-
|
445
|
+
type: "setCustomColors",
|
446
|
+
properties: properties,
|
447
|
+
sessionToken: this.sessionToken,
|
372
448
|
});
|
373
|
-
}
|
449
|
+
};
|
374
450
|
|
375
|
-
changeBackground = (newBackground)=>{
|
451
|
+
changeBackground = (newBackground) => {
|
376
452
|
return this.com.sendMessageToMap({
|
377
453
|
type: "changeBackground",
|
378
454
|
sessionToken: this.sessionToken,
|
379
|
-
newBackground: newBackground
|
380
|
-
});
|
381
|
-
}
|
455
|
+
newBackground: newBackground,
|
456
|
+
});
|
457
|
+
};
|
382
458
|
|
383
|
-
|
459
|
+
centerMap = (coordinates) => {
|
384
460
|
//validate data
|
385
|
-
if(typeof coordinates!==
|
461
|
+
if (typeof coordinates !== "object") {
|
386
462
|
console.error("properties is not an object");
|
387
463
|
return;
|
388
464
|
}
|
389
465
|
return this.com.sendMessageToMap({
|
390
466
|
type: "centerMap",
|
391
467
|
sessionToken: this.sessionToken,
|
392
|
-
coordinates
|
393
|
-
});
|
468
|
+
coordinates: coordinates,
|
469
|
+
});
|
470
|
+
};
|
471
|
+
|
472
|
+
drawGeometryInLayer = (uuid, layerName, geom_astext, label, style) => {
|
473
|
+
return this.com.sendMessageToMap({
|
474
|
+
type: "drawGeometryInLayer",
|
475
|
+
sessionToken: this.sessionToken,
|
476
|
+
uuid,
|
477
|
+
layerName,
|
478
|
+
geom_astext,
|
479
|
+
label,
|
480
|
+
style,
|
481
|
+
});
|
482
|
+
};
|
483
|
+
|
484
|
+
removeGeometryFromLayer = (uuid, layerName) => {
|
485
|
+
return this.com.sendMessageToMap({
|
486
|
+
type: "removeGeometryFromLayer",
|
487
|
+
sessionToken: this.sessionToken,
|
488
|
+
uuid,
|
489
|
+
layerName,
|
490
|
+
});
|
491
|
+
};
|
492
|
+
|
493
|
+
initMeasure = (type,textStart,textContinue)=>{
|
494
|
+
if(type!=='line' && type!=='area'){
|
495
|
+
console.error( );
|
496
|
+
return;
|
497
|
+
}
|
498
|
+
let text = null;
|
499
|
+
if(textStart && textContinue){
|
500
|
+
|
501
|
+
text = {
|
502
|
+
textStart: textStart,
|
503
|
+
textContinue: textContinue,
|
504
|
+
}
|
505
|
+
}
|
506
|
+
|
507
|
+
return this.com.sendMessageToMap({
|
508
|
+
type: "initMeasure",
|
509
|
+
sessionToken: this.sessionToken,
|
510
|
+
measure: type,
|
511
|
+
text: text ? text: null,
|
512
|
+
});
|
394
513
|
}
|
395
514
|
|
515
|
+
cancelMeasure= ()=>{
|
516
|
+
return this.com.sendMessageToMap({
|
517
|
+
type: "cancelMeasure",
|
518
|
+
sessionToken: this.sessionToken,
|
519
|
+
});
|
520
|
+
}
|
396
521
|
}
|
397
522
|
|
398
|
-
export {
|
399
|
-
Communicator,
|
400
|
-
}
|
523
|
+
export { Communicator };
|