1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// Create an overlay on the map from a projected image...
// Author. John D. Coryat 01/2008
// USNaviguide LLC - http://www.usnaviguide.com
// Thanks go to Mile Williams EInsert: http://econym.googlepages.com/einsert.js, Google's GOverlay Example and Bratliff's suggestion...
// Opacity code from TPhoto: http://gmaps.tommangan.us/addtphoto.html
// 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.
//
// Parameters:
// imageUrl: URL of the image
// bounds: Bounds object of image destination
// addZoom: Added Zoom factor as a parameter to the imageUrl (include complete parameter, including separater like '?zoom='
//
function ProjectedOverlay(imageUrl, bounds, addZoom)
{
this.url_ = imageUrl ;
this.bounds_ = bounds ;
this.addZ_ = addZoom ; // Add the zoom to the image as a parameter
// Is this IE, if so we need to use AlphaImageLoader
this.ie = false ;
var agent = navigator.userAgent.toLowerCase();
if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1))
{
this.ie = true ;
}
}
ProjectedOverlay.prototype = new GOverlay();
ProjectedOverlay.prototype.initialize = function(map)
{
var div = document.createElement("div") ;
div.style.position = "absolute" ;
div.setAttribute('id',this.id) ;
map.getPane(G_MAP_MAP_PANE).appendChild(div) ;
this.map_ = map ;
this.div_ = div ;
if( this.percentOpacity )
{
this.setOpacity(this.percentOpacity) ;
}
}
// Remove the main DIV from the map pane
ProjectedOverlay.prototype.remove = function()
{
this.div_.parentNode.removeChild(this.div_);
delete(this.map) ;
delete(this.div) ;
}
// Copy our data to a new ProjectedOverlay...
ProjectedOverlay.prototype.copy = function()
{
return new ProjectedOverlay(this.url_, this.bounds_, this.addZ_);
}
// Redraw based on the current projection and zoom level...
ProjectedOverlay.prototype.redraw = function(force)
{
// We only need to redraw if the coordinate system has changed
if (!force)
{
return ;
}
var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
// 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) + "px";
this.div_.style.top = Math.min(c2.y, c1.y) + "px";
var url = this.url_ ;
var extn = url.substring(url.length - 4, 4) ;
if ( this.addZ_ )
{
url += this.addZ_ + this.map_.getZoom() ;
}
if (this.ie && extn.toLowerCase() == '.png')
{
var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='scale');" ;
this.div_.innerHTML = '<div style="height:' + this.div_.style.height + 'px; width:' + this.div_.style.width + 'px; ' + loader + '" ></div>' ;
} else
{
this.div_.innerHTML = '<img src="' + url + '" width=' + this.div_.style.width + ' height=' + this.div_.style.height + ' >' ;
}
}
ProjectedOverlay.prototype.setOpacity=function(opacity)
{
if (opacity < 0)
{
opacity = 0 ;
}
if(opacity > 100)
{
opacity = 100 ;
}
var c = opacity/100 ;
var d = document.getElementById( this.id ) ;
if (typeof(d.style.filter) =='string')
{
d.style.filter = 'alpha(opacity:' + opacity + ')' ;
}
if (typeof(d.style.KHTMLOpacity) == 'string' )
{
d.style.KHTMLOpacity = c ;
}
if (typeof(d.style.MozOpacity) == 'string')
{
d.style.MozOpacity = c ;
}
if (typeof(d.style.opacity) == 'string')
{
d.style.opacity = c ;
}
}
|