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