1 package com.lamatek.tags.google; 2 3 import java.io.Serializable ; 4 import java.util.Enumeration ; 5 import java.util.Hashtable ; 6 import java.util.Vector ; 7 8 import javax.servlet.jsp.JspWriter ; 9 import javax.servlet.jsp.tagext.BodyTagSupport ; 10 11 import com.lamatek.tags.google.beans.TrafficEventBean; 12 import com.lamatek.tags.google.beans.XMLParser; 13 22 public class GoogleMapTag extends BodyTagSupport implements Serializable , GoogleMapEventListener { 23 24 static final int SMALL_ZOOM_CONTROL = 0; 25 static final int LARGE_ZOOM_CONTROL = 1; 26 Hashtable markers = null; 27 Hashtable points = null; 28 Hashtable polylines = null; 29 Hashtable circles = null; 30 Hashtable polygons = null; 31 Hashtable boxes = null; 32 Hashtable traffic_tags = null; 33 Hashtable overlays = null; 34 Hashtable mapTypes = null; 35 Hashtable wms = null; 36 Vector events = null; 37 Vector labels = null; 38 Vector inserts = null; 39 Hashtable keys = null; 40 boolean showTypeControl = false; 41 boolean showZoomControl = false; 42 boolean showPanControl = true; 43 boolean showScaleControl = false; 44 boolean mouseWheelSupport = false; 45 boolean panEnabled = true; 46 String version = "2"; 47 String id = null; 48 int zoomControlSize = SMALL_ZOOM_CONTROL; 49 String width = null; 50 String height = null; 51 String type = "map"; 52 int zoom = -1; 53 String scope = "page"; 54 double centerLatitude = -181.00d; 55 double centerLongitude = -181.00d; 56 double smallLon = 180.00d; 57 double smallLat = 180.00d; 58 double largeLon = -180.00d; 59 double largeLat = -180.00; 60 String body = ""; 61 GoogleMapMessageTag message = null; 62 GoogleMapOverviewTag overviewControl = null; 63 GoogleMapClusterTag clusterer = null; 64 GoogleMapCoordinatesTag coords = null; 65 String xml = null; 66 boolean debug = false; 67 boolean headless = false; 68 int minZoom = 0; 69 int maxZoom = 17; 70 boolean bound = false; 71 String language = "en"; 72 boolean showDaylight = false; 73 77 public int doStartTag() { 78 if (scope.equalsIgnoreCase("site")) { 79 if (pageContext.getSession().getAttribute(id) == null) { 80 if (xml != null) { 81 parseXML(); 82 } 83 return EVAL_BODY_INCLUDE; 84 } 85 } 86 else { 87 if (pageContext.getAttribute(id) == null) { 88 if (xml != null) { 89 parseXML(); 90 } 91 return EVAL_BODY_INCLUDE; 92 } 93 } 94 return SKIP_BODY; 95 } 96 100 private void parseXML() { 101 XMLParser.parseXML(xml, this); 102 } 103 107 public int doEndTag() { 108 if (scope.equalsIgnoreCase("site")) { 109 if (pageContext.getSession().getAttribute(id) == null) 110 pageContext.getSession().setAttribute(id, this); 111 } 112 else { 113 if (pageContext.getAttribute(id) == null) 114 pageContext.setAttribute(id, this); 115 } 116 return EVAL_PAGE; 117 } 118 123 public void addMarker(GoogleMapMarkerTag marker) { 124 if (markers == null) 125 markers = new Hashtable (); 126 markers.put(marker.getId(), marker); 127 } 128 133 public void removeMarker(GoogleMapMarkerTag marker) { 134 if (markers != null && marker != null) { 135 markers.remove(marker.getId()); 136 } 137 } 138 144 public GoogleMapMarkerTag getMarker(String name) { 145 if (markers != null) { 146 return (GoogleMapMarkerTag) markers.get(name); 147 } 148 else { 149 return null; 150 } 151 } 152 157 public void addMapType(GoogleMapMapTypeTag mapType) { 158 if (mapTypes == null) 159 mapTypes = new Hashtable (); 160 mapTypes.put(mapType.getId(), mapType); 161 } 162 168 public GoogleMapMapTypeTag getMapType(String id) { 169 if (mapTypes == null) 170 return null; 171 else 172 return (GoogleMapMapTypeTag) mapTypes.get(id); 173 } 174 179 public void removeMapType(String id) { 180 if (mapTypes != null) 181 mapTypes.remove(id); 182 } 183 189 public GoogleMapBoxTag getBox(String name) { 190 if (boxes != null) 191 return (GoogleMapBoxTag) boxes.get(name); 192 else 193 return null; 194 } 195 201 public GoogleMapCircleTag getCircle(String name) { 202 if (circles != null) 203 return (GoogleMapCircleTag) circles.get(name); 204 else 205 return null; 206 } 207 213 public GoogleMapImageOverlayTag getImageOverlay(String name) { 214 if (overlays == null) 215 return null; 216 else 217 return (GoogleMapImageOverlayTag) overlays.get(name); 218 } 219 225 public GoogleMapPolygonTag getPolygon(String name) { 226 if (polygons != null) 227 return (GoogleMapPolygonTag) polygons.get(name); 228 else 229 return null; 230 } 231 237 public GoogleMapPolylineTag getPolyline(String name) { 238 if (polylines != null) 239 return (GoogleMapPolylineTag) polylines.get(name); 240 else 241 return null; 242 } 243 250 public void addPoint(GoogleMapPointTag point) { 251 if (points == null) 252 points = new Hashtable (); 253 points.put(point.getId(), point); 254 if (point.getLatitude() < smallLat) 255 smallLat = point.getLatitude(); 256 if (point.getLatitude() > largeLat) 257 largeLat = point.getLatitude(); 258 if (point.getLongitude() < smallLon) 259 smallLon = point.getLongitude(); 260 if (point.getLongitude() > largeLon) 261 largeLon = point.getLongitude(); 262 } 263 268 public void addCircle(GoogleMapCircleTag circle) { 269 if (circles == null) 270 circles = new Hashtable (); 271 circles.put(circle.getId(), circle); 272 } 273 278 public void addImageOverlay(GoogleMapImageOverlayTag image) { 279 if (overlays == null) 280 overlays = new Hashtable (); 281 overlays.put(image.getId(), image); 282 } 283 288 public void addTraffic_tag(GoogleMapTrafficTag traffic) { 289 if (traffic_tags == null) 290 traffic_tags = new Hashtable (); 291 traffic_tags.put(traffic.getId(), traffic); 292 } 293 298 public void addPolygon(GoogleMapPolygonTag polygon) { 299 if (polygons == null) { 300 polygons = new Hashtable (); 301 } 302 polygons.put(polygon.getId(), polygon); 303 } 304 309 public void addPolyline(GoogleMapPolylineTag polyline) { 310 if (polylines == null) 311 polylines = new Hashtable (); 312 polylines.put(polyline.getId(), polyline); 313 } 314 319 public void addBox(GoogleMapBoxTag box) { 320 if (boxes == null) 321 boxes = new Hashtable (); 322 boxes.put(box.getId(), box); 323 } 324 329 public void addEvent(GoogleMapEventTag event) { 330 if (events == null) 331 events = new Vector (); 332 events.add(event); 333 } 334 339 public void addKey(GoogleMapKeyTag key) { 340 if (keys == null) 341 keys = new Hashtable (); 342 keys.put(key.domain, key.key); 343 } 344 349 public void setPanControl(GoogleMapPanControlTag control) { 350 showPanControl = control.isEnable(); 351 panEnabled = control.isEnable(); 352 } 353 358 public void setWheelControl(GoogleMapWheelControlTag control) { 359 mouseWheelSupport = control.isEnable(); 360 } 361 366 public void setTypeControl(GoogleMapTypeControlTag control) { 367 showTypeControl = control.isEnable(); 368 } 369 374 public void setScaleControl(GoogleMapScaleControlTag control) { 375 showScaleControl = control.isEnable(); 376 } 377 382 public void setZoomControl(GoogleMapZoomControlTag control) { 383 if (control.getSize().equalsIgnoreCase("small")) { 384 zoomControlSize = SMALL_ZOOM_CONTROL; 385 } 386 else if (control.getSize().equalsIgnoreCase("large")) { 387 zoomControlSize = LARGE_ZOOM_CONTROL; 388 } 389 showZoomControl = control.isEnable(); 390 } 391 396 public void setHeight(String height) { 397 this.height = height; 398 } 399 406 public void setId(String id) { 407 this.id = id; 408 } 409 414 public void setType(String type) { 415 this.type = type; 416 } 417 424 public void setVersion(String version) { 425 this.version = version; 426 } 427 432 public void setWidth(String width) { 433 this.width = width; 434 } 435 443 public void setMouseWheelSupport(boolean mouseWheelSupport) { 444 this.mouseWheelSupport = mouseWheelSupport; 445 } 446 453 public void setShowPanControl(boolean showPanControl) { 454 this.showPanControl = showPanControl; 455 } 456 463 public void setShowTypeControl(boolean showTypeControl) { 464 this.showTypeControl = showTypeControl; 465 } 466 473 public void setShowZoomControl(boolean showZoomControl) { 474 this.showZoomControl = showZoomControl; 475 } 476 481 public void setZoom(int zoom) { 482 this.zoom = zoom; 483 } 484 491 public void setScope(String scope) { 492 this.scope = scope; 493 } 494 501 public void setBody(String body) { 502 this.body = body; 503 } 504 510 public void setCenterLatitude(double latitude) { 511 this.centerLatitude = latitude; 512 } 513 519 public void setCenterLongitude(double longitude) { 520 this.centerLongitude = longitude; 521 } 522 529 public void generateDivTag(GoogleMapDivTag div) { 530 try { 531 JspWriter out = pageContext.getOut(); 532 String w_unit = "px"; 533 String h_unit = "px"; 534 if (width != null && (width.indexOf("%") > 0 || width.indexOf("px") > 0)) 535 w_unit = ""; 536 if (height != null && (height.indexOf("%") > 0 || height.indexOf("px") > 0)) 537 h_unit = ""; 538 out.print("<div id=\"" + id + "\""); 539 if (div.getStyle() != null) { 540 out.print(" style=\""); 541 if (width != null) { 542 out.print("width: " + width + w_unit + ";"); 543 } 544 if (height != null) { 545 out.print("height: " + height + h_unit + ";"); 546 } 547 out.print(div.getStyle() + "\""); 548 } 549 else { 550 out.print(" style=\"width: " + width + w_unit + "; height: " + height + h_unit + ";\""); 551 } 552 if (div.getCss_class() != null) { 553 out.print(" class=\"" + div.getCss_class() + "\""); 554 } 555 out.print(">"); 556 out.print(body); 557 out.println("</div>"); 558 if (message != null) { 559 out.print("<div id=\"message_div\" "); 560 if (message.getStyle() != null) { 561 out.print(" style=\"" + message.getStyle() + "; visibility: hidden;\">"); 562 } 563 else { 564 out.print(" style=\"border: 1px dotted #660000; background-color: #ffffff; color: #000000; opacity: .75; filter: alpha(opacity=75); visibility: hidden;\">"); 565 } 566 out.println("</div>"); 567 } 568 if (overlays != null) { 569 Enumeration names = overlays.keys(); 570 while (names.hasMoreElements()) { 571 GoogleMapImageOverlayTag image = (GoogleMapImageOverlayTag) overlays.get(names.nextElement()); 572 out.print("<div id=\"" + image.getId() + "\" style=\"opacity: " + image.getOpacity() + "; filter: alhpa(opacity=" + (image.getOpacity() * 100) + "); visibility: hidden;\">"); 573 if (image.getLink() != null) { 574 out.print("<a HREF=\"" + image.getLink() + "\">"); 575 } 576 out.print("<img SRC=\"" + image.getUrl() + "\" border=\"0\"/>"); 577 if (image.getLink() != null) { 578 out.print("</a>"); 579 } 580 out.println("</div>"); 581 } 582 } 583 if (coords != null) { 584 out.print("<div id=\"_coords\""); 585 if (coords.getStyle() != null) 586 out.print(" style=\"" + coords.getStyle() + "; visibility: hidden;\""); 587 else 588 out.print(" style=\"visibility: hidden;\""); 589 if (coords.getCss_class() != null) 590 out.print(" class=\"" + coords.getCss_class() + "\""); 591 out.println("></div>"); 592 } 593 } 594 catch(Exception ex) { 595 ex.printStackTrace(System.err); 596 } 597 } 598 602 public void generateScriptTag() { 603 try { 604 JspWriter out = pageContext.getOut(); 605 String domain = pageContext.getRequest().getServerName(); 606 if (keys != null) { 607 String key = (String ) keys.get(domain); 608 if (key == null) { 610 Enumeration domains = keys.keys(); 611 while (domains.hasMoreElements()) { 612 String domainName = (String ) domains.nextElement(); 613 if (domainName.indexOf(domain) >= 0) 614 key = (String ) keys.get(domainName); 615 } 616 } 617 if (key == null) { 619 System.err.println("ERROR: Unable to locate GoogleMaps API key for domain " + domain); 620 } 621 else { 622 out.println("<script SRC=\"http://maps.google.com/maps?file=api&v=" + version + "&key=" + key + "&hl=" + language + "\" type=\"text/javascript\"></script>"); 623 if (clusterer != null) { 624 out.println("<script SRC=\"" + clusterer.getPathToScript() + "\" type=\"text/javascript\"></script>"); 625 } 626 if (wms != null) { 627 GoogleMapWMSTag tag = (GoogleMapWMSTag) wms.elements().nextElement(); 628 out.println("<script SRC=\"" + tag.getPathToScript() + "\" type=\"text/javascript\"></script>"); 629 } 630 if (showDaylight) { 631 out.println("<script SRC=\"http://www.daylightmap.com/daylight.js\" type=\"text/javascript\"></script>"); 632 } 633 } 634 } 635 else { 636 System.err.println("ERROR: No GoogleMap API keys were registered."); 637 } 638 } 639 catch(Exception ex) { 640 ex.printStackTrace(System.err); 641 } 642 } 643 647 public void generateInitializationCode() { 648 try { 649 JspWriter out = pageContext.getOut(); 650 out.println("<script type=\"text/javascript\">"); 651 out.println("//<![CDATA["); 652 out.println("initializeMap" + id + "();"); 653 if (mouseWheelSupport) { 654 if (version.indexOf("1") == 0) { 655 out.println("hookMouseWheelHandlers(\"" + id + "\")"); 656 } 657 else if (version.indexOf("2") == 0) { 658 } 660 } 661 out.println("//]]>"); 662 out.println("</script>"); 663 } 664 catch(Exception ex) { 665 ex.printStackTrace(System.err); 666 } 667 } 668 672 public void generateJavascript() { 673 try { 674 JspWriter out = pageContext.getOut(); 675 out.println("<style type=\"text/css\">"); 677 out.println("\tv\\:* {"); 678 out.println("\t\tbehavior:url(#default#VML);"); 679 out.println("\t}"); 680 out.println("</style>"); 681 out.println("<script type=\"text/javascript\">"); 683 out.println("//<![CDATA["); 684 out.println("var " + id + ";"); 685 out.println("var lastCenterLat;"); 686 out.println("var lastCenterLon;"); 687 out.println("var lastClick = new Date();"); 688 if (inserts != null && version.indexOf("2") == 0) { 689 for (int i = 0; i < inserts.size(); i++) { 690 out.println("var " + ((GoogleMapInsertTag) inserts.elementAt(i)).getId() + ";"); 691 } 692 } 693 out.println("if(document.implementation.hasFeature(\"http://www.w3.org/TR/SVG11/feature#SVG\",\"1.1\")) {"); 694 out.println("\t_mSvgEnabled = true;"); 695 out.println("\t_mSvgForced = true;"); 696 out.println("}"); 697 out.println("function isDouble() {"); 698 out.println("\tvar now = new Date();"); 699 out.println("\tvar double_click = ((now.getTime() - lastClick.getTime()) < 500);"); 700 out.println("\tlastClick = now;"); 701 out.println("\treturn double_click;"); 702 out.println("}"); 703 if (message != null) { 704 out.println("function showMessage() {"); 705 if (debug && version.indexOf("2") == 0) { 706 out.println("\tGLog.write('Displaying message panel.');"); 707 } 708 out.println("\tvar message_div = document.getElementById(\"message_div\");"); 709 out.println("\tvar google_map = document.getElementById(\"" + id + "\");"); 710 out.println("\tif (message_div != null && google_map != null) {"); 711 out.println("\t\tmessage_div.innerHTML = \"" + message.getMessage() + "\";"); 712 out.println("\t\tgoogle_map.appendChild(message_div);"); 713 out.println("\t\tmessage_div.style.zIndex = parseInt(google_map.style.zIndex + 1);"); 714 out.println("\t\tmessage_div.style.position = 'absolute';"); 715 out.println("\t\tmessage_div.style.top = ((google_map.offsetHeight - message_div.offsetHeight) / 2) + \"px\";"); 716 out.println("\t\tmessage_div.style.left = ((google_map.offsetWidth - message_div.offsetWidth) / 2) + \"px\";"); 717 out.println("\t\tmessage_div.style.visibility = 'visible';"); 718 out.println("\t}"); 719 out.println("}"); 720 out.println("function hideMessage() {"); 721 if (debug && version.indexOf("2") == 0) { 722 out.println("\tGLog.write('Hiding message panel.');"); 723 } 724 out.println("\tvar message_div = document.getElementById(\"message_div\");"); 725 out.println("\tif (message_div != null) {"); 726 out.println("\t\tmessage_div.style.zIndex = 0;"); 727 out.println("\t\tmessage_div.style.visibility = 'hidden';"); 728 out.println("\t}"); 729 out.println("}"); 730 } 731 if (overlays != null) { 732 out.println("function showImageOverlay(image_id, x, y) {"); 733 out.println("\tvar image_div = document.getElementById(image_id);"); 734 out.println("\tvar google_map = document.getElementById(\"" + id + "\");"); 735 out.println("\t\tgoogle_map.appendChild(image_div);"); 736 out.println("\timage_div.style.zIndex = 100;"); 737 out.println("\timage_div.style.position = 'absolute';"); 738 out.println("\timage_div.style.top = y + \"px\";"); 739 out.println("\timage_div.style.left = x + \"px\";"); 740 out.println("\timage_div.style.visibility = 'visible';"); 741 out.println("}"); 742 } 743 if (coords != null && version.indexOf("2") == 0) { 744 out.println("function showCoordinates(x, y) {"); 745 out.println("\tvar coords = document.getElementById(\"_coords\");"); 746 out.println("\tvar google_map = document.getElementById(\"" + id + "\");"); 747 out.println("\tgoogle_map.appendChild(coords);"); 748 out.println("\tcoords.style.zIndex = 100;"); 749 out.println("\tcoords.style.position = 'absolute';"); 750 out.println("\tcoords.style.top = y + \"px\";"); 751 out.println("\tcoords.style.left = x + \"px\";"); 752 out.println("\tcoords.style.visibility = 'visible';"); 753 out.println("}"); 754 out.println("function updateCoordinates(lon, lat) {"); 755 out.println("\tvar coords = document.getElementById(\"_coords\");"); 756 out.println("\tcoords.innerHTML = \"Lon: \" + lon + \"°W Lat: \" + lat + \"°N\";"); 757 out.println("}"); 758 } 759 if (mapTypes != null) { 760 if (version.indexOf("1") == 0) { 761 out.println("function copyObject(original) {"); 762 out.println("\tvar object = new Object();"); 763 out.println("\tfor (var e in original) {"); 764 out.println("\t\tobject[e] = original[e];"); 765 out.println("\t}"); 766 out.println("\treturn object;"); 767 out.println("}"); 768 } 769 } 770 if (labels != null) { 771 if (version.indexOf("2") == 0) { 772 out.println("function Label(point, content, opacity, css_class, xOffset, yOffset) {"); 773 out.println("\tthis.point = point;"); 774 out.println("\tthis.content = content || \"\";"); 775 out.println("\tthis.css_class = css_class || \"\";"); 776 out.println("\tthis.opacity = opacity || 0.50;"); 777 out.println("\tthis.xOffset = xOffset || 0;"); 778 out.println("\tthis.yOffset = yOffset || 0;"); 779 out.println("}"); 780 out.println("Label.prototype = new GOverlay();"); 781 out.println("Label.prototype.initialize = function (googleMap) {"); 782 out.println("\tvar div = document.createElement(\"div\");"); 783 out.println("\tdiv.style.position = \"absolute\";"); 784 out.println("\tdiv.innerHTML = '<div class=\"' + this.css_class + '\">' + this.content + '</div>';"); 785 out.println("\tgoogleMap.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div);"); 786 out.println("\tthis.map_ = googleMap;"); 787 out.println("\tthis.div_ = div;"); 788 out.println("\tif(typeof(div.style.filter)=='string'){div.style.filter='alpha(opacity:'+(this.opacity*100)+')';}"); 789 out.println("\tif(typeof(div.style.KHTMLOpacity)=='string'){div.style.KHTMLOpacity=this.opacity;}"); 790 out.println("\tif(typeof(div.style.MozOpacity)=='string'){div.style.MozOpacity=this.opacity;}"); 791 out.println("\tif(typeof(div.style.opacity)=='string'){div.style.opacity=this.opacity;}"); 792 out.println("}"); 793 out.println("Label.prototype.remove = function() {"); 794 out.println("\tthis.div_.parentNode.removeChild(this.div_);"); 795 out.println("}"); 796 out.println("Label.prototype.copy = function() {"); 797 out.println("\treturn new Label(this.point, this.content, this.css_class, this.opacity);"); 798 out.println("}"); 799 out.println("Label.prototype.redraw = function(force) {"); 800 out.println("\tvar p = this.map_.fromLatLngToDivPixel(this.point);"); 801 out.println("\tvar h = parseInt(this.div_.clientHeight);"); 802 out.println("\tthis.div_.style.left = (p.x + this.xOffset) + \"px\";"); 803 out.println("\tthis.div_.style.top = ((p.y + this.yOffset) - h) + \"px\";"); 804 out.println("}"); 805 } 806 } 807 if (inserts != null) { 808 if (version.indexOf("2") == 0) { 809 out.println("function Insert(point, image, size, basezoom) {"); 810 out.println("\tthis.point = point;"); 811 out.println("\tthis.image = image;"); 812 out.println("\tthis.size = size;"); 813 out.println("\tthis.basezoom = basezoom;"); 814 out.println("\tvar agent = navigator.userAgent.toLowerCase();"); 815 out.println("}"); 816 out.println("Insert.prototype = new GOverlay();"); 817 out.println("Insert.prototype.initialize = function(map) {"); 818 out.println("\tvar div = document.createElement(\"div\");"); 819 out.println("\tdiv.style.position = \"absolute\";"); 820 out.println("\tmap.getPane(G_MAP_MAP_PANE).appendChild(div);"); 821 out.println("\tthis.map_ = map;"); 822 out.println("\tthis.div_ = div;"); 823 out.println("}"); 824 out.println("Insert.prototype.remove = function() {"); 825 out.println("\tthis.div_.parentNode.removeChild(this.div_);"); 826 out.println("}"); 827 out.println("Insert.prototype.copy = function() {"); 828 out.println("\treturn new Insert(this.point, this.image, this.size, this.basezoom);"); 829 out.println("}"); 830 out.println("Insert.prototype.redraw = function(force) {"); 831 out.println("\tif (force) {"); 832 out.println("\t\tvar p = this.map_.fromLatLngToDivPixel(this.point);"); 833 out.println("\t\tvar z = this.map_.getZoom();"); 834 out.println("\t\tvar scale = 1;"); 835 out.println("\t\tif (z > this.basezoom) {"); 836 out.println("\t\t\tscale = Math.pow(2, (z - this.basezoom));"); 837 out.println("\t\t}"); 838 out.println("\t\telse if (this.basezoom > z) {"); 839 out.println("\t\t\tscale = 1 / Math.pow(2, (this.basezoom - z));"); 840 out.println("\t\t}"); 841 out.println("\t\tvar h=this.size.height * scale;"); 842 out.println("\t\tvar w=this.size.width * scale;"); 843 out.println("\t\tthis.div_.style.left = (p.x - w/2) + \"px\";"); 844 out.println("\t\tthis.div_.style.top = (p.y - h/2) + \"px\";"); 845 out.println("\t\tthis.div_.innerHTML = '<img SRC=\"' +this.image+ '\" width='+w+' height='+h+' >';"); 846 out.println("\t\tthis.div_.style.zIndex = -1;"); 847 out.println("\t}"); 848 out.println("}"); 849 out.println("Insert.prototype.show = function() {"); 850 out.println("\tthis.div_.style.display=\"\";"); 851 out.println("}"); 852 out.println("Insert.prototype.hide = function() {"); 853 out.println("\tthis.div_.style.display=\"none\";"); 854 out.println("}"); 855 } 856 } 857 if (overviewControl != null && overviewControl.wasPlaced() && (version.compareTo("2.41") >= 0 || version.equals("2"))) { 858 out.println("function positionOverview(x,y) {"); 859 if (debug && version.indexOf("2") == 0) { 860 out.println("\tGLog.write('Positioning overview control.');"); 861 } 862 out.println("\tvar overview = document.getElementById(\"" + id + "_overview\");"); 863 out.println("\tvar google_map = document.getElementById(\"" + id + "\");"); 864 out.println("\ttry {"); 865 out.println("\t\toverview.style.left = (x) + \"px\";"); 866 out.println("\t\toverview.style.top = (y) + \"px\";"); 867 out.println("\t\toverview.style.position = 'absolute';"); 868 out.println("\t}"); 869 out.println("\tcatch (e) {"); 870 out.println("\t\talert(e);"); 871 out.println("\t}"); 872 out.println("}"); 873 } 874 if (version.indexOf("2") == 0) { 875 out.println("function setZoomLevels() {"); 876 out.println("\tvar mapTypes = " + id + ".getMapTypes();"); 877 out.println("\tfor (var i = 0; i < mapTypes.length; i++) {"); 878 out.println("\t\tmapTypes[i].getMinimumResolution = function() {"); 879 out.println("\t\t\treturn " + minZoom + ";"); 880 out.println("\t\t}"); 881 out.println("\t\tmapTypes[i].getMaximumResolution = function() {"); 882 out.println("\t\t\treturn " + maxZoom + ";"); 883 out.println("\t\t}"); 884 out.println("\t}"); 885 out.println("}"); 886 if (bound) { 887 out.println("var allowedBounds;"); 888 out.println("function checkBounds() {"); 889 out.println("\tif (allowedBounds.contains(" + id + ".getCenter())) {"); 890 out.println("\t\treturn;"); 891 out.println("\t}"); 892 out.println("\telse {"); 893 out.println("\t\tvar C = " + id + ".getCenter();"); 894 out.println("\t\tvar X = C.lng();"); 895 out.println("\t\tvar Y = C.lat();"); 896 out.println("\t\tvar AmaxX = allowedBounds.getNorthEast().lng();"); 897 out.println("\t\tvar AmaxY = allowedBounds.getNorthEast().lat();"); 898 out.println("\t\tvar AminX = allowedBounds.getSouthWest().lng();"); 899 out.println("\t\tvar AminY = allowedBounds.getSouthWest().lat();"); 900 out.println("\t\tif (X < AminX) {X = AminX;}"); 901 out.println("\t\tif (X > AmaxX) {X = AmaxX;}"); 902 out.println("\t\tif (Y < AminY) {Y = AminY;}"); 903 out.println("\t\tif (Y > AmaxY) {Y = AmaxY;}"); 904 out.println("\t\t" + id + ".setCenter(new GLatLng(Y,X));"); 905 out.println("\t}"); 906 out.println("}"); 907 } 908 } 909 out.println("function initializeMap" + id + "() {"); 910 out.println("\tif (GBrowserIsCompatible()) {"); 911 if (debug && version.indexOf("2") == 0) { 912 out.println("\t\tGLog.write('Initializing GMap with id " + id + ".');"); 913 } 914 out.println("\t\t" + id + " = new GMap(document.getElementById(\"" + id + "\"));"); 915 if (message != null) { 916 out.println("\t\tshowMessage();"); 917 } 918 if (showDaylight) { 919 if (debug && version.indexOf("2") == 0) { 920 out.println("\t\tGLog.write('Initializing daylight map for map " + id + "');"); 921 } 922 out.println("\t\tvar daylight = new daylightLayer();"); 923 out.println("\t\tdaylight.addToMap(" + id + ");"); 924 } 925 if (debug && version.indexOf("2") == 0) { 926 out.println("\t\tGLog.write('Setting initial map type to " + type + " for map " + id + "');"); 927 } 928 if (type.equalsIgnoreCase("hybrid")) { 929 out.println("\t\t" + id + ".setMapType(G_HYBRID_TYPE);"); 930 } 931 else if (type.equalsIgnoreCase("satellite")) { 932 out.println("\t\t" + id + ".setMapType(G_SATELLITE_TYPE);"); 933 } 934 else { 935 out.println("\t\t" + id + ".setMapType(G_MAP_TYPE);"); 936 } 937 if (clusterer != null) { 938 if (debug && version.indexOf("2") == 0) { 939 out.println("\t\tGLog.write('Initializing clusterer " + id + "_cluster.');"); 940 } 941 out.println("\t\tvar " + id + "_cluster = new Clusterer(" + id + ", " + debug + ");"); 942 if (clusterer.getIcon() != null) { 943 GoogleMapIconTag icon = clusterer.getIcon(); 944 if (debug && version.indexOf("2") == 0) { 945 out.println("\t\tGLog.write('Creating custom clusterer icons.');"); 946 } 947 out.println("\t\tvar " + id + "_cluster_icon = new GIcon();"); 948 out.println("\t\t" + id + "_cluster_icon.image = '" + icon.getIcon() + "';"); 949 out.println("\t\t" + id + "_cluster_icon.iconSize = new GSize(" + icon.getIconWidth() + ", " + icon.getIconHeight() + ");"); 950 out.println("\t\t" + id + "_cluster_icon.iconAnchor = new GPoint(" + icon.getAnchorX() + ", " + icon.getAnchorY() + ");"); 951 out.println("\t\t" + id + "_cluster_icon.infoWindowAnchor = new GPoint(" + icon.getInfoWindowAnchorX() + ", " + icon.getInfoWindowAnchorY() + ");"); 952 if (icon.getShadow() != null) { 953 out.println("\t\t" + id + "_cluster_icon.shadow = '" + icon.getShadow() + "';"); 954 out.println("\t\t" + id + "_cluster_icon.shadowSize = new GSize(" + icon.getShadowWidth() + ", " + icon.getShadowHeight() + ");"); 955 } 956 out.println("\t\t" + id + "_cluster.SetIcon(" + id + "_cluster_icon);"); 957 } 958 out.println("\t\t" + id + "_cluster.maxVisibleMarkers = " + clusterer.getMaxVisibleMarkers() + ";"); 959 out.println("\t\t" + id + "_cluster.minMarkersPerCluster = " + clusterer.getMarkersPerCluster() + ";"); 960 out.println("\t\t" + id + "_cluster.gridSize = " + clusterer.getGridSize() + ";"); 961 } 962 if (wms != null && version.indexOf("1") == 0) { 963 Enumeration names = wms.keys(); 964 while (names.hasMoreElements()) { 965 GoogleMapWMSTag tag = (GoogleMapWMSTag) wms.get(names.nextElement()); 966 if (debug && version.indexOf("2") == 0) { 967 out.println("\t\tGLog.write('Adding wms map " + tag.getId() + "');"); 968 } 969 out.println("\t\tvar " + tag.getId() + " = new WMSSpec(" + id + ", '" + tag.getUrl() + "', '" + tag.getName() + "', '" + tag.getName() + "', '" + tag.getLayers() + "', '" + tag.getSrs() + "', '" + tag.getVersion() + "', 'default', '" + tag.getFormat() + "', '" + tag.getCopyright() + "');"); 970 if (tag.isShowOverlay()) { 971 if (debug && version.indexOf("2") == 0) { 972 out.println("\t\tGLog.write('Setting overlay for wms map " + tag.getId() + "');"); 973 } 974 out.println("\t\t" + tag.getId() + ".OverlaySpec = " + id + ".mapTypes[2];"); 975 } 976 out.println("\t\t" + id + ".mapTypes[" + id + ".mapTypes.length] = " + tag.getId() + ";"); 977 if (tag.isShowOnStartup()) { 978 if (debug && version.indexOf("2") == 0) { 979 out.println("\t\tGLog.write('Setting Google Map to initially display wms map " + tag.getId() + "');"); 980 } 981 out.println("\t\t" + id + ".setMapType(" + id + ".mapTypes[" + id + ".mapTypes.length-1]);"); 982 } 983 } 984 } 985 else if (wms != null && version.indexOf("2") == 0) { 986 Enumeration names = wms.keys(); 987 while (names.hasMoreElements()) { 988 GoogleMapWMSTag tag = (GoogleMapWMSTag) wms.get(names.nextElement()); 989 if (debug && version.indexOf("2") == 0) { 990 out.println("\t\tGLog.write('Adding wms map " + tag.getId() + "');"); 991 } 992 out.println("\t\tvar " + tag.getId() + " = new WMSSpec(" + id + ", '" + tag.getUrl() + "', '" + tag.getName() + "', '" + tag.getName() + "', '" + tag.getLayers() + "', '" + tag.getSrs() + "', '" + tag.getVersion() + "', 'default', '" + tag.getFormat() + "', '" + tag.getCopyright() + "');"); 993 999 out.println("\t\tvar layer_" + tag.getId() + " = [" + tag.getId() + "];"); 1000 1003 out.println("\t\tvar map_" + tag.getId() + " = new GMapType(layer_" + tag.getId() + ", G_SATELLITE_MAP.getProjection(), \"" + tag.getName() + "\", G_SATELLITE_MAP);"); 1004 out.println("\t\t" + id + ".addMapType(map_" + tag.getId() + ");"); 1005 if (tag.isShowOnStartup()) { 1006 if (debug && version.indexOf("2") == 0) { 1007 out.println("\t\tGLog.write('Setting Google Map to initially display wms map " + tag.getId() + "');"); 1008 } 1009 out.println("\t\t" + id + ".setMapType(map_" + tag.getId() + ");"); 1010 } 1011 } 1012 } 1013 if (mapTypes != null) { 1014 if (version.indexOf("1") == 0) { 1015 Enumeration names = mapTypes.keys(); 1016 while (names.hasMoreElements()) { 1017 GoogleMapMapTypeTag type = (GoogleMapMapTypeTag) mapTypes.get(names.nextElement()); 1018 if (debug && version.indexOf("2") == 0) { 1019 out.println("\t\tGLog.write('Adding custom map " + type.getId() + "');"); 1020 } 1021 int parentType = 0; 1022 if (type.getBaseType().equals("satellite")) 1023 parentType = 1; 1024 else if (type.getBaseType().equals("hybrid")) 1025 parentType = 2; 1026 if (debug && version.indexOf("2") == 0) { 1027 out.println("\t\tGLog.write('Copying base map type " + parentType + " into map " + type.getId() + "');"); 1028 } 1029 out.println("\t\tvar " + type.getId() + " = copyObject(" + id + ".mapTypes[" + parentType + "]);"); 1030 if (type.getUrl() != null) { 1031 if (debug && version.indexOf("2") == 0) { 1032 out.println("\t\tGLog.write('Setting base tile url to " + type.getUrl() + " for map " + type.getId() + "');"); 1033 } 1034 out.println("\t\t" + type.getId() + ".baseUrls = new Array();"); 1035 out.println("\t\t" + type.getId() + ".baseUrls[0]=\"" + type.getUrl() + "?\";"); 1036 } 1037 if (type.getLowResUrl() != null) { 1038 if (debug && version.indexOf("2") == 0) { 1039 out.println("\t\tGLog.write('Setting lowres tile url to " + type.getLowResUrl() + " for map " + type.getId() + "');"); 1040 } 1041 out.println("\t\t" + type.getId() + ".lowResBaseUrls = new Array();"); 1042 out.println("\t\t" + type.getId() + ".lowResBaseUrls[0]=\"" + type.getLowResUrl() + "?\";"); 1043 } 1044 if (type.getOverlayUrl() != null) { 1045 if (debug && version.indexOf("2") == 0) { 1046 out.println("\t\tGLog.write('Setting overlay tile url to " + type.getOverlayUrl() + " for map " + type.getId() + "');"); 1047 } 1048 out.println("\t\t" + type.getId() + ".overlayBaseUrls = new Array();"); 1049 out.println("\t\t" + type.getId() + ".overlayBaseUrls[0]=\"" + type.getOverlayUrl() + "?\";"); 1050 } 1051 if (type.getCopyright() != null) { 1052 if (debug && version.indexOf("2") == 0) { 1053 out.println("\t\tGLog.write('Setting copyright for map " + type.getId() + "');"); 1054 } 1055 out.println("\t\t" + type.getId() + ".getCopyright = function() {"); 1056 out.println("\t\t\treturn '" + type.getCopyright() + "';"); 1057 out.println("\t\t}"); 1058 } 1059 if (type.getMaxZoom() >= 0) { 1060 if (debug && version.indexOf("2") == 0) { 1061 out.println("\t\tGLog.write('Setting max zoom to " + type.getMaxZoom() + " for map " + type.getId() + "');"); 1062 } 1063 out.println("\t\t" + type.getId() + ".getMaxZoomLevel = function() {"); 1064 out.println("\t\t\treturn " + type.getMaxZoom() + ";"); 1065 out.println("\t\t}"); 1066 } 1067 if (type.getBaseType() != null) { 1068 String base = "G_MAP_TYPE"; 1069 if (type.getBaseType().equals("satellite")) 1070 base = "G_SATELLITE_MAP"; 1071 else if (type.getBaseType().equals("hybrid")) 1072 base = "G_HYBRID_TYPE"; 1073 if (debug && version.indexOf("2") == 0) { 1074 out.println("\t\tGLog.write('Setting alternative map type to " + base + " for map " + type.getId() + "');"); 1075 } 1076 out.println("\t\t" + type.getId() + ".getAlternativeMapType = function() {"); 1077 out.println("\t\t\treturn " + base + ";"); 1078 out.println("\t\t}"); 1079 } 1080 if (type.getLowerRightBound() != null && type.getUpperLeftBound() != null && points != null) { 1081 GoogleMapPointTag ul = (GoogleMapPointTag) points.get(type.getUpperLeftBound()); 1082 GoogleMapPointTag lr = (GoogleMapPointTag) points.get(type.getLowerRightBound()); 1083 if (ul != null && lr != null) { 1084 out.println("\t\t" + type.getId() + ".bounds = new GBounds(" + ul.getLongitude() + "," + ul.getLatitude() + "," + lr.getLongitude() + "," + lr.getLatitude() + ");"); 1085 out.println("\t\t" + type.getId() + ".getBounds = function() {"); 1086 out.println("\t\t\treturn this.bounds;"); 1087 out.println("\t\t}"); 1088 } 1089 } 1090 out.println("\t\t" + type.getId() + ".getLinkText = function() {"); 1091 out.println("\t\t\treturn '" + type.getName() + "';"); 1092 out.println("\t\t}"); 1093 out.println("\t\t" + id + ".mapTypes[" + id + ".mapTypes.length] = " + type.getId() + ";"); 1094 if (type.isShowOnStartup()) { 1095 if (debug && version.indexOf("2") == 0) { 1096 out.println("\t\tGLog.write('Setting Google Map to initially display custom map " + type.getId() + "');"); 1097 } 1098 out.println("\t\t" + id + ".setMapType(" + id + ".mapTypes[" + id + ".mapTypes.length-1]);"); 1099 } 1100 } 1101 } 1102 else if (version.indexOf("2") == 0) { 1103 Enumeration names = mapTypes.keys(); 1104 while (names.hasMoreElements()) { 1105 int layerCount = -1; 1106 GoogleMapMapTypeTag type = (GoogleMapMapTypeTag) mapTypes.get(names.nextElement()); 1107 if (debug && version.indexOf("2") == 0) { 1108 out.println("\t\tGLog.write('Adding custom map " + type.getId() + "');"); 1109 } 1110 out.println("\t\tvar " + type.getId() + "_array = new Array();"); 1111 String copy = type.getCopyright(); 1112 int minZoom = type.getMinZoom(); 1113 int maxZoom = type.getMaxZoom(); 1114 if (minZoom < 0) 1115 minZoom = 0; 1116 if (maxZoom < 0) 1117 maxZoom = 0; 1118 if (copy == null) 1119 copy = ""; 1120 String base = "G_NORMAL_MAP"; 1121 if (type.getBaseType() != null) { 1122 if (type.getBaseType().equals("satellite")) 1123 base = "G_SATELLITE_MAP"; 1124 else if (type.getBaseType().equals("hybrid")) 1125 base = "G_HYBRID_TYPE"; 1126 } 1127 if (type.getUrl() != null) { 1128 layerCount++; 1129 if (debug && version.indexOf("2") == 0) { 1130 out.println("\t\tGLog.write('Adding base tile for custom map " + type.getId() + "');"); 1131 } 1132 out.println("\t\tvar " + type.getId() + "_base = new GTileLayer(new GCopyrightCollection(\"" + copy + "\"), " + minZoom + ", " + maxZoom + ");"); 1133 out.println("\t\t" + type.getId() + "_base.getCopyright = function(a, b) {"); 1134 out.println("\t\t\treturn \"" + copy + "\";"); 1135 out.println("\t\t}"); 1136 out.println("\t\t" + type.getId() + "_base.getTileUrl = function(a, b) {"); 1137 out.println("\t\tvar oldZoom = 17 - b;"); 1138 out.println("\t\t\treturn \"" + type.getUrl() + "?x=\" + a.x + \"&y=\" + a.y + \"&zoom=\" + oldZoom;"); 1139 out.println("\t\t}"); 1140 out.println("\t\t" + type.getId() + "_base.isPng = function(a, b) {"); 1141 out.println("\t\t\treturn " + type.isPng() + ";"); 1142 out.println("\t\t}"); 1143 out.println("\t\t" + type.getId() + "_array[" + layerCount + "] = " + type.getId() + "_base;"); 1144 } 1145 if (type.getOverlayUrl() != null) { 1146 layerCount++; 1147 if (debug && version.indexOf("2") == 0) { 1148 out.println("\t\tGLog.write('Adding overlay tile for map " + type.getId() + "');"); 1149 } 1150 out.println("\t\tvar " + type.getId() + "_overlay = new GTileLayer(new GCopyrightCollection(\"" + copy + "\"), " + minZoom + ", " + maxZoom + ");"); 1151 out.println("\t\t" + type.getId() + "_overlay.getCopyright = function(a, b) {"); 1152 out.println("\t\t\treturn \"" + copy + "\";"); 1153 out.println("\t\t}"); 1154 out.println("\t\t" + type.getId() + "_overlay.getTileUrl = function(a, b) {"); 1155 out.println("\t\tvar oldZoom = 17 - b;"); 1156 out.println("\t\t\treturn \"" + type.getOverlayUrl() + "?x=\" + a.x + \"&y=\" + a.y + \"&zoom=\" + oldZoom;"); 1157 out.println("\t\t}"); 1158 out.println("\t\t" + type.getId() + "_overlay.isPng = function(a, b) {"); 1159 out.println("\t\t\treturn " + type.isPng() + ";"); 1160 out.println("\t\t}"); 1161 out.println("\t\t" + type.getId() + "_array[" + layerCount + "] = " + type.getId() + "_overlay;"); 1162 } 1163 out.println("\t\tvar " + type.getId() + " = new GMapType(" + type.getId() + "_array, " + base + ".getProjection(), \"" + type.getName() + "\", {shortName:\"" + type.getName() + "\",maxResolution:" + maxZoom + ",minResolution:" + minZoom + ",errorMessage:_mMapError});"); 1164 out.println("\t\t" + id + ".addMapType(" + type.getId() + ");"); 1165 if (type.isShowOnStartup()) { 1166 if (debug && version.indexOf("2") == 0) { 1167 out.println("\t\tGLog.write('Setting Google Map to initially display custom map " + type.getId() + "');"); 1168 } 1169 out.println("\t\t" + id + ".setMapType(" + type.getId() + ");"); 1170 } 1171 } 1172 } 1173 } 1174 if (version.indexOf("2") == 0) { 1175 out.println("\t\tsetZoomLevels();"); 1176 } 1177 double lon = 0.00d; 1178 double lat = 0.00d; 1179 if (centerLongitude >= -180.00d && centerLatitude >= -180.00d) { 1180 lon = centerLongitude; 1181 lat = centerLatitude; 1182 } 1183 else { lon = (largeLon + smallLon) / 2; 1185 lat = (largeLat + smallLat) / 2; 1186 centerLatitude = lat; 1187 centerLongitude = lon; 1188 } if (bound && version.indexOf("2") == 0) { 1190 if (debug) 1191 out.println("\t\tGLog.write('Creating bounding box for map.');"); 1192 double adjustedSmallLon = smallLon - 0.05; 1193 double adjustedSmallLat = smallLat - 0.05; 1194 double adjustedLargeLon = largeLon + 0.05; 1195 double adjustedLargeLat = largeLat + 0.05; 1196 out.println("\t\tallowedBounds = new GLatLngBounds(new GLatLng(" + adjustedSmallLat + ", " + adjustedSmallLon + "), new GLatLng(" + adjustedLargeLat + ", " + adjustedLargeLon + "));"); 1197 out.println("\t\tGEvent.addListener(" + id + ", 'move', function() {"); 1198 if (debug && version.indexOf("2") == 0) { 1199 out.println("\t\tGLog.write('Move event fired by map " + id + ".');"); 1200 } 1201 out.println("\t\t\tcheckBounds();"); 1202 out.println("\t\t});"); 1203 } 1204 if (debug && version.indexOf("2") == 0) { 1205 out.println("\t\tGLog.write('Calculating default center and zoom values.');"); 1206 } 1207 if (zoom < 0) { 1208 out.println("\t\t" + id + ".centerAndZoom(new GPoint(" + lon + ", " + lat + "), 8);"); 1209 } 1210 else { 1211 out.println("\t\t" + id + ".centerAndZoom(new GPoint(" + lon + ", " + lat + "), " + zoom + ");"); 1212 } 1213 if (version.indexOf("2") == 0 && labels != null) { 1215 for (int i = 0; i < labels.size(); i++) { 1216 GoogleMapLabelTag label = (GoogleMapLabelTag) labels.elementAt(i); 1217 GoogleMapPointTag point = (GoogleMapPointTag) points.get(label.getPoint()); 1218 if (point != null) { 1219 if (debug && version.indexOf("2") == 0) { 1220 out.println("\t\tGLog.write('Adding label to map using point " + point.getId() + "');"); 1221 } 1222 String constructor = "new GLatLng(" + point.getLatitude() + ", " + point.getLongitude() + "), "; 1223 constructor += "'"; 1224 if (label.getStyle() != null) { 1225 constructor += "<div style=\"" + label.getStyle() + "\">"; 1226 } 1227 constructor += label.getContent(); 1228 if (label.getStyle() != null) { 1229 constructor += "</div>"; 1230 } 1231 constructor += "', " + label.getOpacity() + ", "; 1232 if (label.getCss_class() != null) { 1233 constructor += "'" + label.getCss_class() + "'"; 1234 } 1235 else { 1236 constructor += "null"; 1237 } 1238 constructor += ", " + label.getX_offset() + ", " + label.getY_offset(); 1239 out.println("\t\tvar label_" + i + " = new Label(" + constructor + ");"); 1240 out.println("\t\t" + id + ".addOverlay(label_" + i + ");"); 1241 } 1242 } 1243 } 1244 if (version.indexOf("2") == 0 && inserts != null) { 1246 if (debug) { 1247 out.println("\t\tGLog.write('Adding inserts to map with id " + id + "');"); 1248 } 1249 for (int i = 0; i < inserts.size(); i++) { 1250 GoogleMapInsertTag insert = (GoogleMapInsertTag) inserts.elementAt(i); 1251 GoogleMapPointTag point = (GoogleMapPointTag) points.get(insert.getPoint()); 1252 if (point != null) { 1253 if (debug) { 1254 out.println("\t\tGLog.write('Adding insert " + insert.getId() + " to map using point " + point.getId() + "');"); 1255 } 1256 out.println("\t\t" + insert.getId() + " = new Insert(new GLatLng(" + point.getLatitude() + ", " + point.getLongitude() + "), \"" + insert.getUrl() + "\", new GSize(" + insert.getWidth() + ", " + insert.getHeight() + "), " + insert.getBaseZoom() + ");"); 1257 out.println("\t\t" + id + ".addOverlay(" + insert.getId() + ");"); 1258 out.print("\t\tif ("); 1259 for (int j = 0; j < insert.getMapTypeCount(); j++) { 1260 String mapType = insert.getMapType(j); 1261 if (j > 0) { 1262 out.print(" || "); 1263 } 1264 out.print(id + ".getCurrentMapType().getName() == '" + mapType + "'"); 1265 } 1266 out.println(") {"); 1267 out.println("\t\t\t" + insert.getId() + ".show();"); 1268 out.println("\t\t}"); 1269 out.println("\t\telse {"); 1270 out.println("\t\t\t" + insert.getId() + ".hide();"); 1271 out.println("\t\t}"); 1272 } 1273 else { 1274 if (debug) 1275 out.println("\t\tGLog.write('Point was null in " + insert.getId() + "');"); 1276 } 1277 } 1278 } 1279 if (markers != null && markers.size() > 0) { 1281 Enumeration names = markers.keys(); 1282 while (names.hasMoreElements()) { 1283 GoogleMapMarkerTag marker = (GoogleMapMarkerTag) markers.get(names.nextElement()); 1284 GoogleMapPointTag point = (GoogleMapPointTag) points.get(marker.getPoint()); 1285 if (debug && version.indexOf("2") == 0) { 1286 out.println("\t\tGLog.write('Adding marker " + marker.getId() + " using point " + point.getId() + "');"); 1287 } 1288 if (point != null) { 1289 GoogleMapIconTag icon = marker.getIcon(); 1290 if (icon != null) { 1291 if (debug && version.indexOf("2") == 0) { 1292 out.println("\t\tGLog.write('Setting custom icon for marker " + marker.getId() + "');"); 1293 } 1294 out.println("\t\tvar " + marker.getId() + "_icon = new GIcon();"); 1295 out.println("\t\t" + marker.getId() + "_icon.image = \"" + icon.getIcon() + "\";"); 1296 out.println("\t\t" + marker.getId() + "_icon.iconSize = new GSize(" + icon.getIconWidth() + ", " + icon.getIconHeight() + ");"); 1297 if (icon.getShadow() != null) { 1298 out.println("\t\t" + marker.getId() + "_icon.shadow = \"" + icon.getShadow() + "\";"); 1299 out.println("\t\t" + marker.getId() + "_icon.shadowSize = new GSize(" + icon.getShadowWidth() + ", " + icon.getShadowHeight() + ");"); 1300 } 1301 out.println("\t\t" + marker.getId() + "_icon.iconAnchor = new GPoint(" + icon.getAnchorX() + ", " + icon.getAnchorY() + ");"); 1302 out.println("\t\t" + marker.getId() + "_icon.infoWindowAnchor = new GPoint(" + icon.getInfoWindowAnchorX() + ", " + icon.getInfoWindowAnchorY() + ");"); 1303 if (marker.isDraggable() && (version.compareTo("2.46") >= 0 || version.equals("2"))) { 1304 out.println("\t\tvar " + marker.getId() + " = new GMarker(new GLatLng(" + point.getLatitude() + ", " + point.getLongitude() + "), {icon: " + marker.getId() + "_icon, draggable: true});"); 1305 } 1306 else { 1307 out.println("\t\tvar " + marker.getId() + " = new GMarker(new GPoint(" + point.getLongitude() + ", " + point.getLatitude() + "), " + marker.getId() + "_icon);"); 1308 } 1309 } 1310 else { 1311 if (marker.isDraggable() && (version.compareTo("2.46") >= 0 || version.equals("2"))) { 1312 out.println("\t\tvar " + marker.getId() + " = new GMarker(new GLatLng(" + point.getLatitude() + ", " + point.getLongitude() + "), {draggable: true});"); 1313 } 1314 else { 1315 out.println("\t\tvar " + marker.getId() + " = new GMarker(new GPoint(" + point.getLongitude() + ", " + point.getLatitude() + "));"); 1316 } 1317 } 1318 if (clusterer == null) { 1319 if (debug && version.indexOf("2") == 0) { 1320 out.println("\t\tGLog.write('Adding marker " + marker.getId() + " to map " + id + "');"); 1321 } 1322 out.println("\t\t" + id + ".addOverlay(" + marker.getId() + ");"); 1323 } 1324 else { 1325 if (debug && version.indexOf("2") == 0) { 1326 out.println("\t\tGLog.write('Adding marker " + marker.getId() + " to clusterer " + id + "_cluster');"); 1327 } 1328 out.println("\t\t" + id + "_cluster.AddMarker(" + marker.getId() + ", \"Zoom in for details\");"); 1329 } 1330 if (marker.isDraggable() && (version.compareTo("2.46") >= 0 || version.equals("2"))) { 1331 out.println("\t\t" + marker.getId() + ".enableDragging();"); 1332 } 1333 if (marker.getInfoWindow() != null) { 1334 if (marker.getInfoWindow().isTabbed()) { 1335 GoogleMapInfoWindowTabbedTag info = (GoogleMapInfoWindowTabbedTag) marker.getInfoWindow(); 1336 if (debug && version.indexOf("2") == 0) { 1337 out.println("\t\tGLog.write('Setting tabbed infowindow for marker " + marker.getId() + "');"); 1338 } 1339 int tabWidth = 88 * info.getTabCount(); 1340 String style = info.getStyle(); 1341 if (style == null) 1342 style = "white-space: nowrap; width: " + tabWidth + "px;"; 1343 String css_class = ""; 1344 if (info.getCss_class() != null) 1345 css_class = "class=\\\"" + info.getCss_class() + "\\\""; 1346 out.println("\t\tvar " + marker.getId() + "_tabs = new Array();"); 1347 for (int i = 0; i < info.getTabCount(); i++) { 1348 GoogleMapTabTag tab = info.getTab(i); 1349 out.println("\t\t" + marker.getId() + "_tabs.push(new GInfoWindowTab(\"" + tab.getLabel() + "\", \"<div " + css_class + " style=\\\"" + style + "\\\">" + tab.getContent() + "</div>\"));"); 1350 } 1351 out.println("\t\tGEvent.addListener(" + marker.getId() + ", 'click', function() {"); 1352 if (debug && version.indexOf("2") == 0) { 1353 out.println("\t\t\tGLog.write('Click event fired by marker " + marker.getId() + ".');"); 1354 } 1355 out.println("\t\t\t" + marker.getId() + ".openInfoWindowTabsHtml(" + marker.getId() + "_tabs);"); 1356 out.println("\t\t});"); 1357 if (info.isDisplay()) { 1358 out.println("\t\t" + marker.getId() + ".openInfoWindowTabsHtml(" + marker.getId() + "_tabs);"); 1359 } 1360 } 1361 else { 1362 if (debug && version.indexOf("2") == 0) { 1363 out.println("\t\tGLog.write('Setting info window for marker " + marker.getId() + "');"); 1364 } 1365 GoogleMapInfoWindowTag info = (GoogleMapInfoWindowTag) marker.getInfoWindow(); 1366 String style = info.getStyle(); 1367 if (style == null) 1368 style = "white-space: nowrap;"; 1369 String css_class = ""; 1370 if (info.getCss_class() != null) 1371 css_class = "class=\\\"" + info.getCss_class() + "\\\""; 1372 out.println("\t\tGEvent.addListener(" + marker.getId() + ", 'click', function() {"); 1373 if (debug && version.indexOf("2") == 0) { 1374 out.println("\t\t\tGLog.write('Click event fired by marker " + marker.getId() + ".');"); 1375 } 1376 out.println("\t\t\t" + marker.getId() + ".openInfoWindowHtml(\"<div " + css_class + " style=\\\"" + style + "\\\">" + info.getContent() + "</div>\");"); 1377 out.println("\t\t});"); 1378 if (info.isDisplay()) { 1379 out.println("\t\t" + marker.getId() + ".openInfoWindowHtml(\"<div " + css_class + " style=\\\"" + style + "\\\">" + info.getContent() + "</div>\");"); 1380 } 1381 } 1382 } 1383 if (marker.getBlowup() != null) { 1384 if (debug && version.indexOf("2") == 0) { 1385 out.println("\t\tGLog.write('Adding blowup map to marker " + marker.getId() + "');"); 1386 } 1387 out.println("\t\tGEvent.addListener(" + marker.getId() + ", 'click', function() {"); 1388 if (debug && version.indexOf("2") == 0) { 1389 out.println("\t\t\tGLog.write('Click event fired by marker " + marker.getId() + "');"); 1390 } 1391 String parameters = "" + marker.getBlowup().getZoom(); 1392 if (marker.getBlowup().getMaptype() != null) { 1393 if (marker.getBlowup().getMaptype().equalsIgnoreCase("satellite")) 1394 parameters += ", G_SATELLITE_TYPE"; 1395 else if (marker.getBlowup().getMaptype().equalsIgnoreCase("hybrid")) 1396 parameters += ", G_HYBRID_TYPE"; 1397 else 1398 parameters += ", G_MAP_TYPE"; 1399 } 1400 else { 1401 if (type.equalsIgnoreCase("hybrid")) { 1402 parameters += ", G_HYBRID_TYPE"; 1403 } 1404 else if (type.equalsIgnoreCase("satellite")) { 1405 parameters += ", G_SATELLITE_TYPE"; 1406 } 1407 else { 1408 parameters += ", G_MAP_TYPE"; 1409 } 1410 } 1411 out.println("\t\t\t" + marker.getId() + ".showMapBlowup(" + parameters + ");"); 1412 out.println("\t\t});"); 1413 if (marker.getBlowup().isDisplay()) { 1414 out.println("\t\t" + marker.getId() + ".showMapBlowup(" + parameters + ");"); 1415 } 1416 } 1417 if (marker.getEvents() != null) { 1418 Vector e = marker.getEvents(); 1419 for (int i = 0; i < e.size(); i++) { 1420 GoogleMapEventTag event = (GoogleMapEventTag) e.elementAt(i); 1421 String baseURL = event.getUrl(); 1422 if (baseURL.indexOf("?") >= 0) 1423 baseURL += "&"; 1424 else 1425 baseURL += "?"; 1426 if (debug && version.indexOf("2") == 0) { 1427 out.println("\t\tGLog.write('Adding " + event.getAction() + " event to marker " + marker.getId() + "');"); 1428 } 1429 if (event.getAction().equals("click")) { 1430 out.println("\t\tGEvent.addListener(" + marker.getId() + ", '" + event.getAction() + "', function(overlay, point) {"); 1431 if (debug && version.indexOf("2") == 0) { 1432 out.println("\t\t\tGLog.write('Click event fired by marker " + marker.getId() + "');"); 1433 } 1434 if (event.isAsynchronous()) { 1435 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1436 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker\", true);"); 1437 out.println("\t\t\tasr.send(null);"); 1438 } 1439 else { 1440 if (message != null) 1441 out.println("\t\t\tshowMessage();"); 1442 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker\";"); 1443 } 1444 out.println("\t\t});"); 1445 } 1446 else if (event.getAction().indexOf("drag") >= 0 && (version.compareTo("2.46") >= 0 || version.equals("2"))) { 1447 out.println("\t\tGEvent.addListener(" + marker.getId() + ", '" + event.getAction() + "', function(overlay, point) {"); 1448 if (debug && version.indexOf("2") == 0) { 1449 out.println("\t\t\tGLog.write('Drag event fired by marker " + marker.getId() + ".');"); 1450 } 1451 out.println("\t\t\tvar longitude = " + marker.getId() + ".getPoint().x;"); 1452 out.println("\t\t\tvar latitude = " + marker.getId() + ".getPoint().y;"); 1453 if (event.isAsynchronous()) { 1454 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1455 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker&longitude=\" + longitude + \"&latitude=\" + latitude, true);"); 1456 out.println("\t\t\tasr.send(null);"); 1457 } 1458 else { 1459 if (message != null) 1460 out.println("\t\t\tshowMessage();"); 1461 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker&longitude=\" + longitude + \"&latitude=\" + latitude;"); 1462 } 1463 out.println("\t\t});"); 1464 } 1465 else if (event.getAction().equals("dblclick")) { 1466 out.println("\t\tGEvent.addListener(" + marker.getId() + ", 'mouseup', function(overlay, point) {"); 1467 out.println("\t\t\tif (isDouble()) {"); 1468 if (debug && version.indexOf("2") == 0) { 1469 out.println("\t\t\t\tGLog.write('Double click event fired by marker " + marker.getId() + "');"); 1470 } 1471 if (event.isAsynchronous()) { 1472 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1473 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker\", true);"); 1474 out.println("\t\t\t\tasr.send(null);"); 1475 } 1476 else { 1477 if (message != null) 1478 out.println("\t\t\t\tshowMessage();"); 1479 out.println("\t\t\t\tdocument.location=\"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + marker.getId() + "&type=marker\";"); 1480 } 1481 out.println("\t\t\t}"); 1482 out.println("\t\t});"); 1483 } 1484 } 1485 } 1486 } 1487 } 1488 } 1489 if (showZoomControl) { 1491 if (debug && version.indexOf("2") == 0) { 1492 out.println("\t\tGLog.write('Adding zoom controls to map " + id + "');"); 1493 } 1494 if (zoomControlSize == LARGE_ZOOM_CONTROL) { 1495 out.println("\t\t" + id + ".addControl(new GLargeMapControl());"); 1496 } 1497 else { 1498 out.println("\t\t" + id + ".addControl(new GSmallMapControl());"); 1499 } 1500 } 1501 if (showPanControl) { 1502 if (debug && version.indexOf("2") == 0) { 1503 out.println("\t\tGLog.write('Adding pan controls to map " + id + "');"); 1504 } 1505 out.println("\t\t" + id + ".enableDragging();"); 1506 } 1507 else { 1508 out.println("\t\t" + id + ".disableDragging();"); 1509 } 1510 if (showTypeControl) { 1511 if (debug && version.indexOf("2") == 0) { 1512 out.println("\t\tGLog.write('Adding type controls to map " + id + "');"); 1513 } 1514 out.println("\t\t" + id + ".addControl(new GMapTypeControl());"); 1515 } 1516 if (showScaleControl) { 1517 if (debug && version.indexOf("2") == 0) { 1518 out.println("\t\tGLog.write('Adding scale controls to map " + id + "');"); 1519 } 1520 out.println("\t\t" + id + ".addControl(new GScaleControl());"); 1521 } 1522 if (overviewControl != null && (version.compareTo("2.41") >= 0 || version.equals("2"))) { 1523 if (debug && version.indexOf("2") == 0) { 1524 out.println("\t\tGLog.write('Adding overview control to map " + id + "');"); 1525 } 1526 out.println("\t\t" + id + ".addControl(new GOverviewMapControl(new GSize(" + overviewControl.getWidth() + "," + overviewControl.getHeight() + ")));"); 1527 if (overviewControl.wasPlaced()) { 1528 out.println("\t\tsetTimeout(\"positionOverview(" + overviewControl.getX() + "," + overviewControl.getY() + ")\",1);"); 1529 } 1530 else { 1531 out.println("\t\tvar overview = document.getElementById(\"" + id + "_overview\");"); 1532 out.println("\t\tdocument.getElementById(\"" + id + "\").appendChild(overview);"); 1533 } 1534 } 1535 if (headless && (version.compareTo("2.45") >= 0 || version.equals("2"))) { 1536 out.println("\t\t" + id + ".hideControls();"); 1537 out.println("\t\tGEvent.addListener(" + id + ", 'mouseover', function() {"); 1538 if (debug && version.indexOf("2") == 0) { 1539 out.println("\t\t\tGLog.write('Mouseover event fired by map " + id + ".');"); 1540 } 1541 out.println("\t\t\t" + id + ".showControls();"); 1542 out.println("\t\t});"); 1543 out.println("\t\tGEvent.addListener(" + id + ", 'mouseout', function() {"); 1544 if (debug && version.indexOf("2") == 0) { 1545 out.println("\t\t\tGLog.write('Mouseout event fired by map " + id + ".');"); 1546 } 1547 out.println("\t\t\t" + id + ".hideControls();"); 1548 out.println("\t\t});"); 1549 1550 } 1551 if (traffic_tags != null && traffic_tags.size() > 0) { 1553 Enumeration names = traffic_tags.keys(); 1554 while (names.hasMoreElements()) { 1555 GoogleMapTrafficTag events = (GoogleMapTrafficTag) traffic_tags.get(names.nextElement()); 1556 GoogleMapPointTag point = (GoogleMapPointTag) points.get(events.getPoint()); 1557 if (debug && version.indexOf("2") == 0) { 1558 out.println("\t\tGLog.write('Intializing traffic tag " + events.getId() + " using point " + point.getId() + "');"); 1559 } 1560 if (events.geocode(point.getLongitude(), point.getLatitude())) { 1561 for (int i = 0; i < events.eventCount(); i++) { 1562 TrafficEventBean event = events.getEvent(i); 1563 String event_id = events.getId() + "_" + i; 1564 if (debug && version.indexOf("2") == 0) { 1565 out.println("\t\tGLog.write('Adding traffic event " + events.getId() + "_" + i + " to traffic tag " + events.getId() + "');"); 1566 } 1567 GoogleMapPointTag p = new GoogleMapPointTag(); 1568 p.setId(event_id); 1569 p.setLatitude(event.getLatitude()); 1570 p.setLongitude(event.getLongitude()); 1571 addPoint(p); 1572 GoogleMapIconTag icon = events.getIcon(); 1573 if (icon != null) { 1574 if (debug && version.indexOf("2") == 0) { 1575 out.println("\t\tGLog.write('Setting custom icon for traffic event " + events.getId() + "');"); 1576 } 1577 out.println("\t\tvar " + event_id + "_icon = new GIcon();"); 1578 out.println("\t\t" + event_id + "_icon.image = \"" + icon.getIcon() + "\";"); 1579 out.println("\t\t" + event_id + "_icon.iconSize = new GSize(" + icon.getIconWidth() + ", " + icon.getIconHeight() + ");"); 1580 if (icon.getShadow() != null) { 1581 out.println("\t\t" + event_id + "_icon.shadow = \"" + icon.getShadow() + "\";"); 1582 out.println("\t\t" + event_id + "_icon.shadowSize = new GSize(" + icon.getShadowWidth() + ", " + icon.getShadowHeight() + ");"); 1583 } 1584 out.println("\t\t" + event_id + "_icon.iconAnchor = new GPoint(" + icon.getAnchorX() + ", " + icon.getAnchorY() + ");"); 1585 out.println("\t\t" + event_id + "_icon.infoWindowAnchor = new GPoint(" + icon.getInfoWindowAnchorX() + ", " + icon.getInfoWindowAnchorY() + ");"); 1586 out.println("\t\tvar " + event_id + " = new GMarker(new GPoint(" + event.getLongitude() + ", " + event.getLatitude() + "), " + event_id + "_icon);"); 1587 } 1588 else { 1589 out.println("\t\tvar " + event_id + " = new GMarker(new GPoint(" + event.getLongitude() + ", " + event.getLatitude() + "));"); 1590 } 1591 if (clusterer == null) { 1592 if (debug && version.indexOf("2") == 0) { 1593 out.println("\t\tGLog.write('Adding traffic event " + events.getId() + "_" + i + " to clusterer " + id + "_cluster');"); 1594 } 1595 out.println("\t\t" + id + ".addOverlay(" + event_id + ");"); 1596 } 1597 else { 1598 if (debug && version.indexOf("2") == 0) { 1599 out.println("\t\tGLog.write('Adding traffic event " + events.getId() + "_" + i + " to map " + id + "');"); 1600 } 1601 out.println("\t\t" + id + "_cluster.AddMarker(" + event_id + ", \"" + event.getTitle() + "\");"); 1602 } 1603 out.println("\t\tGEvent.addListener(" + event_id + ", 'click', function() {"); 1604 if (debug && version.indexOf("2") == 0) { 1605 out.println("\t\t\tGLog.write('Click event fired by clustered marker " + event_id + ".');"); 1606 } 1607 out.println("\t\t\t" + event_id + ".openInfoWindowHtml(\"<div style=\\\"white-space:nowrap;\\\">" + event.getContent() + "</div>\");"); 1608 out.println("\t\t});"); 1609 } 1610 } 1611 else { 1612 System.err.println("Couldn't geocode, or none found."); 1613 if (debug && version.indexOf("2") == 0) { 1614 out.println("\t\tGLog.write('Error geocoding traffic event in taffic tag " + events.getId() + "');"); 1615 } 1616 } 1617 } 1618 } 1619 if (polylines != null && polylines.size() > 0) { 1621 Enumeration names = polylines.keys(); 1622 while (names.hasMoreElements()) { 1623 GoogleMapPolylineTag line = (GoogleMapPolylineTag) polylines.get(names.nextElement()); 1624 if (debug && version.indexOf("2") == 0) { 1625 out.println("\t\tGLog.write('Adding polyline " + line.getId() + " to map " + id + "');"); 1626 } 1627 out.print("\t\tvar " + line.getId() + " = new GPolyline(["); 1628 for (int p = 0; p < line.pointCount(); p++) { 1629 GoogleMapPointTag point = (GoogleMapPointTag) points.get(line.getPoint(p)); 1630 if (point != null) { 1631 out.print("new GPoint(" + point.getLongitude() + ", " + point.getLatitude() + ")"); 1632 if (p < line.pointCount() - 1) 1633 out.print(", "); 1634 } 1635 } 1636 out.println("], \"" + line.getColor() + "\", " + line.getWeight() + ", " + line.getOpacity() + ");"); 1637 out.println("\t\t" + id + ".addOverlay(" + line.getId() + ");"); 1638 if (line.getEvents() != null) { 1639 Vector e = line.getEvents(); 1640 for (int j = 0; j < e.size(); j++) { 1641 GoogleMapEventTag event = (GoogleMapEventTag) e.elementAt(j); 1642 String baseURL = event.getUrl(); 1643 if (baseURL.indexOf("?") >= 0) 1644 baseURL += "&"; 1645 else 1646 baseURL += "?"; 1647 if (debug && version.indexOf("2") == 0) { 1648 out.println("\t\tGLog.write('Adding " + event.getAction() + " event to polyline " + line.getId() + "');"); 1649 } 1650 if (event.getAction().equals("click")) { 1651 out.println("\t\tGEvent.addListener(" + line.getId() + ", 'click', function(overlay, point) {"); 1652 if (debug && version.indexOf("2") == 0) { 1653 out.println("\t\t\tGLog.write('Click event fired by polyline " + line.getId() + ".');"); 1654 } 1655 if (event.isAsynchronous()) { 1656 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1657 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + line.getId() + "&type=polyline\", true);"); 1658 out.println("\t\t\tasr.send(null);"); 1659 } 1660 else { 1661 if (message != null) 1662 out.println("\t\t\t\tshowMessage();"); 1663 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + line.getId() + "&type=polyline\";"); 1664 } 1665 out.println("\t\t});"); 1666 } 1667 else if (event.getAction().equals("dblclick")) { 1668 out.println("\t\tGEvent.addListener(" + line.getId() + ", 'mouseup', function(overlay, point) {"); 1669 out.println("\t\t\tif (isDouble()) {"); 1670 if (debug && version.indexOf("2") == 0) { 1671 out.println("\t\t\t\tGLog.write('Double click event fired by line " + line.getId() + "');"); 1672 } 1673 if (event.isAsynchronous()) { 1674 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1675 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + line.getId() + "&type=polyline\", true);"); 1676 out.println("\t\t\t\tasr.send(null);"); 1677 } 1678 else { 1679 if (message != null) 1680 out.println("\t\t\t\tshowMessage();"); 1681 out.println("\t\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + line.getId() + "&type=polyline\";"); 1682 } 1683 out.println("\t\t\t}"); 1684 out.println("\t\t});"); 1685 } 1686 } 1687 } 1688 } 1689 } 1690 if (circles != null && circles.size() > 0) { 1692 Enumeration names = circles.keys(); 1693 while(names.hasMoreElements()) { 1694 GoogleMapCircleTag circle = (GoogleMapCircleTag) circles.get(names.nextElement()); 1695 GoogleMapPointTag point = (GoogleMapPointTag) points.get(circle.getPoint()); 1696 if (debug && version.indexOf("2") == 0) { 1697 out.println("\t\tGLog.write('Adding circle " + circle.getId() + " to map " + id + "');"); 1698 } 1699 if (point != null) { 1700 out.println("\t\tvar " + circle.getId() + " = drawCircle(" + point.getLongitude() + ", " + point.getLatitude() + ", " + circle.getRadius() + ", \"" + circle.getColor() + "\", " + circle.getWeight() + ", " + circle.getOpacity() + ");"); 1701 out.println("\t\t" + id + ".addOverlay(" + circle.getId() + ");"); 1702 if (circle.getEvents() != null) { 1703 Vector e = circle.getEvents(); 1704 for (int j = 0; j < e.size(); j++) { 1705 GoogleMapEventTag event = (GoogleMapEventTag) e.elementAt(j); 1706 String baseURL = event.getUrl(); 1707 if (baseURL.indexOf("?") >= 0) 1708 baseURL += "&"; 1709 else 1710 baseURL += "?"; 1711 if (debug && version.indexOf("2") == 0) { 1712 out.println("\t\tGLog.write('Adding " + event.getAction() + " event to cricle " + circle.getId() + "');"); 1713 } 1714 if (event.getAction().equals("click")) { 1715 out.println("\t\tGEvent.addListener(" + circle.getId() + ", 'click', function(overlay, point) {"); 1716 if (debug && version.indexOf("2") == 0) { 1717 out.println("\t\t\tGLog.write('Click event fired by circle " + circle.getId() + ".');"); 1718 } 1719 if (event.isAsynchronous()) { 1720 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1721 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + circle.getId() + "&type=circle\", true);"); 1722 out.println("\t\t\tasr.send(null);"); 1723 } 1724 else { 1725 if (message != null) 1726 out.println("\t\t\t\tshowMessage();"); 1727 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + circle.getId() + "&type=circle\";"); 1728 } 1729 out.println("\t\t});"); 1730 } 1731 else if (event.getAction().equals("dblclick")) { 1732 out.println("\t\tGEvent.addListener(" + circle.getId() + ", 'mouseup', function(overlay, point) {"); 1733 out.println("\t\t\tif (isDouble()) {"); 1734 if (debug && version.indexOf("2") == 0) { 1735 out.println("\t\t\t\tGLog.write('Double click event fired by circle " + circle.getId() + ".');"); 1736 } 1737 if (event.isAsynchronous()) { 1738 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1739 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + circle.getId() + "&type=circle\", true);"); 1740 out.println("\t\t\t\tasr.send(null);"); 1741 } 1742 else { 1743 if (message != null) 1744 out.println("\t\t\t\tshowMessage();"); 1745 out.println("\t\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + circle.getId() + "&type=circle\";"); 1746 } 1747 out.println("\t\t\t}"); 1748 out.println("\t\t});"); 1749 } 1750 } 1751 } 1752 } 1753 } 1754 } 1755 if (polygons != null && polygons.size() > 0) { 1757 Enumeration names = polygons.keys(); 1758 while (names.hasMoreElements()) { 1759 GoogleMapPolygonTag polygon = (GoogleMapPolygonTag) polygons.get(names.nextElement()); 1760 if (debug && version.indexOf("2") == 0) { 1761 out.println("\t\tGLog.write('Adding polygon " + polygon.getId() + " to map " + id + "');"); 1762 } 1763 out.print("\t\tvar " + polygon.getId() + " = new GPolyline(["); 1764 for (int p = 0; p < polygon.pointCount(); p++) { 1765 GoogleMapPointTag point = (GoogleMapPointTag) points.get(polygon.getPoint(p)); 1766 if (point != null) { 1767 out.print("new GPoint(" + point.getLongitude() + ", " + point.getLatitude() + "), "); 1768 } 1769 } 1770 GoogleMapPointTag point = (GoogleMapPointTag) points.get(polygon.getPoint(0)); 1771 out.print("new GPoint(" + point.getLongitude() + ", " + point.getLatitude() + ")"); 1772 out.println("], \"" + polygon.getColor() + "\", " + polygon.getWeight() + ", " + polygon.getOpacity() + ");"); 1773 out.println("\t\t" + id + ".addOverlay(" + polygon.getId() + ");"); 1774 if (polygon.getEvents() != null) { 1775 Vector e = polygon.getEvents(); 1776 for (int j = 0; j < e.size(); j++) { 1777 GoogleMapEventTag event = (GoogleMapEventTag) e.elementAt(j); 1778 String baseURL = event.getUrl(); 1779 if (baseURL.indexOf("?") >= 0) 1780 baseURL += "&"; 1781 else 1782 baseURL += "?"; 1783 if (debug && version.indexOf("2") == 0) { 1784 out.println("\t\tGLog.write('Adding " + event.getAction() + " to polygon " + polygon.getId() + "');"); 1785 } 1786 if (event.getAction().equals("click")) { 1787 out.println("\t\tGEvent.addListener(" + polygon.getId() + ", 'click', function(overlay, point) {"); 1788 if (debug && version.indexOf("2") == 0) { 1789 out.println("\t\t\tGLog.write('Click event fired by polygon " + polygon.getId() + ".');"); 1790 } 1791 if (event.isAsynchronous()) { 1792 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1793 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + polygon.getId() + "&type=polygon\", true);"); 1794 out.println("\t\t\tasr.send(null);"); 1795 } 1796 else { 1797 if (message != null) 1798 out.println("\t\t\t\tshowMessage();"); 1799 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + polygon.getId() + "&type=polygon\";"); 1800 } 1801 out.println("\t\t});"); 1802 } 1803 else if (event.getAction().equals("dblclick")) { 1804 out.println("\t\tGEvent.addListener(" + polygon.getId() + ", 'mouseup', function(overlay, point) {"); 1805 out.println("\t\t\tif (isDouble()) {"); 1806 if (debug && version.indexOf("2") == 0) { 1807 out.println("\t\t\t\tGLog.write('Double click event fired by polygon " + polygon.getId() + ".');"); 1808 } 1809 if (event.isAsynchronous()) { 1810 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1811 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + polygon.getId() + "&type=polygon\", true);"); 1812 out.println("\t\t\t\tasr.send(null);"); 1813 } 1814 else { 1815 if (message != null) 1816 out.println("\t\t\t\tshowMessage();"); 1817 out.println("\t\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + polygon.getId() + "&type=polygon\";"); 1818 } 1819 out.println("\t\t\t}"); 1820 out.println("\t\t});"); 1821 } 1822 } 1823 } 1824 } 1825 } 1826 if (boxes != null && boxes.size() > 0) { 1828 Enumeration names = boxes.keys(); 1829 while (names.hasMoreElements()) { 1830 GoogleMapBoxTag box = (GoogleMapBoxTag) boxes.get(names.nextElement()); 1831 if (debug && version.indexOf("2") == 0) { 1832 out.println("\t\tGLog.write('Adding box " + box.getId() + " to map " + id + "');"); 1833 } 1834 if (box.pointCount() > 1) { 1835 out.print("\t\tvar " + box.getId() + " = new GPolyline(["); 1836 GoogleMapPointTag ul = (GoogleMapPointTag) points.get(box.getPoint(0)); 1837 GoogleMapPointTag lr = (GoogleMapPointTag) points.get(box.getPoint(1)); 1838 out.print("new GPoint(" + ul.getLongitude() + ", " + ul.getLatitude() + "), "); 1839 out.print("new GPoint(" + lr.getLongitude() + ", " + ul.getLatitude() + "), "); 1840 out.print("new GPoint(" + lr.getLongitude() + ", " + lr.getLatitude() + "), "); 1841 out.print("new GPoint(" + ul.getLongitude() + ", " + lr.getLatitude() + "), "); 1842 out.print("new GPoint(" + ul.getLongitude() + ", " + ul.getLatitude() + ")"); 1843 out.println("], \"" + box.getColor() + "\", " + box.getWeight() + ", " + box.getOpacity() + ");"); 1844 out.println("\t\t" + id + ".addOverlay(" + box.getId() + ");"); 1845 if (box.getEvents() != null) { 1846 Vector e = box.getEvents(); 1847 for (int j = 0; j < e.size(); j++) { 1848 GoogleMapEventTag event = (GoogleMapEventTag) e.elementAt(j); 1849 String baseURL = event.getUrl(); 1850 if (baseURL.indexOf("?") >= 0) 1851 baseURL += "&"; 1852 else 1853 baseURL += "?"; 1854 if (debug && version.indexOf("2") == 0) { 1855 out.println("\t\tGLog.write('Adding " + event.getAction() + " event to box " + box.getId() + "');"); 1856 } 1857 if (event.getAction().equals("click")) { 1858 out.println("\t\tGEvent.addListener(" + box.getId() + ", 'click', function(overlay, point) {"); 1859 if (debug && version.indexOf("2") == 0) { 1860 out.println("\t\t\tGLog.write('Click event fired by box " + box.getId() + ".');"); 1861 } 1862 if (event.isAsynchronous()) { 1863 out.println("\t\t\tvar asr = GXmlHttp.create();"); 1864 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + box.getId() + "&type=box\", true);"); 1865 out.println("\t\t\tasr.send(null);"); 1866 } 1867 else { 1868 if (message != null) 1869 out.println("\t\t\t\tshowMessage();"); 1870 out.println("\t\t\tdocument.location=\""+ baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + box.getId() + "&type=box\";"); 1871 } 1872 out.println("\t\t});"); 1873 } 1874 else if (event.getAction().equals("dblclick")) { 1875 out.println("\t\tGEvent.addListener(" + box.getId() + ", 'mouseup', function(overlay, point) {"); 1876 out.println("\t\t\tif (isDouble()) {"); 1877 if (debug && version.indexOf("2") == 0) { 1878 out.println("\t\t\t\tGLog.write('Double click event fired by box " + box.getId() + ".');"); 1879 } 1880 if (event.isAsynchronous()) { 1881 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1882 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + box.getId() + "&type=box\", true);"); 1883 out.println("\t\t\t\tasr.send(null);"); 1884 } 1885 else { 1886 if (message != null) 1887 out.println("\t\t\t\tshowMessage();"); 1888 out.println("\t\t\t\tdocument.location=\"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&component=" + box.getId() + "&type=box\";"); 1889 } 1890 out.println("\t\t\t}"); 1891 out.println("\t\t});"); 1892 } 1893 } 1894 } 1895 } 1896 } 1897 } 1898 if (centerLongitude >= -180.00d && centerLatitude >= -180.00d) { 1901 if (debug && version.indexOf("2") == 0) { 1902 out.println("\t\tGLog.write('Recalculating center for map " + id + "');"); 1903 } 1904 lon = centerLongitude; 1905 lat = centerLatitude; 1906 } 1907 else { lon = (largeLon + smallLon) / 2; 1909 lat = (largeLat + smallLat) / 2; 1910 centerLatitude = lat; 1911 centerLongitude = lon; 1912 } if (zoom < 0) { if (debug && version.indexOf("2") == 0) { 1915 out.println("\t\tGLog.write('Recalculating zoom for map " + id + "');"); 1916 } 1917 double adjustment = 0.50d; 1918 if (showZoomControl || showTypeControl) 1919 adjustment = 1.00d; 1920 if (version.trim().indexOf("1") == 0) { out.println("\t\tvar zoom = " + id + ".spec.getLowestZoomLevel(new GPoint(" + lon + ", " + lat + "), new GSize(" + ((largeLon - smallLon) + adjustment) + ", " + ((largeLat - smallLat) + adjustment) + "), " + id + ".viewSize);"); 1922 out.println("\t\t" + id + ".centerAndZoom(new GPoint(" + lon + ", " + lat + "), zoom);"); 1923 } 1924 else { out.println("\t\tvar bounds = new GLatLngBounds();"); 1926 Enumeration key = points.keys(); 1927 while (key.hasMoreElements()) { 1928 GoogleMapPointTag point = (GoogleMapPointTag) points.get(key.nextElement()); 1929 out.println("\t\tbounds.extend(new GLatLng(" + point.getLatitude() + ", " + point.getLongitude() + "));"); 1930 } 1931 out.println("\t\t" + id + ".setZoom(" + id + ".getBoundsZoomLevel(bounds));"); 1932 out.println("\t\tlastCenterLat = " + id + ".getCenterLatLng().y;"); 1933 out.println("\t\tlastCenterLon = " + id + ".getCenterLatLng().x;"); 1934 } 1935 } 1936 if (events != null) { 1938 for (int i = 0; i < events.size(); i++) { 1939 GoogleMapEventTag event = (GoogleMapEventTag) events.elementAt(i); 1940 String baseURL = event.getUrl(); 1941 if (baseURL.indexOf("?") >= 0) 1942 baseURL += "&"; 1943 else 1944 baseURL += "?"; 1945 if (debug && version.indexOf("2") == 0) { 1946 out.println("\t\tGLog.write('Adding " + event.getAction() + " event to map " + id + "');"); 1947 } 1948 if (event.getAction().equals("click")) { 1949 out.println("\t\tGEvent.addListener(" + id + ", '" + event.getAction() + "', function(overlay, point) {"); 1950 out.println("\t\t\tif (!overlay && point) {"); 1951 if (debug && version.indexOf("2") == 0) { 1952 out.println("\t\t\t\tGLog.write('" + event.getAction() + " event fired by map " + id + ".');"); 1953 } 1954 out.println("\t\t\t\tvar longitude = point.x;"); 1955 out.println("\t\t\t\tvar latitude = point.y;"); 1956 if (event.isAsynchronous()) { 1957 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1958 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude, true);"); 1959 out.println("\t\t\t\tasr.send(null);"); 1960 } 1961 else { 1962 if (message != null) 1963 out.println("\t\t\t\tshowMessage();"); 1964 out.println("\t\t\t\tdocument.location = \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude;"); 1965 } 1966 out.println("\t\t\t}"); 1967 out.println("\t\t});"); 1968 } 1969 else if (event.getAction().equals("dblclick")) { 1970 out.println("\t\tGEvent.addListener(" + id + ", 'mousedown', function(overlay, point) {"); 1971 out.println("\t\t\tif (isDouble()) {"); 1972 if (debug && version.indexOf("2") == 0) { 1973 out.println("\t\t\t\tGLog.write('Double click event fired by map " + id + ".');"); 1974 } 1975 out.println("\t\t\t\tvar longitude = point.x;"); 1976 out.println("\t\t\t\tvar latitude = point.y;"); 1977 if (event.isAsynchronous()) { 1978 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 1979 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude, true);"); 1980 out.println("\t\t\t\tasr.send(null);"); 1981 } 1982 else { 1983 if (message != null) 1984 out.println("\t\t\t\tshowMessage();"); 1985 out.println("\t\t\t\tdocument.location = \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude;"); 1986 } 1987 out.println("\t\t\t}"); 1988 out.println("\t\t});"); 1989 } 1990 else if (event.getAction().equals("moveend")) { 1991 out.println("\t\tGEvent.addListener(" + id + ", '" + event.getAction() + "', function() {"); 1992 if (debug && version.indexOf("2") == 0) { 1993 out.println("\t\t\tGLog.write('Moveend event fired by map " + id + ".');"); 1994 } 1995 out.println("\t\t\tvar longitude = " + id + ".getCenterLatLng().x;"); 1996 out.println("\t\t\tvar latitude = " + id + ".getCenterLatLng().y;"); 1997 out.println("\t\t\tif (latitude != lastCenterLat || longitude != lastCenterLon) {"); 1998 out.println("\t\t\t\tlastCenterLat = latitude;"); 1999 out.println("\t\t\t\tlastCenterLon = longitude;"); 2000 if (event.isAsynchronous()) { 2001 out.println("\t\t\t\tvar asr = GXmlHttp.create();"); 2002 out.println("\t\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude, true);"); 2003 out.println("\t\t\t\tasr.send(null);"); 2004 } 2005 else { 2006 if (message != null) 2007 out.println("\t\t\t\tshowMessage();"); 2008 out.println("\t\t\t\tdocument.location = \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&longitude=\" + longitude + \"&latitude=\" + latitude;"); 2009 } 2010 out.println("\t\t\t}"); 2011 out.println("\t\t});"); 2012 } 2013 else if (event.getAction().equals("zoom")) { 2014 out.println("\t\tGEvent.addListener(" + id + ", '" + event.getAction() + "', function(oldzoom, newzoom) {"); 2015 if (debug && version.indexOf("2") == 0) { 2016 out.println("\t\t\tGLog.write('Zoom event fired by map " + id + ".');"); 2017 } 2018 if (event.isAsynchronous()) { 2019 out.println("\t\t\tvar asr = GXmlHttp.create();"); 2020 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&zoom=\" + newzoom, true);"); 2021 out.println("\t\t\tasr.send(null);"); 2022 } 2023 else { 2024 if (message != null) 2025 out.println("\t\t\tshowMessage();"); 2026 out.println("\t\t\tdocument.location = \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&zoom=\" + newzoom;"); 2027 } 2028 out.println("\t\t});"); 2029 } 2030 else if (event.getAction().equals("maptypechanged")) { 2031 out.println("\t\tGEvent.addListener(" + id + ", '" + event.getAction() + "', function() {"); 2032 out.println("\t\t\tvar type = " + id + ".getCurrentMapType();"); 2033 if (debug && version.indexOf("2") == 0) { 2034 out.println("\t\t\tGLog.write('Maptypechanged event fired by map " + id + ".');"); 2035 out.println("\t\t\tGLog.write('Map type selected is: ' + type.getName());"); 2036 } 2037 out.println("\t\t\tvar typeText = \"\";"); 2038 out.println("\t\t\tif (type == G_MAP_TYPE) {"); 2039 out.println("\t\t\t\ttypeText = \"map\";"); 2040 out.println("\t\t\t}"); 2041 out.println("\t\t\telse if (type == G_HYBRID_TYPE) {"); 2042 out.println("\t\t\t\ttypeText = \"hybrid\";"); 2043 out.println("\t\t\t}"); 2044 out.println("\t\t\tif (type == G_SATELLITE_TYPE) {"); 2045 out.println("\t\t\t\ttypeText = \"satellite\";"); 2046 out.println("\t\t\t}"); 2047 if (event.isAsynchronous()) { 2048 out.println("\t\t\tvar asr = GXmlHttp.create();"); 2049 out.println("\t\t\tasr.open(\"GET\", \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&type=\" + typeText, true);"); 2050 out.println("\t\t\tasr.send(null);"); 2051 } 2052 else { 2053 if (message != null) 2054 out.println("\t\t\tshowMessage();"); 2055 out.println("\t\t\tdocument.location = \"" + baseURL + "event=" + event.getAction() + "&map=" + id + "&type=\" + typeText;"); 2056 } 2057 out.println("\t\t});"); 2058 } 2059 } 2060 } 2061 if (coords != null && version.indexOf("2") == 0) { 2062 out.println("\t\tshowCoordinates(" + coords.getX() + ", " + coords.getY() + ");"); 2063 out.println("\t\tGEvent.addListener(" + id + ", 'mousemove', function(point) {"); 2064 out.println("\t\t\tupdateCoordinates(point.lng().toFixed(8), point.lat().toFixed(8));"); 2065 out.println("\t\t});"); 2066 } 2067 if (version.indexOf("2") == 0 && inserts != null) { 2068 out.println("\t\tGEvent.addListener(" + id + ", 'maptypechanged', function() {"); 2069 out.println("\t\t\tvar _map;"); 2070 out.println("\t\t\tvar mapType;"); 2071 for (int i = 0; i < inserts.size(); i++) { 2072 GoogleMapInsertTag insert = (GoogleMapInsertTag) inserts.elementAt(i); 2073 if (insert.getMapTypeCount() > 0) { 2074 out.println("\t\t\t{"); 2075 out.println("\t\t\t\t_map = " + insert.getId() + ".map_;"); 2076 out.println("\t\t\t\tmapType = _map.getCurrentMapType().getName();"); 2077 out.print("\t\t\t\tif ("); 2078 for (int j = 0; j < insert.getMapTypeCount(); j++) { 2079 String mapType = insert.getMapType(j); 2080 if (j > 0) { 2081 out.print(" || "); 2082 } 2083 out.print("mapType == '" + mapType + "'"); 2084 } 2085 out.println(") {"); 2086 out.println("\t\t\t\t\t" + insert.getId() + ".show();"); 2087 out.println("\t\t\t\t}"); 2088 out.println("\t\t\t\telse {"); 2089 out.println("\t\t\t\t\t" + insert.getId() + ".hide();"); 2090 out.println("\t\t\t\t}"); 2091 out.println("\t\t\t}"); 2092 } 2093 } 2094 out.println("\t\t});"); 2095 } 2096 if (message != null) { 2097 out.println("\t\thideMessage();"); 2098 } 2099 if (overlays != null) { 2100 Enumeration names = overlays.keys(); 2101 while (names.hasMoreElements()) { 2102 GoogleMapImageOverlayTag image = (GoogleMapImageOverlayTag) overlays.get(names.nextElement()); 2103 if (debug && version.indexOf("2") == 0) { 2104 out.println("\t\tGLog.write('Adding overlay image " + image.getId() + " to map " + id + "');"); 2105 } 2106 out.println("\t\tshowImageOverlay(\"" + image.getId() + "\"," + image.getX() + "," + image.getY() + ");"); 2107 } 2108 } 2109 out.println("\t}"); 2111 out.println("\tlastCenterLat = " + centerLatitude + ";"); 2112 out.println("\tlastCenterLon = " + centerLongitude + ";"); 2113 out.println("}"); 2114 if (mouseWheelSupport && version.indexOf("1") == 0) { 2115 if (debug && version.indexOf("2") == 0) { 2116 out.println("\t\tGLog.write('Hooking mousewheel to map " + id + "');"); 2117 } 2118 out.println("function exO(a){"); 2119 out.println("\treturn Math.round(a)+\"px\""); 2120 out.println("}"); 2121 out.println("function clamp(i, min, max) "); 2122 out.println("{"); 2123 out.println("\tif (i <= min) "); 2124 out.println("\t\treturn min; "); 2125 out.println("\telse if (i >= max) "); 2126 out.println("\t\treturn max; "); 2127 out.println("\treturn i; "); 2128 out.println(""); 2129 out.println("}"); 2130 out.println("GMap.prototype.applyZoom = function(a) "); 2131 out.println("{"); 2132 out.println("\tvar b = this; "); 2133 out.println("\tvar c = Math.floor(Math.log(b.viewSize.width) * Math.LOG2E - 2); "); 2134 out.println("\tvar d = b.zoomLevel - a; "); 2135 out.println("\tif (d > c) "); 2136 out.println("\t{"); 2137 out.println("\t\td = c; "); 2138 out.println("\t}"); 2139 out.println("\telse if (d < -c) "); 2140 out.println("\t{"); 2141 out.println("\t\td = -c; "); 2142 out.println("\t}"); 2143 out.println("\tvar e = Math.pow(2, d); "); 2144 out.println("\tb.div.style.zoom = e; "); 2145 out.println("\tvar f = b.viewSize.width * b.centerScreen.x; "); 2146 out.println("\tvar h = b.viewSize.height * b.centerScreen.y; "); 2147 out.println("\tb.div.style.left = exO((this._savedOffset.x - f) * e + f); "); 2148 out.println("\tb.div.style.top = exO((this._savedOffset.y - h) * e + h); "); 2149 out.println("}"); 2150 out.println("function zoom(oEvent, scr) "); 2151 out.println("{"); 2152 out.println("\tvar zoom_in = true; "); 2153 out.println("\tif (scr >= 120) "); 2154 out.println("\t\tzoom_in = false; "); 2155 out.println("\t" + id + ".smoothZoomTo(zoom_in); "); 2156 out.println("\tif (oEvent.preventDefault) "); 2157 out.println("\t\toEvent.preventDefault(); "); 2158 out.println("}"); 2159 out.println("GMap.prototype.smoothZoomTo = function(zoom_in) "); 2160 out.println("{"); 2161 out.println("\tvar a = this; "); 2162 out.println("\tif (!a._zoomInterval) "); 2163 out.println("\t\ta._targetZoom = a.getZoomLevel(); "); 2164 out.println("\ta._targetZoom = clamp(a._targetZoom + (zoom_in ? 1 : -1), 0, 17); "); 2165 out.println("\tif (a.div.style.zoom == undefined) "); 2166 out.println("\t{"); 2167 out.println("\t\ta.zoomTo(a._targetZoom); "); 2168 out.println("\t\treturn; "); 2169 out.println("\t}"); 2170 out.println("\tif (a._zoomInterval) "); 2171 out.println("\t\treturn; "); 2172 out.println("\ta._currentZoom = parseInt(a.getZoomLevel()); "); 2173 out.println("\ta._savedOffset={\"x\" : a.div.offsetLeft, \"y\" : a.div.offsetTop}; "); 2174 out.println("\ta.hideOverlays(); "); 2175 out.println("\tthis._zoomInterval = setInterval(function() { "); 2176 out.println("\t\ta._currentZoom += 0.3 * (a._targetZoom - a._currentZoom); "); 2177 out.println("\t\tif (Math.abs(a._targetZoom - a._currentZoom) < 0.05) "); 2178 out.println("\t\t{"); 2179 out.println("\t\t\tif (a._savedOffset) "); 2180 out.println("\t\t\t{"); 2181 out.println("\t\t\t\ta.div.style.left=exO(a._savedOffset.x); "); 2182 out.println("\t\t\t\ta.div.style.top=exO(a._savedOffset.y); "); 2183 out.println("\t\t\t}"); 2184 out.println("\t\t\ta.div.style.zoom = 1; "); 2185 out.println("\t\t\ta.showOverlays(); "); 2186 out.println("\t\t\ta.zoomTo(a._targetZoom); "); 2187 out.println("\t\t\ta._savedOffset = null; "); 2188 out.println("\t\t\twindow.clearInterval(a._zoomInterval); "); 2189 out.println("\t\t\ta._zoomInterval = null; "); 2190 out.println("\t\t}"); 2191 out.println("\t\telse "); 2192 out.println("\t\t{"); 2193 out.println("\t\t\ta.applyZoom(a._currentZoom); "); 2194 out.println("\t\t}"); 2195 out.println("\t}, 50); "); 2196 out.println("}"); 2197 out.println("function hookMouseWheelHandlers(id) "); 2198 out.println("{"); 2199 out.println("\tvar d = document.getElementById(id); "); 2200 out.println("\tif (d)"); 2201 out.println("\t{"); 2202 out.println("\t\ttry"); 2203 out.println(" \t\t{"); 2204 out.println("\t\t\tif (document.body.addEventListener) "); 2205 out.println("\t\t\t\td.addEventListener('DOMMouseScroll', function(oEvent) { "); 2206 out.println("\t\t\t\tzoom(oEvent, oEvent.detail * -40); }, false); "); 2207 out.println("\t\t\telse "); 2208 out.println("\t\t\t\td.onmousewheel = function() { "); 2209 out.println("\t\t\t\tzoom(event, event.wheelDelta); "); 2210 out.println("\t\t\t\treturn false; "); 2211 out.println("\t\t\t}"); 2212 out.println("\t\t}catch (ex) {} "); 2213 out.println("\t}"); 2214 out.println("}"); 2215 } 2216 out.println("function drawCircle(lng, lat, radius, color, width, opacity) {"); 2217 out.println("\tvar d2r = Math.PI/180;"); 2218 out.println("\tvar r2d = 180/Math.PI; "); 2219 out.println("\tvar Clat = (radius/3963)*r2d; "); 2220 out.println("\tvar Clng = Clat/Math.cos(lat*d2r); "); 2221 out.println("\tvar Cpoints = []; "); 2222 out.println("\tfor (var i=0; i < 33; i++) { "); 2223 out.println("\t\tvar theta = Math.PI * (i/16); "); 2224 out.println("\t\tCx = lng + (Clng * Math.cos(theta)); "); 2225 out.println("\t\tCy = lat + (Clat * Math.sin(theta)); "); 2226 out.println("\t\tvar P = new GPoint(Cx,Cy);"); 2227 out.println("\t\tCpoints.push(P); "); 2228 out.println("\t}; "); 2229 out.println("\treturn new GPolyline(Cpoints, color, width, opacity);"); 2230 out.println("}"); 2231 out.println("//]]>"); 2232 out.println("</script>"); 2233 } 2234 catch(Exception ex) { 2235 ex.printStackTrace(System.err); 2236 } 2237 } 2238 2244 public Hashtable getBoxes() { 2245 return boxes; 2246 } 2247 2252 public void setBoxes(Hashtable boxes) { 2253 this.boxes = boxes; 2254 } 2255 2261 public Hashtable getCircles() { 2262 return circles; 2263 } 2264 2269 public Hashtable getImageOverlays() { 2270 return overlays; 2271 } 2272 2277 public void setCircles(Hashtable circles) { 2278 this.circles = circles; 2279 } 2280 2285 public void setImageOverlays(Hashtable images) { 2286 this.overlays = images; 2287 } 2288 2294 public Hashtable getKeys() { 2295 return keys; 2296 } 2297 2302 public void setKeys(Hashtable keys) { 2303 this.keys = keys; 2304 } 2305 2310 public double getLargeLat() { 2311 return largeLat; 2312 } 2313 2317 public void setLargeLat(double largeLat) { 2318 this.largeLat = largeLat; 2319 } 2320 2326 public double getLargeLon() { 2327 return largeLon; 2328 } 2329 2333 public void setLargeLon(double largeLon) { 2334 this.largeLon = largeLon; 2335 } 2336 2342 public Hashtable getMarkers() { 2343 return markers; 2344 } 2345 2350 public void setMarkers(Hashtable markers) { 2351 this.markers = markers; 2352 } 2353 2359 public boolean isPanEnabled() { 2360 return panEnabled; 2361 } 2362 2367 public void setPanEnabled(boolean panEnabled) { 2368 this.panEnabled = panEnabled; 2369 } 2370 2375 public Hashtable getPoints() { 2376 return points; 2377 } 2378 2384 public void setPoints(Hashtable points) { 2385 this.points = points; 2386 } 2387 2392 public Hashtable getPolygons() { 2393 return polygons; 2394 } 2395 2400 public void setPolygons(Hashtable polygons) { 2401 this.polygons = polygons; 2402 } 2403 2408 public Hashtable getMapTypes() { 2409 return mapTypes; 2410 } 2411 2416 public void setMapTypes(Hashtable mapTypes) { 2417 this.mapTypes = mapTypes; 2418 } 2419 2424 public Hashtable getPolylines() { 2425 return polylines; 2426 } 2427 2432 public void setPolylines(Hashtable polylines) { 2433 this.polylines = polylines; 2434 } 2435 2440 public boolean isShowScaleControl() { 2441 return showScaleControl; 2442 } 2443 2448 public void setShowScaleControl(boolean showScaleControl) { 2449 this.showScaleControl = showScaleControl; 2450 } 2451 2456 public double getSmallLat() { 2457 return smallLat; 2458 } 2459 2466 public void setSmallLat(double smallLat) { 2467 this.smallLat = smallLat; 2468 } 2469 2474 public double getSmallLon() { 2475 return smallLon; 2476 } 2477 2484 public void setSmallLon(double smallLon) { 2485 this.smallLon = smallLon; 2486 } 2487 2493 public int getZoomControlSize() { 2494 return zoomControlSize; 2495 } 2496 2505 public void setZoomControlSize(int zoomControlSize) { 2506 this.zoomControlSize = zoomControlSize; 2507 } 2508 2513 public String getBody() { 2514 return body; 2515 } 2516 2521 public double getCenterLatitude() { 2522 return centerLatitude; 2523 } 2524 2529 public double getCenterLongitude() { 2530 return centerLongitude; 2531 } 2532 2537 public String getHeight() { 2538 return height; 2539 } 2540 2545 public boolean isMouseWheelSupport() { 2546 return mouseWheelSupport; 2547 } 2548 2553 public String getScope() { 2554 return scope; 2555 } 2556 2561 public boolean isShowPanControl() { 2562 return showPanControl; 2563 } 2564 2569 public boolean isShowTypeControl() { 2570 return showTypeControl; 2571 } 2572 2577 public boolean isShowZoomControl() { 2578 return showZoomControl; 2579 } 2580 2585 public String getType() { 2586 return type; 2587 } 2588 2593 public String getVersion() { 2594 return version; 2595 } 2596 2601 public String getWidth() { 2602 return width; 2603 } 2604 2609 public int getZoom() { 2610 return zoom; 2611 } 2612 2618 public Vector getEvents() { 2619 return events; 2620 } 2621 2626 public void setEvents(Vector events) { 2627 this.events = events; 2628 } 2629 2634 public String getId() { 2635 return id; 2636 } 2637 2642 public GoogleMapMessageTag getMessage() { 2643 return message; 2644 } 2645 2650 public void setMessage(GoogleMapMessageTag message) { 2651 this.message = message; 2652 } 2653 2659 public String getXml() { 2660 return xml; 2661 } 2662 2668 public void setXml(String xml) { 2669 this.xml = xml; 2670 } 2671 2676 public GoogleMapOverviewTag getOverviewControl() { 2677 return overviewControl; 2678 } 2679 2684 public void setOverviewControl(GoogleMapOverviewTag overviewControl) { 2685 this.overviewControl = overviewControl; 2686 } 2687 2692 public GoogleMapClusterTag getClusterer() { 2693 return clusterer; 2694 } 2695 2700 public void setClusterer(GoogleMapClusterTag clusterer) { 2701 this.clusterer = clusterer; 2702 } 2703 2708 public void addWMSTag(GoogleMapWMSTag tag) { 2709 if (wms == null) 2710 wms = new Hashtable (); 2711 wms.put(tag.getId(), tag); 2712 } 2713 2719 public GoogleMapWMSTag getWms(String id) { 2720 if (wms == null) 2721 return null; 2722 else 2723 return (GoogleMapWMSTag) wms.get(id); 2724 } 2725 2731 public Hashtable getWmsTypes() { 2732 return wms; 2733 } 2734 2740 public boolean isDebug() { 2741 return debug; 2742 } 2743 2750 public void setDebug(boolean debug) { 2751 if (version != null && version.indexOf("2") == 0) 2752 this.debug = debug; 2753 else 2754 this.debug = false; 2755 } 2756 2761 public void addLabel(GoogleMapLabelTag label) { 2762 if (labels == null) 2763 labels = new Vector (); 2764 labels.addElement(label); 2765 } 2766 2771 public void deleteLabel(GoogleMapLabelTag label) { 2772 if (labels != null) 2773 labels.remove(label); 2774 } 2775 2780 public void setLabels(Vector labels) { 2781 this.labels = labels; 2782 } 2783 2788 public Vector getLabels() { 2789 return labels; 2790 } 2791 2797 public boolean isHeadless() { 2798 return headless; 2799 } 2800 2806 public void setHeadless(boolean headless) { 2807 this.headless = headless; 2808 } 2809 2815 public int getMaxZoom() { 2816 return maxZoom; 2817 } 2818 2824 public void setMaxZoom(int maxZoom) { 2825 this.maxZoom = maxZoom; 2826 } 2827 2833 public int getMinZoom() { 2834 return minZoom; 2835 } 2836 2842 public void setMinZoom(int minZoom) { 2843 this.minZoom = minZoom; 2844 } 2845 2851 public boolean isBound() { 2852 return bound; 2853 } 2854 2861 public void setBound(boolean bound) { 2862 this.bound = bound; 2863 } 2864 2869 public void deleteInsert(GoogleMapInsertTag insert) { 2870 if (inserts != null) 2871 inserts.remove(insert); 2872 } 2873 2878 public void addInsert(GoogleMapInsertTag insert) { 2879 if (inserts == null) 2880 inserts = new Vector (); 2881 inserts.addElement(insert); 2882 } 2883 2888 public void setInserts(Vector inserts) { 2889 this.inserts = inserts; 2890 } 2891 2896 public Vector getInserts() { 2897 return inserts; 2898 } 2899 2904 public void addCoordinates(GoogleMapCoordinatesTag coords) { 2905 this.coords = coords; 2906 } 2907 2912 public String getLanguage() { 2913 return language; 2914 } 2915 2920 public void setLanguage(String language) { 2921 this.language = language; 2922 } 2923 2929 public boolean isShowDaylight() { 2930 return showDaylight; 2931 } 2932 2938 public void setShowDaylight(boolean showDaylight) { 2939 this.showDaylight = showDaylight; 2940 } 2941} 2942 | Popular Tags |