Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / static / fusion / raptor / js / gmap.js
1 var map;
2 var popupTable;
3 var networkOverlay;
4 var selectedNetworkOverlay;
5 var flashTimeout;
6 //var infoDiv;
7 var mainInfoDiv;
8 var locationInfoDiv;
9 var loadingAnimationDiv;
10 var geocoder;
11 var addressMarker;
12 var popupDiv;
13 //var novaButton;
14
15 function novaMapInit() {
16         if (GBrowserIsCompatible()) {
17                 var dmap = document.getElementById("map");
18                 map = new GMap2(dmap);
19                 var defaultCenterLongitude = document.getElementById("defaultCenterLongitude").value;
20                 var defaultCenterLatitude = document.getElementById("defaultCenterLatitude").value;
21                 var defaultZoomLevel = document.getElementById("defaultZoomLevel").value * 1;
22                 
23                 map.setCenter(new GLatLng(defaultCenterLatitude, defaultCenterLongitude), defaultZoomLevel); 
24                 
25             map.enableScrollWheelZoom();
26             map.enableContinuousZoom();
27             map.addControl(new GLargeMapControl());
28             map.addControl(new GMapTypeControl());
29             
30             geocoder = new GClientGeocoder();
31         
32             GEvent.addListener(map, "dragend", mapDragEnd);
33             GEvent.addListener(map, "zoomend", mapZoomChanged);
34             GEvent.addListener(map, "click", mapClicked);
35             GEvent.addListener(map, "moveend", mapMoveEnd)
36             GEvent.addListener(map, "singlerightclick", mapRightClicked);
37             GEvent.addListener(map, "mousemove", function(latlng) {
38                 locationInfoDiv.innerHTML = latlng.lng().toFixed(3) + ", " + latlng.lat().toFixed(3);
39             });
40         
41             var n = document.getElementById("popupmenudiv2");
42             popupDiv = n.cloneNode(true);
43             map.getContainer().appendChild(popupDiv);
44             
45             popupTable = document.getElementById("popupmenudivtb");
46             
47             // detail info div
48                 /*infoDiv = document.createElement("div");
49                 infoDiv.style.display = "none";
50                 infoDiv.style.position = "absolute";
51                 infoDiv.style.overflow = "auto";
52                 infoDiv.style.top = "0px"; 
53                 infoDiv.style.left = "0px";
54                 infoDiv.style.zIndex = "1001";
55                 infoDiv.style.border = "1px outset #000";
56                 infoDiv.style.background = "#C6DEFF";
57                 infoDiv.style.height = "150px";
58                 infoDiv.style.width = "300px";
59                 infoDiv.align = "center";*/
60                 
61                 mainInfoDiv = document.createElement("div");
62                 mainInfoDiv.style.display = "none";
63                 mainInfoDiv.style.position = "absolute";
64                 mainInfoDiv.style.overflow = "auto";
65                 mainInfoDiv.style.top = "0px"; 
66                 mainInfoDiv.style.left = "0px";
67                 mainInfoDiv.style.zIndex = "1001";
68                 mainInfoDiv.style.border = "1px outset #000";
69                 mainInfoDiv.style.background = "#C6DEFF";
70                 mainInfoDiv.style.height = "150px";
71                 mainInfoDiv.style.width = "300px";
72                 mainInfoDiv.align = "center";
73
74                 //mainInfoDiv = infoDiv.appendChild(document.createElement("div"));
75                 mainInfoDiv.style.overflow = "auto";
76                 mainInfoDiv.style.height = "150px";
77                 mainInfoDiv.style.width = "300px";
78                 //mainInfoDiv.align = "center";
79                 
80                 /*var closeInfoDiv = infoDiv.appendChild(document.createElement("div"));
81                 closeInfoDiv.appendChild(document.createTextNode("Close"));
82                 
83                 closeInfoDiv.style.background = "#FFFFF0";
84                 closeInfoDiv.style.color = "black";
85                 closeInfoDiv.style.fontFamily = "Verdana";
86                 closeInfoDiv.style.fontSize = "12px";
87                 closeInfoDiv.style.fontWeight= "bold";
88                 closeInfoDiv.style.border = "2px solid black";
89                 closeInfoDiv.style.padding = "0px";
90                 closeInfoDiv.style.marginBottom = "0px";
91                 closeInfoDiv.style.textAlign = "center";
92                 closeInfoDiv.style.width = "80px";
93                 closeInfoDiv.style.height = "15px";
94                 closeInfoDiv.style.cursor = "pointer";
95                 
96                 GEvent.addDomListener(closeInfoDiv, "click", function() {
97                   infoDiv.style.display = "none";
98                 });     */
99                 
100                 // longitude latitude div
101                 var locationInfoWidth = 200;
102                 var locationInfoHeight = 15;
103                 locationInfoDiv = document.createElement("div");
104                 locationInfoDiv.style.display = "inline";
105                 locationInfoDiv.style.position = "absolute";
106                 locationInfoDiv.style.zIndex = "1";
107                 locationInfoDiv.style.height = locationInfoHeight + "px";
108                 locationInfoDiv.style.width = locationInfoWidth + "px";
109                 locationInfoDiv.align = "center";
110                 locationInfoDiv.style.color = "#4CC417";
111                 locationInfoDiv.style.fontWeight = "bold";
112                 locationInfoDiv.appendChild(document.createTextNode("Longitude Latitude"));
113         
114                 var mapWidth = map.getSize().width;
115                 var mapHeight = map.getSize().height;
116                 
117                 locationInfoDiv.style.top = (mapHeight - locationInfoHeight - 5) + "px";
118                 locationInfoDiv.style.left = (mapWidth / 2 - locationInfoWidth / 2) + "px";
119                 
120                 // loading image animation
121                 loadingAnimationDiv = document.createElement("div");
122                 loadingAnimationDiv.style.position = "absolute";
123                 loadingAnimationDiv.style.zIndex = "100000";
124                 loadingAnimationDiv.style.display = "none";
125                 loadingAnimationDiv.style.width = "50px";
126                 loadingAnimationDiv.style.height = "50px";
127                 loadingAnimationDiv.style.top = (mapHeight / 2 - 50 / 2) + "px";
128                 loadingAnimationDiv.style.left = (mapWidth / 2 - 50 / 2) + "px";
129                 var imgDiv = loadingAnimationDiv.appendChild(document.createElement("img"));
130                 imgDiv.src = document.getElementById("imgFolder").value + "loading.gif";
131                 
132           
133                 //map.getContainer().appendChild(infoDiv);
134                 map.getContainer().appendChild(mainInfoDiv);
135                 map.getContainer().appendChild(locationInfoDiv);
136                 map.getContainer().appendChild(loadingAnimationDiv);
137                 updateImage(0);
138         }
139 }
140
141 function mapRightClicked(point, src) {
142         var latlng = map.fromContainerPixelToLatLng(new GPoint(point.x , point.y));
143         alert(latlng.lng() + ", " + latlng.lat());
144 }
145 /*
146 function searchObject(searchInput, searchType, exactMatch, clickX, clickY) {
147   loadingAnimationDiv.style.display = "inline";
148   var baseURL = document.getElementById("baseURL").value;
149   //var url = baseURL + "/gmap_controller.htm?action=searchObject";
150   //var url = baseURL + "report.gmap.search_object";
151   var url = baseURL + "/gmapservlet?action=searchObject&nextpage=report.gmap.search_object";
152   url += "&search_input=" + searchInput;
153   url += "&search_type=" + searchType;
154   url += "&exact_match=" + exactMatch;
155   url += "&object_type=CELLSITE";
156   
157   if (clickX == null || clickY == null) {
158     var mapWidth = map.getSize().width;
159         var mapHeight = map.getSize().height;
160         clickX = mapWidth / 2;
161         clickY = mapHeight / 2;
162   }
163   
164   url += "&client_x=" + clickX;
165   url += "&client_y=" + clickY;
166   
167   new Ajax.Request(url, {
168         method: 'get',
169         onSuccess: function(transport) {
170           loadingAnimationDiv.style.display = "none";
171           var jsonData = transport.responseText.evalJSON();
172           var list = jsonData.list;
173           
174           if (list == null) {
175             alert("Not found");
176           }
177           else {
178             if (list.length == 1) {
179               var longitude = list[0].longitude;
180               var latitude = list[0].latitude;
181               map.setCenter(new GLatLng(latitude, longitude));
182               updateImage(0);
183             }
184             else {
185               for (var i = popupTable.childNodes.length - 1; i >= 0; i--) {
186             popupTable.removeChild(popupTable.lastChild);
187           }
188             
189               for (var i = 0; i < list.length; i++) {
190                                           var tr = popupTable.appendChild(document.createElement("tr"));                        
191                 var td = tr.appendChild(document.createElement("td"));
192                 td.appendChild(document.createTextNode(list[i].type + "(" + list[i].numberOfT1 + 
193                         "): " + list[i].id));
194                 td.style.border = "solid";
195                 td.style.borderWidth = "thin";
196                 td.style.borderRight = "none";
197                 td.style.borderLeft = "none";
198                 
199                 if (i == 0) {
200                 td.style.borderTop = "none";
201                 }
202                 
203                 if (i == list.length - 1) {
204                         td.style.borderBottom = "none";
205                 }
206                 
207                 td.style.color = "#0000FF";
208                 td.style.background = "#FFFFF0";
209                 td.style.fontSize = "12px";
210                 td.font = "Arial,Helvetica,sans-serif";
211                 td.id = list[i].latitude + ">>" + list[i].longitude;
212                 
213                 td.onmouseover = function(e) {
214               this.style.background = "#0000FF";
215               this.style.color = "#FFFFF0";
216             }
217                 
218                 td.onmouseout = function(e) {
219               this.style.background = "#FFFFF0";
220               this.style.color = "#0000FF";
221             }
222           
223             td.onclick = function(e) {
224               //var popupDiv = document.getElementById("popupmenudiv");
225               popupDiv.style.display = "none";
226               var latitudeLongitude = this.id.split(">>");
227               var latlng = new GLatLng(latitudeLongitude[0], latitudeLongitude[1]);
228                 map.setCenter(latlng);
229                 updateImage(0); 
230             }
231                                   }
232                                   
233                                   //var popupDiv = document.getElementById("popupmenudiv");
234                                   popupDiv.style.display = "";
235         
236           var textWidth = popupDiv.offsetWidth;
237                   var textHeight = popupDiv.offsetHeight;
238          
239           if (textHeight >= 200) {
240                 popupDiv.style.overflow = "auto";
241                 popupDiv.style.height = "200px";
242                 textHeight = 200;
243           }
244         
245           if (textWidth >= 250) {
246                 popupDiv.style.width = "250px";
247                 //textWidth = 250;
248           }
249         
250                 var clientX = jsonData.clientX;
251                 var clientY = jsonData.clientY;
252         
253                 if ((clientX * 1 + textWidth + 20) >= screen.availWidth) {
254                 clientX = clientX - textWidth - 20;
255                 }
256         
257                 if ((clientY * 1 + textHeight) >= document.getElementById("map").offsetHeight) {
258                         clientY = document.getElementById("map").offsetHeight - textHeight;
259                   
260                 }
261                 
262                 popupDiv.style.top = clientY + "px";
263                 popupDiv.style.left = clientX + "px";
264             }
265           }
266         }
267   });   
268 }
269 */
270 function getInfo(info, x, y) {
271   var baseURL = document.getElementById("baseURL").value;
272   //var url = baseURL + "/gmap_controller.htm?action=getInfo";
273   //var url = baseURL + "report.gmap.get_info";
274   var url = baseURL + "/gmapservlet?action=getInfo&nextpage=report.gmap.get_info";
275   url += "&info=" + info;
276   url += "&client_x=" + x;
277   url += "&client_y=" + y;
278   
279   new Ajax.Request(url, {
280         method: 'get',
281         onSuccess: function(transport) {
282                 var jsonData = transport.responseText.evalJSON();
283                 var clientX = jsonData.clientX;
284                 var clientY = jsonData.clientY;
285                 var attributes = jsonData.attributes;
286                 
287                 for (var i = mainInfoDiv.childNodes.length - 1; i >= 0; i--) {
288         mainInfoDiv.removeChild(mainInfoDiv.lastChild);
289       }
290       
291         mainInfoDiv.align="left";
292         var menuUL = mainInfoDiv.appendChild(document.createElement("ul"));
293         var menuItem = document.createElement("li");
294         menuItem.appendChild(document.createTextNode("Row : " + jsonData.id));
295         menuUL.appendChild(menuItem);
296         
297         menuItem = document.createElement("li");
298         menuItem.appendChild(document.createTextNode("Longitude: " + jsonData.longitude));
299         menuUL.appendChild(menuItem);
300         
301         menuItem = document.createElement("li");
302         menuItem.appendChild(document.createTextNode("Latitude: " + jsonData.latitude));
303         menuUL.appendChild(menuItem);
304         
305         var table = mainInfoDiv.appendChild(document.createElement("table"));
306         table.width="100%";
307         table.align="left";
308         var tbody = table.appendChild(document.createElement("tbody"));
309         //tbody.style.borderCollapse = "collapse";
310         //var tr = tbody.appendChild(document.createElement("tr"));
311         var td;
312         for (var i = 0; i < attributes.length ; i++) {
313                 tr = tbody.appendChild(document.createElement("tr"));
314                 td = tr.appendChild(document.createElement("td"));
315                 td.align="left";
316                 td.width="25%"
317                 td.style.padding = "2px";
318                 td.appendChild(document.createTextNode(attributes[i].key));
319                 td = tr.appendChild(document.createElement("td"));
320                 td.style.padding = "2px";
321                 td.appendChild(document.createTextNode(attributes[i].value));
322         }
323         
324         var textWidth = 300;
325         var textHeight = 150 + 15;
326         
327                 if ((clientX * 1 + textWidth + 20) >= screen.availWidth) {
328           clientX = clientX - textWidth - 20;
329         }
330         
331         if ((clientY * 1 + textHeight) >= document.getElementById("map").offsetHeight) {
332                 clientY = document.getElementById("map").offsetHeight - textHeight;               
333         }
334       
335         mainInfoDiv.style.top = clientY + "px";
336         mainInfoDiv.style.left = clientX + "px";
337         mainInfoDiv.style.display = "inline";
338         }
339   });
340 }
341
342 function mapClicked(overlay, latlng, overlaylatlng) {
343         var baseURL = document.getElementById("baseURL").value;
344   //var url = baseURL + "/gmap_controller.htm?action=singleLeftClick";
345   //var url = baseURL + "report.gmap.single_left_click";
346   var url = baseURL + "/gmapservlet?action=singleLeftClick&nextpage=report.gmap.single_left_click";
347   var mapSize = map.getSize();
348   var mapBounds = map.getBounds();
349   var pointSW = mapBounds.getSouthWest();
350   var pointNE = mapBounds.getNorthEast();
351   url += "&click_longitude=" + latlng.lng();
352   url += "&click_latitude=" + latlng.lat();
353   url += "&zoom_level=" + map.getZoom();
354   url += "&map_size=" + mapSize.width + "," + mapSize.height;
355   url += "&map_bounds=" + pointSW.lng() + "," + pointSW.lat() + "," + pointNE.lng() + "," + pointNE.lat();
356   var point = map.fromLatLngToContainerPixel(latlng);
357   var clickX = point.x;
358   var clickY = point.y;
359   url += "&client_x=" + clickX;
360   url += "&client_y=" + clickY;
361   
362   //document.getElementById("popupmenudiv").style.display = "none";
363   popupDiv.style.display="none";
364   mainInfoDiv.style.display="none";
365   new Ajax.Request(url, {
366         method: 'get',
367         onSuccess: function(transport) {
368                 var jsonData = transport.responseText.evalJSON();
369                         var list = jsonData.list;
370                         var selectedImageURL = jsonData.selectedImageURL;
371                         var legendImageURL = jsonData.legendImageURL;
372                         //alert(legendImageURL);
373                         if (legendImageURL != null) {
374                                 repaintLegend(legendImageURL);
375                         }
376                         
377                         if (list != null) {
378                                 for (var i = popupTable.childNodes.length - 1; i >= 0; i--) {
379                                 popupTable.removeChild(popupTable.lastChild);
380                         }
381         
382                                 for (var i = 0; i < list.length; i++) {
383                                         var tr = popupTable.appendChild(document.createElement("tr"));                  
384                                 var td = tr.appendChild(document.createElement("td"));
385                                 td.appendChild(document.createTextNode("Row : " + list[i].id));
386                                 td.style.border = "solid";
387                                 td.style.borderWidth = "thin";
388                                 td.style.borderRight = "none";
389                                 td.style.borderLeft = "none";
390                                 
391                                 if (i == 0) {
392                                         td.style.borderTop = "none";
393                                 }
394                                 
395                                 if (i == list.length - 1) {
396                                         td.style.borderBottom = "none";
397                                 }
398                                 
399                                 td.style.color = "#0000FF";
400                                 td.style.background = "#FFFFF0";
401                                 td.style.fontSize = "12px";
402                                 td.font = "Arial,Helvetica,sans-serif";
403                                 td.id = jsonData.type + ">>" + list[i].id + ">>" + list[i].type;
404                                 
405                                 td.onmouseover = function(e) {
406                             this.style.background = "#0000FF";
407                             this.style.color = "#FFFFF0";
408                                 }
409                 
410                         td.onmouseout = function(e) {
411                     this.style.background = "#FFFFF0";
412                     this.style.color = "#0000FF";
413           }
414           
415           td.onclick = function(e) {
416                   //var popupDiv = document.getElementById("popupmenudiv");
417                   getInfo(this.id, clickX, clickY);
418                     
419                   popupDiv.style.display = "none";
420                   }
421     }
422                                                         
423         //var popupDiv = document.getElementById("popupmenudiv");
424         popupDiv.style.display = "";
425         
426     var textWidth = popupDiv.offsetWidth;
427     var textHeight = popupDiv.offsetHeight;
428          
429     if (textHeight >= 200) {
430         popupDiv.style.overflow = "auto";
431         popupDiv.style.height = "200px";
432                 textHeight = 200;
433         }
434         
435     if (textWidth >= 250) {
436         popupDiv.style.width = "250px";
437         //textWidth = 250;
438         }
439         
440     var clientX = jsonData.clientX;
441     var clientY = jsonData.clientY;
442         
443     if ((clientX * 1 + textWidth + 20) >= screen.availWidth) {
444         clientX = clientX - textWidth - 20;
445      }
446         
447      if ((clientY * 1 + textHeight) >= document.getElementById("map").offsetHeight) {
448         clientY = document.getElementById("map").offsetHeight - textHeight;
449                   
450      }
451       
452      popupDiv.style.top = clientY + "px";
453      popupDiv.style.left = clientX + "px";
454         }
455         else if (selectedImageURL != null) {
456                 repaintSelected(selectedImageURL);
457         }
458         }
459   });
460 }
461
462 //new changes
463
464 function mapMoveEnd() {
465   if (networkOverlay != null) {
466                 map.removeOverlay(networkOverlay);
467         networkOverlay = null;
468   }
469
470   
471         updateImage(0);
472 }
473
474 function mapDragEnd() {
475 }
476
477 function mapZoomChanged(oldZoomLevel, newZoomLevel) {
478 }
479 /*
480 function updateSelectedImage() {
481         var baseURL = document.getElementById("baseURL").value;
482         var url = baseURL + "/gmap_controller.htm?action=nova.gmap.fetch.selected.image";
483         var mapSize = map.getSize();
484         var mapBounds = map.getBounds();
485         var pointSW = mapBounds.getSouthWest();
486         var pointNE = mapBounds.getNorthEast();
487         url += "&zoomLevel=" + map.getZoom();
488         url += "&mapSize=" + mapSize.width + "," + mapSize.height;
489         url += "&mapBounds=" + pointSW.lng() + "," + pointSW.lat() + "," + pointNE.lng() + "," + pointNE.lat();
490         
491         new Ajax.Request(url, {     
492                 method: 'get',
493                 asynchronous: false,
494                 onSuccess: function(transport) {      
495                         var url = transport.responseXML.getElementsByTagName("image-url")[0].childNodes[0].nodeValue;
496                         
497                         if (url != null) {
498                                 repaintSelected(url);
499                         }
500                 }
501         }); 
502 }
503 */
504
505 function updateImage(incDecValue) {
506         //alert();
507         loadingAnimationDiv.style.display = "inline";
508         var baseURL = document.getElementById("baseURL").value;
509         //var url = baseURL + "/gmap_controller.htm?action=getImage";
510         //var url = baseURL + "report.gmap.get_image";
511         var url = baseURL + "/gmapservlet?action=getImage&nextpage=report.gmap.get_image";
512         var mapSize = map.getSize();
513         var mapBounds = map.getBounds();
514         var pointSW = mapBounds.getSouthWest();
515         var pointNE = mapBounds.getNorthEast();
516         url += "&zoom_level=" + map.getZoom();
517         url += "&map_size=" + mapSize.width + "," + mapSize.height;
518         url += "&map_bounds=" + pointSW.lng() + "," + pointSW.lat() + "," + pointNE.lng() + "," + pointNE.lat();
519         url += "&increment_decrement_value=" + incDecValue;
520         url += "&selected_layer_list=" + document.getElementById("selectedLayerList").value; 
521         url += "&color_list=" + document.getElementById("colorList").value;
522         var randomNumber = Math.floor(Math.random() * 5000000)
523         url += "&dummy=" + randomNumber;
524  
525   //disableUserInput();
526   new Ajax.Request(url, {     
527         method: 'get',          
528         onSuccess: function(transport) {  
529                 
530           loadingAnimationDiv.style.display = "none";
531                 var jsonData = transport.responseText.evalJSON();
532                         var imageURL = jsonData.imageURL;
533                         var legendImageURL = jsonData.legendImageURL;
534                         var selectedImageURL = jsonData.selectedImageURL;
535                         var currentMonth = jsonData.currentMonth;
536                         var colorList = jsonData.colorList;
537                         var selectedLayerList = jsonData.selectedLayerList;
538                         
539                         if (legendImageURL != null) {
540                                 repaintLegend(legendImageURL);
541                         }
542                         if (imageURL != null) {
543                                 repaint(imageURL);
544                         }
545                         
546                         if (selectedImageURL != null) {
547                                 repaintSelected(selectedImageURL);
548                         }
549                 
550                         if (currentMonth != null) {
551                           document.getElementById("currentMonthDiv").innerHTML = currentMonth;
552                         }
553                         
554                         if (colorList != null) {
555                           document.getElementById("colorList").value = colorList;
556                           document.getElementById("selectedLayerList").value = selectedLayerList;
557                           NovaButton.prototype.initializeLayerDiv(NovaButton.globals.layerOptionContainer);
558                         }
559                 
560                 
561         }
562   }); 
563 }
564
565         function repaintLegend(url) {
566                 var mapLegend = document.getElementById("mapLegend");
567                 var legendImg = document.getElementById("legendImg");
568                 
569                 mapLegend.removeChild(legendImg);
570             var newpic=document.createElement('img');
571             newpic.src=url;
572             newpic.id="legendImg";
573             //alert(url);
574             mapLegend.appendChild(newpic);
575               
576         }
577
578
579 function repaint(url) {
580   if (networkOverlay != null) {
581         map.removeOverlay(networkOverlay);
582   }
583   
584   networkOverlay = new ProjectedOverlay(url, map.getBounds()) ;
585   map.addOverlay(networkOverlay);
586 }
587
588 function repaintSelected(url) {
589   var mapBounds = map.getBounds();
590   var pointSW = mapBounds.getSouthWest();
591   var pointNE = mapBounds.getNorthEast();
592   
593   if (selectedNetworkOverlay != null) {
594         map.removeOverlay(selectedNetworkOverlay);      
595   }
596   
597   selectedNetworkOverlay = new GGroundOverlay(url, new GLatLngBounds(pointSW, pointNE)) ;
598   map.addOverlay(selectedNetworkOverlay);
599   
600   if (flashTimeout != null) {
601         clearTimeout(flashTimeout);
602   }
603   
604   flashImage();
605 }
606
607 function flashImage() {
608         if (selectedNetworkOverlay.isHidden()) {
609           selectedNetworkOverlay.show();
610         }
611         else {
612                 selectedNetworkOverlay.hide();
613         }
614         
615         flashTimeout = setTimeout(flashImage, 500);
616 }
617
618 function disableUserInput() {
619         map.disableDragging();
620         map.disableDoubleClickZoom();
621         map.disableScrollWheelZoom();
622         map.disableContinuousZoom();
623 }
624
625 function enableUserInput() {
626         map.enableDragging();
627         map.enableDoubleClickZoom();
628         map.enableScrollWheelZoom();
629         map.enableContinuousZoom();
630 }
631
632 String.prototype.trim = function() {
633   return this.replace(/^\s+|\s+$/g, "");
634 }