Automatically exported from code.google.com/p/planningalerts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // A Rectangle is a simple overlay that outlines a lat/lng bounds on the
  2. // map. It has a border of the given weight and color and can optionally
  3. // have a semi-transparent background color.
  4. function Rectangle(bounds, opt_weight, opt_color) {
  5. this.bounds_ = bounds;
  6. this.weight_ = opt_weight || 5;
  7. this.color_ = opt_color || '#EF2C2C';
  8. }
  9. Rectangle.prototype = new GOverlay();
  10. // Creates the DIV representing this rectangle.
  11. Rectangle.prototype.initialize = function(map) {
  12. // Create the DIV representing our rectangle
  13. var div = document.createElement("div");
  14. div.style.border = this.weight_ + "px solid " + this.color_;
  15. div.style.position = "absolute";
  16. // Our rectangle is flat against the map, so we add our selves to the
  17. // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
  18. // below the marker shadows)
  19. map.getPane(G_MAP_MAP_PANE).appendChild(div);
  20. this.map_ = map;
  21. this.div_ = div;
  22. }
  23. // Remove the main DIV from the map pane
  24. Rectangle.prototype.remove = function() {
  25. this.div_.parentNode.removeChild(this.div_);
  26. }
  27. // Copy our data to a new Rectangle
  28. Rectangle.prototype.copy = function() {
  29. return new Rectangle(this.bounds_, this.weight_, this.color_,
  30. this.backgroundColor_, this.opacity_);
  31. }
  32. // Redraw the rectangle based on the current projection and zoom level
  33. Rectangle.prototype.redraw = function(force) {
  34. // We only need to redraw if the coordinate system has changed
  35. if (!force) return;
  36. // Calculate the DIV coordinates of two opposite corners of our bounds to
  37. // get the size and position of our rectangle
  38. var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
  39. var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
  40. // Now position our DIV based on the DIV coordinates of our bounds
  41. this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
  42. this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
  43. this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
  44. this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
  45. }
  46. function load(nCenterLong, nCenterLat, nBottomLeftLong, nBottomLeftLat, TopRightLong, TopRightLat) {
  47. if (GBrowserIsCompatible()) {
  48. var map = new GMap2(document.getElementById("map"));
  49. map.addControl(new GSmallMapControl());
  50. map.addControl(new GMapTypeControl());
  51. map.setCenter(new GLatLng(nCenterLat, nCenterLong), 13);
  52. // Display a rectangle in the center of the map at about a quarter of
  53. // the size of the main map
  54. var bounds = map.getBounds();
  55. var southWest = bounds.getSouthWest();
  56. var northEast = bounds.getNorthEast();
  57. var rectBounds = new GLatLngBounds(
  58. new GLatLng(nBottomLeftLat,
  59. nBottomLeftLong),
  60. new GLatLng(TopRightLat,
  61. TopRightLong));
  62. map.addOverlay(new Rectangle(rectBounds));
  63. }
  64. }