]> git.openstreetmap.org Git - rails.git/blob - public/lib/OpenLayers/Layer/VirtualEarth.js
Add a Maplint layer (OpenLayers.Layer.OSM.Maplint) class. Note that the
[rails.git] / public / lib / OpenLayers / Layer / VirtualEarth.js
1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2  * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3  * text of the license. */
4 // @require: OpenLayers/Layer.js\r
5 \r
6 // load VE map control script\r
7 document.write("<script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script>");\r
8 \r
9 \r
10 /**\r
11  * @class \r
12  */\r
13 OpenLayers.Layer.VirtualEarth = Class.create();\r
14 OpenLayers.Layer.VirtualEarth.prototype = \r
15   Object.extend( new OpenLayers.Layer(), {\r
16 \r
17     /** @type Boolean */\r
18     viewPortLayer: true,\r
19 \r
20     /** @type VEMap */\r
21     vemap: null,\r
22     \r
23     /**\r
24      * @constructor\r
25      * \r
26      * @param {str} name\r
27      */\r
28     initialize:function(name) {\r
29         OpenLayers.Layer.prototype.initialize.apply(this, arguments);\r
30     },\r
31 \r
32     /** \r
33      * @param {OpenLayers.Map} map\r
34      */\r
35     setMap:function(map) {\r
36         OpenLayers.Layer.prototype.setMap.apply(this, arguments);\r
37 \r
38         // once our layer has been added to the map, we can create the vemap\r
39         this.map.events.register("addlayer", this, this.loadVEMap);\r
40     },\r
41 \r
42     /** Virtual Earth layer is always a base class. \r
43      * @type Boolean\r
44      */\r
45     isBaseLayer: function() {\r
46         return true;\r
47     },\r
48 \r
49     /** \r
50      * @param {OpenLayers.Bounds} bounds\r
51      * @param {int} zoomChanged\r
52      */\r
53     moveTo:function(bounds,zoomChanged) {\r
54 \r
55         if (this.vemap != null) {\r
56             var olCenter = this.map.getCenter();\r
57             var olZoom = this.map.getZoom();\r
58     \r
59             this.vemap.SetCenterAndZoom(new VELatLong(olCenter.lat, olCenter.lon),\r
60                                         olZoom + 1);\r
61         }\r
62     },\r
63 \r
64 \r
65     /**\r
66      * \r
67      */\r
68     loadVEMap:function() {\r
69         // create div and set to same size as map\r
70         var veDiv = OpenLayers.Util.createDiv(this.name);\r
71         var sz = this.map.getSize();\r
72         veDiv.style.width = sz.w;\r
73         veDiv.style.height = sz.h;\r
74         this.div.appendChild(veDiv);\r
75 \r
76         // create VEMap, hide nav controls\r
77         this.vemap = new VEMap(this.name);\r
78         this.vemap.LoadMap();\r
79         this.vemap.HideDashboard();\r
80 \r
81         // catch pans and zooms from VE Map\r
82         this.vemap.AttachEvent("onendcontinuouspan", \r
83                                this.catchPanZoom.bindAsEventListener(this)); \r
84         this.vemap.AttachEvent("onendzoom", \r
85                                this.catchPanZoom.bindAsEventListener(this)); \r
86         \r
87 \r
88     },\r
89 \r
90     /**\r
91      * @param {event} e\r
92      */\r
93     catchPanZoom: function(e) { \r
94         var veCenter = this.vemap.GetCenter();\r
95         var veZoom = this.vemap.GetZoomLevel();\r
96         \r
97         var olCenter = new OpenLayers.LonLat(veCenter.Longitude,\r
98                                              veCenter.Latitude);\r
99                                              \r
100         this.map.setCenter(olCenter, veZoom - 1);\r
101         \r
102     },\r
103 \r
104 \r
105     /** @final @type String */\r
106     CLASS_NAME: "OpenLayers.Layer.VirtualEarth"\r
107 });