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