| 1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
|---|
| 2 | * full list of contributors). Published under the Clear BSD license. |
|---|
| 3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt 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 | */ |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * Class: OpenLayers.Layer.VirtualEarth |
|---|
| 15 | * |
|---|
| 16 | * Inherits from: |
|---|
| 17 | * - <OpenLayers.Layer.EventPane> |
|---|
| 18 | * - <OpenLayers.Layer.FixedZoomLevels> |
|---|
| 19 | */ |
|---|
| 20 | OpenLayers.Layer.VirtualEarth = OpenLayers.Class( |
|---|
| 21 | OpenLayers.Layer.EventPane, |
|---|
| 22 | OpenLayers.Layer.FixedZoomLevels, { |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * Constant: MIN_ZOOM_LEVEL |
|---|
| 26 | * {Integer} 1 |
|---|
| 27 | */ |
|---|
| 28 | MIN_ZOOM_LEVEL: 1, |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Constant: MAX_ZOOM_LEVEL |
|---|
| 32 | * {Integer} 19 |
|---|
| 33 | */ |
|---|
| 34 | MAX_ZOOM_LEVEL: 19, |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Constant: RESOLUTIONS |
|---|
| 38 | * {Array(Float)} Hardcode these resolutions so that they are more closely |
|---|
| 39 | * tied with the standard wms projection |
|---|
| 40 | */ |
|---|
| 41 | RESOLUTIONS: [ |
|---|
| 42 | 1.40625, |
|---|
| 43 | 0.703125, |
|---|
| 44 | 0.3515625, |
|---|
| 45 | 0.17578125, |
|---|
| 46 | 0.087890625, |
|---|
| 47 | 0.0439453125, |
|---|
| 48 | 0.02197265625, |
|---|
| 49 | 0.010986328125, |
|---|
| 50 | 0.0054931640625, |
|---|
| 51 | 0.00274658203125, |
|---|
| 52 | 0.001373291015625, |
|---|
| 53 | 0.0006866455078125, |
|---|
| 54 | 0.00034332275390625, |
|---|
| 55 | 0.000171661376953125, |
|---|
| 56 | 0.0000858306884765625, |
|---|
| 57 | 0.00004291534423828125, |
|---|
| 58 | 0.00002145767211914062, |
|---|
| 59 | 0.00001072883605957031, |
|---|
| 60 | 0.00000536441802978515 |
|---|
| 61 | ], |
|---|
| 62 | |
|---|
| 63 | /** |
|---|
| 64 | * APIProperty: type |
|---|
| 65 | * {VEMapType} |
|---|
| 66 | */ |
|---|
| 67 | type: null, |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * APIProperty: wrapDateLine |
|---|
| 71 | * {Boolean} Allow user to pan forever east/west. Default is true. |
|---|
| 72 | * Setting this to false only restricts panning if |
|---|
| 73 | * <sphericalMercator> is true. |
|---|
| 74 | */ |
|---|
| 75 | wrapDateLine: true, |
|---|
| 76 | |
|---|
| 77 | /** |
|---|
| 78 | * APIProperty: sphericalMercator |
|---|
| 79 | * {Boolean} Should the map act as a mercator-projected map? This will |
|---|
| 80 | * cause all interactions with the map to be in the actual map |
|---|
| 81 | * projection, which allows support for vector drawing, overlaying |
|---|
| 82 | * other maps, etc. |
|---|
| 83 | */ |
|---|
| 84 | sphericalMercator: false, |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * APIProperty: animationEnabled |
|---|
| 88 | * {Boolean} If set to true, the transition between zoom levels will be |
|---|
| 89 | * animated. Set to false to match the zooming experience of other |
|---|
| 90 | * layer types. Default is true. |
|---|
| 91 | */ |
|---|
| 92 | animationEnabled: true, |
|---|
| 93 | |
|---|
| 94 | /** |
|---|
| 95 | * Constructor: OpenLayers.Layer.VirtualEarth |
|---|
| 96 | * |
|---|
| 97 | * Parameters: |
|---|
| 98 | * name - {String} |
|---|
| 99 | * options - {Object} |
|---|
| 100 | */ |
|---|
| 101 | initialize: function(name, options) { |
|---|
| 102 | OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments); |
|---|
| 103 | OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, |
|---|
| 104 | arguments); |
|---|
| 105 | if(this.sphericalMercator) { |
|---|
| 106 | OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator); |
|---|
| 107 | this.initMercatorParameters(); |
|---|
| 108 | } |
|---|
| 109 | }, |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Method: loadMapObject |
|---|
| 113 | */ |
|---|
| 114 | loadMapObject:function() { |
|---|
| 115 | |
|---|
| 116 | // create div and set to same size as map |
|---|
| 117 | var veDiv = OpenLayers.Util.createDiv(this.name); |
|---|
| 118 | var sz = this.map.getSize(); |
|---|
| 119 | veDiv.style.width = sz.w + "px"; |
|---|
| 120 | veDiv.style.height = sz.h + "px"; |
|---|
| 121 | this.div.appendChild(veDiv); |
|---|
| 122 | |
|---|
| 123 | try { // crash prevention |
|---|
| 124 | this.mapObject = new VEMap(this.name); |
|---|
| 125 | } catch (e) { } |
|---|
| 126 | |
|---|
| 127 | if (this.mapObject != null) { |
|---|
| 128 | try { // this is to catch a Mozilla bug without falling apart |
|---|
| 129 | |
|---|
| 130 | // The fourth argument is whether the map is 'fixed' -- not |
|---|
| 131 | // draggable. See: |
|---|
| 132 | // http://blogs.msdn.com/virtualearth/archive/2007/09/28/locking-a-virtual-earth-map.aspx |
|---|
| 133 | // |
|---|
| 134 | this.mapObject.LoadMap(null, null, this.type, true); |
|---|
| 135 | this.mapObject.AttachEvent("onmousedown", OpenLayers.Function.True); |
|---|
| 136 | |
|---|
| 137 | } catch (e) { } |
|---|
| 138 | this.mapObject.HideDashboard(); |
|---|
| 139 | if(typeof this.mapObject.SetAnimationEnabled == "function") { |
|---|
| 140 | this.mapObject.SetAnimationEnabled(this.animationEnabled); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | //can we do smooth panning? this is an unpublished method, so we need |
|---|
| 145 | // to be careful |
|---|
| 146 | if ( !this.mapObject || |
|---|
| 147 | !this.mapObject.vemapcontrol || |
|---|
| 148 | !this.mapObject.vemapcontrol.PanMap || |
|---|
| 149 | (typeof this.mapObject.vemapcontrol.PanMap != "function")) { |
|---|
| 150 | |
|---|
| 151 | this.dragPanMapObject = null; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | }, |
|---|
| 155 | |
|---|
| 156 | /** |
|---|
| 157 | * Method: onMapResize |
|---|
| 158 | */ |
|---|
| 159 | onMapResize: function() { |
|---|
| 160 | this.mapObject.Resize(this.map.size.w, this.map.size.h); |
|---|
| 161 | }, |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * APIMethod: getWarningHTML |
|---|
| 165 | * |
|---|
| 166 | * Returns: |
|---|
| 167 | * {String} String with information on why layer is broken, how to get |
|---|
| 168 | * it working. |
|---|
| 169 | */ |
|---|
| 170 | getWarningHTML:function() { |
|---|
| 171 | return OpenLayers.i18n( |
|---|
| 172 | "getLayerWarning", {'layerType':'VE', 'layerLib':'VirtualEarth'} |
|---|
| 173 | ); |
|---|
| 174 | }, |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | /************************************ |
|---|
| 179 | * * |
|---|
| 180 | * MapObject Interface Controls * |
|---|
| 181 | * * |
|---|
| 182 | ************************************/ |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | // Get&Set Center, Zoom |
|---|
| 186 | |
|---|
| 187 | /** |
|---|
| 188 | * APIMethod: setMapObjectCenter |
|---|
| 189 | * Set the mapObject to the specified center and zoom |
|---|
| 190 | * |
|---|
| 191 | * Parameters: |
|---|
| 192 | * center - {Object} MapObject LonLat format |
|---|
| 193 | * zoom - {int} MapObject zoom format |
|---|
| 194 | */ |
|---|
| 195 | setMapObjectCenter: function(center, zoom) { |
|---|
| 196 | this.mapObject.SetCenterAndZoom(center, zoom); |
|---|
| 197 | }, |
|---|
| 198 | |
|---|
| 199 | /** |
|---|
| 200 | * APIMethod: getMapObjectCenter |
|---|
| 201 | * |
|---|
| 202 | * Returns: |
|---|
| 203 | * {Object} The mapObject's current center in Map Object format |
|---|
| 204 | */ |
|---|
| 205 | getMapObjectCenter: function() { |
|---|
| 206 | return this.mapObject.GetCenter(); |
|---|
| 207 | }, |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | * APIMethod: dragPanMapObject |
|---|
| 211 | * |
|---|
| 212 | * Parameters: |
|---|
| 213 | * dX - {Integer} |
|---|
| 214 | * dY - {Integer} |
|---|
| 215 | */ |
|---|
| 216 | dragPanMapObject: function(dX, dY) { |
|---|
| 217 | this.mapObject.vemapcontrol.PanMap(dX, -dY); |
|---|
| 218 | }, |
|---|
| 219 | |
|---|
| 220 | /** |
|---|
| 221 | * APIMethod: getMapObjectZoom |
|---|
| 222 | * |
|---|
| 223 | * Returns: |
|---|
| 224 | * {Integer} The mapObject's current zoom, in Map Object format |
|---|
| 225 | */ |
|---|
| 226 | getMapObjectZoom: function() { |
|---|
| 227 | return this.mapObject.GetZoomLevel(); |
|---|
| 228 | }, |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | // LonLat - Pixel Translation |
|---|
| 232 | |
|---|
| 233 | /** |
|---|
| 234 | * APIMethod: getMapObjectLonLatFromMapObjectPixel |
|---|
| 235 | * |
|---|
| 236 | * Parameters: |
|---|
| 237 | * moPixel - {Object} MapObject Pixel format |
|---|
| 238 | * |
|---|
| 239 | * Returns: |
|---|
| 240 | * {Object} MapObject LonLat translated from MapObject Pixel |
|---|
| 241 | */ |
|---|
| 242 | getMapObjectLonLatFromMapObjectPixel: function(moPixel) { |
|---|
| 243 | //the conditional here is to test if we are running the v6 of VE |
|---|
| 244 | return (typeof VEPixel != 'undefined') |
|---|
| 245 | ? this.mapObject.PixelToLatLong(moPixel) |
|---|
| 246 | : this.mapObject.PixelToLatLong(moPixel.x, moPixel.y); |
|---|
| 247 | }, |
|---|
| 248 | |
|---|
| 249 | /** |
|---|
| 250 | * APIMethod: getMapObjectPixelFromMapObjectLonLat |
|---|
| 251 | * |
|---|
| 252 | * Parameters: |
|---|
| 253 | * moLonLat - {Object} MapObject LonLat format |
|---|
| 254 | * |
|---|
| 255 | * Returns: |
|---|
| 256 | * {Object} MapObject Pixel transtlated from MapObject LonLat |
|---|
| 257 | */ |
|---|
| 258 | getMapObjectPixelFromMapObjectLonLat: function(moLonLat) { |
|---|
| 259 | return this.mapObject.LatLongToPixel(moLonLat); |
|---|
| 260 | }, |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | /************************************ |
|---|
| 264 | * * |
|---|
| 265 | * MapObject Primitives * |
|---|
| 266 | * * |
|---|
| 267 | ************************************/ |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | // LonLat |
|---|
| 271 | |
|---|
| 272 | /** |
|---|
| 273 | * APIMethod: getLongitudeFromMapObjectLonLat |
|---|
| 274 | * |
|---|
| 275 | * Parameters: |
|---|
| 276 | * moLonLat - {Object} MapObject LonLat format |
|---|
| 277 | * |
|---|
| 278 | * Returns: |
|---|
| 279 | * {Float} Longitude of the given MapObject LonLat |
|---|
| 280 | */ |
|---|
| 281 | getLongitudeFromMapObjectLonLat: function(moLonLat) { |
|---|
| 282 | return this.sphericalMercator ? |
|---|
| 283 | this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon : |
|---|
| 284 | moLonLat.Longitude; |
|---|
| 285 | }, |
|---|
| 286 | |
|---|
| 287 | /** |
|---|
| 288 | * APIMethod: getLatitudeFromMapObjectLonLat |
|---|
| 289 | * |
|---|
| 290 | * Parameters: |
|---|
| 291 | * moLonLat - {Object} MapObject LonLat format |
|---|
| 292 | * |
|---|
| 293 | * Returns: |
|---|
| 294 | * {Float} Latitude of the given MapObject LonLat |
|---|
| 295 | */ |
|---|
| 296 | getLatitudeFromMapObjectLonLat: function(moLonLat) { |
|---|
| 297 | return this.sphericalMercator ? |
|---|
| 298 | this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat : |
|---|
| 299 | moLonLat.Latitude; |
|---|
| 300 | }, |
|---|
| 301 | |
|---|
| 302 | /** |
|---|
| 303 | * APIMethod: getMapObjectLonLatFromLonLat |
|---|
| 304 | * |
|---|
| 305 | * Parameters: |
|---|
| 306 | * lon - {Float} |
|---|
| 307 | * lat - {Float} |
|---|
| 308 | * |
|---|
| 309 | * Returns: |
|---|
| 310 | * {Object} MapObject LonLat built from lon and lat params |
|---|
| 311 | */ |
|---|
| 312 | getMapObjectLonLatFromLonLat: function(lon, lat) { |
|---|
| 313 | var veLatLong; |
|---|
| 314 | if(this.sphericalMercator) { |
|---|
| 315 | var lonlat = this.inverseMercator(lon, lat); |
|---|
| 316 | veLatLong = new VELatLong(lonlat.lat, lonlat.lon); |
|---|
| 317 | } else { |
|---|
| 318 | veLatLong = new VELatLong(lat, lon); |
|---|
| 319 | } |
|---|
| 320 | return veLatLong; |
|---|
| 321 | }, |
|---|
| 322 | |
|---|
| 323 | // Pixel |
|---|
| 324 | |
|---|
| 325 | /** |
|---|
| 326 | * APIMethod: getXFromMapObjectPixel |
|---|
| 327 | * |
|---|
| 328 | * Parameters: |
|---|
| 329 | * moPixel - {Object} MapObject Pixel format |
|---|
| 330 | * |
|---|
| 331 | * Returns: |
|---|
| 332 | * {Integer} X value of the MapObject Pixel |
|---|
| 333 | */ |
|---|
| 334 | getXFromMapObjectPixel: function(moPixel) { |
|---|
| 335 | return moPixel.x; |
|---|
| 336 | }, |
|---|
| 337 | |
|---|
| 338 | /** |
|---|
| 339 | * APIMethod: getYFromMapObjectPixel |
|---|
| 340 | * |
|---|
| 341 | * Parameters: |
|---|
| 342 | * moPixel - {Object} MapObject Pixel format |
|---|
| 343 | * |
|---|
| 344 | * Returns: |
|---|
| 345 | * {Integer} Y value of the MapObject Pixel |
|---|
| 346 | */ |
|---|
| 347 | getYFromMapObjectPixel: function(moPixel) { |
|---|
| 348 | return moPixel.y; |
|---|
| 349 | }, |
|---|
| 350 | |
|---|
| 351 | /** |
|---|
| 352 | * APIMethod: getMapObjectPixelFromXY |
|---|
| 353 | * |
|---|
| 354 | * Parameters: |
|---|
| 355 | * x - {Integer} |
|---|
| 356 | * y - {Integer} |
|---|
| 357 | * |
|---|
| 358 | * Returns: |
|---|
| 359 | * {Object} MapObject Pixel from x and y parameters |
|---|
| 360 | */ |
|---|
| 361 | getMapObjectPixelFromXY: function(x, y) { |
|---|
| 362 | //the conditional here is to test if we are running the v6 of VE |
|---|
| 363 | return (typeof VEPixel != 'undefined') ? new VEPixel(x, y) |
|---|
| 364 | : new Msn.VE.Pixel(x, y); |
|---|
| 365 | }, |
|---|
| 366 | |
|---|
| 367 | CLASS_NAME: "OpenLayers.Layer.VirtualEarth" |
|---|
| 368 | }); |
|---|