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,
55 0.00002145767211914062,
56 0.00001072883605957031
66 * APIProperty: sphericalMercator
67 * {Boolean} Should the map act as a mercator-projected map? This will
68 * cause all interactions with the map to be in the actual map projection,
69 * which allows support for vector drawing, overlaying other maps, etc.
71 sphericalMercator: false,
74 * Constructor: OpenLayers.Layer.Yahoo
80 initialize: function(name, options) {
81 OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
82 OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
84 if(this.sphericalMercator) {
85 OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
86 this.initMercatorParameters();
91 * Method: loadMapObject
93 loadMapObject:function() {
95 var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
96 this.mapObject = new YMap(this.div, this.type, size);
97 this.mapObject.disableKeyControls();
98 this.mapObject.disableDragMap();
100 //can we do smooth panning? (moveByXY is not an API function)
101 if ( !this.mapObject.moveByXY ||
102 (typeof this.mapObject.moveByXY != "function" ) ) {
104 this.dragPanMapObject = null;
110 * Method: onMapResize
113 onMapResize: function() {
115 var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
116 this.mapObject.resizeTo(size);
123 * Overridden from EventPane because we need to remove this yahoo event
124 * pane which prohibits our drag and drop, and we can only do this
125 * once the map has been loaded and centered.
128 * map - {<OpenLayers.Map>}
130 setMap: function(map) {
131 OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
133 this.map.events.register("moveend", this, this.fixYahooEventPane);
137 * Method: fixYahooEventPane
138 * The map has been centered, so the mysterious yahoo eventpane has been
139 * added. we remove it so that it doesnt mess with *our* event pane.
141 fixYahooEventPane: function() {
142 var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
143 if (yahooEventPane != null) {
144 if (yahooEventPane.parentNode != null) {
145 yahooEventPane.parentNode.removeChild(yahooEventPane);
147 this.map.events.unregister("moveend", this,
148 this.fixYahooEventPane);
153 * APIMethod: getWarningHTML
156 * {String} String with information on why layer is broken, how to get
159 getWarningHTML:function() {
160 return OpenLayers.i18n(
161 "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
165 /********************************************************/
167 /* Translation Functions */
169 /* The following functions translate GMaps and OL */
170 /* formats for Pixel, LonLat, Bounds, and Zoom */
172 /********************************************************/
176 // TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
180 * APIMethod: getOLZoomFromMapObjectZoom
186 * {Integer} An OpenLayers Zoom level, translated from the passed in gZoom
187 * Returns null if null value is passed in.
189 getOLZoomFromMapObjectZoom: function(moZoom) {
191 if (moZoom != null) {
192 zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
199 * APIMethod: getMapObjectZoomFromOLZoom
205 * {Integer} A MapObject level, translated from the passed in olZoom
206 * Returns null if null value is passed in
208 getMapObjectZoomFromOLZoom: function(olZoom) {
210 if (olZoom != null) {
211 zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
217 /************************************
219 * MapObject Interface Controls *
221 ************************************/
224 // Get&Set Center, Zoom
227 * APIMethod: setMapObjectCenter
228 * Set the mapObject to the specified center and zoom
231 * center - {Object} MapObject LonLat format
232 * zoom - {int} MapObject zoom format
234 setMapObjectCenter: function(center, zoom) {
235 this.mapObject.drawZoomAndCenter(center, zoom);
239 * APIMethod: getMapObjectCenter
242 * {Object} The mapObject's current center in Map Object format
244 getMapObjectCenter: function() {
245 return this.mapObject.getCenterLatLon();
249 * APIMethod: dragPanMapObject
255 dragPanMapObject: function(dX, dY) {
256 this.mapObject.moveByXY({
263 * APIMethod: getMapObjectZoom
266 * {Integer} The mapObject's current zoom, in Map Object format
268 getMapObjectZoom: function() {
269 return this.mapObject.getZoomLevel();
273 // LonLat - Pixel Translation
276 * APIMethod: getMapObjectLonLatFromMapObjectPixel
279 * moPixel - {Object} MapObject Pixel format
282 * {Object} MapObject LonLat translated from MapObject Pixel
284 getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
285 return this.mapObject.convertXYLatLon(moPixel);
289 * APIMethod: getMapObjectPixelFromMapObjectLonLat
292 * moLonLat - {Object} MapObject LonLat format
295 * {Object} MapObject Pixel transtlated from MapObject LonLat
297 getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
298 return this.mapObject.convertLatLonXY(moLonLat);
302 /************************************
304 * MapObject Primitives *
306 ************************************/
312 * APIMethod: getLongitudeFromMapObjectLonLat
315 * moLonLat - {Object} MapObject LonLat format
318 * {Float} Longitude of the given MapObject LonLat
320 getLongitudeFromMapObjectLonLat: function(moLonLat) {
321 return this.sphericalMercator ?
322 this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon :
327 * APIMethod: getLatitudeFromMapObjectLonLat
330 * moLonLat - {Object} MapObject LonLat format
333 * {Float} Latitude of the given MapObject LonLat
335 getLatitudeFromMapObjectLonLat: function(moLonLat) {
336 return this.sphericalMercator ?
337 this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat :
342 * APIMethod: getMapObjectLonLatFromLonLat
349 * {Object} MapObject LonLat built from lon and lat params
351 getMapObjectLonLatFromLonLat: function(lon, lat) {
353 if(this.sphericalMercator) {
354 var lonlat = this.inverseMercator(lon, lat);
355 yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon);
357 yLatLong = new YGeoPoint(lat, lon);
365 * APIMethod: getXFromMapObjectPixel
368 * moPixel - {Object} MapObject Pixel format
371 * {Integer} X value of the MapObject Pixel
373 getXFromMapObjectPixel: function(moPixel) {
378 * APIMethod: getYFromMapObjectPixel
381 * moPixel - {Object} MapObject Pixel format
384 * {Integer} Y value of the MapObject Pixel
386 getYFromMapObjectPixel: function(moPixel) {
391 * APIMethod: getMapObjectPixelFromXY
398 * {Object} MapObject Pixel from x and y parameters
400 getMapObjectPixelFromXY: function(x, y) {
401 return new YCoordPoint(x, y);
407 * APIMethod: getMapObjectSizeFromOLSize
410 * olSize - {<OpenLayers.Size>}
413 * {Object} MapObject Size from olSize parameter
415 getMapObjectSizeFromOLSize: function(olSize) {
416 return new YSize(olSize.w, olSize.h);
419 CLASS_NAME: "OpenLayers.Layer.Yahoo"