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.VirtualEarth
15 * - <OpenLayers.Layer.EventPane>
16 * - <OpenLayers.Layer.FixedZoomLevels>
18 OpenLayers.Layer.VirtualEarth = OpenLayers.Class(
19 OpenLayers.Layer.EventPane,
20 OpenLayers.Layer.FixedZoomLevels, {
23 * Constant: MIN_ZOOM_LEVEL
29 * Constant: MAX_ZOOM_LEVEL
35 * Constant: RESOLUTIONS
36 * {Array(Float)} Hardcode these resolutions so that they are more closely
37 * tied with the standard wms projection
54 0.0000858306884765625,
55 0.00004291534423828125,
56 0.00002145767211914062
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
69 * projection, which allows support for vector drawing, overlaying
72 sphericalMercator: false,
75 * Constructor: OpenLayers.Layer.VirtualEarth
81 initialize: function(name, options) {
82 OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
83 OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
85 if(this.sphericalMercator) {
86 OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
87 this.initMercatorParameters();
92 * Method: loadMapObject
94 loadMapObject:function() {
96 // create div and set to same size as map
97 var veDiv = OpenLayers.Util.createDiv(this.name);
98 var sz = this.map.getSize();
99 veDiv.style.width = sz.w + "px";
100 veDiv.style.height = sz.h + "px";
101 this.div.appendChild(veDiv);
103 try { // crash prevention
104 this.mapObject = new VEMap(this.name);
107 if (this.mapObject != null) {
108 try { // this is to catch a Mozilla bug without falling apart
110 // The fourth argument is whether the map is 'fixed' -- not
112 // http://blogs.msdn.com/virtualearth/archive/2007/09/28/locking-a-virtual-earth-map.aspx
114 this.mapObject.LoadMap(null, null, this.type, true);
115 this.mapObject.AttachEvent("onmousedown", function() {return true; });
118 this.mapObject.HideDashboard();
121 //can we do smooth panning? this is an unpublished method, so we need
123 if ( !this.mapObject ||
124 !this.mapObject.vemapcontrol ||
125 !this.mapObject.vemapcontrol.PanMap ||
126 (typeof this.mapObject.vemapcontrol.PanMap != "function")) {
128 this.dragPanMapObject = null;
134 * APIMethod: getWarningHTML
137 * {String} String with information on why layer is broken, how to get
140 getWarningHTML:function() {
141 return OpenLayers.i18n(
142 "getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'}
148 /************************************
150 * MapObject Interface Controls *
152 ************************************/
155 // Get&Set Center, Zoom
158 * APIMethod: setMapObjectCenter
159 * Set the mapObject to the specified center and zoom
162 * center - {Object} MapObject LonLat format
163 * zoom - {int} MapObject zoom format
165 setMapObjectCenter: function(center, zoom) {
166 this.mapObject.SetCenterAndZoom(center, zoom);
170 * APIMethod: getMapObjectCenter
173 * {Object} The mapObject's current center in Map Object format
175 getMapObjectCenter: function() {
176 return this.mapObject.GetCenter();
180 * APIMethod: dragPanMapObject
186 dragPanMapObject: function(dX, dY) {
187 this.mapObject.vemapcontrol.PanMap(dX, -dY);
191 * APIMethod: getMapObjectZoom
194 * {Integer} The mapObject's current zoom, in Map Object format
196 getMapObjectZoom: function() {
197 return this.mapObject.GetZoomLevel();
201 // LonLat - Pixel Translation
204 * APIMethod: getMapObjectLonLatFromMapObjectPixel
207 * moPixel - {Object} MapObject Pixel format
210 * {Object} MapObject LonLat translated from MapObject Pixel
212 getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
213 //the conditional here is to test if we are running the v6 of VE
214 return (typeof VEPixel != 'undefined')
215 ? this.mapObject.PixelToLatLong(moPixel)
216 : this.mapObject.PixelToLatLong(moPixel.x, moPixel.y);
220 * APIMethod: getMapObjectPixelFromMapObjectLonLat
223 * moLonLat - {Object} MapObject LonLat format
226 * {Object} MapObject Pixel transtlated from MapObject LonLat
228 getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
229 return this.mapObject.LatLongToPixel(moLonLat);
233 /************************************
235 * MapObject Primitives *
237 ************************************/
243 * APIMethod: getLongitudeFromMapObjectLonLat
246 * moLonLat - {Object} MapObject LonLat format
249 * {Float} Longitude of the given MapObject LonLat
251 getLongitudeFromMapObjectLonLat: function(moLonLat) {
252 return this.sphericalMercator ?
253 this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon :
258 * APIMethod: getLatitudeFromMapObjectLonLat
261 * moLonLat - {Object} MapObject LonLat format
264 * {Float} Latitude of the given MapObject LonLat
266 getLatitudeFromMapObjectLonLat: function(moLonLat) {
267 return this.sphericalMercator ?
268 this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat :
273 * APIMethod: getMapObjectLonLatFromLonLat
280 * {Object} MapObject LonLat built from lon and lat params
282 getMapObjectLonLatFromLonLat: function(lon, lat) {
284 if(this.sphericalMercator) {
285 var lonlat = this.inverseMercator(lon, lat);
286 veLatLong = new VELatLong(lonlat.lat, lonlat.lon);
288 veLatLong = new VELatLong(lat, lon);
296 * APIMethod: getXFromMapObjectPixel
299 * moPixel - {Object} MapObject Pixel format
302 * {Integer} X value of the MapObject Pixel
304 getXFromMapObjectPixel: function(moPixel) {
309 * APIMethod: getYFromMapObjectPixel
312 * moPixel - {Object} MapObject Pixel format
315 * {Integer} Y value of the MapObject Pixel
317 getYFromMapObjectPixel: function(moPixel) {
322 * APIMethod: getMapObjectPixelFromXY
329 * {Object} MapObject Pixel from x and y parameters
331 getMapObjectPixelFromXY: function(x, y) {
332 //the conditional here is to test if we are running the v6 of VE
333 return (typeof VEPixel != 'undefined') ? new VEPixel(x, y)
334 : new Msn.VE.Pixel(x, y);
337 CLASS_NAME: "OpenLayers.Layer.VirtualEarth"