1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
2 | * full list of contributors). Published under the Clear BSD license. |
---|
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
4 | * full text of the license. */ |
---|
5 | |
---|
6 | |
---|
7 | /** |
---|
8 | * @requires OpenLayers/Layer/SphericalMercator.js |
---|
9 | * @requires OpenLayers/Layer/EventPane.js |
---|
10 | * @requires OpenLayers/Layer/FixedZoomLevels.js |
---|
11 | */ |
---|
12 | |
---|
13 | /** |
---|
14 | * Class: OpenLayers.Layer.Google |
---|
15 | * |
---|
16 | * Inherits from: |
---|
17 | * - <OpenLayers.Layer.SphericalMercator> |
---|
18 | * - <OpenLayers.Layer.EventPane> |
---|
19 | * - <OpenLayers.Layer.FixedZoomLevels> |
---|
20 | */ |
---|
21 | OpenLayers.Layer.Google = OpenLayers.Class( |
---|
22 | OpenLayers.Layer.EventPane, |
---|
23 | OpenLayers.Layer.FixedZoomLevels, { |
---|
24 | |
---|
25 | /** |
---|
26 | * Constant: MIN_ZOOM_LEVEL |
---|
27 | * {Integer} 0 |
---|
28 | */ |
---|
29 | MIN_ZOOM_LEVEL: 0, |
---|
30 | |
---|
31 | /** |
---|
32 | * Constant: MAX_ZOOM_LEVEL |
---|
33 | * {Integer} 21 |
---|
34 | */ |
---|
35 | MAX_ZOOM_LEVEL: 21, |
---|
36 | |
---|
37 | /** |
---|
38 | * Constant: RESOLUTIONS |
---|
39 | * {Array(Float)} Hardcode these resolutions so that they are more closely |
---|
40 | * tied with the standard wms projection |
---|
41 | */ |
---|
42 | RESOLUTIONS: [ |
---|
43 | 1.40625, |
---|
44 | 0.703125, |
---|
45 | 0.3515625, |
---|
46 | 0.17578125, |
---|
47 | 0.087890625, |
---|
48 | 0.0439453125, |
---|
49 | 0.02197265625, |
---|
50 | 0.010986328125, |
---|
51 | 0.0054931640625, |
---|
52 | 0.00274658203125, |
---|
53 | 0.001373291015625, |
---|
54 | 0.0006866455078125, |
---|
55 | 0.00034332275390625, |
---|
56 | 0.000171661376953125, |
---|
57 | 0.0000858306884765625, |
---|
58 | 0.00004291534423828125, |
---|
59 | 0.00002145767211914062, |
---|
60 | 0.00001072883605957031, |
---|
61 | 0.00000536441802978515, |
---|
62 | 0.00000268220901489257, |
---|
63 | 0.0000013411045074462891, |
---|
64 | 0.00000067055225372314453 |
---|
65 | ], |
---|
66 | |
---|
67 | /** |
---|
68 | * APIProperty: type |
---|
69 | * {GMapType} |
---|
70 | */ |
---|
71 | type: null, |
---|
72 | |
---|
73 | /** |
---|
74 | * APIProperty: wrapDateLine |
---|
75 | * {Boolean} Allow user to pan forever east/west. Default is true. |
---|
76 | * Setting this to false only restricts panning if |
---|
77 | * <sphericalMercator> is true. |
---|
78 | */ |
---|
79 | wrapDateLine: true, |
---|
80 | |
---|
81 | /** |
---|
82 | * APIProperty: sphericalMercator |
---|
83 | * {Boolean} Should the map act as a mercator-projected map? This will |
---|
84 | * cause all interactions with the map to be in the actual map |
---|
85 | * projection, which allows support for vector drawing, overlaying |
---|
86 | * other maps, etc. |
---|
87 | */ |
---|
88 | sphericalMercator: false, |
---|
89 | |
---|
90 | /** |
---|
91 | * Property: version |
---|
92 | * {Number} The version of the Google Maps API |
---|
93 | */ |
---|
94 | version: null, |
---|
95 | |
---|
96 | /** |
---|
97 | * Constructor: OpenLayers.Layer.Google |
---|
98 | * |
---|
99 | * Parameters: |
---|
100 | * name - {String} A name for the layer. |
---|
101 | * options - {Object} An optional object whose properties will be set |
---|
102 | * on the layer. |
---|
103 | */ |
---|
104 | initialize: function(name, options) { |
---|
105 | options = options || {}; |
---|
106 | if(!options.version) { |
---|
107 | options.version = typeof GMap2 === "function" ? "2" : "3"; |
---|
108 | } |
---|
109 | var mixin = OpenLayers.Layer.Google["v" + |
---|
110 | options.version.replace(/\./g, "_")]; |
---|
111 | if (mixin) { |
---|
112 | OpenLayers.Util.applyDefaults(options, mixin); |
---|
113 | } else { |
---|
114 | throw "Unsupported Google Maps API version: " + options.version; |
---|
115 | } |
---|
116 | |
---|
117 | OpenLayers.Util.applyDefaults(options, mixin.DEFAULTS); |
---|
118 | if (options.maxExtent) { |
---|
119 | options.maxExtent = options.maxExtent.clone(); |
---|
120 | } |
---|
121 | |
---|
122 | OpenLayers.Layer.EventPane.prototype.initialize.apply(this, |
---|
123 | [name, options]); |
---|
124 | OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, |
---|
125 | [name, options]); |
---|
126 | |
---|
127 | if (this.sphericalMercator) { |
---|
128 | OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); |
---|
129 | this.initMercatorParameters(); |
---|
130 | } |
---|
131 | }, |
---|
132 | |
---|
133 | /** |
---|
134 | * Method: clone |
---|
135 | * Create a clone of this layer |
---|
136 | * |
---|
137 | * Returns: |
---|
138 | * {<OpenLayers.Layer.Google>} An exact clone of this layer |
---|
139 | */ |
---|
140 | clone: function() { |
---|
141 | /** |
---|
142 | * This method isn't intended to be called by a subclass and it |
---|
143 | * doesn't call the same method on the superclass. We don't call |
---|
144 | * the super's clone because we don't want properties that are set |
---|
145 | * on this layer after initialize (i.e. this.mapObject etc.). |
---|
146 | */ |
---|
147 | return new OpenLayers.Layer.Google( |
---|
148 | this.name, this.getOptions() |
---|
149 | ); |
---|
150 | }, |
---|
151 | |
---|
152 | /** |
---|
153 | * APIMethod: setVisibility |
---|
154 | * Set the visibility flag for the layer and hide/show & redraw |
---|
155 | * accordingly. Fire event unless otherwise specified |
---|
156 | * |
---|
157 | * Note that visibility is no longer simply whether or not the layer's |
---|
158 | * style.display is set to "block". Now we store a 'visibility' state |
---|
159 | * property on the layer class, this allows us to remember whether or |
---|
160 | * not we *desire* for a layer to be visible. In the case where the |
---|
161 | * map's resolution is out of the layer's range, this desire may be |
---|
162 | * subverted. |
---|
163 | * |
---|
164 | * Parameters: |
---|
165 | * visible - {Boolean} Display the layer (if in range) |
---|
166 | */ |
---|
167 | setVisibility: function(visible) { |
---|
168 | // sharing a map container, opacity has to be set per layer |
---|
169 | var opacity = this.opacity == null ? 1 : this.opacity; |
---|
170 | OpenLayers.Layer.EventPane.prototype.setVisibility.apply(this, arguments); |
---|
171 | this.setOpacity(opacity); |
---|
172 | }, |
---|
173 | |
---|
174 | /** |
---|
175 | * APIMethod: display |
---|
176 | * Hide or show the Layer |
---|
177 | * |
---|
178 | * Parameters: |
---|
179 | * display - {Boolean} |
---|
180 | */ |
---|
181 | display: function(visible) { |
---|
182 | if (!this._dragging) { |
---|
183 | this.setGMapVisibility(visible); |
---|
184 | } |
---|
185 | OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments); |
---|
186 | }, |
---|
187 | |
---|
188 | /** |
---|
189 | * Method: moveTo |
---|
190 | * |
---|
191 | * Parameters: |
---|
192 | * bound - {<OpenLayers.Bounds>} |
---|
193 | * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to |
---|
194 | * do some init work in that case. |
---|
195 | * dragging - {Boolean} |
---|
196 | */ |
---|
197 | moveTo: function(bounds, zoomChanged, dragging) { |
---|
198 | this._dragging = dragging; |
---|
199 | OpenLayers.Layer.EventPane.prototype.moveTo.apply(this, arguments); |
---|
200 | delete this._dragging; |
---|
201 | }, |
---|
202 | |
---|
203 | /** |
---|
204 | * APIMethod: setOpacity |
---|
205 | * Sets the opacity for the entire layer (all images) |
---|
206 | * |
---|
207 | * Parameter: |
---|
208 | * opacity - {Float} |
---|
209 | */ |
---|
210 | setOpacity: function(opacity) { |
---|
211 | if (opacity !== this.opacity) { |
---|
212 | if (this.map != null) { |
---|
213 | this.map.events.triggerEvent("changelayer", { |
---|
214 | layer: this, |
---|
215 | property: "opacity" |
---|
216 | }); |
---|
217 | } |
---|
218 | this.opacity = opacity; |
---|
219 | } |
---|
220 | // Though this layer's opacity may not change, we're sharing a container |
---|
221 | // and need to update the opacity for the entire container. |
---|
222 | if (this.getVisibility()) { |
---|
223 | var container = this.getMapContainer(); |
---|
224 | OpenLayers.Util.modifyDOMElement( |
---|
225 | container, null, null, null, null, null, null, opacity |
---|
226 | ); |
---|
227 | } |
---|
228 | }, |
---|
229 | |
---|
230 | /** |
---|
231 | * APIMethod: destroy |
---|
232 | * Clean up this layer. |
---|
233 | */ |
---|
234 | destroy: function() { |
---|
235 | /** |
---|
236 | * We have to override this method because the event pane destroy |
---|
237 | * deletes the mapObject reference before removing this layer from |
---|
238 | * the map. |
---|
239 | */ |
---|
240 | if (this.map) { |
---|
241 | this.setGMapVisibility(false); |
---|
242 | var cache = OpenLayers.Layer.Google.cache[this.map.id]; |
---|
243 | if (cache && cache.count <= 1) { |
---|
244 | this.removeGMapElements(); |
---|
245 | } |
---|
246 | } |
---|
247 | OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments); |
---|
248 | }, |
---|
249 | |
---|
250 | /** |
---|
251 | * Method: removeGMapElements |
---|
252 | * Remove all elements added to the dom. This should only be called if |
---|
253 | * this is the last of the Google layers for the given map. |
---|
254 | */ |
---|
255 | removeGMapElements: function() { |
---|
256 | var cache = OpenLayers.Layer.Google.cache[this.map.id]; |
---|
257 | if (cache) { |
---|
258 | // remove shared elements from dom |
---|
259 | var container = this.mapObject && this.getMapContainer(); |
---|
260 | if (container && container.parentNode) { |
---|
261 | container.parentNode.removeChild(container); |
---|
262 | } |
---|
263 | var termsOfUse = cache.termsOfUse; |
---|
264 | if (termsOfUse && termsOfUse.parentNode) { |
---|
265 | termsOfUse.parentNode.removeChild(termsOfUse); |
---|
266 | } |
---|
267 | var poweredBy = cache.poweredBy; |
---|
268 | if (poweredBy && poweredBy.parentNode) { |
---|
269 | poweredBy.parentNode.removeChild(poweredBy); |
---|
270 | } |
---|
271 | } |
---|
272 | }, |
---|
273 | |
---|
274 | /** |
---|
275 | * APIMethod: removeMap |
---|
276 | * On being removed from the map, also remove termsOfUse and poweredBy divs |
---|
277 | * |
---|
278 | * Parameters: |
---|
279 | * map - {<OpenLayers.Map>} |
---|
280 | */ |
---|
281 | removeMap: function(map) { |
---|
282 | // hide layer before removing |
---|
283 | if (this.visibility && this.mapObject) { |
---|
284 | this.setGMapVisibility(false); |
---|
285 | } |
---|
286 | // check to see if last Google layer in this map |
---|
287 | var cache = OpenLayers.Layer.Google.cache[map.id]; |
---|
288 | if (cache) { |
---|
289 | if (cache.count <= 1) { |
---|
290 | this.removeGMapElements(); |
---|
291 | delete OpenLayers.Layer.Google.cache[map.id]; |
---|
292 | } else { |
---|
293 | // decrement the layer count |
---|
294 | --cache.count; |
---|
295 | } |
---|
296 | } |
---|
297 | // remove references to gmap elements |
---|
298 | delete this.termsOfUse; |
---|
299 | delete this.poweredBy; |
---|
300 | delete this.mapObject; |
---|
301 | delete this.dragObject; |
---|
302 | OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments); |
---|
303 | }, |
---|
304 | |
---|
305 | // |
---|
306 | // TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds |
---|
307 | // |
---|
308 | |
---|
309 | /** |
---|
310 | * APIMethod: getOLBoundsFromMapObjectBounds |
---|
311 | * |
---|
312 | * Parameters: |
---|
313 | * moBounds - {Object} |
---|
314 | * |
---|
315 | * Returns: |
---|
316 | * {<OpenLayers.Bounds>} An <OpenLayers.Bounds>, translated from the |
---|
317 | * passed-in MapObject Bounds. |
---|
318 | * Returns null if null value is passed in. |
---|
319 | */ |
---|
320 | getOLBoundsFromMapObjectBounds: function(moBounds) { |
---|
321 | var olBounds = null; |
---|
322 | if (moBounds != null) { |
---|
323 | var sw = moBounds.getSouthWest(); |
---|
324 | var ne = moBounds.getNorthEast(); |
---|
325 | if (this.sphericalMercator) { |
---|
326 | sw = this.forwardMercator(sw.lng(), sw.lat()); |
---|
327 | ne = this.forwardMercator(ne.lng(), ne.lat()); |
---|
328 | } else { |
---|
329 | sw = new OpenLayers.LonLat(sw.lng(), sw.lat()); |
---|
330 | ne = new OpenLayers.LonLat(ne.lng(), ne.lat()); |
---|
331 | } |
---|
332 | olBounds = new OpenLayers.Bounds(sw.lon, |
---|
333 | sw.lat, |
---|
334 | ne.lon, |
---|
335 | ne.lat ); |
---|
336 | } |
---|
337 | return olBounds; |
---|
338 | }, |
---|
339 | |
---|
340 | /** |
---|
341 | * APIMethod: getWarningHTML |
---|
342 | * |
---|
343 | * Returns: |
---|
344 | * {String} String with information on why layer is broken, how to get |
---|
345 | * it working. |
---|
346 | */ |
---|
347 | getWarningHTML:function() { |
---|
348 | return OpenLayers.i18n("googleWarning"); |
---|
349 | }, |
---|
350 | |
---|
351 | |
---|
352 | /************************************ |
---|
353 | * * |
---|
354 | * MapObject Interface Controls * |
---|
355 | * * |
---|
356 | ************************************/ |
---|
357 | |
---|
358 | |
---|
359 | // Get&Set Center, Zoom |
---|
360 | |
---|
361 | /** |
---|
362 | * APIMethod: getMapObjectCenter |
---|
363 | * |
---|
364 | * Returns: |
---|
365 | * {Object} The mapObject's current center in Map Object format |
---|
366 | */ |
---|
367 | getMapObjectCenter: function() { |
---|
368 | return this.mapObject.getCenter(); |
---|
369 | }, |
---|
370 | |
---|
371 | /** |
---|
372 | * APIMethod: getMapObjectZoom |
---|
373 | * |
---|
374 | * Returns: |
---|
375 | * {Integer} The mapObject's current zoom, in Map Object format |
---|
376 | */ |
---|
377 | getMapObjectZoom: function() { |
---|
378 | return this.mapObject.getZoom(); |
---|
379 | }, |
---|
380 | |
---|
381 | |
---|
382 | /************************************ |
---|
383 | * * |
---|
384 | * MapObject Primitives * |
---|
385 | * * |
---|
386 | ************************************/ |
---|
387 | |
---|
388 | |
---|
389 | // LonLat |
---|
390 | |
---|
391 | /** |
---|
392 | * APIMethod: getLongitudeFromMapObjectLonLat |
---|
393 | * |
---|
394 | * Parameters: |
---|
395 | * moLonLat - {Object} MapObject LonLat format |
---|
396 | * |
---|
397 | * Returns: |
---|
398 | * {Float} Longitude of the given MapObject LonLat |
---|
399 | */ |
---|
400 | getLongitudeFromMapObjectLonLat: function(moLonLat) { |
---|
401 | return this.sphericalMercator ? |
---|
402 | this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lon : |
---|
403 | moLonLat.lng(); |
---|
404 | }, |
---|
405 | |
---|
406 | /** |
---|
407 | * APIMethod: getLatitudeFromMapObjectLonLat |
---|
408 | * |
---|
409 | * Parameters: |
---|
410 | * moLonLat - {Object} MapObject LonLat format |
---|
411 | * |
---|
412 | * Returns: |
---|
413 | * {Float} Latitude of the given MapObject LonLat |
---|
414 | */ |
---|
415 | getLatitudeFromMapObjectLonLat: function(moLonLat) { |
---|
416 | var lat = this.sphericalMercator ? |
---|
417 | this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lat : |
---|
418 | moLonLat.lat(); |
---|
419 | return lat; |
---|
420 | }, |
---|
421 | |
---|
422 | // Pixel |
---|
423 | |
---|
424 | /** |
---|
425 | * APIMethod: getXFromMapObjectPixel |
---|
426 | * |
---|
427 | * Parameters: |
---|
428 | * moPixel - {Object} MapObject Pixel format |
---|
429 | * |
---|
430 | * Returns: |
---|
431 | * {Integer} X value of the MapObject Pixel |
---|
432 | */ |
---|
433 | getXFromMapObjectPixel: function(moPixel) { |
---|
434 | return moPixel.x; |
---|
435 | }, |
---|
436 | |
---|
437 | /** |
---|
438 | * APIMethod: getYFromMapObjectPixel |
---|
439 | * |
---|
440 | * Parameters: |
---|
441 | * moPixel - {Object} MapObject Pixel format |
---|
442 | * |
---|
443 | * Returns: |
---|
444 | * {Integer} Y value of the MapObject Pixel |
---|
445 | */ |
---|
446 | getYFromMapObjectPixel: function(moPixel) { |
---|
447 | return moPixel.y; |
---|
448 | }, |
---|
449 | |
---|
450 | CLASS_NAME: "OpenLayers.Layer.Google" |
---|
451 | }); |
---|
452 | |
---|
453 | /** |
---|
454 | * Property: OpenLayers.Layer.Google.cache |
---|
455 | * {Object} Cache for elements that should only be created once per map. |
---|
456 | */ |
---|
457 | OpenLayers.Layer.Google.cache = {}; |
---|
458 | |
---|
459 | |
---|
460 | /** |
---|
461 | * Constant: OpenLayers.Layer.Google.v2 |
---|
462 | * |
---|
463 | * Mixin providing functionality specific to the Google Maps API v2. |
---|
464 | */ |
---|
465 | OpenLayers.Layer.Google.v2 = { |
---|
466 | |
---|
467 | /** |
---|
468 | * Property: termsOfUse |
---|
469 | * {DOMElement} Div for Google's copyright and terms of use link |
---|
470 | */ |
---|
471 | termsOfUse: null, |
---|
472 | |
---|
473 | /** |
---|
474 | * Property: poweredBy |
---|
475 | * {DOMElement} Div for Google's powered by logo and link |
---|
476 | */ |
---|
477 | poweredBy: null, |
---|
478 | |
---|
479 | /** |
---|
480 | * Property: dragObject |
---|
481 | * {GDraggableObject} Since 2.93, Google has exposed the ability to get |
---|
482 | * the maps GDraggableObject. We can now use this for smooth panning |
---|
483 | */ |
---|
484 | dragObject: null, |
---|
485 | |
---|
486 | /** |
---|
487 | * Method: loadMapObject |
---|
488 | * Load the GMap and register appropriate event listeners. If we can't |
---|
489 | * load GMap2, then display a warning message. |
---|
490 | */ |
---|
491 | loadMapObject:function() { |
---|
492 | if (!this.type) { |
---|
493 | this.type = G_NORMAL_MAP; |
---|
494 | } |
---|
495 | var mapObject, termsOfUse, poweredBy; |
---|
496 | var cache = OpenLayers.Layer.Google.cache[this.map.id]; |
---|
497 | if (cache) { |
---|
498 | // there are already Google layers added to this map |
---|
499 | mapObject = cache.mapObject; |
---|
500 | termsOfUse = cache.termsOfUse; |
---|
501 | poweredBy = cache.poweredBy; |
---|
502 | // increment the layer count |
---|
503 | ++cache.count; |
---|
504 | } else { |
---|
505 | // this is the first Google layer for this map |
---|
506 | |
---|
507 | var container = this.map.viewPortDiv; |
---|
508 | var div = document.createElement("div"); |
---|
509 | div.id = this.map.id + "_GMap2Container"; |
---|
510 | div.style.position = "absolute"; |
---|
511 | div.style.width = "100%"; |
---|
512 | div.style.height = "100%"; |
---|
513 | container.appendChild(div); |
---|
514 | |
---|
515 | // create GMap and shuffle elements |
---|
516 | try { |
---|
517 | mapObject = new GMap2(div); |
---|
518 | |
---|
519 | // move the ToS and branding stuff up to the container div |
---|
520 | termsOfUse = div.lastChild; |
---|
521 | container.appendChild(termsOfUse); |
---|
522 | termsOfUse.style.zIndex = "1100"; |
---|
523 | termsOfUse.style.right = ""; |
---|
524 | termsOfUse.style.bottom = ""; |
---|
525 | termsOfUse.className = "olLayerGoogleCopyright"; |
---|
526 | |
---|
527 | poweredBy = div.lastChild; |
---|
528 | container.appendChild(poweredBy); |
---|
529 | poweredBy.style.zIndex = "1100"; |
---|
530 | poweredBy.style.right = ""; |
---|
531 | poweredBy.style.bottom = ""; |
---|
532 | poweredBy.className = "olLayerGooglePoweredBy gmnoprint"; |
---|
533 | |
---|
534 | } catch (e) { |
---|
535 | throw(e); |
---|
536 | } |
---|
537 | // cache elements for use by any other google layers added to |
---|
538 | // this same map |
---|
539 | OpenLayers.Layer.Google.cache[this.map.id] = { |
---|
540 | mapObject: mapObject, |
---|
541 | termsOfUse: termsOfUse, |
---|
542 | poweredBy: poweredBy, |
---|
543 | count: 1 |
---|
544 | }; |
---|
545 | } |
---|
546 | |
---|
547 | this.mapObject = mapObject; |
---|
548 | this.termsOfUse = termsOfUse; |
---|
549 | this.poweredBy = poweredBy; |
---|
550 | |
---|
551 | // ensure this layer type is one of the mapObject types |
---|
552 | if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(), |
---|
553 | this.type) === -1) { |
---|
554 | this.mapObject.addMapType(this.type); |
---|
555 | } |
---|
556 | |
---|
557 | //since v 2.93 getDragObject is now available. |
---|
558 | if(typeof mapObject.getDragObject == "function") { |
---|
559 | this.dragObject = mapObject.getDragObject(); |
---|
560 | } else { |
---|
561 | this.dragPanMapObject = null; |
---|
562 | } |
---|
563 | |
---|
564 | if(this.isBaseLayer === false) { |
---|
565 | this.setGMapVisibility(this.div.style.display !== "none"); |
---|
566 | } |
---|
567 | |
---|
568 | }, |
---|
569 | |
---|
570 | /** |
---|
571 | * APIMethod: onMapResize |
---|
572 | */ |
---|
573 | onMapResize: function() { |
---|
574 | // workaround for resizing of invisible or not yet fully loaded layers |
---|
575 | // where GMap2.checkResize() does not work. We need to load the GMap |
---|
576 | // for the old div size, then checkResize(), and then call |
---|
577 | // layer.moveTo() to trigger GMap.setCenter() (which will finish |
---|
578 | // the GMap initialization). |
---|
579 | if(this.visibility && this.mapObject.isLoaded()) { |
---|
580 | this.mapObject.checkResize(); |
---|
581 | } else { |
---|
582 | if(!this._resized) { |
---|
583 | var layer = this; |
---|
584 | var handle = GEvent.addListener(this.mapObject, "load", function() { |
---|
585 | GEvent.removeListener(handle); |
---|
586 | delete layer._resized; |
---|
587 | layer.mapObject.checkResize(); |
---|
588 | layer.moveTo(layer.map.getCenter(), layer.map.getZoom()); |
---|
589 | }); |
---|
590 | } |
---|
591 | this._resized = true; |
---|
592 | } |
---|
593 | }, |
---|
594 | |
---|
595 | /** |
---|
596 | * Method: setGMapVisibility |
---|
597 | * Display the GMap container and associated elements. |
---|
598 | * |
---|
599 | * Parameters: |
---|
600 | * visible - {Boolean} Display the GMap elements. |
---|
601 | */ |
---|
602 | setGMapVisibility: function(visible) { |
---|
603 | var cache = OpenLayers.Layer.Google.cache[this.map.id]; |
---|
604 | if (cache) { |
---|
605 | var container = this.mapObject.getContainer(); |
---|
606 | if (visible === true) { |
---|
607 | this.mapObject.setMapType(this.type); |
---|
608 | container.style.display = ""; |
---|
609 | this.termsOfUse.style.left = ""; |
---|
610 | this.termsOfUse.style.display = ""; |
---|
611 | this.poweredBy.style.display = ""; |
---|
612 | cache.displayed = this.id; |
---|
613 | } else { |
---|
614 | if (cache.displayed === this.id) { |
---|
615 | delete cache.displayed; |
---|
616 | } |
---|
617 | if (!cache.displayed) { |
---|
618 | container.style.display = "none"; |
---|
619 | this.termsOfUse.style.display = "none"; |
---|
620 | // move ToU far to the left in addition to setting display |
---|
621 | // to "none", because at the end of the GMap2 load |
---|
622 | // sequence, display: none will be unset and ToU would be |
---|
623 | // visible after loading a map with a google layer that is |
---|
624 | // initially hidden. |
---|
625 | this.termsOfUse.style.left = "-9999px"; |
---|
626 | this.poweredBy.style.display = "none"; |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | }, |
---|
631 | |
---|
632 | /** |
---|
633 | * Method: getMapContainer |
---|
634 | * |
---|
635 | * Returns: |
---|
636 | * {DOMElement} the GMap container's div |
---|
637 | */ |
---|
638 | getMapContainer: function() { |
---|
639 | return this.mapObject.getContainer(); |
---|
640 | }, |
---|
641 | |
---|
642 | // |
---|
643 | // TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds |
---|
644 | // |
---|
645 | |
---|
646 | /** |
---|
647 | * APIMethod: getMapObjectBoundsFromOLBounds |
---|
648 | * |
---|
649 | * Parameters: |
---|
650 | * olBounds - {<OpenLayers.Bounds>} |
---|
651 | * |
---|
652 | * Returns: |
---|
653 | * {Object} A MapObject Bounds, translated from olBounds |
---|
654 | * Returns null if null value is passed in |
---|
655 | */ |
---|
656 | getMapObjectBoundsFromOLBounds: function(olBounds) { |
---|
657 | var moBounds = null; |
---|
658 | if (olBounds != null) { |
---|
659 | var sw = this.sphericalMercator ? |
---|
660 | this.inverseMercator(olBounds.bottom, olBounds.left) : |
---|
661 | new OpenLayers.LonLat(olBounds.bottom, olBounds.left); |
---|
662 | var ne = this.sphericalMercator ? |
---|
663 | this.inverseMercator(olBounds.top, olBounds.right) : |
---|
664 | new OpenLayers.LonLat(olBounds.top, olBounds.right); |
---|
665 | moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon), |
---|
666 | new GLatLng(ne.lat, ne.lon)); |
---|
667 | } |
---|
668 | return moBounds; |
---|
669 | }, |
---|
670 | |
---|
671 | |
---|
672 | /************************************ |
---|
673 | * * |
---|
674 | * MapObject Interface Controls * |
---|
675 | * * |
---|
676 | ************************************/ |
---|
677 | |
---|
678 | |
---|
679 | // Get&Set Center, Zoom |
---|
680 | |
---|
681 | /** |
---|
682 | * APIMethod: setMapObjectCenter |
---|
683 | * Set the mapObject to the specified center and zoom |
---|
684 | * |
---|
685 | * Parameters: |
---|
686 | * center - {Object} MapObject LonLat format |
---|
687 | * zoom - {int} MapObject zoom format |
---|
688 | */ |
---|
689 | setMapObjectCenter: function(center, zoom) { |
---|
690 | this.mapObject.setCenter(center, zoom); |
---|
691 | }, |
---|
692 | |
---|
693 | /** |
---|
694 | * APIMethod: dragPanMapObject |
---|
695 | * |
---|
696 | * Parameters: |
---|
697 | * dX - {Integer} |
---|
698 | * dY - {Integer} |
---|
699 | */ |
---|
700 | dragPanMapObject: function(dX, dY) { |
---|
701 | this.dragObject.moveBy(new GSize(-dX, dY)); |
---|
702 | }, |
---|
703 | |
---|
704 | |
---|
705 | // LonLat - Pixel Translation |
---|
706 | |
---|
707 | /** |
---|
708 | * APIMethod: getMapObjectLonLatFromMapObjectPixel |
---|
709 | * |
---|
710 | * Parameters: |
---|
711 | * moPixel - {Object} MapObject Pixel format |
---|
712 | * |
---|
713 | * Returns: |
---|
714 | * {Object} MapObject LonLat translated from MapObject Pixel |
---|
715 | */ |
---|
716 | getMapObjectLonLatFromMapObjectPixel: function(moPixel) { |
---|
717 | return this.mapObject.fromContainerPixelToLatLng(moPixel); |
---|
718 | }, |
---|
719 | |
---|
720 | /** |
---|
721 | * APIMethod: getMapObjectPixelFromMapObjectLonLat |
---|
722 | * |
---|
723 | * Parameters: |
---|
724 | * moLonLat - {Object} MapObject LonLat format |
---|
725 | * |
---|
726 | * Returns: |
---|
727 | * {Object} MapObject Pixel transtlated from MapObject LonLat |
---|
728 | */ |
---|
729 | getMapObjectPixelFromMapObjectLonLat: function(moLonLat) { |
---|
730 | return this.mapObject.fromLatLngToContainerPixel(moLonLat); |
---|
731 | }, |
---|
732 | |
---|
733 | |
---|
734 | // Bounds |
---|
735 | |
---|
736 | /** |
---|
737 | * APIMethod: getMapObjectZoomFromMapObjectBounds |
---|
738 | * |
---|
739 | * Parameters: |
---|
740 | * moBounds - {Object} MapObject Bounds format |
---|
741 | * |
---|
742 | * Returns: |
---|
743 | * {Object} MapObject Zoom for specified MapObject Bounds |
---|
744 | */ |
---|
745 | getMapObjectZoomFromMapObjectBounds: function(moBounds) { |
---|
746 | return this.mapObject.getBoundsZoomLevel(moBounds); |
---|
747 | }, |
---|
748 | |
---|
749 | /************************************ |
---|
750 | * * |
---|
751 | * MapObject Primitives * |
---|
752 | * * |
---|
753 | ************************************/ |
---|
754 | |
---|
755 | |
---|
756 | // LonLat |
---|
757 | |
---|
758 | /** |
---|
759 | * APIMethod: getMapObjectLonLatFromLonLat |
---|
760 | * |
---|
761 | * Parameters: |
---|
762 | * lon - {Float} |
---|
763 | * lat - {Float} |
---|
764 | * |
---|
765 | * Returns: |
---|
766 | * {Object} MapObject LonLat built from lon and lat params |
---|
767 | */ |
---|
768 | getMapObjectLonLatFromLonLat: function(lon, lat) { |
---|
769 | var gLatLng; |
---|
770 | if(this.sphericalMercator) { |
---|
771 | var lonlat = this.inverseMercator(lon, lat); |
---|
772 | gLatLng = new GLatLng(lonlat.lat, lonlat.lon); |
---|
773 | } else { |
---|
774 | gLatLng = new GLatLng(lat, lon); |
---|
775 | } |
---|
776 | return gLatLng; |
---|
777 | }, |
---|
778 | |
---|
779 | // Pixel |
---|
780 | |
---|
781 | /** |
---|
782 | * APIMethod: getMapObjectPixelFromXY |
---|
783 | * |
---|
784 | * Parameters: |
---|
785 | * x - {Integer} |
---|
786 | * y - {Integer} |
---|
787 | * |
---|
788 | * Returns: |
---|
789 | * {Object} MapObject Pixel from x and y parameters |
---|
790 | */ |
---|
791 | getMapObjectPixelFromXY: function(x, y) { |
---|
792 | return new GPoint(x, y); |
---|
793 | } |
---|
794 | |
---|
795 | }; |
---|