@vidro/map-handler 1.0.4 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. package/README.md +326 -118
  2. package/dist/map-handler.js +1 -1
  3. package/doc/giswater.png +0 -0
  4. package/doc/giswaterInfo.png +0 -0
  5. package/doc/giswaterInfoApi.png +0 -0
  6. package/doc/giswatergeojson.png +0 -0
  7. package/doc/multiTile.png +0 -0
  8. package/doc/multiTileNoGutter.png +0 -0
  9. package/doc/togglelayergiswater.png +0 -0
  10. package/doc/vidromaps-basic.png +0 -0
  11. package/examples/externalwms/index.js +20 -0
  12. package/examples/externalwms/index.php +88 -0
  13. package/examples/full/apidemo.js +54 -11
  14. package/examples/full/cachedToken.dat +1 -1
  15. package/examples/full/cachedTokenData.dat +1 -1
  16. package/examples/full/index.php +37 -18
  17. package/examples/full/tester.js +177 -13
  18. package/examples/integration/tool/css/dist/home.css.min.css +0 -0
  19. package/examples/integration/tool/css/dist/home.min.css +1 -0
  20. package/examples/integration/tool/css/dist/home.min.css.map +10 -0
  21. package/examples/integration/tool/css/dist/style-login.css.min.css +0 -0
  22. package/examples/integration/tool/css/dist/style-login.min.css +1 -0
  23. package/examples/integration/tool/css/dist/style-login.min.css.map +10 -0
  24. package/examples/integration/tool/css/dist/style.css.min.css +0 -0
  25. package/examples/integration/tool/css/dist/style.min.css +1 -0
  26. package/examples/integration/tool/css/dist/style.min.css.map +23 -0
  27. package/examples/integration/tool/css/master/_bottom-sheet-2.scss +103 -0
  28. package/examples/integration/tool/css/master/_bottom-sheet.scss +142 -0
  29. package/examples/integration/tool/css/master/_colors.scss +35 -0
  30. package/examples/integration/tool/css/master/_dropdown-form.scss +167 -0
  31. package/examples/integration/tool/css/master/_forms.scss +416 -0
  32. package/examples/integration/tool/css/master/_header.scss +134 -0
  33. package/examples/integration/tool/css/master/_menu-toc.scss +135 -0
  34. package/examples/integration/tool/css/master/_menu-tools.scss +187 -0
  35. package/examples/integration/tool/css/master/_mixins.scss +42 -0
  36. package/examples/integration/tool/css/master/_notifyjs.scss +39 -0
  37. package/examples/integration/tool/css/master/_ol-map-controls.scss +117 -0
  38. package/examples/integration/tool/css/master/_simplelightbox.scss +287 -0
  39. package/examples/integration/tool/css/master/_toc-config.scss +28 -0
  40. package/examples/integration/tool/css/master/_toc-layouts.scss +173 -0
  41. package/examples/integration/tool/css/master/_tooltip.scss +34 -0
  42. package/examples/integration/tool/css/master/home.scss +266 -0
  43. package/examples/integration/tool/css/master/style-login.scss +240 -0
  44. package/examples/integration/tool/css/master/style.scss +166 -0
  45. package/examples/integration/tool/img/doc-gallery-placeholder.svg +3 -0
  46. package/examples/integration/tool/img/home/ic_calendar-clock.svg +1 -0
  47. package/examples/integration/tool/img/home/ic_caret-down.svg +1 -0
  48. package/examples/integration/tool/img/home/ic_cog.svg +1 -0
  49. package/examples/integration/tool/img/home/ic_marker.svg +1 -0
  50. package/examples/integration/tool/img/home/ic_play-circle.svg +1 -0
  51. package/examples/integration/tool/img/home/ic_power.svg +1 -0
  52. package/examples/integration/tool/img/home/ic_squares.svg +1 -0
  53. package/examples/integration/tool/img/home/ic_user-pointer.svg +1 -0
  54. package/examples/integration/tool/img/home/ic_user-square.svg +1 -0
  55. package/examples/integration/tool/img/home/logo_footer.svg +1 -0
  56. package/examples/integration/tool/img/ic/accessControl.svg +1 -0
  57. package/examples/integration/tool/img/ic/account-location.svg +1 -0
  58. package/examples/integration/tool/img/ic/actionDelete.svg +64 -0
  59. package/examples/integration/tool/img/ic/actionOpen.svg +64 -0
  60. package/examples/integration/tool/img/ic/addFile.svg +100 -0
  61. package/examples/integration/tool/img/ic/addFile_off.svg +102 -0
  62. package/examples/integration/tool/img/ic/arrow-left.svg +1 -0
  63. package/examples/integration/tool/img/ic/arrow-right-drop-circle-outline.svg +1 -0
  64. package/examples/integration/tool/img/ic/bt_add_photo.svg +3 -0
  65. package/examples/integration/tool/img/ic/bug.svg +1 -0
  66. package/examples/integration/tool/img/ic/caret-down-bottomsheet.svg +3 -0
  67. package/examples/integration/tool/img/ic/checkbox-blank-outline-grey.svg +8 -0
  68. package/examples/integration/tool/img/ic/checkbox-blank-outline-white.svg +8 -0
  69. package/examples/integration/tool/img/ic/checkbox-blank-outline.svg +1 -0
  70. package/examples/integration/tool/img/ic/checkbox-marked-outline-grey.svg +8 -0
  71. package/examples/integration/tool/img/ic/checkbox-marked-outline-white.svg +8 -0
  72. package/examples/integration/tool/img/ic/checkbox-marked-outline.svg +1 -0
  73. package/examples/integration/tool/img/ic/chevron-down-grey.svg +7 -0
  74. package/examples/integration/tool/img/ic/chevron-down-white.svg +7 -0
  75. package/examples/integration/tool/img/ic/chevron-down.svg +1 -0
  76. package/examples/integration/tool/img/ic/chevron-right-grey.svg +7 -0
  77. package/examples/integration/tool/img/ic/chevron-right-white.svg +7 -0
  78. package/examples/integration/tool/img/ic/chevron-right.svg +1 -0
  79. package/examples/integration/tool/img/ic/comment-text-outline.svg +1 -0
  80. package/examples/integration/tool/img/ic/cookie.svg +1 -0
  81. package/examples/integration/tool/img/ic/delete.svg +1 -0
  82. package/examples/integration/tool/img/ic/dot.svg +1 -0
  83. package/examples/integration/tool/img/ic/dump.svg +1 -0
  84. package/examples/integration/tool/img/ic/e.svg +9 -0
  85. package/examples/integration/tool/img/ic/eye-off.svg +1 -0
  86. package/examples/integration/tool/img/ic/eye.svg +1 -0
  87. package/examples/integration/tool/img/ic/forbidden.svg +1 -0
  88. package/examples/integration/tool/img/ic/form-title-1.svg +3 -0
  89. package/examples/integration/tool/img/ic/group.svg +1 -0
  90. package/examples/integration/tool/img/ic/hamburger.svg +1 -0
  91. package/examples/integration/tool/img/ic/ic-users.svg +1 -0
  92. package/examples/integration/tool/img/ic/ic_dropdown-form-close.svg +3 -0
  93. package/examples/integration/tool/img/ic/ic_dropdown-form-link.svg +3 -0
  94. package/examples/integration/tool/img/ic/ic_feature-edit-cancel.svg +14 -0
  95. package/examples/integration/tool/img/ic/ic_feature-edit-save.svg +14 -0
  96. package/examples/integration/tool/img/ic/ic_gallery-item-delete.svg +3 -0
  97. package/examples/integration/tool/img/ic/ic_gallery-item-view.svg +3 -0
  98. package/examples/integration/tool/img/ic/ic_gps.svg +3 -0
  99. package/examples/integration/tool/img/ic/ic_search.svg +5 -0
  100. package/examples/integration/tool/img/ic/ic_selector_fechas.svg +63 -0
  101. package/examples/integration/tool/img/ic/ic_zoom-to-extent.svg +3 -0
  102. package/examples/integration/tool/img/ic/icon_reminder.png +0 -0
  103. package/examples/integration/tool/img/ic/image-gallery-placeholder.svg +55 -0
  104. package/examples/integration/tool/img/ic/imaqua.svg +87 -0
  105. package/examples/integration/tool/img/ic/incidencia.svg +77 -0
  106. package/examples/integration/tool/img/ic/info_multi_selection.svg +230 -0
  107. package/examples/integration/tool/img/ic/layers.svg +1 -0
  108. package/examples/integration/tool/img/ic/map-marker.svg +3 -0
  109. package/examples/integration/tool/img/ic/map.svg +1 -0
  110. package/examples/integration/tool/img/ic/measure_area.svg +111 -0
  111. package/examples/integration/tool/img/ic/minus.svg +7 -0
  112. package/examples/integration/tool/img/ic/notification.svg +1 -0
  113. package/examples/integration/tool/img/ic/offline.svg +3 -0
  114. package/examples/integration/tool/img/ic/online.svg +1 -0
  115. package/examples/integration/tool/img/ic/pencil.svg +3 -0
  116. package/examples/integration/tool/img/ic/plus.svg +1 -0
  117. package/examples/integration/tool/img/ic/polygon_selection.svg +68 -0
  118. package/examples/integration/tool/img/ic/power.svg +1 -0
  119. package/examples/integration/tool/img/ic/remoteLocalized.svg +4 -0
  120. package/examples/integration/tool/img/ic/remoteStartLocalize.svg +4 -0
  121. package/examples/integration/tool/img/ic/ruler.svg +125 -0
  122. package/examples/integration/tool/img/ic/selection-plus.svg +10 -0
  123. package/examples/integration/tool/img/ic/selection.svg +1 -0
  124. package/examples/integration/tool/img/ic/settings.svg +1 -0
  125. package/examples/integration/tool/img/ic/sort.svg +1 -0
  126. package/examples/integration/tool/img/ic/sort_asc.svg +1 -0
  127. package/examples/integration/tool/img/ic/sort_desc.svg +1 -0
  128. package/examples/integration/tool/img/ic/spreadsheet.svg +3 -0
  129. package/examples/integration/tool/img/ic/times.svg +1 -0
  130. package/examples/integration/tool/img/ic/toolbar/AB3.svg +1 -0
  131. package/examples/integration/tool/img/ic/toolbar/AB4.svg +1 -0
  132. package/examples/integration/tool/img/ic/toolbar/IC1.svg +1 -0
  133. package/examples/integration/tool/img/ic/toolbar/TB1.svg +1 -0
  134. package/examples/integration/tool/img/ic/toolbar/TB11.svg +5 -0
  135. package/examples/integration/tool/img/ic/toolbar/TB2.svg +1 -0
  136. package/examples/integration/tool/img/ic/toolbar/TB20.svg +1 -0
  137. package/examples/integration/tool/img/ic/toolbar/TB21.svg +54 -0
  138. package/examples/integration/tool/img/ic/toolbar/TB3.svg +1 -0
  139. package/examples/integration/tool/img/ic/toolbar/TB31.svg +1 -0
  140. package/examples/integration/tool/img/ic/toolbar/TB32.svg +57 -0
  141. package/examples/integration/tool/img/ic/toolbar/TB4.svg +1 -0
  142. package/examples/integration/tool/img/ic/toolbar/TB5.svg +1 -0
  143. package/examples/integration/tool/img/ic/toolbar/TB6.svg +1 -0
  144. package/examples/integration/tool/img/ic/toolbar/TB7.svg +1 -0
  145. package/examples/integration/tool/img/ic/toolbar/TB8.svg +1 -0
  146. package/examples/integration/tool/img/ic/tools.svg +28 -0
  147. package/examples/integration/tool/img/ic/user.svg +1 -0
  148. package/examples/integration/tool/img/ic/vector-polygon.svg +1 -0
  149. package/examples/integration/tool/img/ic/visit_manager.svg +135 -0
  150. package/examples/integration/tool/img/logo-footer-login.png +0 -0
  151. package/examples/integration/tool/img/logo-footer.png +0 -0
  152. package/examples/integration/tool/img/logo-header-login.png +0 -0
  153. package/examples/integration/tool/img/logo-header-login@2x.png +0 -0
  154. package/examples/integration/tool/img/logo-header-login@3x.png +0 -0
  155. package/examples/integration/tool/img/logo-header.png +0 -0
  156. package/examples/integration/tool/img/logo-header@2x.png +0 -0
  157. package/examples/integration/tool/img/logo-header@3x.png +0 -0
  158. package/examples/integration/tool/img/logo_project.png +0 -0
  159. package/examples/integration/tool/img/photo-gallery-placeholder.svg +3 -0
  160. package/examples/integration/tool/img/pixel.png +0 -0
  161. package/examples/integration/tool/index.html +228 -0
  162. package/examples/integration/tool/js/demo.js +238 -0
  163. package/examples/integration/tool/js/interface.js +147 -0
  164. package/examples/integration/tool/js/jquery.js +4 -0
  165. package/examples/integration/vanguardia.html +6636 -0
  166. package/examples/multipleIframes/index.js +82 -0
  167. package/examples/multipleIframes/index.php +52 -0
  168. package/examples/serverLess/dist/index.23420cfa.js +2973 -0
  169. package/examples/serverLess/dist/index.23420cfa.js.map +1 -0
  170. package/examples/serverLess/dist/index.91b6cacc.js +2 -0
  171. package/examples/serverLess/dist/index.91b6cacc.js.map +1 -0
  172. package/examples/serverLess/dist/index.html +1 -0
  173. package/examples/serverLess/index.html +39 -0
  174. package/examples/serverLess/main.js +113 -0
  175. package/examples/serverLess/package.json +18 -0
  176. package/examples/serverLess/readme.md +41 -0
  177. package/examples/simple/index.html +1 -1
  178. package/examples/simple/simple.js +63 -65
  179. package/examples/vidromap/index.js +20 -0
  180. package/examples/vidromap/index.php +48 -51
  181. package/flows.md +73 -0
  182. package/package.json +2 -2
  183. package/src/index.js +156 -42
  184. package/src/shared/iframe-communicator.js +12 -5
  185. package/examples/vidromap/vidromap.js +0 -87
