Google.js
5.14 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
* full list of contributors). Published under the Clear BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/BaseTypes/Class.js
* @requires OpenLayers/Util.js
* @requires OpenLayers/Tile.js
*/
/*
* Class: OpenLayers.Tile.Google
* Instances of OpenLayers.Tile.Google are used to manage the tiles created
* by google.maps.MapType (see
* http://code.google.com/apis/maps/documentation/javascript/reference.html#MapType).
*
* Inherits from:
* - <OpenLayers.Tile>
*/
OpenLayers.Tile.Google = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: node
* {DOMElement} The tile node from the MapType's getTile method
*/
node: null,
/**
* Constructor: OpenLayers.Tile.Google
* Constructor for a new <OpenLayers.Tile.Google> instance.
*
* Parameters:
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
* position - {<OpenLayers.Pixel>}
* bounds - {<OpenLayers.Bounds>}
* options - {Object}
*/
initialize: function(layer, position, bounds, options) {
OpenLayers.Tile.prototype.initialize.apply(this, [
layer, position, bounds, null, null, options
]);
},
/**
* APIMethod: destroy
* Nullify references to prevent circular references and memory leaks.
*/
destroy:function() {
this.node && this.clear();
this.node = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
},
/**
* Method: clone
*
* Parameters:
* obj - {<OpenLayers.Tile>} The tile to be cloned
*
* Returns:
* {<OpenLayers.Tile>} An exact clone of this <OpenLayers.Tile.Google>
*/
clone: function (obj) {
if (obj == null) {
obj = new OpenLayers.Tile.Google(this.layer,
this.position,
this.bounds);
}
// catch any randomly tagged-on properties
OpenLayers.Util.applyDefaults(obj, this);
obj.node = null;
return obj;
},
/**
* Method: draw
* Check that a tile should be drawn, and draw it.
*
* Returns:
* {Boolean} Always returns true.
*/
draw: function() {
var layerType = OpenLayers.Layer.GoogleNG.mapObject.mapTypes[
this.layer.type
];
if (layerType && OpenLayers.Tile.prototype.draw.apply(this, arguments)) {
var xyz = this.layer.getXYZ(this.bounds);
var point = new google.maps.Point(xyz.x, xyz.y);
// The hybrid tile consists of two images. For some reason, we have
// to make sure that the satellite image loads first, otherwise we
// occasionally get blank tiles for one of the two images. This is
// done by requesting the tile for just the satellite mapType
// first, before requesting the hybrid one.
//TODO revisit this - it may be a temporary issue with GMaps
var tempTile;
if (this.layer.type === google.maps.MapTypeId.HYBRID) {
tempTile = layerType.getTile(point, xyz.z, document);
}
this.node = layerType.getTile(point, xyz.z, document);
this.isLoading = true;
this.events.triggerEvent("loadstart");
this.layer.div.appendChild(this.node);
// We only modify what we need to - we expect the size to be set
// by getTile, and we have a test that will fail if this changes.
OpenLayers.Util.modifyDOMElement(
this.node, null, this.position, null, "absolute"
);
// The images inside the node returned from getTile seem to be
// preloaded already, so registering onload events on these images
// won't work. Instead, we trigger the loadend event immediately
// in the next cycle.
window.setTimeout(OpenLayers.Function.bind(function() {
this.isLoading = false;
// check for this.events - we may be destroyed already
this.events && this.events.triggerEvent("loadend");
// see hybrid tile issue above
//TODO revisit this - it may be a temporary issue with GMaps
if (tempTile) {
layerType.releaseTile(tempTile);
}
}, this), 0);
}
return true;
},
/**
* Method: clear
* Clear the tile of any bounds/position-related data so that it can
* be reused in a new location. To be implemented by subclasses.
*/
clear: function() {
if (this.node) {
this.node.parentNode &&
this.node.parentNode.removeChild(this.node);
OpenLayers.Layer.GoogleNG.mapObject.mapTypes[
this.layer.type
].releaseTile(this.node);
}
},
CLASS_NAME: "OpenLayers.Tile.Google"
});