1// Create an overlay on the map from a projected image - Maps v3... 2// Author. John D. Coryat 05/2009 3// USNaviguide LLC - http://www.usnaviguide.com 4// Thanks go to Mile Williams EInsert: http://econym.googlepages.com/einsert.js, Google's GOverlay Example and Bratliff's suggestion... 5// Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html 6// This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 7// 8// Parameters: 9// map: This Map 10// imageUrl: URL of the image (Mandatory) 11// bounds: Bounds object of image destination (Mandatory) 12// Options: 13// addZoom: Added Zoom factor as a parameter to the imageUrl (include complete parameter, including separater like '?zoom=' 14// percentOpacity: Default 50, percent opacity to use when the image is loaded 0-100. 15// id: Default imageUrl, ID of the div 16// 17 18function ProjectedOverlay(map, imageUrl, bounds, opts) 19{ 20 google.maps.OverlayView.call(this); 21 22 this.map_ = map; 23 this.url_ = imageUrl ; 24 this.bounds_ = bounds ; 25 this.addZ_ = opts.addZoom || '' ; // Add the zoom to the image as a parameter 26 this.id_ = opts.id || this.url_ ; // Added to allow for multiple images 27 this.percentOpacity_ = opts.percentOpacity || 70 ; 28 this.setMap(map); 29} 30 31ProjectedOverlay.prototype = new google.maps.OverlayView(); 32 33ProjectedOverlay.prototype.createElement = function() 34{ 35 var panes = this.getPanes() ; 36 var div = this.div_ ; 37 38 if (!div) 39 { 40 div = this.div_ = document.createElement("div"); 41 div.style.position = "absolute" ; 42 div.setAttribute('id',this.id_) ; 43 this.div_ = div ; 44 this.lastZoom_ = -1 ; 45 if( this.percentOpacity_ ) 46 { 47 this.setOpacity(this.percentOpacity_) ; 48 } 49 panes.overlayLayer.appendChild(div); 50 } 51} 52 53// Remove the main DIV from the map pane 54 55ProjectedOverlay.prototype.remove = function() 56{ 57 if (this.div_) 58 { 59 this.div_.parentNode.removeChild(this.div_); 60 this.div_ = null; 61 } 62} 63 64// Redraw based on the current projection and zoom level... 65 66ProjectedOverlay.prototype.draw = function(firstTime) 67{ 68 // Creates the element if it doesn't exist already. 69 70 this.createElement(); 71 72 if (!this.div_) 73 { 74 return ; 75 } 76 77 var c1 = this.get('projection').fromLatLngToDivPixel(this.bounds_.getSouthWest
77()); 78 var c2 = this.get('projection').fromLatLngToDivPixel(this.bounds_.getNorthEast()); 79 80 if (!c1 || !c2) return; 81 82 // Now position our DIV based on the DIV coordinates of our bounds 83 84 this.div_.style.width = Math.abs(c2.x - c1.x) + "px"; 85 this.div_.style.height = Math.abs(c2.y - c1.y) + "px"; 86 this.div_.style.left = Math.min(c2.x, c1.x) + "px"; 87 this.div_.style.top = Math.min(c2.y, c1.y) + "px"; 88 89 // Do the rest only if the zoom has changed... 90 91 var url = this.url_ ; 92 93 if ( this.addZ_ ) 94 { 95 url += this.addZ_ + this.map_.getZoom() ; 96 } 97 98 this.div_.innerHTML = '<img src="' + url + '" width=' + this.div_.style.width + ' height=' + this.div_.style.height + ' >' ; 99 100 // Do the rest only if the zoom has changed... 101 102 if ( this.lastZoom_ == this.map_.getZoom() ) 103 { 104 return ; 105 } 106 107 this.lastZoom_ = this.map_.getZoom() ; 108} 109 110ProjectedOverlay.prototype.setOpacity=function(opacity) 111{ 112 if (opacity < 0) 113 { 114 opacity = 0 ; 115 } 116 if(opacity > 100) 117 { 118 opacity = 100 ; 119 } 120 var c = opacity/100 ; 121 122 if (typeof(this.div_.style.filter) =='string') 123 { 124 this.div_.style.filter = 'alpha(opacity:' + opacity + ')' ; 125 } 126 if (typeof(this.div_.style.KHTMLOpacity) == 'string' ) 127 { 128 this.div_.style.KHTMLOpacity = c ; 129 } 130 if (typeof(this.div_.style.MozOpacity) == 'string') 131 { 132 this.div_.style.MozOpacity = c ; 133 } 134 if (typeof(this.div_.style.opacity) == 'string') 135 { 136 this.div_.style.opacity = c ; 137 } 138} 139
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.