package/src/index.js CHANGED
@@ -1,71 +1,116 @@
1
1
  import { EventEmitter } from "events"
2
- import { sendMessageToMap } from "./shared/iframe-communicator";
3
-
2
+ import { iframeCommunicator } from "./shared/iframe-communicator";
4
3
  class Communicator extends EventEmitter {
5
4
 
6
- constructor({ sessionToken }){
5
+ constructor(data){
7
6
  super();
8
-
7
+ this.domId = 'map-frame';
9
8
  if(typeof window === 'undefined'){
10
9
  return;
11
10
  };
12
-
11
+ if(typeof data.id==="string"){
12
+ this.domId = data.id;
13
+ }
14
+ this.com = new iframeCommunicator(data)
13
15
  window.addEventListener("message", e => this.onMessageReceived(e));
14
- this.sessionToken = sessionToken;
15
-
16
+ this.sessionToken = data.sessionToken;
16
17
  }
17
18
 
18
19
  onMessageReceived = e => {
19
20
  switch(e.data.type){
20
- case "onZoomChange": this.emit("onZoomChange", e.data.zoom); break;
21
- case "geomAdded": this.emit("geomAdded", e.data.geom_astext); break;
22
- case "layers": this.emit("layers", e.data.layers); break;
23
- case "geoJSONlayers": this.emit("geoJSONlayers", e.data.layers); break;
24
- case "info": this.emit("info", e.data); break;
25
- case "error": this.emit("error", e.data); break;
26
- case "coordinates": this.emit("coordinates", e.data); break;
27
- case "activeLayer": this.emit("activeLayer", e.data); break;
28
- case "geolocation": this.emit("geolocation", e.data); break;
29
- case "WMSInfoAvailable": this.emit("WMSInfoAvailable", e.data); break;
30
- case "giswaterTiledBackgroundDisplayed": this.emit("giswaterTiledBackgroundDisplayed", e.data); break;
31
- case "giswaterTiledBackgroundAvailable": this.emit("giswaterTiledBackgroundAvailable", e.data); break;
32
- case "GiswaterLayerAvailableFilters": this.emit("GiswaterLayerAvailableFilters", e.data); break;
33
-
21
+ case "onZoomChange": this.emitEvent("onZoomChange", e.data.zoom,e.data.domId); break;
22
+ case "geomAdded": this.emitEvent("geomAdded", e.data.geom_astext,e.data.domId); break;
23
+ case "layers": this.emitEvent("layers", e.data.layers,e.data.domId); break;
24
+ case "geoJSONlayers": this.emitEvent("geoJSONlayers", e.data.layers,e.data.domId); break;
25
+ case "info": this.emitEvent("info", e.data,e.data.domId); break;
26
+ case "error": this.emitEvent("error", e.data,e.data.domId); break;
27
+ case "coordinates": this.emitEvent("coordinates", e.data,e.data.domId); break;
28
+ case "activeLayer": this.emitEvent("activeLayer", e.data,e.data.domId); break;
29
+ case "geolocation": this.emitEvent("geolocation", e.data,e.data.domId); break;
30
+ case "WMSInfoAvailable": this.emitEvent("WMSInfoAvailable", e.data,e.data.domId); break;
31
+ case "giswaterTiledBackgroundDisplayed": this.emitEvent("giswaterTiledBackgroundDisplayed", e.data,e.data.domId); break;
32
+ case "giswaterTiledBackgroundAvailable": this.emitEvent("giswaterTiledBackgroundAvailable", e.data,e.data.domId); break;
33
+ case "GiswaterLayerAvailableFilters": this.emitEvent("GiswaterLayerAvailableFilters", e.data,e.data.domId); break;
34
+ case "loaded": this.emitEvent("loaded", e.data,e.data.domId); break;
35
+ case "availableWMSLayers": this.emitEvent("availableWMSLayers", e.data.layers,e.data.domId); break;
36
+ }
37
+
38
+ }
39
+
40
+ emitEvent = (type,data,domId)=>{
41
+ if(domId===this.domId){
42
+ delete data.domId;
43
+ this.emit(type, data);
34
44
  }
35
45
  }
36
46
 
37
47
  ZoomIn = () => {
38
- sendMessageToMap({
48
+ this.com.sendMessageToMap({
39
49
  type: "zoomIn",
40
50
  sessionToken: this.sessionToken,
41
- });
51
+ });
52
+
42
53
  }
43
54
 
44
55
  ZoomOut = () => {
45
- sendMessageToMap({
56
+ this.com.sendMessageToMap({
46
57
  type: "zoomOut",
47
58
  sessionToken: this.sessionToken,
48
59
  });
49
60
  }
50
61
 
51
62
  AddGeom = (geomtype) => {
52
- sendMessageToMap({
63
+ this.com.sendMessageToMap({
53
64
  type: "AddGeom",
54
65
  geom: geomtype,
55
66
  sessionToken: this.sessionToken,
56
67
  });
57
68
  }
58
69
 
59
- toggleLayer = (layer) => {
60
- sendMessageToMap({
70
+ toggleLayer = (layer,properties) => {
71
+ if(typeof properties==='undefined'){
72
+ properties = {
73
+ gutter: null,
74
+ transparent: null,
75
+ singletile: null
76
+ };
77
+ }
78
+
79
+ if(properties.singletile!==null){
80
+ if(typeof properties.singletile!=='boolean'){
81
+ properties.singletile = null;
82
+ this.emit("error",{error:"singleTile must be a Boolean"});
83
+ }
84
+ }
85
+ if(properties.gutter!=='' && properties.gutter!==null){
86
+ if(isNaN(parseInt(properties.gutter))){
87
+ properties.gutter = null;
88
+ this.emit("error",{error:"Gutter must be a number"});
89
+ }
90
+ if(properties.singletile){
91
+ properties.gutter = null;
92
+ this.emit("error",{error:"Gutter can only be user with multitile layers; set singletile to false"});
93
+ }
94
+ }
95
+
96
+ if(properties.transparent!==null){
97
+ if(typeof properties.transparent!=='boolean'){
98
+ properties.transparent = null;
99
+ this.emit("error",{error:"transparent must be a Boolean"});
100
+ }
101
+ }
102
+ this.com.sendMessageToMap({
61
103
  type: "toggleLayer",
62
104
  layer: layer,
105
+ gutter: !isNaN(parseInt(properties.gutter)) ? parseInt(properties.gutter) : null,
106
+ transparent: properties.transparent,
107
+ singletile: properties.singletile,
63
108
  sessionToken: this.sessionToken,
64
109
  });
65
110
  }
66
111
 
67
112
  setActiveLayer = (layer) => {
68
- sendMessageToMap({
113
+ this.com.sendMessageToMap({
69
114
  type: "setActiveLayer",
70
115
  layer: layer,
71
116
  sessionToken: this.sessionToken,
@@ -73,21 +118,28 @@ class Communicator extends EventEmitter {
73
118
  }
74
119
 
75
120
  getActiveLayer = () => {
76
- sendMessageToMap({
121
+ this.com.sendMessageToMap({
77
122
  type: "getActiveLayer",
78
123
  sessionToken: this.sessionToken,
79
124
  });
80
125
  }
81
126
 
127
+ loadWMSAvailableLayers = () => {
128
+ this.com.sendMessageToMap({
129
+ type: "loadWMSAvailableLayers",
130
+ sessionToken: this.sessionToken,
131
+ });
132
+ }
133
+
82
134
  clear = () => {
83
- sendMessageToMap({
135
+ this.com.sendMessageToMap({
84
136
  type: "clear",
85
137
  sessionToken: this.sessionToken,
86
138
  });
87
139
  }
88
140
 
89
141
  Highlight = (options) => {
90
- sendMessageToMap({
142
+ this.com.sendMessageToMap({
91
143
  type: "highlight",
92
144
  geom: options.geom,
93
145
  zoom: options.zoom,
@@ -96,15 +148,26 @@ class Communicator extends EventEmitter {
96
148
  }
97
149
 
98
150
  zoomToExtent = () => {
99
- sendMessageToMap({
151
+ this.com.sendMessageToMap({
100
152
  type: "zoomToExtent",
101
153
  sessionToken: this.sessionToken,
102
154
  });
103
155
  }
104
156
 
157
+ zoomToCoordinates= (lat,lon,zoomLevel) => {
158
+ if(!isNaN(parseInt(zoomLevel))){
159
+ this.com.sendMessageToMap({
160
+ type: "zoomToCoordinates",
161
+ sessionToken: this.sessionToken,
162
+ coordinates:[lat,lon],
163
+ zoomLevel: zoomLevel
164
+ });
165
+ }
166
+ }
167
+
105
168
  infoFromCoordinates = (type,layer,hitTolerance) => {
106
169
  const _layer = (typeof layer=='undefined') ? null : layer
107
- sendMessageToMap({
170
+ this.com.sendMessageToMap({
108
171
  type: "infoFromCoordinates",
109
172
  info: type,
110
173
  layer: _layer,
@@ -114,7 +177,7 @@ class Communicator extends EventEmitter {
114
177
  }
115
178
 
116
179
  Geolocalize = (toggle) => {
117
- sendMessageToMap({
180
+ this.com.sendMessageToMap({
118
181
  type: "Geolocalize",
119
182
  toggle: toggle,
120
183
  sessionToken: this.sessionToken,
@@ -122,7 +185,7 @@ class Communicator extends EventEmitter {
122
185
  }
123
186
 
124
187
  toggleGiswaterTiled = (toggle) => {
125
- sendMessageToMap({
188
+ this.com.sendMessageToMap({
126
189
  type: "toggleGiswaterTiled",
127
190
  toggle: toggle,
128
191
  sessionToken: this.sessionToken,
@@ -130,7 +193,7 @@ class Communicator extends EventEmitter {
130
193
  }
131
194
 
132
195
  reloadDisplayedLayers = ()=>{
133
- return sendMessageToMap({
196
+ return this.com.sendMessageToMap({
134
197
  type: "reloadDisplayedLayers",
135
198
  sessionToken: this.sessionToken,
136
199
  });
@@ -138,7 +201,7 @@ class Communicator extends EventEmitter {
138
201
 
139
202
  addGeoJSON = (geoJSON,options, name)=>{
140
203
  if(geoJSON){
141
- return sendMessageToMap({
204
+ return this.com.sendMessageToMap({
142
205
  type: "addGeoJSON",
143
206
  geoJSON: geoJSON,
144
207
  options: (typeof options!='undefined') ? options : {fillcolor:null,strokecolor:null},
@@ -152,7 +215,7 @@ class Communicator extends EventEmitter {
152
215
  }
153
216
 
154
217
  clearGeoJSON = ()=>{
155
- return sendMessageToMap({
218
+ return this.com.sendMessageToMap({
156
219
  type: "clearGeoJSON",
157
220
  sessionToken: this.sessionToken,
158
221
  });
@@ -160,7 +223,7 @@ class Communicator extends EventEmitter {
160
223
 
161
224
  removeGeoJSONLayer = (name)=>{
162
225
  if(name){
163
- return sendMessageToMap({
226
+ return this.com.sendMessageToMap({
164
227
  type: "removeGeoJSONLayer",
165
228
  name: name,
166
229
  sessionToken: this.sessionToken,
@@ -186,7 +249,7 @@ class Communicator extends EventEmitter {
186
249
  }
187
250
  }
188
251
 
189
- return sendMessageToMap({
252
+ return this.com.sendMessageToMap({
190
253
  type: "setGiswaterFilters",
191
254
  filters: filtersJson,
192
255
  sessionToken: this.sessionToken,
@@ -199,7 +262,7 @@ class Communicator extends EventEmitter {
199
262
 
200
263
  getGiswaterLayerAvailableFilters = (layer_name)=>{
201
264
  if(layer_name){
202
- return sendMessageToMap({
265
+ return this.com.sendMessageToMap({
203
266
  type: "getGiswaterLayerAvailableFilters",
204
267
  name: layer_name,
205
268
  sessionToken: this.sessionToken,
@@ -210,7 +273,58 @@ class Communicator extends EventEmitter {
210
273
  }
211
274
  }
212
275
 
213
-
276
+ setDebug = (what) =>{
277
+ if(!isNaN(parseInt(what))){
278
+ this.com.sendMessageToMap({
279
+ type: "setDebug",
280
+ what: what,
281
+ sessionToken: this.sessionToken,
282
+ });
283
+ }else{
284
+ console.error("Debug is not a integer");
285
+ }
286
+ }
287
+
288
+ setCustomColors = (properties)=>{
289
+ //validate data
290
+ if(typeof properties!=='object'){
291
+ console.error("properties is not an object");
292
+ return;
293
+ }
294
+ if(properties.hasOwnProperty('geom_stroke_width')){
295
+ if(isNaN(parseInt(properties.geom_stroke_width))){
296
+ console.error("geom_stroke_width is not an number");
297
+ return;
298
+ }else{
299
+ properties.geom_stroke_width = parseInt(properties.geom_stroke_width);
300
+ }
301
+ }else{
302
+ properties.geom_stroke_width = 1;
303
+ }
304
+ if(properties.hasOwnProperty('geom_radius')){
305
+ if(isNaN(parseInt(properties.geom_radius))){
306
+ console.error("geom_stroke_width is not an number");
307
+ return;
308
+ }else{
309
+ properties.geom_radius = parseInt(properties.geom_radius);
310
+ }
311
+ }else{
312
+ properties.geom_radius = 4;
313
+ }
314
+
315
+ if(properties.hasOwnProperty('geom_shape')){
316
+ if(properties.geom_shape!=="circle" && properties.geom_shape!=="square"){
317
+ properties.geom_shape = 'circle';
318
+ console.error("geom_shape must be either 'circle' or 'square'");
319
+ }
320
+ }
321
+ this.com.sendMessageToMap({
322
+ type: "setCustomColors",
323
+ properties: properties,
324
+ sessionToken: this.sessionToken,
325
+ });
326
+ }
327
+
214
328
  }
215
329
 
216
330
  export {
@@ -1,11 +1,18 @@
1
1
  const isSSR = typeof window === 'undefined';
2
+ class iframeCommunicator {
3
+ constructor(data){
4
+ this.domId = 'map-frame';
5
+ if(typeof data.id==="string"){
6
+ this.domId = data.id;
7
+ }
8
+ }
2
9
 
3
- const sendMessageToMap = message => {
4
- if(isSSR) return;
5
- window.top.frames['map-frame'].postMessage(message, "*");
10
+ sendMessageToMap = message => {
11
+ if(isSSR) return;
12
+ window.top.frames[this.domId].postMessage(message, "*");
13
+ }
6
14
  }
7
15
 
8
-
9
16
  export {
10
- sendMessageToMap,
17
+ iframeCommunicator,
11
18
  }
@@ -1,87 +0,0 @@
1
- // Config:
2
-
3
-
4
- // UI:
5
-
6
- var loginContainer = document.querySelector("#loginContainer");
7
-
8
- var btLoadMap = document.querySelector("#btLoadMap");
9
-
10
-
11
- var sessionToken = document.querySelector("#sessionToken");
12
- var mapContainer = document.querySelector("#mapContainer");
13
- var iframe = document.querySelector("#map-frame");
14
- var errorContainer = document.querySelector("#Error_container");
15
- mapContainer.classList.add("hide");
16
-
17
-
18
-
19
- //************** MAP EXAMPLE
20
-
21
- btLoadMap.addEventListener("click", function (evt) {
22
- apiUrl = document.querySelector("#apiurl").value;
23
- var debug = parseInt(document.getElementById("debug").value);
24
- //Build XMLHttpRequest for map
25
- var name = document.querySelector("#name").value;
26
- var uri = `${apiUrl}/vidromap/${name}`;
27
- var zoom = document.querySelector("#zoom").value;
28
- var data = { zoom: zoom};
29
-
30
- var srid = document.querySelector("#srid").value;
31
- if(srid){
32
- data.srid = srid;
33
- }
34
- var geoserver = document.querySelector("#geoserver").value;
35
- if(geoserver){
36
- data.geoserver = geoserver;
37
- }
38
- var geoserverdata = document.querySelector("#geoserverdata").value;
39
- if(geoserverdata){
40
- data.geoserverdata = geoserverdata;
41
- }
42
- var show_layers = document.querySelector("#show_layers").value;
43
- if(show_layers){
44
- data.show_layers = show_layers;
45
- }
46
- var extent = document.querySelector("#extent").value;
47
- if(extent){
48
- data.extent = extent;
49
- }
50
-
51
-
52
- var oReq = new XMLHttpRequest();
53
-
54
- oReq.addEventListener("load", mapListener);
55
- oReq.open("POST", uri, true);
56
- oReq.setRequestHeader("Content-type", "application/json");
57
- oReq.send(JSON.stringify(data));
58
- console.log("Attempt to load map", `${apiUrl}/vidromap/${name}`);
59
- });
60
-
61
- function mapListener() {
62
- if (this.status === 200) {
63
- console.log("mapListener response", this.responseText);
64
- var res = JSON.parse(this.responseText);
65
- errorContainer.classList.add("hide");
66
- mapContainer.classList.remove("hide");
67
- iframe.src = `${res.message.iframe}?sessionToken=${res.message.sessionToken}`;
68
- sessionToken.innerHTML = res.message.sessionToken;
69
- localStorage.setItem("iframe", iframe.src);
70
- localStorage.setItem("sessionToken", res.message.sessionToken);
71
- } else {
72
- console.error(this.status);
73
- var res = JSON.parse(this.responseText);
74
- console.log(res.error);
75
- //show DOM error element
76
- errorContainer.innerHTML = res.error;
77
- errorContainer.classList.remove("hide");
78
- mapContainer.classList.add("hide");
79
- }
80
- }
81
- //************** END MAP EXAMPLE
82
-
83
-
84
-
85
-
86
-
87
-