/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt * for the full text of the license. */ /** * @requires OpenLayers/Layer/EventPane.js * @requires OpenLayers/Layer/FixedZoomLevels.js * * Class: OpenLayers.Layer.Yahoo * * Inherits: * - * - v */ OpenLayers.Layer.Yahoo = OpenLayers.Class( OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, { /** * Constant: MIN_ZOOM_LEVEL * {Integer} 0 */ MIN_ZOOM_LEVEL: 0, /** * Constant: MAX_ZOOM_LEVEL * {Integer} 15 */ MAX_ZOOM_LEVEL: 15, /** * Constant: RESOLUTIONS * {Array(Float)} Hardcode these resolutions so that they are more closely * tied with the standard wms projection */ RESOLUTIONS: [1.40625,0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125], /** * APIProperty: type * {YahooMapType} */ type: null, /** * Constructor: OpenLayers.Layer.Yahoo * * Parameters: * name - {String} * options - {Object} */ initialize: function(name, options) { OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments); OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, arguments); }, /** * Method: loadMapObject */ loadMapObject:function() { try { //do not crash! var size = this.getMapObjectSizeFromOLSize(this.map.getSize()); this.mapObject = new YMap(this.div, this.type, size); this.mapObject.disableKeyControls(); } catch(e) {} }, /** * Method: onMapResize * */ onMapResize: function() { try { var size = this.getMapObjectSizeFromOLSize(this.map.getSize()); this.mapObject.resizeTo(size); } catch(e) {} }, /** * APIMethod: setMap * Overridden from EventPane because we need to remove this yahoo event * pane which prohibits our drag and drop, and we can only do this * once the map has been loaded and centered. * * Parameters: * map - {} */ setMap: function(map) { OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments); this.map.events.register("moveend", this, this.fixYahooEventPane); }, /** * Method: fixYahooEventPane * The map has been centered, so the mysterious yahoo eventpane has been * added. we remove it so that it doesnt mess with *our* event pane. */ fixYahooEventPane: function() { var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv"); if (yahooEventPane != null) { if (yahooEventPane.parentNode != null) yahooEventPane.parentNode.removeChild(yahooEventPane); this.map.events.unregister("moveend", this, this.fixYahooEventPane); } }, /** * APIMethod: getWarningHTML * * Return: * {String} String with information on why layer is broken, how to get * it working. */ getWarningHTML:function() { var html = ""; html += "The Yahoo Layer was unable to load correctly.
"; html += "
"; html += "To get rid of this message, select a new BaseLayer " html += "in the layer switcher in the upper-right corner.
"; html += "
"; html += "Most likely, this is because the Yahoo library"; html += " script was either not correctly included.
"; html += "
"; html += "Developers: For help getting this working correctly, "; html += " OpenLayers Zoom // /** * APIMethod: getOLZoomFromMapObjectZoom * * Parameters: * gZoom - {Integer} * * Return: * {Integer} An OpenLayers Zoom level, translated from the passed in gZoom * Returns null if null value is passed in. */ getOLZoomFromMapObjectZoom: function(moZoom) { var zoom = null; if (moZoom != null) { zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]); zoom = 18 - zoom; } return zoom; }, /** * APIMethod: getMapObjectZoomFromOLZoom * * Parameters: * olZoom - {Integer} * * Return: * {Integer} A MapObject level, translated from the passed in olZoom * Returns null if null value is passed in */ getMapObjectZoomFromOLZoom: function(olZoom) { var zoom = null; if (olZoom != null) { zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]); zoom = 18 - zoom; } return zoom; }, /************************************ * * * MapObject Interface Controls * * * ************************************/ // Get&Set Center, Zoom /** * APIMethod: setMapObjectCenter * Set the mapObject to the specified center and zoom * * Parameters: * center - {Object} MapObject LonLat format * zoom - {int} MapObject zoom format */ setMapObjectCenter: function(center, zoom) { this.mapObject.drawZoomAndCenter(center, zoom); }, /** * APIMethod: getMapObjectCenter * * Return: * {Object} The mapObject's current center in Map Object format */ getMapObjectCenter: function() { return this.mapObject.getCenterLatLon(); }, /** * APIMethod: getMapObjectZoom * * Return: * {Integer} The mapObject's current zoom, in Map Object format */ getMapObjectZoom: function() { return this.mapObject.getZoomLevel(); }, // LonLat - Pixel Translation /** * APIMethod: getMapObjectLonLatFromMapObjectPixel * * Parameters: * moPixel - {Object} MapObject Pixel format * * Return: * {Object} MapObject LonLat translated from MapObject Pixel */ getMapObjectLonLatFromMapObjectPixel: function(moPixel) { return this.mapObject.convertXYLatLon(moPixel); }, /** * APIMethod: getMapObjectPixelFromMapObjectLonLat * * Parameters: * moLonLat - {Object} MapObject LonLat format * * Return: * {Object} MapObject Pixel transtlated from MapObject LonLat */ getMapObjectPixelFromMapObjectLonLat: function(moLonLat) { return this.mapObject.convertLatLonXY(moLonLat); }, /************************************ * * * MapObject Primitives * * * ************************************/ // LonLat /** * APIMethod: getLongitudeFromMapObjectLonLat * * Parameters: * moLonLat - {Object} MapObject LonLat format * * Return: * {Float} Longitude of the given MapObject LonLat */ getLongitudeFromMapObjectLonLat: function(moLonLat) { return moLonLat.Lon; }, /** * APIMethod: getLatitudeFromMapObjectLonLat * * Parameters: * moLonLat - {Object} MapObject LonLat format * * Return: * {Float} Latitude of the given MapObject LonLat */ getLatitudeFromMapObjectLonLat: function(moLonLat) { return moLonLat.Lat; }, /** * APIMethod: getMapObjectLonLatFromLonLat * * Parameters: * lon - {Float} * lat - {Float} * * Return: * {Object} MapObject LonLat built from lon and lat params */ getMapObjectLonLatFromLonLat: function(lon, lat) { return new YGeoPoint(lat, lon); }, // Pixel /** * APIMethod: getXFromMapObjectPixel * * Parameters: * moPixel - {Object} MapObject Pixel format * * Return: * {Integer} X value of the MapObject Pixel */ getXFromMapObjectPixel: function(moPixel) { return moPixel.x; }, /** * APIMethod: getYFromMapObjectPixel * * Parameters: * moPixel - {Object} MapObject Pixel format * * Return: * {Integer} Y value of the MapObject Pixel */ getYFromMapObjectPixel: function(moPixel) { return moPixel.y; }, /** * APIMethod: getMapObjectPixelFromXY * * Parameters: * x - {Integer} * y - {Integer} * * Return: * {Object} MapObject Pixel from x and y parameters */ getMapObjectPixelFromXY: function(x, y) { return new YCoordPoint(x, y); }, // Size /** * APIMethod: getMapObjectSizeFromOLSize * * Parameters: * olSize - {} * * Return: * {Object} MapObject Size from olSize parameter */ getMapObjectSizeFromOLSize: function(olSize) { return new YSize(olSize.w, olSize.h); }, CLASS_NAME: "OpenLayers.Layer.Yahoo" });