function initialize(){ if (google.maps.BrowserIsCompatible()) { /*alert('initializing');*/ var marker1_value = document.getElementById('marker1_value'); /*alert(marker1_value.value);*/ var marker2_value = document.getElementById('marker2_value'); var ne_coord = document.getElementById('ne_coord'); var sw_coord = document.getElementById('sw_coord'); var loc1 = '(39.829631721333726, -86.53656005859375)';var loc2 = '(40.130591063801795, -85.8746337890625)'; marker1_value.value = loc1; /*alert(marker1_value.value);*/ marker2_value.value = loc2; var map = new google.maps.Map2(document.getElementById('map_canvas')); var center = new google.maps.LatLng(39.8686124, -86.0980764); map.setCenter(center, 10); var geocoder = new google.maps.ClientGeocoder(); var mapControl = new google.maps.MapTypeControl(); map.addControl(mapControl); map.addControl(new google.maps.LargeMapControl()); function drawRectangle(){ // A Rectangle is a simple overlay that outlines a lat/lng bounds on the // map. It has a border of the given weight and color and can optionally // have a semi-transparent background color. function Rectangle(bounds, opt_weight, opt_color, opt_opacity, opt_bgcolor) { this.bounds_ = bounds; this.weight_ = opt_weight || 2; this.color_ = opt_color || "#888888"; this.opacity_ = opt_opacity || '.40'; this.opacity_2 = opt_opacity || '0.40'; this.opacity_3 = opt_opacity || 'alpha(opacity=40)'; this.backgroundColor_ = opt_bgcolor || "#dddddd"; } Rectangle.prototype = new google.maps.Overlay(); // Creates the DIV representing this rectangle. Rectangle.prototype.initialize = function(map) { for(var ii = 0; ii < map.getPane(G_MAP_MAP_PANE).getElementsByTagName('div').length; ii++){ var div = map.getPane(G_MAP_MAP_PANE).getElementsByTagName('div')[ii]; map.getPane(G_MAP_MAP_PANE).removeChild(div); } // Create the DIV representing our rectangle var div = document.createElement("div"); div.style.border = this.weight_ + "px solid " + this.color_; div.style.position = "absolute"; div.style.opacity = this.opacity_; div.style.filter = this.opacity_3; div.style.mozOpacity = this.opacity_2; div.style.backgroundColor = this.backgroundColor_; // Our rectangle is flat against the map, so we add our selves to the // MAP_PANE pane, which is at the same z-index as the map itself (i.e., // below the marker shadows) map.getPane(G_MAP_MAP_PANE).appendChild(div); this.map_ = map; this.div_ = div; } // Copy our data to a new Rectangle Rectangle.prototype.copy = function() { return new Rectangle(this.bounds_, this.weight_, this.color_, this.backgroundColor_, this.opacity_); } // Redraw the rectangle based on the current projection and zoom level Rectangle.prototype.redraw = function(force) { // We only need to redraw if the coordinate system has changed if (!force) return; // Calculate the DIV coordinates of two opposite corners of our bounds to // get the size and position of our rectangle var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest()); var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast()); /* var d = marker1_value.value; var e = marker2_value.value; alert(d); alert(e); var c1 = this.map_.fromLatLngToDivPixel(a1,a3); var c2 = this.map_.fromLatLngToDivPixel(b1,b3); */ /*alert(c1); alert(c2);*/ // Now position our DIV based on the DIV coordinates of our bounds this.div_.style.width = Math.abs(c2.x - c1.x) + "px"; this.div_.style.height = Math.abs(c2.y - c1.y) + "px"; this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px"; this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px"; /*Rectangle.remove = new Rectangle.prototype.remove(this.div_);*/ /*Rectangle.prototype.remove(this.div_);*/ } /*alert('SouthWest '+marker1_value.value); alert('NorthEast '+marker2_value.value);*/ var a = marker1_value.value; var b = marker2_value.value; var tmp1 = strpos(marker1_value.value, ', '); var a1 = marker1_value.value.substr(1,tmp1-1); var a2 = marker1_value.value.substr(tmp1+2); var a3 = a2.replace(/\)/g, ''); var tmp2 = strpos(marker2_value.value, ', '); var b1 = marker2_value.value.substr(1,tmp2-1); var b2 = marker2_value.value.substr(tmp2+2); var b3 = b2.replace(/\)/g, ''); /*alert(b1); alert(b3);*/ /*alert('SouthWest '+a); alert('NorthEast '+b);*/ var rectBounds = new google.maps.LatLngBounds( new google.maps.LatLng(a1,a3), new google.maps.LatLng(b1,b3));/*southwest first, northeast second*/ map.addOverlay(new Rectangle(rectBounds)); } drawRectangle(); } } function strpos( haystack, needle, offset){ // http://kevin.vanzonneveld.net // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Onno Marsman // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14 var i = (haystack+'').indexOf( needle, offset ); return i===-1 ? false : i; } function ec(){ alert('Saving Coordinates!'); return true; }