1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
7
* @requires OpenLayers/Layer/EventPane.js
8
* @requires OpenLayers/Layer/FixedZoomLevels.js
12
* Class: OpenLayers.Layer.Yahoo
15
* - <OpenLayers.Layer.EventPane>
16
* - <OpenLayers.Layer.FixedZoomLevels>
18
OpenLayers.Layer.Yahoo = OpenLayers.Class(
19
OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
22
* Constant: MIN_ZOOM_LEVEL
28
* Constant: MAX_ZOOM_LEVEL
34
* Constant: RESOLUTIONS
35
* {Array(Float)} Hardcode these resolutions so that they are more closely
36
* tied with the standard wms projection
53
0.0000858306884765625,
54
0.00004291534423828125
64
* APIProperty: sphericalMercator
65
* {Boolean} Should the map act as a mercator-projected map? This will
66
* cause all interactions with the map to be in the actual map projection,
67
* which allows support for vector drawing, overlaying other maps, etc.
69
sphericalMercator: false,
72
* Constructor: OpenLayers.Layer.Yahoo
78
initialize: function(name, options) {
79
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
80
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
82
if(this.sphericalMercator) {
83
OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
84
this.initMercatorParameters();
89
* Method: loadMapObject
91
loadMapObject:function() {
93
var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
94
this.mapObject = new YMap(this.div, this.type, size);
95
this.mapObject.disableKeyControls();
96
this.mapObject.disableDragMap();
98
//can we do smooth panning? (moveByXY is not an API function)
99
if ( !this.mapObject.moveByXY ||
100
(typeof this.mapObject.moveByXY != "function" ) ) {
102
this.dragPanMapObject = null;
108
* Method: onMapResize
111
onMapResize: function() {
113
var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
114
this.mapObject.resizeTo(size);
121
* Overridden from EventPane because we need to remove this yahoo event
122
* pane which prohibits our drag and drop, and we can only do this
123
* once the map has been loaded and centered.
126
* map - {<OpenLayers.Map>}
128
setMap: function(map) {
129
OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
131
this.map.events.register("moveend", this, this.fixYahooEventPane);
135
* Method: fixYahooEventPane
136
* The map has been centered, so the mysterious yahoo eventpane has been
137
* added. we remove it so that it doesnt mess with *our* event pane.
139
fixYahooEventPane: function() {
140
var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
141
if (yahooEventPane != null) {
142
if (yahooEventPane.parentNode != null) {
143
yahooEventPane.parentNode.removeChild(yahooEventPane);
145
this.map.events.unregister("moveend", this,
146
this.fixYahooEventPane);
151
* APIMethod: getWarningHTML
154
* {String} String with information on why layer is broken, how to get
157
getWarningHTML:function() {
158
return OpenLayers.i18n(
159
"getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
163
/********************************************************/
165
/* Translation Functions */
167
/* The following functions translate GMaps and OL */
168
/* formats for Pixel, LonLat, Bounds, and Zoom */
170
/********************************************************/
174
// TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
178
* APIMethod: getOLZoomFromMapObjectZoom
184
* {Integer} An OpenLayers Zoom level, translated from the passed in gZoom
185
* Returns null if null value is passed in.
187
getOLZoomFromMapObjectZoom: function(moZoom) {
189
if (moZoom != null) {
190
zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
197
* APIMethod: getMapObjectZoomFromOLZoom
203
* {Integer} A MapObject level, translated from the passed in olZoom
204
* Returns null if null value is passed in
206
getMapObjectZoomFromOLZoom: function(olZoom) {
208
if (olZoom != null) {
209
zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
215
/************************************
217
* MapObject Interface Controls *
219
************************************/
222
// Get&Set Center, Zoom
225
* APIMethod: setMapObjectCenter
226
* Set the mapObject to the specified center and zoom
229
* center - {Object} MapObject LonLat format
230
* zoom - {int} MapObject zoom format
232
setMapObjectCenter: function(center, zoom) {
233
this.mapObject.drawZoomAndCenter(center, zoom);
237
* APIMethod: getMapObjectCenter
240
* {Object} The mapObject's current center in Map Object format
242
getMapObjectCenter: function() {
243
return this.mapObject.getCenterLatLon();
247
* APIMethod: dragPanMapObject
253
dragPanMapObject: function(dX, dY) {
254
this.mapObject.moveByXY({
261
* APIMethod: getMapObjectZoom
264
* {Integer} The mapObject's current zoom, in Map Object format
266
getMapObjectZoom: function() {
267
return this.mapObject.getZoomLevel();
271
// LonLat - Pixel Translation
274
* APIMethod: getMapObjectLonLatFromMapObjectPixel
277
* moPixel - {Object} MapObject Pixel format
280
* {Object} MapObject LonLat translated from MapObject Pixel
282
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
283
return this.mapObject.convertXYLatLon(moPixel);
287
* APIMethod: getMapObjectPixelFromMapObjectLonLat
290
* moLonLat - {Object} MapObject LonLat format
293
* {Object} MapObject Pixel transtlated from MapObject LonLat
295
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
296
return this.mapObject.convertLatLonXY(moLonLat);
300
/************************************
302
* MapObject Primitives *
304
************************************/
310
* APIMethod: getLongitudeFromMapObjectLonLat
313
* moLonLat - {Object} MapObject LonLat format
316
* {Float} Longitude of the given MapObject LonLat
318
getLongitudeFromMapObjectLonLat: function(moLonLat) {
319
return this.sphericalMercator ?
320
this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon :
325
* APIMethod: getLatitudeFromMapObjectLonLat
328
* moLonLat - {Object} MapObject LonLat format
331
* {Float} Latitude of the given MapObject LonLat
333
getLatitudeFromMapObjectLonLat: function(moLonLat) {
334
return this.sphericalMercator ?
335
this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat :
340
* APIMethod: getMapObjectLonLatFromLonLat
347
* {Object} MapObject LonLat built from lon and lat params
349
getMapObjectLonLatFromLonLat: function(lon, lat) {
351
if(this.sphericalMercator) {
352
var lonlat = this.inverseMercator(lon, lat);
353
yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon);
355
yLatLong = new YGeoPoint(lat, lon);
363
* APIMethod: getXFromMapObjectPixel
366
* moPixel - {Object} MapObject Pixel format
369
* {Integer} X value of the MapObject Pixel
371
getXFromMapObjectPixel: function(moPixel) {
376
* APIMethod: getYFromMapObjectPixel
379
* moPixel - {Object} MapObject Pixel format
382
* {Integer} Y value of the MapObject Pixel
384
getYFromMapObjectPixel: function(moPixel) {
389
* APIMethod: getMapObjectPixelFromXY
396
* {Object} MapObject Pixel from x and y parameters
398
getMapObjectPixelFromXY: function(x, y) {
399
return new YCoordPoint(x, y);
405
* APIMethod: getMapObjectSizeFromOLSize
408
* olSize - {<OpenLayers.Size>}
411
* {Object} MapObject Size from olSize parameter
413
getMapObjectSizeFromOLSize: function(olSize) {
414
return new YSize(olSize.w, olSize.h);
417
CLASS_NAME: "OpenLayers.Layer.Yahoo"